diff --git a/.azure-pipelines/docs.yml b/.azure-pipelines/docs.yml index f83f220ff14d..a66d7513ec1d 100644 --- a/.azure-pipelines/docs.yml +++ b/.azure-pipelines/docs.yml @@ -11,7 +11,7 @@ jobs: skipComponentGovernanceDetection: true timeoutInMinutes: 120 pool: - vmImage: 'vs2017-win2016' + vmImage: 'windows-2019' steps: - powershell: | @@ -79,7 +79,7 @@ jobs: skipComponentGovernanceDetection: true timeoutInMinutes: 120 pool: - vmImage: 'vs2017-win2016' + vmImage: 'windows-2019' steps: # We `install` separately from running `site:site site:stage` so that the `install` brings in the non-shipping-modules, @@ -96,6 +96,18 @@ jobs: publishJUnitResults: false goals: 'install' + - task: Maven@3 + displayName: 'Install azure-sdk-parent' + inputs: + mavenPomFile: parent/pom.xml + options: '$(DefaultOptions) -DskipTests -Dgpg.skip' + mavenOptions: '$(LoggingOptions)' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.11' + jdkArchitectureOption: 'x64' + publishJUnitResults: false + goals: 'install' + - task: Maven@3 displayName: 'Install Data Packages' inputs: diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 3352c4744a3b..f3a1a4beab5d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -10,6 +10,7 @@ # Service teams /sdk/appconfiguration/ @alzimmermsft @conniey @sima-zhu +/sdk/batch/ @xingwu1 @bgklein @matthchr /sdk/core/ @alzimmermsft @jianghaolu @srnagar @hemanttanwar /sdk/cosmos/ @moderakh @christopheranderson @kushagraThapar /sdk/eventhubs/ @conniey @srnagar @mssfang @@ -18,7 +19,7 @@ /sdk/servicebus/ @yvgopal @nemakam /sdk/tracing/ @samvaity @alzimmermsft -/sdk/storage/ @rickle-msft @jaschrep-msft @alzimmermsft @sima-zhu +/sdk/storage/ @rickle-msft @jaschrep-msft @gapra-msft @alzimmermsft @sima-zhu # Management Plane /**/resource-manager/ @yaohaizh @@ -28,5 +29,8 @@ ########### /eng/ @weshaggard @mitchdenny @danieljurek /eng/code-quality-reports/ @mssfang @JonathanGiles +/eng/jacoco-test-coverage/ @srnagar @JonathanGiles +/eng/spotbugs-aggregate-report/ @srnagar @JonathanGiles + /**/tests.yml @danieljurek /**/ci.yml @mitchdenny diff --git a/CHECKENFORCER b/CHECKENFORCER new file mode 100644 index 000000000000..02c2e26d53ec --- /dev/null +++ b/CHECKENFORCER @@ -0,0 +1,3 @@ +format: v0.1-alpha +enabled: true +minimumCheckRuns: 2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2ef9810e8c56..f3baa1c0ba4a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,49 @@ # How to contribute -If you encounter any bugs with the library please file an issue in the [Issues](https://github.com/Azure/azure-sdk-for-java/issues) section of the project. +Thank you for your interest in contributing to Azure SDK for Java. -If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.com/guidelines.html). \ No newline at end of file +## About Azure SDK for java project + +- For reporting bugs, requesting features or asking for support, please file an issue in the [issues](https://github.com/Azure/azure-sdk-for-java/issues) section of the project. + +- If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft Azure Projects Contribution Guidelines](http://azure.github.com/guidelines.html). + +- To make code changes, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the repo, make the change and propose it back by submitting a pull request. + +- Refer to the [wiki](https://github.com/Azure/azure-sdk-for-java/wiki/Building#testing-for-spotbugs-and-checkstyle-issues) to learn about how Azure SDK for java generates CheckStyle, SpotBugs, Jacoco, and JavaDoc reports. + +- There are two Maven projects in the repo. Refer to the [wiki](https://github.com/Azure/azure-sdk-for-java/wiki/Building#pomclientxml-vs-pomdataxml) to learn about project structure for each. + +## Developer Guide + +### Pre-requisites +- Install Java Development Kit 8 + - add `JAVA_HOME` to environment variables +- Install [Maven](http://maven.apache.org/download.cgi) + - add `MAVEN_HOME` to environment variables + + +>**Note:** If you are on `Windows`, enable paths longer than 260 characters by:

+1.- Run this as Administrator on a command prompt:
+`REG ADD HKLM\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1`
*(might need to type `yes` to override key if it already exists)*

+2.- Set up `git` by running:
`git config --system core.longpaths true` + +### Building and Testing +The easiest way to build is by running the following command from the root folder: +``` +mvn -f pom.client.xml -Dgpg.skip -DskipTests clean install +``` +- `-f pom.client.xml`: tells maven to target latest Azure SDK for Java project. +- `-Dgpg.skip`: disables [gpg](https://mran.microsoft.com/snapshot/2016-12-19/web/packages/gpg/vignettes/intro.html) signing. +- `-DskipTests:` Building without running unit tests would speed operation up, however, make sure all tests pass before creating a new PR. +- `clean:` will remove any previous generated output. +- `install:` compiles project and installs it in the local Maven cache. + +>**Note**: Refer to [wiki](https://github.com/Azure/azure-sdk-for-java/wiki/Building) for learning about how to build using Java 11 + +### Compiling one project only +``` +mvn -f sdk/{projectForlderDir}/pom.xml -Dgpg.skip clean install + +//example: mvn -f sdk/keyvault/azure-keyvault-keys/pom.xml clean install +``` diff --git a/README.md b/README.md index 3a89fec4d97e..8d01aaa910b2 100644 --- a/README.md +++ b/README.md @@ -14,27 +14,31 @@ To get started with a specific library, see the **README.md** file located in th For tutorials, samples, quick starts and other documentation, visit [Azure for Java Developers](https://docs.microsoft.com/java/azure/). ### Prerequisites -Java 8 or later is required to use the July 2019 client preview libraries, otherwise Java 7 or later is required. +Java 8 or later is required to use the September 2019 client preview libraries, otherwise Java 7 or later is required. ## Packages available Each service might have a number of libraries available from each of the following categories: -* [Client - July 2019 Preview](#Client-July-2019-Preview) +* [Client - September 2019 Preview](#Client-September-2019-Preview) * [Client - Stable](#Client-Stable) * [Management](#Management) -### Client: July 2019 Preview -New wave of packages that we are currently releasing in **preview**. These libraries follow the [Azure SDK Design Guidelines for Java](https://azuresdkspecs.z5.web.core.windows.net/JavaSpec.html) and share a number of core features such as HTTP retries, logging, transport protocols, authentication protocols, etc., so that once you learn how to use these features in one client library, you will know how to use them in other client libraries. You can learn about these shared features [here](core). +### Client: September 2019 Preview +New wave of packages that we are currently releasing in **preview**. These libraries follow the [Azure SDK Design Guidelines for Java](https://azure.github.io/azure-sdk/java/guidelines/) and share a number of core features such as HTTP retries, logging, transport protocols, authentication protocols, etc., so that once you learn how to use these features in one client library, you will know how to use them in other client libraries. You can learn about these shared features [here](core). These preview libraries can be easily identified by their folder, package, and namespaces names starting with `azure-`, e.g. `azure-keyvault`. -The libraries released in the July 2019 preview: +The libraries released in the September 2019 preview: - [App Configuration](sdk/appconfiguration/azure-data-appconfiguration/README.md) - [Event Hubs](sdk/eventhubs/azure-messaging-eventhubs/README.md) +- [Event Hubs Checkpoint Store](sdk/eventhubs/azure-messaging-eventhubs-checkpointstore-blob/README.md) - [Identity](sdk/identity/azure-identity/README.md) +- [Key Vault Certificates](sdk/keyvault/azure-keyvault-certificates/README.md) - [Key Vault Keys](sdk/keyvault/azure-keyvault-keys/README.md) -- [Key Vault Secrets](sdk/keyvault/client/azure-keyvault-secrets/README.md) +- [Key Vault Secrets](sdk/keyvault/azure-keyvault-secrets/README.md) - [Storage Blobs](sdk/storage/azure-storage-blob/README.md) +- [Storage Files](sdk/storage/azure-storage-file/README.md) +- [Storage Queues](sdk/storage/azure-storage-queue/README.md) >NOTE: If you need to ensure your code is ready for production, use one of the stable libraries. diff --git a/api-specs.json b/api-specs.json index bd963d00995b..0166ab5c4fdb 100644 --- a/api-specs.json +++ b/api-specs.json @@ -34,6 +34,10 @@ "source": "specification/authorization/resource-manager/readme.md", "args": "--multiapi --fluent" }, + "azure-kusto/resource-manager": { + "source": "specification/azure-kusto/resource-manager/readme.md", + "args": "--multiapi --fluent" + }, "azurestack/resource-manager": { "source": "specification/azurestack/resource-manager/readme.md", "args": "--multiapi --fluent" @@ -272,6 +276,10 @@ "source": "specification/storage/resource-manager/readme.md", "args": "--multiapi --fluent" }, + "storagecache/resource-manager": { + "source": "specification/storagecache/resource-manager/readme.md", + "args": "--multiapi --fluent" + }, "storageimportexport/resource-manager": { "source": "specification/storageimportexport/resource-manager/readme.md", "args": "--multiapi --fluent" diff --git a/containerservice/resource-manager/v2019_08_01/pom.xml b/containerservice/resource-manager/v2019_08_01/pom.xml new file mode 100644 index 000000000000..9fe51ff4ffd3 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/pom.xml @@ -0,0 +1,135 @@ + + + 4.0.0 + com.microsoft.azure.containerservice.v2019_08_01 + + com.microsoft.azure + azure-arm-parent + 1.1.0 + ../../../pom.management.xml + + azure-mgmt-containerservice + 1.0.0-beta + jar + Microsoft Azure SDK for ContainerService Management + This package contains Microsoft ContainerService Management SDK. + https://github.com/Azure/azure-sdk-for-java + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + UTF-8 + + + + + microsoft + Microsoft + + + + + com.microsoft.azure + azure-client-runtime + + + com.microsoft.azure + azure-arm-client-runtime + + + junit + junit + test + + + com.microsoft.azure + azure-client-authentication + test + + + com.microsoft.azure + azure-mgmt-resources + test + + + com.microsoft.azure + azure-arm-client-runtime + test-jar + test + + 1.6.5 + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + true + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + com.microsoft.azure.management.apigeneration.LangDefinitionProcessor + + + true + true + + true + true + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8 + + *.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.search + + + /** +
* Copyright (c) Microsoft Corporation. All rights reserved. +
* Licensed under the MIT License. See License.txt in the project root for +
* license information. +
*/ + ]]> +
+
+
+
+
+
diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPool.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPool.java new file mode 100644 index 000000000000..3f4d900add37 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPool.java @@ -0,0 +1,534 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.AgentPoolInner; +import com.microsoft.azure.arm.model.Indexable; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import java.util.List; + +/** + * Type representing AgentPool. + */ +public interface AgentPool extends HasInner, Indexable, Refreshable, Updatable, HasManager { + /** + * @return the agentPoolType value. + */ + AgentPoolType agentPoolType(); + + /** + * @return the availabilityZones value. + */ + List availabilityZones(); + + /** + * @return the count value. + */ + int count(); + + /** + * @return the enableAutoScaling value. + */ + Boolean enableAutoScaling(); + + /** + * @return the enableNodePublicIP value. + */ + Boolean enableNodePublicIP(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the maxCount value. + */ + Integer maxCount(); + + /** + * @return the maxPods value. + */ + Integer maxPods(); + + /** + * @return the minCount value. + */ + Integer minCount(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the nodeTaints value. + */ + List nodeTaints(); + + /** + * @return the orchestratorVersion value. + */ + String orchestratorVersion(); + + /** + * @return the osDiskSizeGB value. + */ + Integer osDiskSizeGB(); + + /** + * @return the osType value. + */ + OSType osType(); + + /** + * @return the provisioningState value. + */ + String provisioningState(); + + /** + * @return the scaleSetEvictionPolicy value. + */ + ScaleSetEvictionPolicy scaleSetEvictionPolicy(); + + /** + * @return the scaleSetPriority value. + */ + ScaleSetPriority scaleSetPriority(); + + /** + * @return the type value. + */ + String type(); + + /** + * @return the vmSize value. + */ + ContainerServiceVMSizeTypes vmSize(); + + /** + * @return the vnetSubnetID value. + */ + String vnetSubnetID(); + + /** + * The entirety of the AgentPool definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithManagedCluster, DefinitionStages.WithCount, DefinitionStages.WithVmSize, DefinitionStages.WithCreate { + } + + /** + * Grouping of AgentPool definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a AgentPool definition. + */ + interface Blank extends WithManagedCluster { + } + + /** + * The stage of the agentpool definition allowing to specify ManagedCluster. + */ + interface WithManagedCluster { + /** + * Specifies resourceGroupName, resourceName. + * @param resourceGroupName The name of the resource group + * @param resourceName The name of the managed cluster resource + * @return the next definition stage + */ + WithCount withExistingManagedCluster(String resourceGroupName, String resourceName); + } + + /** + * The stage of the agentpool definition allowing to specify Count. + */ + interface WithCount { + /** + * Specifies count. + * @param count Number of agents (VMs) to host docker containers. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1 + * @return the next definition stage + */ + WithVmSize withCount(int count); + } + + /** + * The stage of the agentpool definition allowing to specify VmSize. + */ + interface WithVmSize { + /** + * Specifies vmSize. + * @param vmSize Size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6' + * @return the next definition stage + */ + WithCreate withVmSize(ContainerServiceVMSizeTypes vmSize); + } + + /** + * The stage of the agentpool definition allowing to specify AgentPoolType. + */ + interface WithAgentPoolType { + /** + * Specifies agentPoolType. + * @param agentPoolType AgentPoolType represents types of an agent pool. Possible values include: 'VirtualMachineScaleSets', 'AvailabilitySet' + * @return the next definition stage + */ + WithCreate withAgentPoolType(AgentPoolType agentPoolType); + } + + /** + * The stage of the agentpool definition allowing to specify AvailabilityZones. + */ + interface WithAvailabilityZones { + /** + * Specifies availabilityZones. + * @param availabilityZones (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType + * @return the next definition stage + */ + WithCreate withAvailabilityZones(List availabilityZones); + } + + /** + * The stage of the agentpool definition allowing to specify EnableAutoScaling. + */ + interface WithEnableAutoScaling { + /** + * Specifies enableAutoScaling. + * @param enableAutoScaling Whether to enable auto-scaler + * @return the next definition stage + */ + WithCreate withEnableAutoScaling(Boolean enableAutoScaling); + } + + /** + * The stage of the agentpool definition allowing to specify EnableNodePublicIP. + */ + interface WithEnableNodePublicIP { + /** + * Specifies enableNodePublicIP. + * @param enableNodePublicIP Enable public IP for nodes + * @return the next definition stage + */ + WithCreate withEnableNodePublicIP(Boolean enableNodePublicIP); + } + + /** + * The stage of the agentpool definition allowing to specify MaxCount. + */ + interface WithMaxCount { + /** + * Specifies maxCount. + * @param maxCount Maximum number of nodes for auto-scaling + * @return the next definition stage + */ + WithCreate withMaxCount(Integer maxCount); + } + + /** + * The stage of the agentpool definition allowing to specify MaxPods. + */ + interface WithMaxPods { + /** + * Specifies maxPods. + * @param maxPods Maximum number of pods that can run on a node + * @return the next definition stage + */ + WithCreate withMaxPods(Integer maxPods); + } + + /** + * The stage of the agentpool definition allowing to specify MinCount. + */ + interface WithMinCount { + /** + * Specifies minCount. + * @param minCount Minimum number of nodes for auto-scaling + * @return the next definition stage + */ + WithCreate withMinCount(Integer minCount); + } + + /** + * The stage of the agentpool definition allowing to specify NodeTaints. + */ + interface WithNodeTaints { + /** + * Specifies nodeTaints. + * @param nodeTaints Taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule + * @return the next definition stage + */ + WithCreate withNodeTaints(List nodeTaints); + } + + /** + * The stage of the agentpool definition allowing to specify OrchestratorVersion. + */ + interface WithOrchestratorVersion { + /** + * Specifies orchestratorVersion. + * @param orchestratorVersion Version of orchestrator specified when creating the managed cluster + * @return the next definition stage + */ + WithCreate withOrchestratorVersion(String orchestratorVersion); + } + + /** + * The stage of the agentpool definition allowing to specify OsDiskSizeGB. + */ + interface WithOsDiskSizeGB { + /** + * Specifies osDiskSizeGB. + * @param osDiskSizeGB OS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified + * @return the next definition stage + */ + WithCreate withOsDiskSizeGB(Integer osDiskSizeGB); + } + + /** + * The stage of the agentpool definition allowing to specify OsType. + */ + interface WithOsType { + /** + * Specifies osType. + * @param osType OsType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows' + * @return the next definition stage + */ + WithCreate withOsType(OSType osType); + } + + /** + * The stage of the agentpool definition allowing to specify ScaleSetEvictionPolicy. + */ + interface WithScaleSetEvictionPolicy { + /** + * Specifies scaleSetEvictionPolicy. + * @param scaleSetEvictionPolicy ScaleSetEvictionPolicy to be used to specify eviction policy for low priority virtual machine scale set. Default to Delete. Possible values include: 'Delete', 'Deallocate' + * @return the next definition stage + */ + WithCreate withScaleSetEvictionPolicy(ScaleSetEvictionPolicy scaleSetEvictionPolicy); + } + + /** + * The stage of the agentpool definition allowing to specify ScaleSetPriority. + */ + interface WithScaleSetPriority { + /** + * Specifies scaleSetPriority. + * @param scaleSetPriority ScaleSetPriority to be used to specify virtual machine scale set priority. Default to regular. Possible values include: 'Low', 'Regular' + * @return the next definition stage + */ + WithCreate withScaleSetPriority(ScaleSetPriority scaleSetPriority); + } + + /** + * The stage of the agentpool definition allowing to specify VnetSubnetID. + */ + interface WithVnetSubnetID { + /** + * Specifies vnetSubnetID. + * @param vnetSubnetID VNet SubnetID specifies the VNet's subnet identifier + * @return the next definition stage + */ + WithCreate withVnetSubnetID(String vnetSubnetID); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable, DefinitionStages.WithAgentPoolType, DefinitionStages.WithAvailabilityZones, DefinitionStages.WithEnableAutoScaling, DefinitionStages.WithEnableNodePublicIP, DefinitionStages.WithMaxCount, DefinitionStages.WithMaxPods, DefinitionStages.WithMinCount, DefinitionStages.WithNodeTaints, DefinitionStages.WithOrchestratorVersion, DefinitionStages.WithOsDiskSizeGB, DefinitionStages.WithOsType, DefinitionStages.WithScaleSetEvictionPolicy, DefinitionStages.WithScaleSetPriority, DefinitionStages.WithVnetSubnetID { + } + } + /** + * The template for a AgentPool update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, UpdateStages.WithAgentPoolType, UpdateStages.WithAvailabilityZones, UpdateStages.WithEnableAutoScaling, UpdateStages.WithEnableNodePublicIP, UpdateStages.WithMaxCount, UpdateStages.WithMaxPods, UpdateStages.WithMinCount, UpdateStages.WithNodeTaints, UpdateStages.WithOrchestratorVersion, UpdateStages.WithOsDiskSizeGB, UpdateStages.WithOsType, UpdateStages.WithScaleSetEvictionPolicy, UpdateStages.WithScaleSetPriority, UpdateStages.WithVnetSubnetID { + } + + /** + * Grouping of AgentPool update stages. + */ + interface UpdateStages { + /** + * The stage of the agentpool update allowing to specify AgentPoolType. + */ + interface WithAgentPoolType { + /** + * Specifies agentPoolType. + * @param agentPoolType AgentPoolType represents types of an agent pool. Possible values include: 'VirtualMachineScaleSets', 'AvailabilitySet' + * @return the next update stage + */ + Update withAgentPoolType(AgentPoolType agentPoolType); + } + + /** + * The stage of the agentpool update allowing to specify AvailabilityZones. + */ + interface WithAvailabilityZones { + /** + * Specifies availabilityZones. + * @param availabilityZones (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType + * @return the next update stage + */ + Update withAvailabilityZones(List availabilityZones); + } + + /** + * The stage of the agentpool update allowing to specify EnableAutoScaling. + */ + interface WithEnableAutoScaling { + /** + * Specifies enableAutoScaling. + * @param enableAutoScaling Whether to enable auto-scaler + * @return the next update stage + */ + Update withEnableAutoScaling(Boolean enableAutoScaling); + } + + /** + * The stage of the agentpool update allowing to specify EnableNodePublicIP. + */ + interface WithEnableNodePublicIP { + /** + * Specifies enableNodePublicIP. + * @param enableNodePublicIP Enable public IP for nodes + * @return the next update stage + */ + Update withEnableNodePublicIP(Boolean enableNodePublicIP); + } + + /** + * The stage of the agentpool update allowing to specify MaxCount. + */ + interface WithMaxCount { + /** + * Specifies maxCount. + * @param maxCount Maximum number of nodes for auto-scaling + * @return the next update stage + */ + Update withMaxCount(Integer maxCount); + } + + /** + * The stage of the agentpool update allowing to specify MaxPods. + */ + interface WithMaxPods { + /** + * Specifies maxPods. + * @param maxPods Maximum number of pods that can run on a node + * @return the next update stage + */ + Update withMaxPods(Integer maxPods); + } + + /** + * The stage of the agentpool update allowing to specify MinCount. + */ + interface WithMinCount { + /** + * Specifies minCount. + * @param minCount Minimum number of nodes for auto-scaling + * @return the next update stage + */ + Update withMinCount(Integer minCount); + } + + /** + * The stage of the agentpool update allowing to specify NodeTaints. + */ + interface WithNodeTaints { + /** + * Specifies nodeTaints. + * @param nodeTaints Taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule + * @return the next update stage + */ + Update withNodeTaints(List nodeTaints); + } + + /** + * The stage of the agentpool update allowing to specify OrchestratorVersion. + */ + interface WithOrchestratorVersion { + /** + * Specifies orchestratorVersion. + * @param orchestratorVersion Version of orchestrator specified when creating the managed cluster + * @return the next update stage + */ + Update withOrchestratorVersion(String orchestratorVersion); + } + + /** + * The stage of the agentpool update allowing to specify OsDiskSizeGB. + */ + interface WithOsDiskSizeGB { + /** + * Specifies osDiskSizeGB. + * @param osDiskSizeGB OS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified + * @return the next update stage + */ + Update withOsDiskSizeGB(Integer osDiskSizeGB); + } + + /** + * The stage of the agentpool update allowing to specify OsType. + */ + interface WithOsType { + /** + * Specifies osType. + * @param osType OsType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows' + * @return the next update stage + */ + Update withOsType(OSType osType); + } + + /** + * The stage of the agentpool update allowing to specify ScaleSetEvictionPolicy. + */ + interface WithScaleSetEvictionPolicy { + /** + * Specifies scaleSetEvictionPolicy. + * @param scaleSetEvictionPolicy ScaleSetEvictionPolicy to be used to specify eviction policy for low priority virtual machine scale set. Default to Delete. Possible values include: 'Delete', 'Deallocate' + * @return the next update stage + */ + Update withScaleSetEvictionPolicy(ScaleSetEvictionPolicy scaleSetEvictionPolicy); + } + + /** + * The stage of the agentpool update allowing to specify ScaleSetPriority. + */ + interface WithScaleSetPriority { + /** + * Specifies scaleSetPriority. + * @param scaleSetPriority ScaleSetPriority to be used to specify virtual machine scale set priority. Default to regular. Possible values include: 'Low', 'Regular' + * @return the next update stage + */ + Update withScaleSetPriority(ScaleSetPriority scaleSetPriority); + } + + /** + * The stage of the agentpool update allowing to specify VnetSubnetID. + */ + interface WithVnetSubnetID { + /** + * Specifies vnetSubnetID. + * @param vnetSubnetID VNet SubnetID specifies the VNet's subnet identifier + * @return the next update stage + */ + Update withVnetSubnetID(String vnetSubnetID); + } + + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolAvailableVersions.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolAvailableVersions.java new file mode 100644 index 000000000000..d2023548caf6 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolAvailableVersions.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.AgentPoolAvailableVersionsInner; +import java.util.List; + +/** + * Type representing AgentPoolAvailableVersions. + */ +public interface AgentPoolAvailableVersions extends HasInner, HasManager { + /** + * @return the agentPoolVersions value. + */ + List agentPoolVersions(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the type value. + */ + String type(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem.java new file mode 100644 index 000000000000..8cebcf840f03 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem model. + */ +public class AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem { + /** + * Whether this version is the default agent pool version. + */ + @JsonProperty(value = "default") + private Boolean defaultProperty; + + /** + * Kubernetes version (major, minor, patch). + */ + @JsonProperty(value = "kubernetesVersion") + private String kubernetesVersion; + + /** + * Whether Kubernetes version is currently in preview. + */ + @JsonProperty(value = "isPreview") + private Boolean isPreview; + + /** + * Get whether this version is the default agent pool version. + * + * @return the defaultProperty value + */ + public Boolean defaultProperty() { + return this.defaultProperty; + } + + /** + * Set whether this version is the default agent pool version. + * + * @param defaultProperty the defaultProperty value to set + * @return the AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem object itself. + */ + public AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem withDefaultProperty(Boolean defaultProperty) { + this.defaultProperty = defaultProperty; + return this; + } + + /** + * Get kubernetes version (major, minor, patch). + * + * @return the kubernetesVersion value + */ + public String kubernetesVersion() { + return this.kubernetesVersion; + } + + /** + * Set kubernetes version (major, minor, patch). + * + * @param kubernetesVersion the kubernetesVersion value to set + * @return the AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem object itself. + */ + public AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem withKubernetesVersion(String kubernetesVersion) { + this.kubernetesVersion = kubernetesVersion; + return this; + } + + /** + * Get whether Kubernetes version is currently in preview. + * + * @return the isPreview value + */ + public Boolean isPreview() { + return this.isPreview; + } + + /** + * Set whether Kubernetes version is currently in preview. + * + * @param isPreview the isPreview value to set + * @return the AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem object itself. + */ + public AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem withIsPreview(Boolean isPreview) { + this.isPreview = isPreview; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolType.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolType.java new file mode 100644 index 000000000000..8ec122af9c1e --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for AgentPoolType. + */ +public final class AgentPoolType extends ExpandableStringEnum { + /** Static value VirtualMachineScaleSets for AgentPoolType. */ + public static final AgentPoolType VIRTUAL_MACHINE_SCALE_SETS = fromString("VirtualMachineScaleSets"); + + /** Static value AvailabilitySet for AgentPoolType. */ + public static final AgentPoolType AVAILABILITY_SET = fromString("AvailabilitySet"); + + /** + * Creates or finds a AgentPoolType from its string representation. + * @param name a name to look for + * @return the corresponding AgentPoolType + */ + @JsonCreator + public static AgentPoolType fromString(String name) { + return fromString(name, AgentPoolType.class); + } + + /** + * @return known AgentPoolType values + */ + public static Collection values() { + return values(AgentPoolType.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolUpgradeProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolUpgradeProfile.java new file mode 100644 index 000000000000..f72c825af7db --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolUpgradeProfile.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.AgentPoolUpgradeProfileInner; +import java.util.List; + +/** + * Type representing AgentPoolUpgradeProfile. + */ +public interface AgentPoolUpgradeProfile extends HasInner, HasManager { + /** + * @return the id value. + */ + String id(); + + /** + * @return the kubernetesVersion value. + */ + String kubernetesVersion(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the osType value. + */ + OSType osType(); + + /** + * @return the type value. + */ + String type(); + + /** + * @return the upgrades value. + */ + List upgrades(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolUpgradeProfilePropertiesUpgradesItem.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolUpgradeProfilePropertiesUpgradesItem.java new file mode 100644 index 000000000000..2b9824130eaf --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPoolUpgradeProfilePropertiesUpgradesItem.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The AgentPoolUpgradeProfilePropertiesUpgradesItem model. + */ +public class AgentPoolUpgradeProfilePropertiesUpgradesItem { + /** + * Kubernetes version (major, minor, patch). + */ + @JsonProperty(value = "kubernetesVersion") + private String kubernetesVersion; + + /** + * Whether Kubernetes version is currently in preview. + */ + @JsonProperty(value = "isPreview") + private Boolean isPreview; + + /** + * Get kubernetes version (major, minor, patch). + * + * @return the kubernetesVersion value + */ + public String kubernetesVersion() { + return this.kubernetesVersion; + } + + /** + * Set kubernetes version (major, minor, patch). + * + * @param kubernetesVersion the kubernetesVersion value to set + * @return the AgentPoolUpgradeProfilePropertiesUpgradesItem object itself. + */ + public AgentPoolUpgradeProfilePropertiesUpgradesItem withKubernetesVersion(String kubernetesVersion) { + this.kubernetesVersion = kubernetesVersion; + return this; + } + + /** + * Get whether Kubernetes version is currently in preview. + * + * @return the isPreview value + */ + public Boolean isPreview() { + return this.isPreview; + } + + /** + * Set whether Kubernetes version is currently in preview. + * + * @param isPreview the isPreview value to set + * @return the AgentPoolUpgradeProfilePropertiesUpgradesItem object itself. + */ + public AgentPoolUpgradeProfilePropertiesUpgradesItem withIsPreview(Boolean isPreview) { + this.isPreview = isPreview; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPools.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPools.java new file mode 100644 index 000000000000..7428e17148c3 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/AgentPools.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import rx.Completable; +import rx.Observable; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.AgentPoolsInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing AgentPools. + */ +public interface AgentPools extends SupportsCreating, HasInner { + /** + * Gets the agent pool. + * Gets the details of the agent pool by managed cluster and resource group. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAsync(String resourceGroupName, String resourceName, String agentPoolName); + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listAsync(final String resourceGroupName, final String resourceName); + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable deleteAsync(String resourceGroupName, String resourceName, String agentPoolName); + + /** + * Gets upgrade profile for an agent pool. + * Gets the details of the upgrade profile for an agent pool with a specified resource group and managed cluster name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getUpgradeProfileAsync(String resourceGroupName, String resourceName, String agentPoolName); + + /** + * Gets a list of supported versions for the specified agent pool. + * Gets a list of supported versions for the specified agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAvailableAgentPoolVersionsAsync(String resourceGroupName, String resourceName, String agentPoolName); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerService.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerService.java new file mode 100644 index 000000000000..2239d56b5e8e --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerService.java @@ -0,0 +1,270 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.Resource; +import com.microsoft.azure.arm.resources.models.GroupableResourceCore; +import com.microsoft.azure.arm.resources.models.HasResourceGroup; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceInner; + +/** + * Type representing ContainerService. + */ +public interface ContainerService extends HasInner, Resource, GroupableResourceCore, HasResourceGroup, Refreshable, Updatable, HasManager { + /** + * @return the agentPoolProfiles value. + */ + List agentPoolProfiles(); + + /** + * @return the customProfile value. + */ + ContainerServiceCustomProfile customProfile(); + + /** + * @return the diagnosticsProfile value. + */ + ContainerServiceDiagnosticsProfile diagnosticsProfile(); + + /** + * @return the linuxProfile value. + */ + ContainerServiceLinuxProfile linuxProfile(); + + /** + * @return the masterProfile value. + */ + ContainerServiceMasterProfile masterProfile(); + + /** + * @return the orchestratorProfile value. + */ + ContainerServiceOrchestratorProfile orchestratorProfile(); + + /** + * @return the provisioningState value. + */ + String provisioningState(); + + /** + * @return the servicePrincipalProfile value. + */ + ContainerServiceServicePrincipalProfile servicePrincipalProfile(); + + /** + * @return the windowsProfile value. + */ + ContainerServiceWindowsProfile windowsProfile(); + + /** + * The entirety of the ContainerService definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, DefinitionStages.WithLinuxProfile, DefinitionStages.WithMasterProfile, DefinitionStages.WithOrchestratorProfile, DefinitionStages.WithCreate { + } + + /** + * Grouping of ContainerService definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a ContainerService definition. + */ + interface Blank extends GroupableResourceCore.DefinitionWithRegion { + } + + /** + * The stage of the ContainerService definition allowing to specify the resource group. + */ + interface WithGroup extends GroupableResourceCore.DefinitionStages.WithGroup { + } + + /** + * The stage of the containerservice definition allowing to specify LinuxProfile. + */ + interface WithLinuxProfile { + /** + * Specifies linuxProfile. + * @param linuxProfile Profile for Linux VMs in the container service cluster + * @return the next definition stage +*/ + WithMasterProfile withLinuxProfile(ContainerServiceLinuxProfile linuxProfile); + } + + /** + * The stage of the containerservice definition allowing to specify MasterProfile. + */ + interface WithMasterProfile { + /** + * Specifies masterProfile. + * @param masterProfile Profile for the container service master + * @return the next definition stage +*/ + WithOrchestratorProfile withMasterProfile(ContainerServiceMasterProfile masterProfile); + } + + /** + * The stage of the containerservice definition allowing to specify OrchestratorProfile. + */ + interface WithOrchestratorProfile { + /** + * Specifies orchestratorProfile. + * @param orchestratorProfile Profile for the container service orchestrator + * @return the next definition stage +*/ + WithCreate withOrchestratorProfile(ContainerServiceOrchestratorProfile orchestratorProfile); + } + + /** + * The stage of the containerservice definition allowing to specify AgentPoolProfiles. + */ + interface WithAgentPoolProfiles { + /** + * Specifies agentPoolProfiles. + * @param agentPoolProfiles Properties of the agent pool + * @return the next definition stage + */ + WithCreate withAgentPoolProfiles(List agentPoolProfiles); + } + + /** + * The stage of the containerservice definition allowing to specify CustomProfile. + */ + interface WithCustomProfile { + /** + * Specifies customProfile. + * @param customProfile Properties to configure a custom container service cluster + * @return the next definition stage + */ + WithCreate withCustomProfile(ContainerServiceCustomProfile customProfile); + } + + /** + * The stage of the containerservice definition allowing to specify DiagnosticsProfile. + */ + interface WithDiagnosticsProfile { + /** + * Specifies diagnosticsProfile. + * @param diagnosticsProfile Profile for diagnostics in the container service cluster + * @return the next definition stage + */ + WithCreate withDiagnosticsProfile(ContainerServiceDiagnosticsProfile diagnosticsProfile); + } + + /** + * The stage of the containerservice definition allowing to specify ServicePrincipalProfile. + */ + interface WithServicePrincipalProfile { + /** + * Specifies servicePrincipalProfile. + * @param servicePrincipalProfile Information about a service principal identity for the cluster to use for manipulating Azure APIs. Exact one of secret or keyVaultSecretRef need to be specified + * @return the next definition stage + */ + WithCreate withServicePrincipalProfile(ContainerServiceServicePrincipalProfile servicePrincipalProfile); + } + + /** + * The stage of the containerservice definition allowing to specify WindowsProfile. + */ + interface WithWindowsProfile { + /** + * Specifies windowsProfile. + * @param windowsProfile Profile for Windows VMs in the container service cluster + * @return the next definition stage + */ + WithCreate withWindowsProfile(ContainerServiceWindowsProfile windowsProfile); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable, Resource.DefinitionWithTags, DefinitionStages.WithAgentPoolProfiles, DefinitionStages.WithCustomProfile, DefinitionStages.WithDiagnosticsProfile, DefinitionStages.WithServicePrincipalProfile, DefinitionStages.WithWindowsProfile { + } + } + /** + * The template for a ContainerService update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, Resource.UpdateWithTags, UpdateStages.WithAgentPoolProfiles, UpdateStages.WithCustomProfile, UpdateStages.WithDiagnosticsProfile, UpdateStages.WithServicePrincipalProfile, UpdateStages.WithWindowsProfile { + } + + /** + * Grouping of ContainerService update stages. + */ + interface UpdateStages { + /** + * The stage of the containerservice update allowing to specify AgentPoolProfiles. + */ + interface WithAgentPoolProfiles { + /** + * Specifies agentPoolProfiles. + * @param agentPoolProfiles Properties of the agent pool + * @return the next update stage + */ + Update withAgentPoolProfiles(List agentPoolProfiles); + } + + /** + * The stage of the containerservice update allowing to specify CustomProfile. + */ + interface WithCustomProfile { + /** + * Specifies customProfile. + * @param customProfile Properties to configure a custom container service cluster + * @return the next update stage + */ + Update withCustomProfile(ContainerServiceCustomProfile customProfile); + } + + /** + * The stage of the containerservice update allowing to specify DiagnosticsProfile. + */ + interface WithDiagnosticsProfile { + /** + * Specifies diagnosticsProfile. + * @param diagnosticsProfile Profile for diagnostics in the container service cluster + * @return the next update stage + */ + Update withDiagnosticsProfile(ContainerServiceDiagnosticsProfile diagnosticsProfile); + } + + /** + * The stage of the containerservice update allowing to specify ServicePrincipalProfile. + */ + interface WithServicePrincipalProfile { + /** + * Specifies servicePrincipalProfile. + * @param servicePrincipalProfile Information about a service principal identity for the cluster to use for manipulating Azure APIs. Exact one of secret or keyVaultSecretRef need to be specified + * @return the next update stage + */ + Update withServicePrincipalProfile(ContainerServiceServicePrincipalProfile servicePrincipalProfile); + } + + /** + * The stage of the containerservice update allowing to specify WindowsProfile. + */ + interface WithWindowsProfile { + /** + * Specifies windowsProfile. + * @param windowsProfile Profile for Windows VMs in the container service cluster + * @return the next update stage + */ + Update withWindowsProfile(ContainerServiceWindowsProfile windowsProfile); + } + + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceAgentPoolProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceAgentPoolProfile.java new file mode 100644 index 000000000000..458d166b2458 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceAgentPoolProfile.java @@ -0,0 +1,327 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for the container service agent pool. + */ +public class ContainerServiceAgentPoolProfile { + /** + * Unique name of the agent pool profile in the context of the subscription + * and resource group. + */ + @JsonProperty(value = "name", required = true) + private String name; + + /** + * Number of agents (VMs) to host docker containers. Allowed values must be + * in the range of 1 to 100 (inclusive). The default value is 1. + */ + @JsonProperty(value = "count") + private Integer count; + + /** + * Size of agent VMs. Possible values include: 'Standard_A1', + * 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', + * 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', + * 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', + * 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', + * 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', + * 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', + * 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', + * 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', + * 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', + * 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', + * 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', + * 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', + * 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', + * 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', + * 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', + * 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', + * 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', + * 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', + * 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', + * 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', + * 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', + * 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', + * 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', + * 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', + * 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', + * 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', + * 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', + * 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', + * 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', + * 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', + * 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', + * 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', + * 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', + * 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', + * 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', + * 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', + * 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', + * 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', + * 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', + * 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', + * 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', + * 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', + * 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', + * 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', + * 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', + * 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', + * 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', + * 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', + * 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', + * 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', + * 'Standard_NV6'. + */ + @JsonProperty(value = "vmSize", required = true) + private ContainerServiceVMSizeTypes vmSize; + + /** + * OS Disk Size in GB to be used to specify the disk size for every machine + * in this master/agent pool. If you specify 0, it will apply the default + * osDisk size according to the vmSize specified. + */ + @JsonProperty(value = "osDiskSizeGB") + private Integer osDiskSizeGB; + + /** + * DNS prefix to be used to create the FQDN for the agent pool. + */ + @JsonProperty(value = "dnsPrefix") + private String dnsPrefix; + + /** + * FQDN for the agent pool. + */ + @JsonProperty(value = "fqdn", access = JsonProperty.Access.WRITE_ONLY) + private String fqdn; + + /** + * Ports number array used to expose on this agent pool. The default opened + * ports are different based on your choice of orchestrator. + */ + @JsonProperty(value = "ports") + private List ports; + + /** + * Storage profile specifies what kind of storage used. Choose from + * StorageAccount and ManagedDisks. Leave it empty, we will choose for you + * based on the orchestrator choice. Possible values include: + * 'StorageAccount', 'ManagedDisks'. + */ + @JsonProperty(value = "storageProfile") + private ContainerServiceStorageProfileTypes storageProfile; + + /** + * VNet SubnetID specifies the VNet's subnet identifier. + */ + @JsonProperty(value = "vnetSubnetID") + private String vnetSubnetID; + + /** + * OsType to be used to specify os type. Choose from Linux and Windows. + * Default to Linux. Possible values include: 'Linux', 'Windows'. + */ + @JsonProperty(value = "osType") + private OSType osType; + + /** + * Get unique name of the agent pool profile in the context of the subscription and resource group. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set unique name of the agent pool profile in the context of the subscription and resource group. + * + * @param name the name value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withName(String name) { + this.name = name; + return this; + } + + /** + * Get number of agents (VMs) to host docker containers. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @return the count value + */ + public Integer count() { + return this.count; + } + + /** + * Set number of agents (VMs) to host docker containers. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @param count the count value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withCount(Integer count) { + this.count = count; + return this; + } + + /** + * Get size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @return the vmSize value + */ + public ContainerServiceVMSizeTypes vmSize() { + return this.vmSize; + } + + /** + * Set size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @param vmSize the vmSize value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withVmSize(ContainerServiceVMSizeTypes vmSize) { + this.vmSize = vmSize; + return this; + } + + /** + * Get oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @return the osDiskSizeGB value + */ + public Integer osDiskSizeGB() { + return this.osDiskSizeGB; + } + + /** + * Set oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @param osDiskSizeGB the osDiskSizeGB value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withOsDiskSizeGB(Integer osDiskSizeGB) { + this.osDiskSizeGB = osDiskSizeGB; + return this; + } + + /** + * Get dNS prefix to be used to create the FQDN for the agent pool. + * + * @return the dnsPrefix value + */ + public String dnsPrefix() { + return this.dnsPrefix; + } + + /** + * Set dNS prefix to be used to create the FQDN for the agent pool. + * + * @param dnsPrefix the dnsPrefix value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withDnsPrefix(String dnsPrefix) { + this.dnsPrefix = dnsPrefix; + return this; + } + + /** + * Get fQDN for the agent pool. + * + * @return the fqdn value + */ + public String fqdn() { + return this.fqdn; + } + + /** + * Get ports number array used to expose on this agent pool. The default opened ports are different based on your choice of orchestrator. + * + * @return the ports value + */ + public List ports() { + return this.ports; + } + + /** + * Set ports number array used to expose on this agent pool. The default opened ports are different based on your choice of orchestrator. + * + * @param ports the ports value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withPorts(List ports) { + this.ports = ports; + return this; + } + + /** + * Get storage profile specifies what kind of storage used. Choose from StorageAccount and ManagedDisks. Leave it empty, we will choose for you based on the orchestrator choice. Possible values include: 'StorageAccount', 'ManagedDisks'. + * + * @return the storageProfile value + */ + public ContainerServiceStorageProfileTypes storageProfile() { + return this.storageProfile; + } + + /** + * Set storage profile specifies what kind of storage used. Choose from StorageAccount and ManagedDisks. Leave it empty, we will choose for you based on the orchestrator choice. Possible values include: 'StorageAccount', 'ManagedDisks'. + * + * @param storageProfile the storageProfile value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withStorageProfile(ContainerServiceStorageProfileTypes storageProfile) { + this.storageProfile = storageProfile; + return this; + } + + /** + * Get vNet SubnetID specifies the VNet's subnet identifier. + * + * @return the vnetSubnetID value + */ + public String vnetSubnetID() { + return this.vnetSubnetID; + } + + /** + * Set vNet SubnetID specifies the VNet's subnet identifier. + * + * @param vnetSubnetID the vnetSubnetID value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withVnetSubnetID(String vnetSubnetID) { + this.vnetSubnetID = vnetSubnetID; + return this; + } + + /** + * Get osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @return the osType value + */ + public OSType osType() { + return this.osType; + } + + /** + * Set osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @param osType the osType value to set + * @return the ContainerServiceAgentPoolProfile object itself. + */ + public ContainerServiceAgentPoolProfile withOsType(OSType osType) { + this.osType = osType; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceCustomProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceCustomProfile.java new file mode 100644 index 000000000000..5166dd87aa88 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceCustomProfile.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Properties to configure a custom container service cluster. + */ +public class ContainerServiceCustomProfile { + /** + * The name of the custom orchestrator to use. + */ + @JsonProperty(value = "orchestrator", required = true) + private String orchestrator; + + /** + * Get the name of the custom orchestrator to use. + * + * @return the orchestrator value + */ + public String orchestrator() { + return this.orchestrator; + } + + /** + * Set the name of the custom orchestrator to use. + * + * @param orchestrator the orchestrator value to set + * @return the ContainerServiceCustomProfile object itself. + */ + public ContainerServiceCustomProfile withOrchestrator(String orchestrator) { + this.orchestrator = orchestrator; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceDiagnosticsProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceDiagnosticsProfile.java new file mode 100644 index 000000000000..bfe6b2dc0a74 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceDiagnosticsProfile.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for diagnostics on the container service cluster. + */ +public class ContainerServiceDiagnosticsProfile { + /** + * Profile for diagnostics on the container service VMs. + */ + @JsonProperty(value = "vmDiagnostics", required = true) + private ContainerServiceVMDiagnostics vmDiagnostics; + + /** + * Get profile for diagnostics on the container service VMs. + * + * @return the vmDiagnostics value + */ + public ContainerServiceVMDiagnostics vmDiagnostics() { + return this.vmDiagnostics; + } + + /** + * Set profile for diagnostics on the container service VMs. + * + * @param vmDiagnostics the vmDiagnostics value to set + * @return the ContainerServiceDiagnosticsProfile object itself. + */ + public ContainerServiceDiagnosticsProfile withVmDiagnostics(ContainerServiceVMDiagnostics vmDiagnostics) { + this.vmDiagnostics = vmDiagnostics; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceLinuxProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceLinuxProfile.java new file mode 100644 index 000000000000..4eb352b2e916 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceLinuxProfile.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for Linux VMs in the container service cluster. + */ +public class ContainerServiceLinuxProfile { + /** + * The administrator username to use for Linux VMs. + */ + @JsonProperty(value = "adminUsername", required = true) + private String adminUsername; + + /** + * SSH configuration for Linux-based VMs running on Azure. + */ + @JsonProperty(value = "ssh", required = true) + private ContainerServiceSshConfiguration ssh; + + /** + * Get the administrator username to use for Linux VMs. + * + * @return the adminUsername value + */ + public String adminUsername() { + return this.adminUsername; + } + + /** + * Set the administrator username to use for Linux VMs. + * + * @param adminUsername the adminUsername value to set + * @return the ContainerServiceLinuxProfile object itself. + */ + public ContainerServiceLinuxProfile withAdminUsername(String adminUsername) { + this.adminUsername = adminUsername; + return this; + } + + /** + * Get sSH configuration for Linux-based VMs running on Azure. + * + * @return the ssh value + */ + public ContainerServiceSshConfiguration ssh() { + return this.ssh; + } + + /** + * Set sSH configuration for Linux-based VMs running on Azure. + * + * @param ssh the ssh value to set + * @return the ContainerServiceLinuxProfile object itself. + */ + public ContainerServiceLinuxProfile withSsh(ContainerServiceSshConfiguration ssh) { + this.ssh = ssh; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceMasterProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceMasterProfile.java new file mode 100644 index 000000000000..e249782148dc --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceMasterProfile.java @@ -0,0 +1,271 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for the container service master. + */ +public class ContainerServiceMasterProfile { + /** + * Number of masters (VMs) in the container service cluster. Allowed values + * are 1, 3, and 5. The default value is 1. + */ + @JsonProperty(value = "count") + private Integer count; + + /** + * DNS prefix to be used to create the FQDN for the master pool. + */ + @JsonProperty(value = "dnsPrefix", required = true) + private String dnsPrefix; + + /** + * Size of agent VMs. Possible values include: 'Standard_A1', + * 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', + * 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', + * 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', + * 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', + * 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', + * 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', + * 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', + * 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', + * 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', + * 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', + * 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', + * 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', + * 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', + * 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', + * 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', + * 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', + * 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', + * 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', + * 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', + * 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', + * 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', + * 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', + * 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', + * 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', + * 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', + * 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', + * 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', + * 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', + * 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', + * 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', + * 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', + * 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', + * 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', + * 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', + * 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', + * 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', + * 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', + * 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', + * 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', + * 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', + * 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', + * 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', + * 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', + * 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', + * 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', + * 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', + * 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', + * 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', + * 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', + * 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', + * 'Standard_NV6'. + */ + @JsonProperty(value = "vmSize", required = true) + private ContainerServiceVMSizeTypes vmSize; + + /** + * OS Disk Size in GB to be used to specify the disk size for every machine + * in this master/agent pool. If you specify 0, it will apply the default + * osDisk size according to the vmSize specified. + */ + @JsonProperty(value = "osDiskSizeGB") + private Integer osDiskSizeGB; + + /** + * VNet SubnetID specifies the VNet's subnet identifier. + */ + @JsonProperty(value = "vnetSubnetID") + private String vnetSubnetID; + + /** + * FirstConsecutiveStaticIP used to specify the first static ip of masters. + */ + @JsonProperty(value = "firstConsecutiveStaticIP") + private String firstConsecutiveStaticIP; + + /** + * Storage profile specifies what kind of storage used. Choose from + * StorageAccount and ManagedDisks. Leave it empty, we will choose for you + * based on the orchestrator choice. Possible values include: + * 'StorageAccount', 'ManagedDisks'. + */ + @JsonProperty(value = "storageProfile") + private ContainerServiceStorageProfileTypes storageProfile; + + /** + * FQDN for the master pool. + */ + @JsonProperty(value = "fqdn", access = JsonProperty.Access.WRITE_ONLY) + private String fqdn; + + /** + * Get number of masters (VMs) in the container service cluster. Allowed values are 1, 3, and 5. The default value is 1. + * + * @return the count value + */ + public Integer count() { + return this.count; + } + + /** + * Set number of masters (VMs) in the container service cluster. Allowed values are 1, 3, and 5. The default value is 1. + * + * @param count the count value to set + * @return the ContainerServiceMasterProfile object itself. + */ + public ContainerServiceMasterProfile withCount(Integer count) { + this.count = count; + return this; + } + + /** + * Get dNS prefix to be used to create the FQDN for the master pool. + * + * @return the dnsPrefix value + */ + public String dnsPrefix() { + return this.dnsPrefix; + } + + /** + * Set dNS prefix to be used to create the FQDN for the master pool. + * + * @param dnsPrefix the dnsPrefix value to set + * @return the ContainerServiceMasterProfile object itself. + */ + public ContainerServiceMasterProfile withDnsPrefix(String dnsPrefix) { + this.dnsPrefix = dnsPrefix; + return this; + } + + /** + * Get size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @return the vmSize value + */ + public ContainerServiceVMSizeTypes vmSize() { + return this.vmSize; + } + + /** + * Set size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @param vmSize the vmSize value to set + * @return the ContainerServiceMasterProfile object itself. + */ + public ContainerServiceMasterProfile withVmSize(ContainerServiceVMSizeTypes vmSize) { + this.vmSize = vmSize; + return this; + } + + /** + * Get oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @return the osDiskSizeGB value + */ + public Integer osDiskSizeGB() { + return this.osDiskSizeGB; + } + + /** + * Set oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @param osDiskSizeGB the osDiskSizeGB value to set + * @return the ContainerServiceMasterProfile object itself. + */ + public ContainerServiceMasterProfile withOsDiskSizeGB(Integer osDiskSizeGB) { + this.osDiskSizeGB = osDiskSizeGB; + return this; + } + + /** + * Get vNet SubnetID specifies the VNet's subnet identifier. + * + * @return the vnetSubnetID value + */ + public String vnetSubnetID() { + return this.vnetSubnetID; + } + + /** + * Set vNet SubnetID specifies the VNet's subnet identifier. + * + * @param vnetSubnetID the vnetSubnetID value to set + * @return the ContainerServiceMasterProfile object itself. + */ + public ContainerServiceMasterProfile withVnetSubnetID(String vnetSubnetID) { + this.vnetSubnetID = vnetSubnetID; + return this; + } + + /** + * Get firstConsecutiveStaticIP used to specify the first static ip of masters. + * + * @return the firstConsecutiveStaticIP value + */ + public String firstConsecutiveStaticIP() { + return this.firstConsecutiveStaticIP; + } + + /** + * Set firstConsecutiveStaticIP used to specify the first static ip of masters. + * + * @param firstConsecutiveStaticIP the firstConsecutiveStaticIP value to set + * @return the ContainerServiceMasterProfile object itself. + */ + public ContainerServiceMasterProfile withFirstConsecutiveStaticIP(String firstConsecutiveStaticIP) { + this.firstConsecutiveStaticIP = firstConsecutiveStaticIP; + return this; + } + + /** + * Get storage profile specifies what kind of storage used. Choose from StorageAccount and ManagedDisks. Leave it empty, we will choose for you based on the orchestrator choice. Possible values include: 'StorageAccount', 'ManagedDisks'. + * + * @return the storageProfile value + */ + public ContainerServiceStorageProfileTypes storageProfile() { + return this.storageProfile; + } + + /** + * Set storage profile specifies what kind of storage used. Choose from StorageAccount and ManagedDisks. Leave it empty, we will choose for you based on the orchestrator choice. Possible values include: 'StorageAccount', 'ManagedDisks'. + * + * @param storageProfile the storageProfile value to set + * @return the ContainerServiceMasterProfile object itself. + */ + public ContainerServiceMasterProfile withStorageProfile(ContainerServiceStorageProfileTypes storageProfile) { + this.storageProfile = storageProfile; + return this; + } + + /** + * Get fQDN for the master pool. + * + * @return the fqdn value + */ + public String fqdn() { + return this.fqdn; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceNetworkProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceNetworkProfile.java new file mode 100644 index 000000000000..2ffd5e9a4821 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceNetworkProfile.java @@ -0,0 +1,233 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile of network configuration. + */ +public class ContainerServiceNetworkProfile { + /** + * Network plugin used for building Kubernetes network. Possible values + * include: 'azure', 'kubenet'. + */ + @JsonProperty(value = "networkPlugin") + private NetworkPlugin networkPlugin; + + /** + * Network policy used for building Kubernetes network. Possible values + * include: 'calico', 'azure'. + */ + @JsonProperty(value = "networkPolicy") + private NetworkPolicy networkPolicy; + + /** + * A CIDR notation IP range from which to assign pod IPs when kubenet is + * used. + */ + @JsonProperty(value = "podCidr") + private String podCidr; + + /** + * A CIDR notation IP range from which to assign service cluster IPs. It + * must not overlap with any Subnet IP ranges. + */ + @JsonProperty(value = "serviceCidr") + private String serviceCidr; + + /** + * An IP address assigned to the Kubernetes DNS service. It must be within + * the Kubernetes service address range specified in serviceCidr. + */ + @JsonProperty(value = "dnsServiceIP") + private String dnsServiceIP; + + /** + * A CIDR notation IP range assigned to the Docker bridge network. It must + * not overlap with any Subnet IP ranges or the Kubernetes service address + * range. + */ + @JsonProperty(value = "dockerBridgeCidr") + private String dockerBridgeCidr; + + /** + * The load balancer sku for the managed cluster. Possible values include: + * 'standard', 'basic'. + */ + @JsonProperty(value = "loadBalancerSku") + private LoadBalancerSku loadBalancerSku; + + /** + * Profile of the cluster load balancer. + */ + @JsonProperty(value = "loadBalancerProfile") + private ManagedClusterLoadBalancerProfile loadBalancerProfile; + + /** + * Get network plugin used for building Kubernetes network. Possible values include: 'azure', 'kubenet'. + * + * @return the networkPlugin value + */ + public NetworkPlugin networkPlugin() { + return this.networkPlugin; + } + + /** + * Set network plugin used for building Kubernetes network. Possible values include: 'azure', 'kubenet'. + * + * @param networkPlugin the networkPlugin value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withNetworkPlugin(NetworkPlugin networkPlugin) { + this.networkPlugin = networkPlugin; + return this; + } + + /** + * Get network policy used for building Kubernetes network. Possible values include: 'calico', 'azure'. + * + * @return the networkPolicy value + */ + public NetworkPolicy networkPolicy() { + return this.networkPolicy; + } + + /** + * Set network policy used for building Kubernetes network. Possible values include: 'calico', 'azure'. + * + * @param networkPolicy the networkPolicy value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withNetworkPolicy(NetworkPolicy networkPolicy) { + this.networkPolicy = networkPolicy; + return this; + } + + /** + * Get a CIDR notation IP range from which to assign pod IPs when kubenet is used. + * + * @return the podCidr value + */ + public String podCidr() { + return this.podCidr; + } + + /** + * Set a CIDR notation IP range from which to assign pod IPs when kubenet is used. + * + * @param podCidr the podCidr value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withPodCidr(String podCidr) { + this.podCidr = podCidr; + return this; + } + + /** + * Get a CIDR notation IP range from which to assign service cluster IPs. It must not overlap with any Subnet IP ranges. + * + * @return the serviceCidr value + */ + public String serviceCidr() { + return this.serviceCidr; + } + + /** + * Set a CIDR notation IP range from which to assign service cluster IPs. It must not overlap with any Subnet IP ranges. + * + * @param serviceCidr the serviceCidr value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withServiceCidr(String serviceCidr) { + this.serviceCidr = serviceCidr; + return this; + } + + /** + * Get an IP address assigned to the Kubernetes DNS service. It must be within the Kubernetes service address range specified in serviceCidr. + * + * @return the dnsServiceIP value + */ + public String dnsServiceIP() { + return this.dnsServiceIP; + } + + /** + * Set an IP address assigned to the Kubernetes DNS service. It must be within the Kubernetes service address range specified in serviceCidr. + * + * @param dnsServiceIP the dnsServiceIP value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withDnsServiceIP(String dnsServiceIP) { + this.dnsServiceIP = dnsServiceIP; + return this; + } + + /** + * Get a CIDR notation IP range assigned to the Docker bridge network. It must not overlap with any Subnet IP ranges or the Kubernetes service address range. + * + * @return the dockerBridgeCidr value + */ + public String dockerBridgeCidr() { + return this.dockerBridgeCidr; + } + + /** + * Set a CIDR notation IP range assigned to the Docker bridge network. It must not overlap with any Subnet IP ranges or the Kubernetes service address range. + * + * @param dockerBridgeCidr the dockerBridgeCidr value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withDockerBridgeCidr(String dockerBridgeCidr) { + this.dockerBridgeCidr = dockerBridgeCidr; + return this; + } + + /** + * Get the load balancer sku for the managed cluster. Possible values include: 'standard', 'basic'. + * + * @return the loadBalancerSku value + */ + public LoadBalancerSku loadBalancerSku() { + return this.loadBalancerSku; + } + + /** + * Set the load balancer sku for the managed cluster. Possible values include: 'standard', 'basic'. + * + * @param loadBalancerSku the loadBalancerSku value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withLoadBalancerSku(LoadBalancerSku loadBalancerSku) { + this.loadBalancerSku = loadBalancerSku; + return this; + } + + /** + * Get profile of the cluster load balancer. + * + * @return the loadBalancerProfile value + */ + public ManagedClusterLoadBalancerProfile loadBalancerProfile() { + return this.loadBalancerProfile; + } + + /** + * Set profile of the cluster load balancer. + * + * @param loadBalancerProfile the loadBalancerProfile value to set + * @return the ContainerServiceNetworkProfile object itself. + */ + public ContainerServiceNetworkProfile withLoadBalancerProfile(ManagedClusterLoadBalancerProfile loadBalancerProfile) { + this.loadBalancerProfile = loadBalancerProfile; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceOrchestratorProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceOrchestratorProfile.java new file mode 100644 index 000000000000..3f38b5d099b1 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceOrchestratorProfile.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for the container service orchestrator. + */ +public class ContainerServiceOrchestratorProfile { + /** + * The orchestrator to use to manage container service cluster resources. + * Valid values are Kubernetes, Swarm, DCOS, DockerCE and Custom. Possible + * values include: 'Kubernetes', 'Swarm', 'DCOS', 'DockerCE', 'Custom'. + */ + @JsonProperty(value = "orchestratorType", required = true) + private ContainerServiceOrchestratorTypes orchestratorType; + + /** + * The version of the orchestrator to use. You can specify the + * major.minor.patch part of the actual version.For example, you can + * specify version as "1.6.11". + */ + @JsonProperty(value = "orchestratorVersion") + private String orchestratorVersion; + + /** + * Get the orchestrator to use to manage container service cluster resources. Valid values are Kubernetes, Swarm, DCOS, DockerCE and Custom. Possible values include: 'Kubernetes', 'Swarm', 'DCOS', 'DockerCE', 'Custom'. + * + * @return the orchestratorType value + */ + public ContainerServiceOrchestratorTypes orchestratorType() { + return this.orchestratorType; + } + + /** + * Set the orchestrator to use to manage container service cluster resources. Valid values are Kubernetes, Swarm, DCOS, DockerCE and Custom. Possible values include: 'Kubernetes', 'Swarm', 'DCOS', 'DockerCE', 'Custom'. + * + * @param orchestratorType the orchestratorType value to set + * @return the ContainerServiceOrchestratorProfile object itself. + */ + public ContainerServiceOrchestratorProfile withOrchestratorType(ContainerServiceOrchestratorTypes orchestratorType) { + this.orchestratorType = orchestratorType; + return this; + } + + /** + * Get the version of the orchestrator to use. You can specify the major.minor.patch part of the actual version.For example, you can specify version as "1.6.11". + * + * @return the orchestratorVersion value + */ + public String orchestratorVersion() { + return this.orchestratorVersion; + } + + /** + * Set the version of the orchestrator to use. You can specify the major.minor.patch part of the actual version.For example, you can specify version as "1.6.11". + * + * @param orchestratorVersion the orchestratorVersion value to set + * @return the ContainerServiceOrchestratorProfile object itself. + */ + public ContainerServiceOrchestratorProfile withOrchestratorVersion(String orchestratorVersion) { + this.orchestratorVersion = orchestratorVersion; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceOrchestratorTypes.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceOrchestratorTypes.java new file mode 100644 index 000000000000..d81ff9c943f7 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceOrchestratorTypes.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ContainerServiceOrchestratorTypes. + */ +public final class ContainerServiceOrchestratorTypes extends ExpandableStringEnum { + /** Static value Kubernetes for ContainerServiceOrchestratorTypes. */ + public static final ContainerServiceOrchestratorTypes KUBERNETES = fromString("Kubernetes"); + + /** Static value Swarm for ContainerServiceOrchestratorTypes. */ + public static final ContainerServiceOrchestratorTypes SWARM = fromString("Swarm"); + + /** Static value DCOS for ContainerServiceOrchestratorTypes. */ + public static final ContainerServiceOrchestratorTypes DCOS = fromString("DCOS"); + + /** Static value DockerCE for ContainerServiceOrchestratorTypes. */ + public static final ContainerServiceOrchestratorTypes DOCKER_CE = fromString("DockerCE"); + + /** Static value Custom for ContainerServiceOrchestratorTypes. */ + public static final ContainerServiceOrchestratorTypes CUSTOM = fromString("Custom"); + + /** + * Creates or finds a ContainerServiceOrchestratorTypes from its string representation. + * @param name a name to look for + * @return the corresponding ContainerServiceOrchestratorTypes + */ + @JsonCreator + public static ContainerServiceOrchestratorTypes fromString(String name) { + return fromString(name, ContainerServiceOrchestratorTypes.class); + } + + /** + * @return known ContainerServiceOrchestratorTypes values + */ + public static Collection values() { + return values(ContainerServiceOrchestratorTypes.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceServicePrincipalProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceServicePrincipalProfile.java new file mode 100644 index 000000000000..5d3e69921416 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceServicePrincipalProfile.java @@ -0,0 +1,97 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Information about a service principal identity for the cluster to use for + * manipulating Azure APIs. Either secret or keyVaultSecretRef must be + * specified. + */ +public class ContainerServiceServicePrincipalProfile { + /** + * The ID for the service principal. + */ + @JsonProperty(value = "clientId", required = true) + private String clientId; + + /** + * The secret password associated with the service principal in plain text. + */ + @JsonProperty(value = "secret") + private String secret; + + /** + * Reference to a secret stored in Azure Key Vault. + */ + @JsonProperty(value = "keyVaultSecretRef") + private KeyVaultSecretRef keyVaultSecretRef; + + /** + * Get the ID for the service principal. + * + * @return the clientId value + */ + public String clientId() { + return this.clientId; + } + + /** + * Set the ID for the service principal. + * + * @param clientId the clientId value to set + * @return the ContainerServiceServicePrincipalProfile object itself. + */ + public ContainerServiceServicePrincipalProfile withClientId(String clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the secret password associated with the service principal in plain text. + * + * @return the secret value + */ + public String secret() { + return this.secret; + } + + /** + * Set the secret password associated with the service principal in plain text. + * + * @param secret the secret value to set + * @return the ContainerServiceServicePrincipalProfile object itself. + */ + public ContainerServiceServicePrincipalProfile withSecret(String secret) { + this.secret = secret; + return this; + } + + /** + * Get reference to a secret stored in Azure Key Vault. + * + * @return the keyVaultSecretRef value + */ + public KeyVaultSecretRef keyVaultSecretRef() { + return this.keyVaultSecretRef; + } + + /** + * Set reference to a secret stored in Azure Key Vault. + * + * @param keyVaultSecretRef the keyVaultSecretRef value to set + * @return the ContainerServiceServicePrincipalProfile object itself. + */ + public ContainerServiceServicePrincipalProfile withKeyVaultSecretRef(KeyVaultSecretRef keyVaultSecretRef) { + this.keyVaultSecretRef = keyVaultSecretRef; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceSshConfiguration.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceSshConfiguration.java new file mode 100644 index 000000000000..a0de8c467e6c --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceSshConfiguration.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SSH configuration for Linux-based VMs running on Azure. + */ +public class ContainerServiceSshConfiguration { + /** + * The list of SSH public keys used to authenticate with Linux-based VMs. + * Only expect one key specified. + */ + @JsonProperty(value = "publicKeys", required = true) + private List publicKeys; + + /** + * Get the list of SSH public keys used to authenticate with Linux-based VMs. Only expect one key specified. + * + * @return the publicKeys value + */ + public List publicKeys() { + return this.publicKeys; + } + + /** + * Set the list of SSH public keys used to authenticate with Linux-based VMs. Only expect one key specified. + * + * @param publicKeys the publicKeys value to set + * @return the ContainerServiceSshConfiguration object itself. + */ + public ContainerServiceSshConfiguration withPublicKeys(List publicKeys) { + this.publicKeys = publicKeys; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceSshPublicKey.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceSshPublicKey.java new file mode 100644 index 000000000000..acbaaa3b68c9 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceSshPublicKey.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Contains information about SSH certificate public key data. + */ +public class ContainerServiceSshPublicKey { + /** + * Certificate public key used to authenticate with VMs through SSH. The + * certificate must be in PEM format with or without headers. + */ + @JsonProperty(value = "keyData", required = true) + private String keyData; + + /** + * Get certificate public key used to authenticate with VMs through SSH. The certificate must be in PEM format with or without headers. + * + * @return the keyData value + */ + public String keyData() { + return this.keyData; + } + + /** + * Set certificate public key used to authenticate with VMs through SSH. The certificate must be in PEM format with or without headers. + * + * @param keyData the keyData value to set + * @return the ContainerServiceSshPublicKey object itself. + */ + public ContainerServiceSshPublicKey withKeyData(String keyData) { + this.keyData = keyData; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceStorageProfileTypes.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceStorageProfileTypes.java new file mode 100644 index 000000000000..53aa4619feb2 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceStorageProfileTypes.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ContainerServiceStorageProfileTypes. + */ +public final class ContainerServiceStorageProfileTypes extends ExpandableStringEnum { + /** Static value StorageAccount for ContainerServiceStorageProfileTypes. */ + public static final ContainerServiceStorageProfileTypes STORAGE_ACCOUNT = fromString("StorageAccount"); + + /** Static value ManagedDisks for ContainerServiceStorageProfileTypes. */ + public static final ContainerServiceStorageProfileTypes MANAGED_DISKS = fromString("ManagedDisks"); + + /** + * Creates or finds a ContainerServiceStorageProfileTypes from its string representation. + * @param name a name to look for + * @return the corresponding ContainerServiceStorageProfileTypes + */ + @JsonCreator + public static ContainerServiceStorageProfileTypes fromString(String name) { + return fromString(name, ContainerServiceStorageProfileTypes.class); + } + + /** + * @return known ContainerServiceStorageProfileTypes values + */ + public static Collection values() { + return values(ContainerServiceStorageProfileTypes.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceVMDiagnostics.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceVMDiagnostics.java new file mode 100644 index 000000000000..48e6a9514165 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceVMDiagnostics.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for diagnostics on the container service VMs. + */ +public class ContainerServiceVMDiagnostics { + /** + * Whether the VM diagnostic agent is provisioned on the VM. + */ + @JsonProperty(value = "enabled", required = true) + private boolean enabled; + + /** + * The URI of the storage account where diagnostics are stored. + */ + @JsonProperty(value = "storageUri", access = JsonProperty.Access.WRITE_ONLY) + private String storageUri; + + /** + * Get whether the VM diagnostic agent is provisioned on the VM. + * + * @return the enabled value + */ + public boolean enabled() { + return this.enabled; + } + + /** + * Set whether the VM diagnostic agent is provisioned on the VM. + * + * @param enabled the enabled value to set + * @return the ContainerServiceVMDiagnostics object itself. + */ + public ContainerServiceVMDiagnostics withEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + /** + * Get the URI of the storage account where diagnostics are stored. + * + * @return the storageUri value + */ + public String storageUri() { + return this.storageUri; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceVMSizeTypes.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceVMSizeTypes.java new file mode 100644 index 000000000000..33558b7248b8 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceVMSizeTypes.java @@ -0,0 +1,557 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ContainerServiceVMSizeTypes. + */ +public final class ContainerServiceVMSizeTypes extends ExpandableStringEnum { + /** Static value Standard_A1 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A1 = fromString("Standard_A1"); + + /** Static value Standard_A10 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A10 = fromString("Standard_A10"); + + /** Static value Standard_A11 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A11 = fromString("Standard_A11"); + + /** Static value Standard_A1_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A1_V2 = fromString("Standard_A1_v2"); + + /** Static value Standard_A2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A2 = fromString("Standard_A2"); + + /** Static value Standard_A2_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A2_V2 = fromString("Standard_A2_v2"); + + /** Static value Standard_A2m_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A2M_V2 = fromString("Standard_A2m_v2"); + + /** Static value Standard_A3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A3 = fromString("Standard_A3"); + + /** Static value Standard_A4 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A4 = fromString("Standard_A4"); + + /** Static value Standard_A4_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A4_V2 = fromString("Standard_A4_v2"); + + /** Static value Standard_A4m_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A4M_V2 = fromString("Standard_A4m_v2"); + + /** Static value Standard_A5 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A5 = fromString("Standard_A5"); + + /** Static value Standard_A6 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A6 = fromString("Standard_A6"); + + /** Static value Standard_A7 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A7 = fromString("Standard_A7"); + + /** Static value Standard_A8 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A8 = fromString("Standard_A8"); + + /** Static value Standard_A8_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A8_V2 = fromString("Standard_A8_v2"); + + /** Static value Standard_A8m_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A8M_V2 = fromString("Standard_A8m_v2"); + + /** Static value Standard_A9 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_A9 = fromString("Standard_A9"); + + /** Static value Standard_B2ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_B2MS = fromString("Standard_B2ms"); + + /** Static value Standard_B2s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_B2S = fromString("Standard_B2s"); + + /** Static value Standard_B4ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_B4MS = fromString("Standard_B4ms"); + + /** Static value Standard_B8ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_B8MS = fromString("Standard_B8ms"); + + /** Static value Standard_D1 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D1 = fromString("Standard_D1"); + + /** Static value Standard_D11 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D11 = fromString("Standard_D11"); + + /** Static value Standard_D11_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D11_V2 = fromString("Standard_D11_v2"); + + /** Static value Standard_D11_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D11_V2_PROMO = fromString("Standard_D11_v2_Promo"); + + /** Static value Standard_D12 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D12 = fromString("Standard_D12"); + + /** Static value Standard_D12_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D12_V2 = fromString("Standard_D12_v2"); + + /** Static value Standard_D12_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D12_V2_PROMO = fromString("Standard_D12_v2_Promo"); + + /** Static value Standard_D13 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D13 = fromString("Standard_D13"); + + /** Static value Standard_D13_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D13_V2 = fromString("Standard_D13_v2"); + + /** Static value Standard_D13_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D13_V2_PROMO = fromString("Standard_D13_v2_Promo"); + + /** Static value Standard_D14 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D14 = fromString("Standard_D14"); + + /** Static value Standard_D14_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D14_V2 = fromString("Standard_D14_v2"); + + /** Static value Standard_D14_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D14_V2_PROMO = fromString("Standard_D14_v2_Promo"); + + /** Static value Standard_D15_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D15_V2 = fromString("Standard_D15_v2"); + + /** Static value Standard_D16_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D16_V3 = fromString("Standard_D16_v3"); + + /** Static value Standard_D16s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D16S_V3 = fromString("Standard_D16s_v3"); + + /** Static value Standard_D1_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D1_V2 = fromString("Standard_D1_v2"); + + /** Static value Standard_D2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D2 = fromString("Standard_D2"); + + /** Static value Standard_D2_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D2_V2 = fromString("Standard_D2_v2"); + + /** Static value Standard_D2_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D2_V2_PROMO = fromString("Standard_D2_v2_Promo"); + + /** Static value Standard_D2_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D2_V3 = fromString("Standard_D2_v3"); + + /** Static value Standard_D2s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D2S_V3 = fromString("Standard_D2s_v3"); + + /** Static value Standard_D3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D3 = fromString("Standard_D3"); + + /** Static value Standard_D32_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D32_V3 = fromString("Standard_D32_v3"); + + /** Static value Standard_D32s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D32S_V3 = fromString("Standard_D32s_v3"); + + /** Static value Standard_D3_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D3_V2 = fromString("Standard_D3_v2"); + + /** Static value Standard_D3_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D3_V2_PROMO = fromString("Standard_D3_v2_Promo"); + + /** Static value Standard_D4 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D4 = fromString("Standard_D4"); + + /** Static value Standard_D4_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D4_V2 = fromString("Standard_D4_v2"); + + /** Static value Standard_D4_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D4_V2_PROMO = fromString("Standard_D4_v2_Promo"); + + /** Static value Standard_D4_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D4_V3 = fromString("Standard_D4_v3"); + + /** Static value Standard_D4s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D4S_V3 = fromString("Standard_D4s_v3"); + + /** Static value Standard_D5_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D5_V2 = fromString("Standard_D5_v2"); + + /** Static value Standard_D5_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D5_V2_PROMO = fromString("Standard_D5_v2_Promo"); + + /** Static value Standard_D64_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D64_V3 = fromString("Standard_D64_v3"); + + /** Static value Standard_D64s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D64S_V3 = fromString("Standard_D64s_v3"); + + /** Static value Standard_D8_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D8_V3 = fromString("Standard_D8_v3"); + + /** Static value Standard_D8s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_D8S_V3 = fromString("Standard_D8s_v3"); + + /** Static value Standard_DS1 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS1 = fromString("Standard_DS1"); + + /** Static value Standard_DS11 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS11 = fromString("Standard_DS11"); + + /** Static value Standard_DS11_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS11_V2 = fromString("Standard_DS11_v2"); + + /** Static value Standard_DS11_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS11_V2_PROMO = fromString("Standard_DS11_v2_Promo"); + + /** Static value Standard_DS12 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS12 = fromString("Standard_DS12"); + + /** Static value Standard_DS12_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS12_V2 = fromString("Standard_DS12_v2"); + + /** Static value Standard_DS12_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS12_V2_PROMO = fromString("Standard_DS12_v2_Promo"); + + /** Static value Standard_DS13 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS13 = fromString("Standard_DS13"); + + /** Static value Standard_DS13-2_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS13_2_V2 = fromString("Standard_DS13-2_v2"); + + /** Static value Standard_DS13-4_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS13_4_V2 = fromString("Standard_DS13-4_v2"); + + /** Static value Standard_DS13_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS13_V2 = fromString("Standard_DS13_v2"); + + /** Static value Standard_DS13_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS13_V2_PROMO = fromString("Standard_DS13_v2_Promo"); + + /** Static value Standard_DS14 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS14 = fromString("Standard_DS14"); + + /** Static value Standard_DS14-4_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS14_4_V2 = fromString("Standard_DS14-4_v2"); + + /** Static value Standard_DS14-8_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS14_8_V2 = fromString("Standard_DS14-8_v2"); + + /** Static value Standard_DS14_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS14_V2 = fromString("Standard_DS14_v2"); + + /** Static value Standard_DS14_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS14_V2_PROMO = fromString("Standard_DS14_v2_Promo"); + + /** Static value Standard_DS15_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS15_V2 = fromString("Standard_DS15_v2"); + + /** Static value Standard_DS1_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS1_V2 = fromString("Standard_DS1_v2"); + + /** Static value Standard_DS2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS2 = fromString("Standard_DS2"); + + /** Static value Standard_DS2_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS2_V2 = fromString("Standard_DS2_v2"); + + /** Static value Standard_DS2_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS2_V2_PROMO = fromString("Standard_DS2_v2_Promo"); + + /** Static value Standard_DS3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS3 = fromString("Standard_DS3"); + + /** Static value Standard_DS3_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS3_V2 = fromString("Standard_DS3_v2"); + + /** Static value Standard_DS3_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS3_V2_PROMO = fromString("Standard_DS3_v2_Promo"); + + /** Static value Standard_DS4 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS4 = fromString("Standard_DS4"); + + /** Static value Standard_DS4_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS4_V2 = fromString("Standard_DS4_v2"); + + /** Static value Standard_DS4_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS4_V2_PROMO = fromString("Standard_DS4_v2_Promo"); + + /** Static value Standard_DS5_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS5_V2 = fromString("Standard_DS5_v2"); + + /** Static value Standard_DS5_v2_Promo for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_DS5_V2_PROMO = fromString("Standard_DS5_v2_Promo"); + + /** Static value Standard_E16_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E16_V3 = fromString("Standard_E16_v3"); + + /** Static value Standard_E16s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E16S_V3 = fromString("Standard_E16s_v3"); + + /** Static value Standard_E2_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E2_V3 = fromString("Standard_E2_v3"); + + /** Static value Standard_E2s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E2S_V3 = fromString("Standard_E2s_v3"); + + /** Static value Standard_E32-16s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E32_16S_V3 = fromString("Standard_E32-16s_v3"); + + /** Static value Standard_E32-8s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E32_8S_V3 = fromString("Standard_E32-8s_v3"); + + /** Static value Standard_E32_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E32_V3 = fromString("Standard_E32_v3"); + + /** Static value Standard_E32s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E32S_V3 = fromString("Standard_E32s_v3"); + + /** Static value Standard_E4_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E4_V3 = fromString("Standard_E4_v3"); + + /** Static value Standard_E4s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E4S_V3 = fromString("Standard_E4s_v3"); + + /** Static value Standard_E64-16s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E64_16S_V3 = fromString("Standard_E64-16s_v3"); + + /** Static value Standard_E64-32s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E64_32S_V3 = fromString("Standard_E64-32s_v3"); + + /** Static value Standard_E64_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E64_V3 = fromString("Standard_E64_v3"); + + /** Static value Standard_E64s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E64S_V3 = fromString("Standard_E64s_v3"); + + /** Static value Standard_E8_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E8_V3 = fromString("Standard_E8_v3"); + + /** Static value Standard_E8s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_E8S_V3 = fromString("Standard_E8s_v3"); + + /** Static value Standard_F1 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F1 = fromString("Standard_F1"); + + /** Static value Standard_F16 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F16 = fromString("Standard_F16"); + + /** Static value Standard_F16s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F16S = fromString("Standard_F16s"); + + /** Static value Standard_F16s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F16S_V2 = fromString("Standard_F16s_v2"); + + /** Static value Standard_F1s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F1S = fromString("Standard_F1s"); + + /** Static value Standard_F2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F2 = fromString("Standard_F2"); + + /** Static value Standard_F2s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F2S = fromString("Standard_F2s"); + + /** Static value Standard_F2s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F2S_V2 = fromString("Standard_F2s_v2"); + + /** Static value Standard_F32s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F32S_V2 = fromString("Standard_F32s_v2"); + + /** Static value Standard_F4 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F4 = fromString("Standard_F4"); + + /** Static value Standard_F4s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F4S = fromString("Standard_F4s"); + + /** Static value Standard_F4s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F4S_V2 = fromString("Standard_F4s_v2"); + + /** Static value Standard_F64s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F64S_V2 = fromString("Standard_F64s_v2"); + + /** Static value Standard_F72s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F72S_V2 = fromString("Standard_F72s_v2"); + + /** Static value Standard_F8 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F8 = fromString("Standard_F8"); + + /** Static value Standard_F8s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F8S = fromString("Standard_F8s"); + + /** Static value Standard_F8s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_F8S_V2 = fromString("Standard_F8s_v2"); + + /** Static value Standard_G1 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_G1 = fromString("Standard_G1"); + + /** Static value Standard_G2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_G2 = fromString("Standard_G2"); + + /** Static value Standard_G3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_G3 = fromString("Standard_G3"); + + /** Static value Standard_G4 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_G4 = fromString("Standard_G4"); + + /** Static value Standard_G5 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_G5 = fromString("Standard_G5"); + + /** Static value Standard_GS1 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS1 = fromString("Standard_GS1"); + + /** Static value Standard_GS2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS2 = fromString("Standard_GS2"); + + /** Static value Standard_GS3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS3 = fromString("Standard_GS3"); + + /** Static value Standard_GS4 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS4 = fromString("Standard_GS4"); + + /** Static value Standard_GS4-4 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS4_4 = fromString("Standard_GS4-4"); + + /** Static value Standard_GS4-8 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS4_8 = fromString("Standard_GS4-8"); + + /** Static value Standard_GS5 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS5 = fromString("Standard_GS5"); + + /** Static value Standard_GS5-16 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS5_16 = fromString("Standard_GS5-16"); + + /** Static value Standard_GS5-8 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_GS5_8 = fromString("Standard_GS5-8"); + + /** Static value Standard_H16 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_H16 = fromString("Standard_H16"); + + /** Static value Standard_H16m for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_H16M = fromString("Standard_H16m"); + + /** Static value Standard_H16mr for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_H16MR = fromString("Standard_H16mr"); + + /** Static value Standard_H16r for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_H16R = fromString("Standard_H16r"); + + /** Static value Standard_H8 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_H8 = fromString("Standard_H8"); + + /** Static value Standard_H8m for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_H8M = fromString("Standard_H8m"); + + /** Static value Standard_L16s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_L16S = fromString("Standard_L16s"); + + /** Static value Standard_L32s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_L32S = fromString("Standard_L32s"); + + /** Static value Standard_L4s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_L4S = fromString("Standard_L4s"); + + /** Static value Standard_L8s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_L8S = fromString("Standard_L8s"); + + /** Static value Standard_M128-32ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M128_32MS = fromString("Standard_M128-32ms"); + + /** Static value Standard_M128-64ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M128_64MS = fromString("Standard_M128-64ms"); + + /** Static value Standard_M128ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M128MS = fromString("Standard_M128ms"); + + /** Static value Standard_M128s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M128S = fromString("Standard_M128s"); + + /** Static value Standard_M64-16ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M64_16MS = fromString("Standard_M64-16ms"); + + /** Static value Standard_M64-32ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M64_32MS = fromString("Standard_M64-32ms"); + + /** Static value Standard_M64ms for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M64MS = fromString("Standard_M64ms"); + + /** Static value Standard_M64s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_M64S = fromString("Standard_M64s"); + + /** Static value Standard_NC12 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC12 = fromString("Standard_NC12"); + + /** Static value Standard_NC12s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC12S_V2 = fromString("Standard_NC12s_v2"); + + /** Static value Standard_NC12s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC12S_V3 = fromString("Standard_NC12s_v3"); + + /** Static value Standard_NC24 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC24 = fromString("Standard_NC24"); + + /** Static value Standard_NC24r for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC24R = fromString("Standard_NC24r"); + + /** Static value Standard_NC24rs_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC24RS_V2 = fromString("Standard_NC24rs_v2"); + + /** Static value Standard_NC24rs_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC24RS_V3 = fromString("Standard_NC24rs_v3"); + + /** Static value Standard_NC24s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC24S_V2 = fromString("Standard_NC24s_v2"); + + /** Static value Standard_NC24s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC24S_V3 = fromString("Standard_NC24s_v3"); + + /** Static value Standard_NC6 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC6 = fromString("Standard_NC6"); + + /** Static value Standard_NC6s_v2 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC6S_V2 = fromString("Standard_NC6s_v2"); + + /** Static value Standard_NC6s_v3 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NC6S_V3 = fromString("Standard_NC6s_v3"); + + /** Static value Standard_ND12s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_ND12S = fromString("Standard_ND12s"); + + /** Static value Standard_ND24rs for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_ND24RS = fromString("Standard_ND24rs"); + + /** Static value Standard_ND24s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_ND24S = fromString("Standard_ND24s"); + + /** Static value Standard_ND6s for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_ND6S = fromString("Standard_ND6s"); + + /** Static value Standard_NV12 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NV12 = fromString("Standard_NV12"); + + /** Static value Standard_NV24 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NV24 = fromString("Standard_NV24"); + + /** Static value Standard_NV6 for ContainerServiceVMSizeTypes. */ + public static final ContainerServiceVMSizeTypes STANDARD_NV6 = fromString("Standard_NV6"); + + /** + * Creates or finds a ContainerServiceVMSizeTypes from its string representation. + * @param name a name to look for + * @return the corresponding ContainerServiceVMSizeTypes + */ + @JsonCreator + public static ContainerServiceVMSizeTypes fromString(String name) { + return fromString(name, ContainerServiceVMSizeTypes.class); + } + + /** + * @return known ContainerServiceVMSizeTypes values + */ + public static Collection values() { + return values(ContainerServiceVMSizeTypes.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceWindowsProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceWindowsProfile.java new file mode 100644 index 000000000000..6f596676c67d --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServiceWindowsProfile.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for Windows VMs in the container service cluster. + */ +public class ContainerServiceWindowsProfile { + /** + * The administrator username to use for Windows VMs. + */ + @JsonProperty(value = "adminUsername", required = true) + private String adminUsername; + + /** + * The administrator password to use for Windows VMs. + */ + @JsonProperty(value = "adminPassword", required = true) + private String adminPassword; + + /** + * Get the administrator username to use for Windows VMs. + * + * @return the adminUsername value + */ + public String adminUsername() { + return this.adminUsername; + } + + /** + * Set the administrator username to use for Windows VMs. + * + * @param adminUsername the adminUsername value to set + * @return the ContainerServiceWindowsProfile object itself. + */ + public ContainerServiceWindowsProfile withAdminUsername(String adminUsername) { + this.adminUsername = adminUsername; + return this; + } + + /** + * Get the administrator password to use for Windows VMs. + * + * @return the adminPassword value + */ + public String adminPassword() { + return this.adminPassword; + } + + /** + * Set the administrator password to use for Windows VMs. + * + * @param adminPassword the adminPassword value to set + * @return the ContainerServiceWindowsProfile object itself. + */ + public ContainerServiceWindowsProfile withAdminPassword(String adminPassword) { + this.adminPassword = adminPassword; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServices.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServices.java new file mode 100644 index 000000000000..c987fec856e3 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ContainerServices.java @@ -0,0 +1,35 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import com.microsoft.azure.arm.resources.collection.SupportsDeletingByResourceGroup; +import com.microsoft.azure.arm.resources.collection.SupportsBatchDeletion; +import com.microsoft.azure.arm.resources.collection.SupportsGettingByResourceGroup; +import rx.Observable; +import com.microsoft.azure.arm.resources.collection.SupportsListingByResourceGroup; +import com.microsoft.azure.arm.collection.SupportsListing; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServicesInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing ContainerServices. + */ +public interface ContainerServices extends SupportsCreating, SupportsDeletingByResourceGroup, SupportsBatchDeletion, SupportsGettingByResourceGroup, SupportsListingByResourceGroup, SupportsListing, HasInner { + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listOrchestratorsAsync(String location); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/CredentialResult.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/CredentialResult.java new file mode 100644 index 000000000000..ee020612cd74 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/CredentialResult.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The credential result response. + */ +public class CredentialResult { + /** + * The name of the credential. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * Base64-encoded Kubernetes configuration file. + */ + @JsonProperty(value = "value", access = JsonProperty.Access.WRITE_ONLY) + private byte[] value; + + /** + * Get the name of the credential. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get base64-encoded Kubernetes configuration file. + * + * @return the value value + */ + public byte[] value() { + return this.value; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/CredentialResults.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/CredentialResults.java new file mode 100644 index 000000000000..3e82b6edb7b7 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/CredentialResults.java @@ -0,0 +1,26 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.CredentialResultsInner; +import java.util.List; + +/** + * Type representing CredentialResults. + */ +public interface CredentialResults extends HasInner, HasManager { + /** + * @return the kubeconfigs value. + */ + List kubeconfigs(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/KeyVaultSecretRef.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/KeyVaultSecretRef.java new file mode 100644 index 000000000000..3ed5a2acf8de --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/KeyVaultSecretRef.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Reference to a secret stored in Azure Key Vault. + */ +public class KeyVaultSecretRef { + /** + * Key vault identifier. + */ + @JsonProperty(value = "vaultID", required = true) + private String vaultID; + + /** + * The secret name. + */ + @JsonProperty(value = "secretName", required = true) + private String secretName; + + /** + * The secret version. + */ + @JsonProperty(value = "version") + private String version; + + /** + * Get key vault identifier. + * + * @return the vaultID value + */ + public String vaultID() { + return this.vaultID; + } + + /** + * Set key vault identifier. + * + * @param vaultID the vaultID value to set + * @return the KeyVaultSecretRef object itself. + */ + public KeyVaultSecretRef withVaultID(String vaultID) { + this.vaultID = vaultID; + return this; + } + + /** + * Get the secret name. + * + * @return the secretName value + */ + public String secretName() { + return this.secretName; + } + + /** + * Set the secret name. + * + * @param secretName the secretName value to set + * @return the KeyVaultSecretRef object itself. + */ + public KeyVaultSecretRef withSecretName(String secretName) { + this.secretName = secretName; + return this; + } + + /** + * Get the secret version. + * + * @return the version value + */ + public String version() { + return this.version; + } + + /** + * Set the secret version. + * + * @param version the version value to set + * @return the KeyVaultSecretRef object itself. + */ + public KeyVaultSecretRef withVersion(String version) { + this.version = version; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/LoadBalancerSku.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/LoadBalancerSku.java new file mode 100644 index 000000000000..a8ce0d012e30 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/LoadBalancerSku.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for LoadBalancerSku. + */ +public final class LoadBalancerSku extends ExpandableStringEnum { + /** Static value standard for LoadBalancerSku. */ + public static final LoadBalancerSku STANDARD = fromString("standard"); + + /** Static value basic for LoadBalancerSku. */ + public static final LoadBalancerSku BASIC = fromString("basic"); + + /** + * Creates or finds a LoadBalancerSku from its string representation. + * @param name a name to look for + * @return the corresponding LoadBalancerSku + */ + @JsonCreator + public static LoadBalancerSku fromString(String name) { + return fromString(name, LoadBalancerSku.class); + } + + /** + * @return known LoadBalancerSku values + */ + public static Collection values() { + return values(LoadBalancerSku.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedCluster.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedCluster.java new file mode 100644 index 000000000000..4e002464971f --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedCluster.java @@ -0,0 +1,491 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.Resource; +import com.microsoft.azure.arm.resources.models.GroupableResourceCore; +import com.microsoft.azure.arm.resources.models.HasResourceGroup; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import java.util.List; +import java.util.Map; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ManagedClusterInner; + +/** + * Type representing ManagedCluster. + */ +public interface ManagedCluster extends HasInner, Resource, GroupableResourceCore, HasResourceGroup, Refreshable, Updatable, HasManager { + /** + * @return the aadProfile value. + */ + ManagedClusterAADProfile aadProfile(); + + /** + * @return the addonProfiles value. + */ + Map addonProfiles(); + + /** + * @return the agentPoolProfiles value. + */ + List agentPoolProfiles(); + + /** + * @return the apiServerAccessProfile value. + */ + ManagedClusterAPIServerAccessProfile apiServerAccessProfile(); + + /** + * @return the dnsPrefix value. + */ + String dnsPrefix(); + + /** + * @return the enablePodSecurityPolicy value. + */ + Boolean enablePodSecurityPolicy(); + + /** + * @return the enableRBAC value. + */ + Boolean enableRBAC(); + + /** + * @return the fqdn value. + */ + String fqdn(); + + /** + * @return the identity value. + */ + ManagedClusterIdentity identity(); + + /** + * @return the kubernetesVersion value. + */ + String kubernetesVersion(); + + /** + * @return the linuxProfile value. + */ + ContainerServiceLinuxProfile linuxProfile(); + + /** + * @return the maxAgentPools value. + */ + Integer maxAgentPools(); + + /** + * @return the networkProfile value. + */ + ContainerServiceNetworkProfile networkProfile(); + + /** + * @return the nodeResourceGroup value. + */ + String nodeResourceGroup(); + + /** + * @return the provisioningState value. + */ + String provisioningState(); + + /** + * @return the servicePrincipalProfile value. + */ + ManagedClusterServicePrincipalProfile servicePrincipalProfile(); + + /** + * @return the windowsProfile value. + */ + ManagedClusterWindowsProfile windowsProfile(); + + /** + * The entirety of the ManagedCluster definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, DefinitionStages.WithCreate { + } + + /** + * Grouping of ManagedCluster definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a ManagedCluster definition. + */ + interface Blank extends GroupableResourceCore.DefinitionWithRegion { + } + + /** + * The stage of the ManagedCluster definition allowing to specify the resource group. + */ + interface WithGroup extends GroupableResourceCore.DefinitionStages.WithGroup { + } + + /** + * The stage of the managedcluster definition allowing to specify AadProfile. + */ + interface WithAadProfile { + /** + * Specifies aadProfile. + * @param aadProfile Profile of Azure Active Directory configuration + * @return the next definition stage + */ + WithCreate withAadProfile(ManagedClusterAADProfile aadProfile); + } + + /** + * The stage of the managedcluster definition allowing to specify AddonProfiles. + */ + interface WithAddonProfiles { + /** + * Specifies addonProfiles. + * @param addonProfiles Profile of managed cluster add-on + * @return the next definition stage + */ + WithCreate withAddonProfiles(Map addonProfiles); + } + + /** + * The stage of the managedcluster definition allowing to specify AgentPoolProfiles. + */ + interface WithAgentPoolProfiles { + /** + * Specifies agentPoolProfiles. + * @param agentPoolProfiles Properties of the agent pool + * @return the next definition stage + */ + WithCreate withAgentPoolProfiles(List agentPoolProfiles); + } + + /** + * The stage of the managedcluster definition allowing to specify ApiServerAccessProfile. + */ + interface WithApiServerAccessProfile { + /** + * Specifies apiServerAccessProfile. + * @param apiServerAccessProfile Access profile for managed cluster API server + * @return the next definition stage + */ + WithCreate withApiServerAccessProfile(ManagedClusterAPIServerAccessProfile apiServerAccessProfile); + } + + /** + * The stage of the managedcluster definition allowing to specify DnsPrefix. + */ + interface WithDnsPrefix { + /** + * Specifies dnsPrefix. + * @param dnsPrefix DNS prefix specified when creating the managed cluster + * @return the next definition stage + */ + WithCreate withDnsPrefix(String dnsPrefix); + } + + /** + * The stage of the managedcluster definition allowing to specify EnablePodSecurityPolicy. + */ + interface WithEnablePodSecurityPolicy { + /** + * Specifies enablePodSecurityPolicy. + * @param enablePodSecurityPolicy (PREVIEW) Whether to enable Kubernetes Pod security policy + * @return the next definition stage + */ + WithCreate withEnablePodSecurityPolicy(Boolean enablePodSecurityPolicy); + } + + /** + * The stage of the managedcluster definition allowing to specify EnableRBAC. + */ + interface WithEnableRBAC { + /** + * Specifies enableRBAC. + * @param enableRBAC Whether to enable Kubernetes Role-Based Access Control + * @return the next definition stage + */ + WithCreate withEnableRBAC(Boolean enableRBAC); + } + + /** + * The stage of the managedcluster definition allowing to specify Identity. + */ + interface WithIdentity { + /** + * Specifies identity. + * @param identity The identity of the managed cluster, if configured + * @return the next definition stage + */ + WithCreate withIdentity(ManagedClusterIdentity identity); + } + + /** + * The stage of the managedcluster definition allowing to specify KubernetesVersion. + */ + interface WithKubernetesVersion { + /** + * Specifies kubernetesVersion. + * @param kubernetesVersion Version of Kubernetes specified when creating the managed cluster + * @return the next definition stage + */ + WithCreate withKubernetesVersion(String kubernetesVersion); + } + + /** + * The stage of the managedcluster definition allowing to specify LinuxProfile. + */ + interface WithLinuxProfile { + /** + * Specifies linuxProfile. + * @param linuxProfile Profile for Linux VMs in the container service cluster + * @return the next definition stage + */ + WithCreate withLinuxProfile(ContainerServiceLinuxProfile linuxProfile); + } + + /** + * The stage of the managedcluster definition allowing to specify NetworkProfile. + */ + interface WithNetworkProfile { + /** + * Specifies networkProfile. + * @param networkProfile Profile of network configuration + * @return the next definition stage + */ + WithCreate withNetworkProfile(ContainerServiceNetworkProfile networkProfile); + } + + /** + * The stage of the managedcluster definition allowing to specify NodeResourceGroup. + */ + interface WithNodeResourceGroup { + /** + * Specifies nodeResourceGroup. + * @param nodeResourceGroup Name of the resource group containing agent pool nodes + * @return the next definition stage + */ + WithCreate withNodeResourceGroup(String nodeResourceGroup); + } + + /** + * The stage of the managedcluster definition allowing to specify ServicePrincipalProfile. + */ + interface WithServicePrincipalProfile { + /** + * Specifies servicePrincipalProfile. + * @param servicePrincipalProfile Information about a service principal identity for the cluster to use for manipulating Azure APIs + * @return the next definition stage + */ + WithCreate withServicePrincipalProfile(ManagedClusterServicePrincipalProfile servicePrincipalProfile); + } + + /** + * The stage of the managedcluster definition allowing to specify WindowsProfile. + */ + interface WithWindowsProfile { + /** + * Specifies windowsProfile. + * @param windowsProfile Profile for Windows VMs in the container service cluster + * @return the next definition stage + */ + WithCreate withWindowsProfile(ManagedClusterWindowsProfile windowsProfile); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable, Resource.DefinitionWithTags, DefinitionStages.WithAadProfile, DefinitionStages.WithAddonProfiles, DefinitionStages.WithAgentPoolProfiles, DefinitionStages.WithApiServerAccessProfile, DefinitionStages.WithDnsPrefix, DefinitionStages.WithEnablePodSecurityPolicy, DefinitionStages.WithEnableRBAC, DefinitionStages.WithIdentity, DefinitionStages.WithKubernetesVersion, DefinitionStages.WithLinuxProfile, DefinitionStages.WithNetworkProfile, DefinitionStages.WithNodeResourceGroup, DefinitionStages.WithServicePrincipalProfile, DefinitionStages.WithWindowsProfile { + } + } + /** + * The template for a ManagedCluster update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, Resource.UpdateWithTags, UpdateStages.WithAadProfile, UpdateStages.WithAddonProfiles, UpdateStages.WithAgentPoolProfiles, UpdateStages.WithApiServerAccessProfile, UpdateStages.WithDnsPrefix, UpdateStages.WithEnablePodSecurityPolicy, UpdateStages.WithEnableRBAC, UpdateStages.WithIdentity, UpdateStages.WithKubernetesVersion, UpdateStages.WithLinuxProfile, UpdateStages.WithNetworkProfile, UpdateStages.WithNodeResourceGroup, UpdateStages.WithServicePrincipalProfile, UpdateStages.WithWindowsProfile { + } + + /** + * Grouping of ManagedCluster update stages. + */ + interface UpdateStages { + /** + * The stage of the managedcluster update allowing to specify AadProfile. + */ + interface WithAadProfile { + /** + * Specifies aadProfile. + * @param aadProfile Profile of Azure Active Directory configuration + * @return the next update stage + */ + Update withAadProfile(ManagedClusterAADProfile aadProfile); + } + + /** + * The stage of the managedcluster update allowing to specify AddonProfiles. + */ + interface WithAddonProfiles { + /** + * Specifies addonProfiles. + * @param addonProfiles Profile of managed cluster add-on + * @return the next update stage + */ + Update withAddonProfiles(Map addonProfiles); + } + + /** + * The stage of the managedcluster update allowing to specify AgentPoolProfiles. + */ + interface WithAgentPoolProfiles { + /** + * Specifies agentPoolProfiles. + * @param agentPoolProfiles Properties of the agent pool + * @return the next update stage + */ + Update withAgentPoolProfiles(List agentPoolProfiles); + } + + /** + * The stage of the managedcluster update allowing to specify ApiServerAccessProfile. + */ + interface WithApiServerAccessProfile { + /** + * Specifies apiServerAccessProfile. + * @param apiServerAccessProfile Access profile for managed cluster API server + * @return the next update stage + */ + Update withApiServerAccessProfile(ManagedClusterAPIServerAccessProfile apiServerAccessProfile); + } + + /** + * The stage of the managedcluster update allowing to specify DnsPrefix. + */ + interface WithDnsPrefix { + /** + * Specifies dnsPrefix. + * @param dnsPrefix DNS prefix specified when creating the managed cluster + * @return the next update stage + */ + Update withDnsPrefix(String dnsPrefix); + } + + /** + * The stage of the managedcluster update allowing to specify EnablePodSecurityPolicy. + */ + interface WithEnablePodSecurityPolicy { + /** + * Specifies enablePodSecurityPolicy. + * @param enablePodSecurityPolicy (PREVIEW) Whether to enable Kubernetes Pod security policy + * @return the next update stage + */ + Update withEnablePodSecurityPolicy(Boolean enablePodSecurityPolicy); + } + + /** + * The stage of the managedcluster update allowing to specify EnableRBAC. + */ + interface WithEnableRBAC { + /** + * Specifies enableRBAC. + * @param enableRBAC Whether to enable Kubernetes Role-Based Access Control + * @return the next update stage + */ + Update withEnableRBAC(Boolean enableRBAC); + } + + /** + * The stage of the managedcluster update allowing to specify Identity. + */ + interface WithIdentity { + /** + * Specifies identity. + * @param identity The identity of the managed cluster, if configured + * @return the next update stage + */ + Update withIdentity(ManagedClusterIdentity identity); + } + + /** + * The stage of the managedcluster update allowing to specify KubernetesVersion. + */ + interface WithKubernetesVersion { + /** + * Specifies kubernetesVersion. + * @param kubernetesVersion Version of Kubernetes specified when creating the managed cluster + * @return the next update stage + */ + Update withKubernetesVersion(String kubernetesVersion); + } + + /** + * The stage of the managedcluster update allowing to specify LinuxProfile. + */ + interface WithLinuxProfile { + /** + * Specifies linuxProfile. + * @param linuxProfile Profile for Linux VMs in the container service cluster + * @return the next update stage + */ + Update withLinuxProfile(ContainerServiceLinuxProfile linuxProfile); + } + + /** + * The stage of the managedcluster update allowing to specify NetworkProfile. + */ + interface WithNetworkProfile { + /** + * Specifies networkProfile. + * @param networkProfile Profile of network configuration + * @return the next update stage + */ + Update withNetworkProfile(ContainerServiceNetworkProfile networkProfile); + } + + /** + * The stage of the managedcluster update allowing to specify NodeResourceGroup. + */ + interface WithNodeResourceGroup { + /** + * Specifies nodeResourceGroup. + * @param nodeResourceGroup Name of the resource group containing agent pool nodes + * @return the next update stage + */ + Update withNodeResourceGroup(String nodeResourceGroup); + } + + /** + * The stage of the managedcluster update allowing to specify ServicePrincipalProfile. + */ + interface WithServicePrincipalProfile { + /** + * Specifies servicePrincipalProfile. + * @param servicePrincipalProfile Information about a service principal identity for the cluster to use for manipulating Azure APIs + * @return the next update stage + */ + Update withServicePrincipalProfile(ManagedClusterServicePrincipalProfile servicePrincipalProfile); + } + + /** + * The stage of the managedcluster update allowing to specify WindowsProfile. + */ + interface WithWindowsProfile { + /** + * Specifies windowsProfile. + * @param windowsProfile Profile for Windows VMs in the container service cluster + * @return the next update stage + */ + Update withWindowsProfile(ManagedClusterWindowsProfile windowsProfile); + } + + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAADProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAADProfile.java new file mode 100644 index 000000000000..5bb7d3effab8 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAADProfile.java @@ -0,0 +1,122 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * AADProfile specifies attributes for Azure Active Directory integration. + */ +public class ManagedClusterAADProfile { + /** + * The client AAD application ID. + */ + @JsonProperty(value = "clientAppID", required = true) + private String clientAppID; + + /** + * The server AAD application ID. + */ + @JsonProperty(value = "serverAppID", required = true) + private String serverAppID; + + /** + * The server AAD application secret. + */ + @JsonProperty(value = "serverAppSecret") + private String serverAppSecret; + + /** + * The AAD tenant ID to use for authentication. If not specified, will use + * the tenant of the deployment subscription. + */ + @JsonProperty(value = "tenantID") + private String tenantID; + + /** + * Get the client AAD application ID. + * + * @return the clientAppID value + */ + public String clientAppID() { + return this.clientAppID; + } + + /** + * Set the client AAD application ID. + * + * @param clientAppID the clientAppID value to set + * @return the ManagedClusterAADProfile object itself. + */ + public ManagedClusterAADProfile withClientAppID(String clientAppID) { + this.clientAppID = clientAppID; + return this; + } + + /** + * Get the server AAD application ID. + * + * @return the serverAppID value + */ + public String serverAppID() { + return this.serverAppID; + } + + /** + * Set the server AAD application ID. + * + * @param serverAppID the serverAppID value to set + * @return the ManagedClusterAADProfile object itself. + */ + public ManagedClusterAADProfile withServerAppID(String serverAppID) { + this.serverAppID = serverAppID; + return this; + } + + /** + * Get the server AAD application secret. + * + * @return the serverAppSecret value + */ + public String serverAppSecret() { + return this.serverAppSecret; + } + + /** + * Set the server AAD application secret. + * + * @param serverAppSecret the serverAppSecret value to set + * @return the ManagedClusterAADProfile object itself. + */ + public ManagedClusterAADProfile withServerAppSecret(String serverAppSecret) { + this.serverAppSecret = serverAppSecret; + return this; + } + + /** + * Get the AAD tenant ID to use for authentication. If not specified, will use the tenant of the deployment subscription. + * + * @return the tenantID value + */ + public String tenantID() { + return this.tenantID; + } + + /** + * Set the AAD tenant ID to use for authentication. If not specified, will use the tenant of the deployment subscription. + * + * @param tenantID the tenantID value to set + * @return the ManagedClusterAADProfile object itself. + */ + public ManagedClusterAADProfile withTenantID(String tenantID) { + this.tenantID = tenantID; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAPIServerAccessProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAPIServerAccessProfile.java new file mode 100644 index 000000000000..e28893148faa --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAPIServerAccessProfile.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Access profile for managed cluster API server. + */ +public class ManagedClusterAPIServerAccessProfile { + /** + * Authorized IP Ranges to kubernetes API server. + */ + @JsonProperty(value = "authorizedIPRanges") + private List authorizedIPRanges; + + /** + * Whether to create the cluster as a private cluster or not. + */ + @JsonProperty(value = "enablePrivateCluster") + private Boolean enablePrivateCluster; + + /** + * Get authorized IP Ranges to kubernetes API server. + * + * @return the authorizedIPRanges value + */ + public List authorizedIPRanges() { + return this.authorizedIPRanges; + } + + /** + * Set authorized IP Ranges to kubernetes API server. + * + * @param authorizedIPRanges the authorizedIPRanges value to set + * @return the ManagedClusterAPIServerAccessProfile object itself. + */ + public ManagedClusterAPIServerAccessProfile withAuthorizedIPRanges(List authorizedIPRanges) { + this.authorizedIPRanges = authorizedIPRanges; + return this; + } + + /** + * Get whether to create the cluster as a private cluster or not. + * + * @return the enablePrivateCluster value + */ + public Boolean enablePrivateCluster() { + return this.enablePrivateCluster; + } + + /** + * Set whether to create the cluster as a private cluster or not. + * + * @param enablePrivateCluster the enablePrivateCluster value to set + * @return the ManagedClusterAPIServerAccessProfile object itself. + */ + public ManagedClusterAPIServerAccessProfile withEnablePrivateCluster(Boolean enablePrivateCluster) { + this.enablePrivateCluster = enablePrivateCluster; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAccessProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAccessProfile.java new file mode 100644 index 000000000000..c11a33700689 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAccessProfile.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ManagedClusterAccessProfileInner; +import java.util.Map; + +/** + * Type representing ManagedClusterAccessProfile. + */ +public interface ManagedClusterAccessProfile extends HasInner, HasManager { + /** + * @return the id value. + */ + String id(); + + /** + * @return the kubeConfig value. + */ + byte[] kubeConfig(); + + /** + * @return the location value. + */ + String location(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the tags value. + */ + Map tags(); + + /** + * @return the type value. + */ + String type(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAddonProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAddonProfile.java new file mode 100644 index 000000000000..6700ba66acb0 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAddonProfile.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A Kubernetes add-on profile for a managed cluster. + */ +public class ManagedClusterAddonProfile { + /** + * Whether the add-on is enabled or not. + */ + @JsonProperty(value = "enabled", required = true) + private boolean enabled; + + /** + * Key-value pairs for configuring an add-on. + */ + @JsonProperty(value = "config") + private Map config; + + /** + * Get whether the add-on is enabled or not. + * + * @return the enabled value + */ + public boolean enabled() { + return this.enabled; + } + + /** + * Set whether the add-on is enabled or not. + * + * @param enabled the enabled value to set + * @return the ManagedClusterAddonProfile object itself. + */ + public ManagedClusterAddonProfile withEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + /** + * Get key-value pairs for configuring an add-on. + * + * @return the config value + */ + public Map config() { + return this.config; + } + + /** + * Set key-value pairs for configuring an add-on. + * + * @param config the config value to set + * @return the ManagedClusterAddonProfile object itself. + */ + public ManagedClusterAddonProfile withConfig(Map config) { + this.config = config; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAgentPoolProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAgentPoolProfile.java new file mode 100644 index 000000000000..4af0e3f80c1c --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAgentPoolProfile.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for the container service agent pool. + */ +public class ManagedClusterAgentPoolProfile extends ManagedClusterAgentPoolProfileProperties { + /** + * Unique name of the agent pool profile in the context of the subscription + * and resource group. + */ + @JsonProperty(value = "name", required = true) + private String name; + + /** + * Get unique name of the agent pool profile in the context of the subscription and resource group. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set unique name of the agent pool profile in the context of the subscription and resource group. + * + * @param name the name value to set + * @return the ManagedClusterAgentPoolProfile object itself. + */ + public ManagedClusterAgentPoolProfile withName(String name) { + this.name = name; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAgentPoolProfileProperties.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAgentPoolProfileProperties.java new file mode 100644 index 000000000000..71a75d7f1378 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterAgentPoolProfileProperties.java @@ -0,0 +1,511 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Properties for the container service agent pool profile. + */ +public class ManagedClusterAgentPoolProfileProperties { + /** + * Number of agents (VMs) to host docker containers. Allowed values must be + * in the range of 1 to 100 (inclusive). The default value is 1. + */ + @JsonProperty(value = "count", required = true) + private int count; + + /** + * Size of agent VMs. Possible values include: 'Standard_A1', + * 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', + * 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', + * 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', + * 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', + * 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', + * 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', + * 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', + * 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', + * 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', + * 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', + * 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', + * 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', + * 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', + * 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', + * 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', + * 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', + * 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', + * 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', + * 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', + * 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', + * 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', + * 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', + * 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', + * 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', + * 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', + * 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', + * 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', + * 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', + * 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', + * 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', + * 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', + * 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', + * 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', + * 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', + * 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', + * 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', + * 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', + * 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', + * 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', + * 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', + * 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', + * 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', + * 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', + * 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', + * 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', + * 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', + * 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', + * 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', + * 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', + * 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', + * 'Standard_NV6'. + */ + @JsonProperty(value = "vmSize", required = true) + private ContainerServiceVMSizeTypes vmSize; + + /** + * OS Disk Size in GB to be used to specify the disk size for every machine + * in this master/agent pool. If you specify 0, it will apply the default + * osDisk size according to the vmSize specified. + */ + @JsonProperty(value = "osDiskSizeGB") + private Integer osDiskSizeGB; + + /** + * VNet SubnetID specifies the VNet's subnet identifier. + */ + @JsonProperty(value = "vnetSubnetID") + private String vnetSubnetID; + + /** + * Maximum number of pods that can run on a node. + */ + @JsonProperty(value = "maxPods") + private Integer maxPods; + + /** + * OsType to be used to specify os type. Choose from Linux and Windows. + * Default to Linux. Possible values include: 'Linux', 'Windows'. + */ + @JsonProperty(value = "osType") + private OSType osType; + + /** + * Maximum number of nodes for auto-scaling. + */ + @JsonProperty(value = "maxCount") + private Integer maxCount; + + /** + * Minimum number of nodes for auto-scaling. + */ + @JsonProperty(value = "minCount") + private Integer minCount; + + /** + * Whether to enable auto-scaler. + */ + @JsonProperty(value = "enableAutoScaling") + private Boolean enableAutoScaling; + + /** + * AgentPoolType represents types of an agent pool. Possible values + * include: 'VirtualMachineScaleSets', 'AvailabilitySet'. + */ + @JsonProperty(value = "type") + private AgentPoolType type; + + /** + * Version of orchestrator specified when creating the managed cluster. + */ + @JsonProperty(value = "orchestratorVersion") + private String orchestratorVersion; + + /** + * The current deployment or provisioning state, which only appears in the + * response. + */ + @JsonProperty(value = "provisioningState", access = JsonProperty.Access.WRITE_ONLY) + private String provisioningState; + + /** + * (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets + * AgentPoolType. + */ + @JsonProperty(value = "availabilityZones") + private List availabilityZones; + + /** + * Enable public IP for nodes. + */ + @JsonProperty(value = "enableNodePublicIP") + private Boolean enableNodePublicIP; + + /** + * ScaleSetPriority to be used to specify virtual machine scale set + * priority. Default to regular. Possible values include: 'Low', 'Regular'. + */ + @JsonProperty(value = "scaleSetPriority") + private ScaleSetPriority scaleSetPriority; + + /** + * ScaleSetEvictionPolicy to be used to specify eviction policy for low + * priority virtual machine scale set. Default to Delete. Possible values + * include: 'Delete', 'Deallocate'. + */ + @JsonProperty(value = "scaleSetEvictionPolicy") + private ScaleSetEvictionPolicy scaleSetEvictionPolicy; + + /** + * Taints added to new nodes during node pool create and scale. For + * example, key=value:NoSchedule. + */ + @JsonProperty(value = "nodeTaints") + private List nodeTaints; + + /** + * Get number of agents (VMs) to host docker containers. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @return the count value + */ + public int count() { + return this.count; + } + + /** + * Set number of agents (VMs) to host docker containers. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @param count the count value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withCount(int count) { + this.count = count; + return this; + } + + /** + * Get size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @return the vmSize value + */ + public ContainerServiceVMSizeTypes vmSize() { + return this.vmSize; + } + + /** + * Set size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @param vmSize the vmSize value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withVmSize(ContainerServiceVMSizeTypes vmSize) { + this.vmSize = vmSize; + return this; + } + + /** + * Get oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @return the osDiskSizeGB value + */ + public Integer osDiskSizeGB() { + return this.osDiskSizeGB; + } + + /** + * Set oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @param osDiskSizeGB the osDiskSizeGB value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withOsDiskSizeGB(Integer osDiskSizeGB) { + this.osDiskSizeGB = osDiskSizeGB; + return this; + } + + /** + * Get vNet SubnetID specifies the VNet's subnet identifier. + * + * @return the vnetSubnetID value + */ + public String vnetSubnetID() { + return this.vnetSubnetID; + } + + /** + * Set vNet SubnetID specifies the VNet's subnet identifier. + * + * @param vnetSubnetID the vnetSubnetID value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withVnetSubnetID(String vnetSubnetID) { + this.vnetSubnetID = vnetSubnetID; + return this; + } + + /** + * Get maximum number of pods that can run on a node. + * + * @return the maxPods value + */ + public Integer maxPods() { + return this.maxPods; + } + + /** + * Set maximum number of pods that can run on a node. + * + * @param maxPods the maxPods value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withMaxPods(Integer maxPods) { + this.maxPods = maxPods; + return this; + } + + /** + * Get osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @return the osType value + */ + public OSType osType() { + return this.osType; + } + + /** + * Set osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @param osType the osType value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withOsType(OSType osType) { + this.osType = osType; + return this; + } + + /** + * Get maximum number of nodes for auto-scaling. + * + * @return the maxCount value + */ + public Integer maxCount() { + return this.maxCount; + } + + /** + * Set maximum number of nodes for auto-scaling. + * + * @param maxCount the maxCount value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withMaxCount(Integer maxCount) { + this.maxCount = maxCount; + return this; + } + + /** + * Get minimum number of nodes for auto-scaling. + * + * @return the minCount value + */ + public Integer minCount() { + return this.minCount; + } + + /** + * Set minimum number of nodes for auto-scaling. + * + * @param minCount the minCount value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withMinCount(Integer minCount) { + this.minCount = minCount; + return this; + } + + /** + * Get whether to enable auto-scaler. + * + * @return the enableAutoScaling value + */ + public Boolean enableAutoScaling() { + return this.enableAutoScaling; + } + + /** + * Set whether to enable auto-scaler. + * + * @param enableAutoScaling the enableAutoScaling value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withEnableAutoScaling(Boolean enableAutoScaling) { + this.enableAutoScaling = enableAutoScaling; + return this; + } + + /** + * Get agentPoolType represents types of an agent pool. Possible values include: 'VirtualMachineScaleSets', 'AvailabilitySet'. + * + * @return the type value + */ + public AgentPoolType type() { + return this.type; + } + + /** + * Set agentPoolType represents types of an agent pool. Possible values include: 'VirtualMachineScaleSets', 'AvailabilitySet'. + * + * @param type the type value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withType(AgentPoolType type) { + this.type = type; + return this; + } + + /** + * Get version of orchestrator specified when creating the managed cluster. + * + * @return the orchestratorVersion value + */ + public String orchestratorVersion() { + return this.orchestratorVersion; + } + + /** + * Set version of orchestrator specified when creating the managed cluster. + * + * @param orchestratorVersion the orchestratorVersion value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withOrchestratorVersion(String orchestratorVersion) { + this.orchestratorVersion = orchestratorVersion; + return this; + } + + /** + * Get the current deployment or provisioning state, which only appears in the response. + * + * @return the provisioningState value + */ + public String provisioningState() { + return this.provisioningState; + } + + /** + * Get (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. + * + * @return the availabilityZones value + */ + public List availabilityZones() { + return this.availabilityZones; + } + + /** + * Set (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. + * + * @param availabilityZones the availabilityZones value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withAvailabilityZones(List availabilityZones) { + this.availabilityZones = availabilityZones; + return this; + } + + /** + * Get enable public IP for nodes. + * + * @return the enableNodePublicIP value + */ + public Boolean enableNodePublicIP() { + return this.enableNodePublicIP; + } + + /** + * Set enable public IP for nodes. + * + * @param enableNodePublicIP the enableNodePublicIP value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withEnableNodePublicIP(Boolean enableNodePublicIP) { + this.enableNodePublicIP = enableNodePublicIP; + return this; + } + + /** + * Get scaleSetPriority to be used to specify virtual machine scale set priority. Default to regular. Possible values include: 'Low', 'Regular'. + * + * @return the scaleSetPriority value + */ + public ScaleSetPriority scaleSetPriority() { + return this.scaleSetPriority; + } + + /** + * Set scaleSetPriority to be used to specify virtual machine scale set priority. Default to regular. Possible values include: 'Low', 'Regular'. + * + * @param scaleSetPriority the scaleSetPriority value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withScaleSetPriority(ScaleSetPriority scaleSetPriority) { + this.scaleSetPriority = scaleSetPriority; + return this; + } + + /** + * Get scaleSetEvictionPolicy to be used to specify eviction policy for low priority virtual machine scale set. Default to Delete. Possible values include: 'Delete', 'Deallocate'. + * + * @return the scaleSetEvictionPolicy value + */ + public ScaleSetEvictionPolicy scaleSetEvictionPolicy() { + return this.scaleSetEvictionPolicy; + } + + /** + * Set scaleSetEvictionPolicy to be used to specify eviction policy for low priority virtual machine scale set. Default to Delete. Possible values include: 'Delete', 'Deallocate'. + * + * @param scaleSetEvictionPolicy the scaleSetEvictionPolicy value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withScaleSetEvictionPolicy(ScaleSetEvictionPolicy scaleSetEvictionPolicy) { + this.scaleSetEvictionPolicy = scaleSetEvictionPolicy; + return this; + } + + /** + * Get taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule. + * + * @return the nodeTaints value + */ + public List nodeTaints() { + return this.nodeTaints; + } + + /** + * Set taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule. + * + * @param nodeTaints the nodeTaints value to set + * @return the ManagedClusterAgentPoolProfileProperties object itself. + */ + public ManagedClusterAgentPoolProfileProperties withNodeTaints(List nodeTaints) { + this.nodeTaints = nodeTaints; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterIdentity.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterIdentity.java new file mode 100644 index 000000000000..90f8a418b46a --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterIdentity.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Identity for the managed cluster. + */ +public class ManagedClusterIdentity { + /** + * The principal id of the system assigned identity which is used by master + * components. + */ + @JsonProperty(value = "principalId", access = JsonProperty.Access.WRITE_ONLY) + private String principalId; + + /** + * The tenant id of the system assigned identity which is used by master + * components. + */ + @JsonProperty(value = "tenantId", access = JsonProperty.Access.WRITE_ONLY) + private String tenantId; + + /** + * The type of identity used for the managed cluster. Type 'SystemAssigned' + * will use an implicitly created identity in master components and an + * auto-created user assigned identity in MC_ resource group in agent + * nodes. Type 'None' will not use MSI for the managed cluster, service + * principal will be used instead. Possible values include: + * 'SystemAssigned', 'None'. + */ + @JsonProperty(value = "type") + private ResourceIdentityType type; + + /** + * Get the principal id of the system assigned identity which is used by master components. + * + * @return the principalId value + */ + public String principalId() { + return this.principalId; + } + + /** + * Get the tenant id of the system assigned identity which is used by master components. + * + * @return the tenantId value + */ + public String tenantId() { + return this.tenantId; + } + + /** + * Get the type of identity used for the managed cluster. Type 'SystemAssigned' will use an implicitly created identity in master components and an auto-created user assigned identity in MC_ resource group in agent nodes. Type 'None' will not use MSI for the managed cluster, service principal will be used instead. Possible values include: 'SystemAssigned', 'None'. + * + * @return the type value + */ + public ResourceIdentityType type() { + return this.type; + } + + /** + * Set the type of identity used for the managed cluster. Type 'SystemAssigned' will use an implicitly created identity in master components and an auto-created user assigned identity in MC_ resource group in agent nodes. Type 'None' will not use MSI for the managed cluster, service principal will be used instead. Possible values include: 'SystemAssigned', 'None'. + * + * @param type the type value to set + * @return the ManagedClusterIdentity object itself. + */ + public ManagedClusterIdentity withType(ResourceIdentityType type) { + this.type = type; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfile.java new file mode 100644 index 000000000000..1a8b539f9bf8 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfile.java @@ -0,0 +1,122 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile of the managed cluster load balancer. + */ +public class ManagedClusterLoadBalancerProfile { + /** + * Desired managed outbound IPs for the cluster load balancer. + */ + @JsonProperty(value = "managedOutboundIPs") + private ManagedClusterLoadBalancerProfileManagedOutboundIPs managedOutboundIPs; + + /** + * Desired outbound IP Prefix resources for the cluster load balancer. + */ + @JsonProperty(value = "outboundIPPrefixes") + private ManagedClusterLoadBalancerProfileOutboundIPPrefixes outboundIPPrefixes; + + /** + * Desired outbound IP resources for the cluster load balancer. + */ + @JsonProperty(value = "outboundIPs") + private ManagedClusterLoadBalancerProfileOutboundIPs outboundIPs; + + /** + * The effective outbound IP resources of the cluster load balancer. + */ + @JsonProperty(value = "effectiveOutboundIPs") + private List effectiveOutboundIPs; + + /** + * Get desired managed outbound IPs for the cluster load balancer. + * + * @return the managedOutboundIPs value + */ + public ManagedClusterLoadBalancerProfileManagedOutboundIPs managedOutboundIPs() { + return this.managedOutboundIPs; + } + + /** + * Set desired managed outbound IPs for the cluster load balancer. + * + * @param managedOutboundIPs the managedOutboundIPs value to set + * @return the ManagedClusterLoadBalancerProfile object itself. + */ + public ManagedClusterLoadBalancerProfile withManagedOutboundIPs(ManagedClusterLoadBalancerProfileManagedOutboundIPs managedOutboundIPs) { + this.managedOutboundIPs = managedOutboundIPs; + return this; + } + + /** + * Get desired outbound IP Prefix resources for the cluster load balancer. + * + * @return the outboundIPPrefixes value + */ + public ManagedClusterLoadBalancerProfileOutboundIPPrefixes outboundIPPrefixes() { + return this.outboundIPPrefixes; + } + + /** + * Set desired outbound IP Prefix resources for the cluster load balancer. + * + * @param outboundIPPrefixes the outboundIPPrefixes value to set + * @return the ManagedClusterLoadBalancerProfile object itself. + */ + public ManagedClusterLoadBalancerProfile withOutboundIPPrefixes(ManagedClusterLoadBalancerProfileOutboundIPPrefixes outboundIPPrefixes) { + this.outboundIPPrefixes = outboundIPPrefixes; + return this; + } + + /** + * Get desired outbound IP resources for the cluster load balancer. + * + * @return the outboundIPs value + */ + public ManagedClusterLoadBalancerProfileOutboundIPs outboundIPs() { + return this.outboundIPs; + } + + /** + * Set desired outbound IP resources for the cluster load balancer. + * + * @param outboundIPs the outboundIPs value to set + * @return the ManagedClusterLoadBalancerProfile object itself. + */ + public ManagedClusterLoadBalancerProfile withOutboundIPs(ManagedClusterLoadBalancerProfileOutboundIPs outboundIPs) { + this.outboundIPs = outboundIPs; + return this; + } + + /** + * Get the effective outbound IP resources of the cluster load balancer. + * + * @return the effectiveOutboundIPs value + */ + public List effectiveOutboundIPs() { + return this.effectiveOutboundIPs; + } + + /** + * Set the effective outbound IP resources of the cluster load balancer. + * + * @param effectiveOutboundIPs the effectiveOutboundIPs value to set + * @return the ManagedClusterLoadBalancerProfile object itself. + */ + public ManagedClusterLoadBalancerProfile withEffectiveOutboundIPs(List effectiveOutboundIPs) { + this.effectiveOutboundIPs = effectiveOutboundIPs; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileManagedOutboundIPs.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileManagedOutboundIPs.java new file mode 100644 index 000000000000..52376a69697b --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileManagedOutboundIPs.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Desired managed outbound IPs for the cluster load balancer. + */ +public class ManagedClusterLoadBalancerProfileManagedOutboundIPs { + /** + * Desired number of outbound IP created/managed by Azure for the cluster + * load balancer. Allowed values must be in the range of 1 to 100 + * (inclusive). The default value is 1. + */ + @JsonProperty(value = "count") + private Integer count; + + /** + * Get desired number of outbound IP created/managed by Azure for the cluster load balancer. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @return the count value + */ + public Integer count() { + return this.count; + } + + /** + * Set desired number of outbound IP created/managed by Azure for the cluster load balancer. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @param count the count value to set + * @return the ManagedClusterLoadBalancerProfileManagedOutboundIPs object itself. + */ + public ManagedClusterLoadBalancerProfileManagedOutboundIPs withCount(Integer count) { + this.count = count; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileOutboundIPPrefixes.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileOutboundIPPrefixes.java new file mode 100644 index 000000000000..10ec84941db5 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileOutboundIPPrefixes.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Desired outbound IP Prefix resources for the cluster load balancer. + */ +public class ManagedClusterLoadBalancerProfileOutboundIPPrefixes { + /** + * A list of public IP prefix resources. + */ + @JsonProperty(value = "publicIPPrefixes") + private List publicIPPrefixes; + + /** + * Get a list of public IP prefix resources. + * + * @return the publicIPPrefixes value + */ + public List publicIPPrefixes() { + return this.publicIPPrefixes; + } + + /** + * Set a list of public IP prefix resources. + * + * @param publicIPPrefixes the publicIPPrefixes value to set + * @return the ManagedClusterLoadBalancerProfileOutboundIPPrefixes object itself. + */ + public ManagedClusterLoadBalancerProfileOutboundIPPrefixes withPublicIPPrefixes(List publicIPPrefixes) { + this.publicIPPrefixes = publicIPPrefixes; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileOutboundIPs.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileOutboundIPs.java new file mode 100644 index 000000000000..9f709a148ab8 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterLoadBalancerProfileOutboundIPs.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Desired outbound IP resources for the cluster load balancer. + */ +public class ManagedClusterLoadBalancerProfileOutboundIPs { + /** + * A list of public IP resources. + */ + @JsonProperty(value = "publicIPs") + private List publicIPs; + + /** + * Get a list of public IP resources. + * + * @return the publicIPs value + */ + public List publicIPs() { + return this.publicIPs; + } + + /** + * Set a list of public IP resources. + * + * @param publicIPs the publicIPs value to set + * @return the ManagedClusterLoadBalancerProfileOutboundIPs object itself. + */ + public ManagedClusterLoadBalancerProfileOutboundIPs withPublicIPs(List publicIPs) { + this.publicIPs = publicIPs; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterPoolUpgradeProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterPoolUpgradeProfile.java new file mode 100644 index 000000000000..bbcade8ba9dd --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterPoolUpgradeProfile.java @@ -0,0 +1,123 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The list of available upgrade versions. + */ +public class ManagedClusterPoolUpgradeProfile { + /** + * Kubernetes version (major, minor, patch). + */ + @JsonProperty(value = "kubernetesVersion", required = true) + private String kubernetesVersion; + + /** + * Pool name. + */ + @JsonProperty(value = "name") + private String name; + + /** + * OsType to be used to specify os type. Choose from Linux and Windows. + * Default to Linux. Possible values include: 'Linux', 'Windows'. + */ + @JsonProperty(value = "osType", required = true) + private OSType osType; + + /** + * List of orchestrator types and versions available for upgrade. + */ + @JsonProperty(value = "upgrades") + private List upgrades; + + /** + * Get kubernetes version (major, minor, patch). + * + * @return the kubernetesVersion value + */ + public String kubernetesVersion() { + return this.kubernetesVersion; + } + + /** + * Set kubernetes version (major, minor, patch). + * + * @param kubernetesVersion the kubernetesVersion value to set + * @return the ManagedClusterPoolUpgradeProfile object itself. + */ + public ManagedClusterPoolUpgradeProfile withKubernetesVersion(String kubernetesVersion) { + this.kubernetesVersion = kubernetesVersion; + return this; + } + + /** + * Get pool name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set pool name. + * + * @param name the name value to set + * @return the ManagedClusterPoolUpgradeProfile object itself. + */ + public ManagedClusterPoolUpgradeProfile withName(String name) { + this.name = name; + return this; + } + + /** + * Get osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @return the osType value + */ + public OSType osType() { + return this.osType; + } + + /** + * Set osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @param osType the osType value to set + * @return the ManagedClusterPoolUpgradeProfile object itself. + */ + public ManagedClusterPoolUpgradeProfile withOsType(OSType osType) { + this.osType = osType; + return this; + } + + /** + * Get list of orchestrator types and versions available for upgrade. + * + * @return the upgrades value + */ + public List upgrades() { + return this.upgrades; + } + + /** + * Set list of orchestrator types and versions available for upgrade. + * + * @param upgrades the upgrades value to set + * @return the ManagedClusterPoolUpgradeProfile object itself. + */ + public ManagedClusterPoolUpgradeProfile withUpgrades(List upgrades) { + this.upgrades = upgrades; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterPoolUpgradeProfileUpgradesItem.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterPoolUpgradeProfileUpgradesItem.java new file mode 100644 index 000000000000..2e437bbe2a35 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterPoolUpgradeProfileUpgradesItem.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The ManagedClusterPoolUpgradeProfileUpgradesItem model. + */ +public class ManagedClusterPoolUpgradeProfileUpgradesItem { + /** + * Kubernetes version (major, minor, patch). + */ + @JsonProperty(value = "kubernetesVersion") + private String kubernetesVersion; + + /** + * Whether Kubernetes version is currently in preview. + */ + @JsonProperty(value = "isPreview") + private Boolean isPreview; + + /** + * Get kubernetes version (major, minor, patch). + * + * @return the kubernetesVersion value + */ + public String kubernetesVersion() { + return this.kubernetesVersion; + } + + /** + * Set kubernetes version (major, minor, patch). + * + * @param kubernetesVersion the kubernetesVersion value to set + * @return the ManagedClusterPoolUpgradeProfileUpgradesItem object itself. + */ + public ManagedClusterPoolUpgradeProfileUpgradesItem withKubernetesVersion(String kubernetesVersion) { + this.kubernetesVersion = kubernetesVersion; + return this; + } + + /** + * Get whether Kubernetes version is currently in preview. + * + * @return the isPreview value + */ + public Boolean isPreview() { + return this.isPreview; + } + + /** + * Set whether Kubernetes version is currently in preview. + * + * @param isPreview the isPreview value to set + * @return the ManagedClusterPoolUpgradeProfileUpgradesItem object itself. + */ + public ManagedClusterPoolUpgradeProfileUpgradesItem withIsPreview(Boolean isPreview) { + this.isPreview = isPreview; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterServicePrincipalProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterServicePrincipalProfile.java new file mode 100644 index 000000000000..a010b1760468 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterServicePrincipalProfile.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Information about a service principal identity for the cluster to use for + * manipulating Azure APIs. + */ +public class ManagedClusterServicePrincipalProfile { + /** + * The ID for the service principal. + */ + @JsonProperty(value = "clientId", required = true) + private String clientId; + + /** + * The secret password associated with the service principal in plain text. + */ + @JsonProperty(value = "secret") + private String secret; + + /** + * Get the ID for the service principal. + * + * @return the clientId value + */ + public String clientId() { + return this.clientId; + } + + /** + * Set the ID for the service principal. + * + * @param clientId the clientId value to set + * @return the ManagedClusterServicePrincipalProfile object itself. + */ + public ManagedClusterServicePrincipalProfile withClientId(String clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the secret password associated with the service principal in plain text. + * + * @return the secret value + */ + public String secret() { + return this.secret; + } + + /** + * Set the secret password associated with the service principal in plain text. + * + * @param secret the secret value to set + * @return the ManagedClusterServicePrincipalProfile object itself. + */ + public ManagedClusterServicePrincipalProfile withSecret(String secret) { + this.secret = secret; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterUpgradeProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterUpgradeProfile.java new file mode 100644 index 000000000000..3c0a3f09f119 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterUpgradeProfile.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ManagedClusterUpgradeProfileInner; +import java.util.List; + +/** + * Type representing ManagedClusterUpgradeProfile. + */ +public interface ManagedClusterUpgradeProfile extends HasInner, HasManager { + /** + * @return the agentPoolProfiles value. + */ + List agentPoolProfiles(); + + /** + * @return the controlPlaneProfile value. + */ + ManagedClusterPoolUpgradeProfile controlPlaneProfile(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the type value. + */ + String type(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterWindowsProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterWindowsProfile.java new file mode 100644 index 000000000000..19234fa8e11c --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusterWindowsProfile.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Profile for Windows VMs in the container service cluster. + */ +public class ManagedClusterWindowsProfile { + /** + * The administrator username to use for Windows VMs. + */ + @JsonProperty(value = "adminUsername", required = true) + private String adminUsername; + + /** + * The administrator password to use for Windows VMs. + */ + @JsonProperty(value = "adminPassword") + private String adminPassword; + + /** + * Get the administrator username to use for Windows VMs. + * + * @return the adminUsername value + */ + public String adminUsername() { + return this.adminUsername; + } + + /** + * Set the administrator username to use for Windows VMs. + * + * @param adminUsername the adminUsername value to set + * @return the ManagedClusterWindowsProfile object itself. + */ + public ManagedClusterWindowsProfile withAdminUsername(String adminUsername) { + this.adminUsername = adminUsername; + return this; + } + + /** + * Get the administrator password to use for Windows VMs. + * + * @return the adminPassword value + */ + public String adminPassword() { + return this.adminPassword; + } + + /** + * Set the administrator password to use for Windows VMs. + * + * @param adminPassword the adminPassword value to set + * @return the ManagedClusterWindowsProfile object itself. + */ + public ManagedClusterWindowsProfile withAdminPassword(String adminPassword) { + this.adminPassword = adminPassword; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusters.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusters.java new file mode 100644 index 000000000000..429838adfadd --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ManagedClusters.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import com.microsoft.azure.arm.resources.collection.SupportsDeletingByResourceGroup; +import com.microsoft.azure.arm.resources.collection.SupportsBatchDeletion; +import com.microsoft.azure.arm.resources.collection.SupportsGettingByResourceGroup; +import rx.Observable; +import com.microsoft.azure.arm.resources.collection.SupportsListingByResourceGroup; +import com.microsoft.azure.arm.collection.SupportsListing; +import rx.Completable; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ManagedClustersInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing ManagedClusters. + */ +public interface ManagedClusters extends SupportsCreating, SupportsDeletingByResourceGroup, SupportsBatchDeletion, SupportsGettingByResourceGroup, SupportsListingByResourceGroup, SupportsListing, HasInner { + /** + * Gets cluster admin credential of a managed cluster. + * Gets cluster admin credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listClusterAdminCredentialsAsync(String resourceGroupName, String resourceName); + + /** + * Gets cluster user credential of a managed cluster. + * Gets cluster user credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listClusterUserCredentialsAsync(String resourceGroupName, String resourceName); + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable resetServicePrincipalProfileAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters); + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable resetAADProfileAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters); + + /** + * Gets upgrade profile for a managed cluster. + * Gets the details of the upgrade profile for a managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getUpgradeProfileAsync(String resourceGroupName, String resourceName); + + /** + * Gets an access profile of a managed cluster. + * Gets the accessProfile for the specified role name of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param roleName The name of the role for managed cluster accessProfile resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAccessProfileAsync(String resourceGroupName, String resourceName, String roleName); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkPlugin.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkPlugin.java new file mode 100644 index 000000000000..93bf8665b2b1 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkPlugin.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for NetworkPlugin. + */ +public final class NetworkPlugin extends ExpandableStringEnum { + /** Static value azure for NetworkPlugin. */ + public static final NetworkPlugin AZURE = fromString("azure"); + + /** Static value kubenet for NetworkPlugin. */ + public static final NetworkPlugin KUBENET = fromString("kubenet"); + + /** + * Creates or finds a NetworkPlugin from its string representation. + * @param name a name to look for + * @return the corresponding NetworkPlugin + */ + @JsonCreator + public static NetworkPlugin fromString(String name) { + return fromString(name, NetworkPlugin.class); + } + + /** + * @return known NetworkPlugin values + */ + public static Collection values() { + return values(NetworkPlugin.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkPolicy.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkPolicy.java new file mode 100644 index 000000000000..6c629b6babcd --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkPolicy.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for NetworkPolicy. + */ +public final class NetworkPolicy extends ExpandableStringEnum { + /** Static value calico for NetworkPolicy. */ + public static final NetworkPolicy CALICO = fromString("calico"); + + /** Static value azure for NetworkPolicy. */ + public static final NetworkPolicy AZURE = fromString("azure"); + + /** + * Creates or finds a NetworkPolicy from its string representation. + * @param name a name to look for + * @return the corresponding NetworkPolicy + */ + @JsonCreator + public static NetworkPolicy fromString(String name) { + return fromString(name, NetworkPolicy.class); + } + + /** + * @return known NetworkPolicy values + */ + public static Collection values() { + return values(NetworkPolicy.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkProfile.java new file mode 100644 index 000000000000..d5e922d0b260 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/NetworkProfile.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents the OpenShift networking configuration. + */ +public class NetworkProfile { + /** + * CIDR for the OpenShift Vnet. + */ + @JsonProperty(value = "vnetCidr") + private String vnetCidr; + + /** + * CIDR of the Vnet to peer. + */ + @JsonProperty(value = "peerVnetId") + private String peerVnetId; + + /** + * ID of the Vnet created for OSA cluster. + */ + @JsonProperty(value = "vnetId") + private String vnetId; + + /** + * Get cIDR for the OpenShift Vnet. + * + * @return the vnetCidr value + */ + public String vnetCidr() { + return this.vnetCidr; + } + + /** + * Set cIDR for the OpenShift Vnet. + * + * @param vnetCidr the vnetCidr value to set + * @return the NetworkProfile object itself. + */ + public NetworkProfile withVnetCidr(String vnetCidr) { + this.vnetCidr = vnetCidr; + return this; + } + + /** + * Get cIDR of the Vnet to peer. + * + * @return the peerVnetId value + */ + public String peerVnetId() { + return this.peerVnetId; + } + + /** + * Set cIDR of the Vnet to peer. + * + * @param peerVnetId the peerVnetId value to set + * @return the NetworkProfile object itself. + */ + public NetworkProfile withPeerVnetId(String peerVnetId) { + this.peerVnetId = peerVnetId; + return this; + } + + /** + * Get iD of the Vnet created for OSA cluster. + * + * @return the vnetId value + */ + public String vnetId() { + return this.vnetId; + } + + /** + * Set iD of the Vnet created for OSA cluster. + * + * @param vnetId the vnetId value to set + * @return the NetworkProfile object itself. + */ + public NetworkProfile withVnetId(String vnetId) { + this.vnetId = vnetId; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OSType.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OSType.java new file mode 100644 index 000000000000..a8b4fe9dd66f --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OSType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for OSType. + */ +public final class OSType extends ExpandableStringEnum { + /** Static value Linux for OSType. */ + public static final OSType LINUX = fromString("Linux"); + + /** Static value Windows for OSType. */ + public static final OSType WINDOWS = fromString("Windows"); + + /** + * Creates or finds a OSType from its string representation. + * @param name a name to look for + * @return the corresponding OSType + */ + @JsonCreator + public static OSType fromString(String name) { + return fromString(name, OSType.class); + } + + /** + * @return known OSType values + */ + public static Collection values() { + return values(OSType.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftAgentPoolProfileRole.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftAgentPoolProfileRole.java new file mode 100644 index 000000000000..13d6cccd7b16 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftAgentPoolProfileRole.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for OpenShiftAgentPoolProfileRole. + */ +public final class OpenShiftAgentPoolProfileRole extends ExpandableStringEnum { + /** Static value compute for OpenShiftAgentPoolProfileRole. */ + public static final OpenShiftAgentPoolProfileRole COMPUTE = fromString("compute"); + + /** Static value infra for OpenShiftAgentPoolProfileRole. */ + public static final OpenShiftAgentPoolProfileRole INFRA = fromString("infra"); + + /** + * Creates or finds a OpenShiftAgentPoolProfileRole from its string representation. + * @param name a name to look for + * @return the corresponding OpenShiftAgentPoolProfileRole + */ + @JsonCreator + public static OpenShiftAgentPoolProfileRole fromString(String name) { + return fromString(name, OpenShiftAgentPoolProfileRole.class); + } + + /** + * @return known OpenShiftAgentPoolProfileRole values + */ + public static Collection values() { + return values(OpenShiftAgentPoolProfileRole.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftContainerServiceVMSize.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftContainerServiceVMSize.java new file mode 100644 index 000000000000..ea35d7fe61bb --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftContainerServiceVMSize.java @@ -0,0 +1,134 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for OpenShiftContainerServiceVMSize. + */ +public final class OpenShiftContainerServiceVMSize extends ExpandableStringEnum { + /** Static value Standard_D2s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_D2S_V3 = fromString("Standard_D2s_v3"); + + /** Static value Standard_D4s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_D4S_V3 = fromString("Standard_D4s_v3"); + + /** Static value Standard_D8s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_D8S_V3 = fromString("Standard_D8s_v3"); + + /** Static value Standard_D16s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_D16S_V3 = fromString("Standard_D16s_v3"); + + /** Static value Standard_D32s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_D32S_V3 = fromString("Standard_D32s_v3"); + + /** Static value Standard_D64s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_D64S_V3 = fromString("Standard_D64s_v3"); + + /** Static value Standard_DS4_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_DS4_V2 = fromString("Standard_DS4_v2"); + + /** Static value Standard_DS5_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_DS5_V2 = fromString("Standard_DS5_v2"); + + /** Static value Standard_F8s_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_F8S_V2 = fromString("Standard_F8s_v2"); + + /** Static value Standard_F16s_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_F16S_V2 = fromString("Standard_F16s_v2"); + + /** Static value Standard_F32s_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_F32S_V2 = fromString("Standard_F32s_v2"); + + /** Static value Standard_F64s_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_F64S_V2 = fromString("Standard_F64s_v2"); + + /** Static value Standard_F72s_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_F72S_V2 = fromString("Standard_F72s_v2"); + + /** Static value Standard_F8s for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_F8S = fromString("Standard_F8s"); + + /** Static value Standard_F16s for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_F16S = fromString("Standard_F16s"); + + /** Static value Standard_E4s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_E4S_V3 = fromString("Standard_E4s_v3"); + + /** Static value Standard_E8s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_E8S_V3 = fromString("Standard_E8s_v3"); + + /** Static value Standard_E16s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_E16S_V3 = fromString("Standard_E16s_v3"); + + /** Static value Standard_E20s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_E20S_V3 = fromString("Standard_E20s_v3"); + + /** Static value Standard_E32s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_E32S_V3 = fromString("Standard_E32s_v3"); + + /** Static value Standard_E64s_v3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_E64S_V3 = fromString("Standard_E64s_v3"); + + /** Static value Standard_GS2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_GS2 = fromString("Standard_GS2"); + + /** Static value Standard_GS3 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_GS3 = fromString("Standard_GS3"); + + /** Static value Standard_GS4 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_GS4 = fromString("Standard_GS4"); + + /** Static value Standard_GS5 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_GS5 = fromString("Standard_GS5"); + + /** Static value Standard_DS12_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_DS12_V2 = fromString("Standard_DS12_v2"); + + /** Static value Standard_DS13_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_DS13_V2 = fromString("Standard_DS13_v2"); + + /** Static value Standard_DS14_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_DS14_V2 = fromString("Standard_DS14_v2"); + + /** Static value Standard_DS15_v2 for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_DS15_V2 = fromString("Standard_DS15_v2"); + + /** Static value Standard_L4s for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_L4S = fromString("Standard_L4s"); + + /** Static value Standard_L8s for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_L8S = fromString("Standard_L8s"); + + /** Static value Standard_L16s for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_L16S = fromString("Standard_L16s"); + + /** Static value Standard_L32s for OpenShiftContainerServiceVMSize. */ + public static final OpenShiftContainerServiceVMSize STANDARD_L32S = fromString("Standard_L32s"); + + /** + * Creates or finds a OpenShiftContainerServiceVMSize from its string representation. + * @param name a name to look for + * @return the corresponding OpenShiftContainerServiceVMSize + */ + @JsonCreator + public static OpenShiftContainerServiceVMSize fromString(String name) { + return fromString(name, OpenShiftContainerServiceVMSize.class); + } + + /** + * @return known OpenShiftContainerServiceVMSize values + */ + public static Collection values() { + return values(OpenShiftContainerServiceVMSize.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedCluster.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedCluster.java new file mode 100644 index 000000000000..de5f1eca1699 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedCluster.java @@ -0,0 +1,280 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.Resource; +import com.microsoft.azure.arm.resources.models.GroupableResourceCore; +import com.microsoft.azure.arm.resources.models.HasResourceGroup; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.OpenShiftManagedClusterInner; + +/** + * Type representing OpenShiftManagedCluster. + */ +public interface OpenShiftManagedCluster extends HasInner, Resource, GroupableResourceCore, HasResourceGroup, Refreshable, Updatable, HasManager { + /** + * @return the agentPoolProfiles value. + */ + List agentPoolProfiles(); + + /** + * @return the authProfile value. + */ + OpenShiftManagedClusterAuthProfile authProfile(); + + /** + * @return the clusterVersion value. + */ + String clusterVersion(); + + /** + * @return the fqdn value. + */ + String fqdn(); + + /** + * @return the masterPoolProfile value. + */ + OpenShiftManagedClusterMasterPoolProfile masterPoolProfile(); + + /** + * @return the networkProfile value. + */ + NetworkProfile networkProfile(); + + /** + * @return the openShiftVersion value. + */ + String openShiftVersion(); + + /** + * @return the plan value. + */ + PurchasePlan plan(); + + /** + * @return the provisioningState value. + */ + String provisioningState(); + + /** + * @return the publicHostname value. + */ + String publicHostname(); + + /** + * @return the routerProfiles value. + */ + List routerProfiles(); + + /** + * The entirety of the OpenShiftManagedCluster definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, DefinitionStages.WithOpenShiftVersion, DefinitionStages.WithCreate { + } + + /** + * Grouping of OpenShiftManagedCluster definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a OpenShiftManagedCluster definition. + */ + interface Blank extends GroupableResourceCore.DefinitionWithRegion { + } + + /** + * The stage of the OpenShiftManagedCluster definition allowing to specify the resource group. + */ + interface WithGroup extends GroupableResourceCore.DefinitionStages.WithGroup { + } + + /** + * The stage of the openshiftmanagedcluster definition allowing to specify OpenShiftVersion. + */ + interface WithOpenShiftVersion { + /** + * Specifies openShiftVersion. + * @param openShiftVersion Version of OpenShift specified when creating the cluster + * @return the next definition stage +*/ + WithCreate withOpenShiftVersion(String openShiftVersion); + } + + /** + * The stage of the openshiftmanagedcluster definition allowing to specify AgentPoolProfiles. + */ + interface WithAgentPoolProfiles { + /** + * Specifies agentPoolProfiles. + * @param agentPoolProfiles Configuration of OpenShift cluster VMs + * @return the next definition stage + */ + WithCreate withAgentPoolProfiles(List agentPoolProfiles); + } + + /** + * The stage of the openshiftmanagedcluster definition allowing to specify AuthProfile. + */ + interface WithAuthProfile { + /** + * Specifies authProfile. + * @param authProfile Configures OpenShift authentication + * @return the next definition stage + */ + WithCreate withAuthProfile(OpenShiftManagedClusterAuthProfile authProfile); + } + + /** + * The stage of the openshiftmanagedcluster definition allowing to specify MasterPoolProfile. + */ + interface WithMasterPoolProfile { + /** + * Specifies masterPoolProfile. + * @param masterPoolProfile Configuration for OpenShift master VMs + * @return the next definition stage + */ + WithCreate withMasterPoolProfile(OpenShiftManagedClusterMasterPoolProfile masterPoolProfile); + } + + /** + * The stage of the openshiftmanagedcluster definition allowing to specify NetworkProfile. + */ + interface WithNetworkProfile { + /** + * Specifies networkProfile. + * @param networkProfile Configuration for OpenShift networking + * @return the next definition stage + */ + WithCreate withNetworkProfile(NetworkProfile networkProfile); + } + + /** + * The stage of the openshiftmanagedcluster definition allowing to specify Plan. + */ + interface WithPlan { + /** + * Specifies plan. + * @param plan Define the resource plan as required by ARM for billing purposes + * @return the next definition stage + */ + WithCreate withPlan(PurchasePlan plan); + } + + /** + * The stage of the openshiftmanagedcluster definition allowing to specify RouterProfiles. + */ + interface WithRouterProfiles { + /** + * Specifies routerProfiles. + * @param routerProfiles Configuration for OpenShift router(s) + * @return the next definition stage + */ + WithCreate withRouterProfiles(List routerProfiles); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable, Resource.DefinitionWithTags, DefinitionStages.WithAgentPoolProfiles, DefinitionStages.WithAuthProfile, DefinitionStages.WithMasterPoolProfile, DefinitionStages.WithNetworkProfile, DefinitionStages.WithPlan, DefinitionStages.WithRouterProfiles { + } + } + /** + * The template for a OpenShiftManagedCluster update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, Resource.UpdateWithTags, UpdateStages.WithAgentPoolProfiles, UpdateStages.WithAuthProfile, UpdateStages.WithMasterPoolProfile, UpdateStages.WithNetworkProfile, UpdateStages.WithPlan, UpdateStages.WithRouterProfiles { + } + + /** + * Grouping of OpenShiftManagedCluster update stages. + */ + interface UpdateStages { + /** + * The stage of the openshiftmanagedcluster update allowing to specify AgentPoolProfiles. + */ + interface WithAgentPoolProfiles { + /** + * Specifies agentPoolProfiles. + * @param agentPoolProfiles Configuration of OpenShift cluster VMs + * @return the next update stage + */ + Update withAgentPoolProfiles(List agentPoolProfiles); + } + + /** + * The stage of the openshiftmanagedcluster update allowing to specify AuthProfile. + */ + interface WithAuthProfile { + /** + * Specifies authProfile. + * @param authProfile Configures OpenShift authentication + * @return the next update stage + */ + Update withAuthProfile(OpenShiftManagedClusterAuthProfile authProfile); + } + + /** + * The stage of the openshiftmanagedcluster update allowing to specify MasterPoolProfile. + */ + interface WithMasterPoolProfile { + /** + * Specifies masterPoolProfile. + * @param masterPoolProfile Configuration for OpenShift master VMs + * @return the next update stage + */ + Update withMasterPoolProfile(OpenShiftManagedClusterMasterPoolProfile masterPoolProfile); + } + + /** + * The stage of the openshiftmanagedcluster update allowing to specify NetworkProfile. + */ + interface WithNetworkProfile { + /** + * Specifies networkProfile. + * @param networkProfile Configuration for OpenShift networking + * @return the next update stage + */ + Update withNetworkProfile(NetworkProfile networkProfile); + } + + /** + * The stage of the openshiftmanagedcluster update allowing to specify Plan. + */ + interface WithPlan { + /** + * Specifies plan. + * @param plan Define the resource plan as required by ARM for billing purposes + * @return the next update stage + */ + Update withPlan(PurchasePlan plan); + } + + /** + * The stage of the openshiftmanagedcluster update allowing to specify RouterProfiles. + */ + interface WithRouterProfiles { + /** + * Specifies routerProfiles. + * @param routerProfiles Configuration for OpenShift router(s) + * @return the next update stage + */ + Update withRouterProfiles(List routerProfiles); + } + + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAADIdentityProvider.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAADIdentityProvider.java new file mode 100644 index 000000000000..5f29092c1e5c --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAADIdentityProvider.java @@ -0,0 +1,125 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * Defines the Identity provider for MS AAD. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "kind", defaultImpl = OpenShiftManagedClusterAADIdentityProvider.class) +@JsonTypeName("AADIdentityProvider") +public class OpenShiftManagedClusterAADIdentityProvider extends OpenShiftManagedClusterBaseIdentityProvider { + /** + * The clientId password associated with the provider. + */ + @JsonProperty(value = "clientId") + private String clientId; + + /** + * The secret password associated with the provider. + */ + @JsonProperty(value = "secret") + private String secret; + + /** + * The tenantId associated with the provider. + */ + @JsonProperty(value = "tenantId") + private String tenantId; + + /** + * The groupId to be granted cluster admin role. + */ + @JsonProperty(value = "customerAdminGroupId") + private String customerAdminGroupId; + + /** + * Get the clientId password associated with the provider. + * + * @return the clientId value + */ + public String clientId() { + return this.clientId; + } + + /** + * Set the clientId password associated with the provider. + * + * @param clientId the clientId value to set + * @return the OpenShiftManagedClusterAADIdentityProvider object itself. + */ + public OpenShiftManagedClusterAADIdentityProvider withClientId(String clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the secret password associated with the provider. + * + * @return the secret value + */ + public String secret() { + return this.secret; + } + + /** + * Set the secret password associated with the provider. + * + * @param secret the secret value to set + * @return the OpenShiftManagedClusterAADIdentityProvider object itself. + */ + public OpenShiftManagedClusterAADIdentityProvider withSecret(String secret) { + this.secret = secret; + return this; + } + + /** + * Get the tenantId associated with the provider. + * + * @return the tenantId value + */ + public String tenantId() { + return this.tenantId; + } + + /** + * Set the tenantId associated with the provider. + * + * @param tenantId the tenantId value to set + * @return the OpenShiftManagedClusterAADIdentityProvider object itself. + */ + public OpenShiftManagedClusterAADIdentityProvider withTenantId(String tenantId) { + this.tenantId = tenantId; + return this; + } + + /** + * Get the groupId to be granted cluster admin role. + * + * @return the customerAdminGroupId value + */ + public String customerAdminGroupId() { + return this.customerAdminGroupId; + } + + /** + * Set the groupId to be granted cluster admin role. + * + * @param customerAdminGroupId the customerAdminGroupId value to set + * @return the OpenShiftManagedClusterAADIdentityProvider object itself. + */ + public OpenShiftManagedClusterAADIdentityProvider withCustomerAdminGroupId(String customerAdminGroupId) { + this.customerAdminGroupId = customerAdminGroupId; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAgentPoolProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAgentPoolProfile.java new file mode 100644 index 000000000000..3eccb30f5587 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAgentPoolProfile.java @@ -0,0 +1,186 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Defines the configuration of the OpenShift cluster VMs. + */ +public class OpenShiftManagedClusterAgentPoolProfile { + /** + * Unique name of the pool profile in the context of the subscription and + * resource group. + */ + @JsonProperty(value = "name", required = true) + private String name; + + /** + * Number of agents (VMs) to host docker containers. + */ + @JsonProperty(value = "count", required = true) + private int count; + + /** + * Size of agent VMs. Possible values include: 'Standard_D2s_v3', + * 'Standard_D4s_v3', 'Standard_D8s_v3', 'Standard_D16s_v3', + * 'Standard_D32s_v3', 'Standard_D64s_v3', 'Standard_DS4_v2', + * 'Standard_DS5_v2', 'Standard_F8s_v2', 'Standard_F16s_v2', + * 'Standard_F32s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', + * 'Standard_F8s', 'Standard_F16s', 'Standard_E4s_v3', 'Standard_E8s_v3', + * 'Standard_E16s_v3', 'Standard_E20s_v3', 'Standard_E32s_v3', + * 'Standard_E64s_v3', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', + * 'Standard_GS5', 'Standard_DS12_v2', 'Standard_DS13_v2', + * 'Standard_DS14_v2', 'Standard_DS15_v2', 'Standard_L4s', 'Standard_L8s', + * 'Standard_L16s', 'Standard_L32s'. + */ + @JsonProperty(value = "vmSize", required = true) + private OpenShiftContainerServiceVMSize vmSize; + + /** + * Subnet CIDR for the peering. + */ + @JsonProperty(value = "subnetCidr") + private String subnetCidr; + + /** + * OsType to be used to specify os type. Choose from Linux and Windows. + * Default to Linux. Possible values include: 'Linux', 'Windows'. + */ + @JsonProperty(value = "osType") + private OSType osType; + + /** + * Define the role of the AgentPoolProfile. Possible values include: + * 'compute', 'infra'. + */ + @JsonProperty(value = "role") + private OpenShiftAgentPoolProfileRole role; + + /** + * Get unique name of the pool profile in the context of the subscription and resource group. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set unique name of the pool profile in the context of the subscription and resource group. + * + * @param name the name value to set + * @return the OpenShiftManagedClusterAgentPoolProfile object itself. + */ + public OpenShiftManagedClusterAgentPoolProfile withName(String name) { + this.name = name; + return this; + } + + /** + * Get number of agents (VMs) to host docker containers. + * + * @return the count value + */ + public int count() { + return this.count; + } + + /** + * Set number of agents (VMs) to host docker containers. + * + * @param count the count value to set + * @return the OpenShiftManagedClusterAgentPoolProfile object itself. + */ + public OpenShiftManagedClusterAgentPoolProfile withCount(int count) { + this.count = count; + return this; + } + + /** + * Get size of agent VMs. Possible values include: 'Standard_D2s_v3', 'Standard_D4s_v3', 'Standard_D8s_v3', 'Standard_D16s_v3', 'Standard_D32s_v3', 'Standard_D64s_v3', 'Standard_DS4_v2', 'Standard_DS5_v2', 'Standard_F8s_v2', 'Standard_F16s_v2', 'Standard_F32s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8s', 'Standard_F16s', 'Standard_E4s_v3', 'Standard_E8s_v3', 'Standard_E16s_v3', 'Standard_E20s_v3', 'Standard_E32s_v3', 'Standard_E64s_v3', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS5', 'Standard_DS12_v2', 'Standard_DS13_v2', 'Standard_DS14_v2', 'Standard_DS15_v2', 'Standard_L4s', 'Standard_L8s', 'Standard_L16s', 'Standard_L32s'. + * + * @return the vmSize value + */ + public OpenShiftContainerServiceVMSize vmSize() { + return this.vmSize; + } + + /** + * Set size of agent VMs. Possible values include: 'Standard_D2s_v3', 'Standard_D4s_v3', 'Standard_D8s_v3', 'Standard_D16s_v3', 'Standard_D32s_v3', 'Standard_D64s_v3', 'Standard_DS4_v2', 'Standard_DS5_v2', 'Standard_F8s_v2', 'Standard_F16s_v2', 'Standard_F32s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8s', 'Standard_F16s', 'Standard_E4s_v3', 'Standard_E8s_v3', 'Standard_E16s_v3', 'Standard_E20s_v3', 'Standard_E32s_v3', 'Standard_E64s_v3', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS5', 'Standard_DS12_v2', 'Standard_DS13_v2', 'Standard_DS14_v2', 'Standard_DS15_v2', 'Standard_L4s', 'Standard_L8s', 'Standard_L16s', 'Standard_L32s'. + * + * @param vmSize the vmSize value to set + * @return the OpenShiftManagedClusterAgentPoolProfile object itself. + */ + public OpenShiftManagedClusterAgentPoolProfile withVmSize(OpenShiftContainerServiceVMSize vmSize) { + this.vmSize = vmSize; + return this; + } + + /** + * Get subnet CIDR for the peering. + * + * @return the subnetCidr value + */ + public String subnetCidr() { + return this.subnetCidr; + } + + /** + * Set subnet CIDR for the peering. + * + * @param subnetCidr the subnetCidr value to set + * @return the OpenShiftManagedClusterAgentPoolProfile object itself. + */ + public OpenShiftManagedClusterAgentPoolProfile withSubnetCidr(String subnetCidr) { + this.subnetCidr = subnetCidr; + return this; + } + + /** + * Get osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @return the osType value + */ + public OSType osType() { + return this.osType; + } + + /** + * Set osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @param osType the osType value to set + * @return the OpenShiftManagedClusterAgentPoolProfile object itself. + */ + public OpenShiftManagedClusterAgentPoolProfile withOsType(OSType osType) { + this.osType = osType; + return this; + } + + /** + * Get define the role of the AgentPoolProfile. Possible values include: 'compute', 'infra'. + * + * @return the role value + */ + public OpenShiftAgentPoolProfileRole role() { + return this.role; + } + + /** + * Set define the role of the AgentPoolProfile. Possible values include: 'compute', 'infra'. + * + * @param role the role value to set + * @return the OpenShiftManagedClusterAgentPoolProfile object itself. + */ + public OpenShiftManagedClusterAgentPoolProfile withRole(OpenShiftAgentPoolProfileRole role) { + this.role = role; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAuthProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAuthProfile.java new file mode 100644 index 000000000000..5e168240bca5 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterAuthProfile.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Defines all possible authentication profiles for the OpenShift cluster. + */ +public class OpenShiftManagedClusterAuthProfile { + /** + * Type of authentication profile to use. + */ + @JsonProperty(value = "identityProviders") + private List identityProviders; + + /** + * Get type of authentication profile to use. + * + * @return the identityProviders value + */ + public List identityProviders() { + return this.identityProviders; + } + + /** + * Set type of authentication profile to use. + * + * @param identityProviders the identityProviders value to set + * @return the OpenShiftManagedClusterAuthProfile object itself. + */ + public OpenShiftManagedClusterAuthProfile withIdentityProviders(List identityProviders) { + this.identityProviders = identityProviders; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterBaseIdentityProvider.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterBaseIdentityProvider.java new file mode 100644 index 000000000000..e278f76c7f5d --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterBaseIdentityProvider.java @@ -0,0 +1,24 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Structure for any Identity provider. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "kind", defaultImpl = OpenShiftManagedClusterBaseIdentityProvider.class) +@JsonTypeName("OpenShiftManagedClusterBaseIdentityProvider") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "AADIdentityProvider", value = OpenShiftManagedClusterAADIdentityProvider.class) +}) +public class OpenShiftManagedClusterBaseIdentityProvider { +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterIdentityProvider.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterIdentityProvider.java new file mode 100644 index 000000000000..377b1f92ae39 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterIdentityProvider.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Defines the configuration of the identity providers to be used in the + * OpenShift cluster. + */ +public class OpenShiftManagedClusterIdentityProvider { + /** + * Name of the provider. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Configuration of the provider. + */ + @JsonProperty(value = "provider") + private OpenShiftManagedClusterBaseIdentityProvider provider; + + /** + * Get name of the provider. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set name of the provider. + * + * @param name the name value to set + * @return the OpenShiftManagedClusterIdentityProvider object itself. + */ + public OpenShiftManagedClusterIdentityProvider withName(String name) { + this.name = name; + return this; + } + + /** + * Get configuration of the provider. + * + * @return the provider value + */ + public OpenShiftManagedClusterBaseIdentityProvider provider() { + return this.provider; + } + + /** + * Set configuration of the provider. + * + * @param provider the provider value to set + * @return the OpenShiftManagedClusterIdentityProvider object itself. + */ + public OpenShiftManagedClusterIdentityProvider withProvider(OpenShiftManagedClusterBaseIdentityProvider provider) { + this.provider = provider; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterMasterPoolProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterMasterPoolProfile.java new file mode 100644 index 000000000000..f441f3611c1b --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusterMasterPoolProfile.java @@ -0,0 +1,161 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * OpenShiftManagedClusterMaterPoolProfile contains configuration for OpenShift + * master VMs. + */ +public class OpenShiftManagedClusterMasterPoolProfile { + /** + * Unique name of the master pool profile in the context of the + * subscription and resource group. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Number of masters (VMs) to host docker containers. The default value is + * 3. + */ + @JsonProperty(value = "count", required = true) + private int count; + + /** + * Size of agent VMs. Possible values include: 'Standard_D2s_v3', + * 'Standard_D4s_v3', 'Standard_D8s_v3', 'Standard_D16s_v3', + * 'Standard_D32s_v3', 'Standard_D64s_v3', 'Standard_DS4_v2', + * 'Standard_DS5_v2', 'Standard_F8s_v2', 'Standard_F16s_v2', + * 'Standard_F32s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', + * 'Standard_F8s', 'Standard_F16s', 'Standard_E4s_v3', 'Standard_E8s_v3', + * 'Standard_E16s_v3', 'Standard_E20s_v3', 'Standard_E32s_v3', + * 'Standard_E64s_v3', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', + * 'Standard_GS5', 'Standard_DS12_v2', 'Standard_DS13_v2', + * 'Standard_DS14_v2', 'Standard_DS15_v2', 'Standard_L4s', 'Standard_L8s', + * 'Standard_L16s', 'Standard_L32s'. + */ + @JsonProperty(value = "vmSize", required = true) + private OpenShiftContainerServiceVMSize vmSize; + + /** + * Subnet CIDR for the peering. + */ + @JsonProperty(value = "subnetCidr") + private String subnetCidr; + + /** + * OsType to be used to specify os type. Choose from Linux and Windows. + * Default to Linux. Possible values include: 'Linux', 'Windows'. + */ + @JsonProperty(value = "osType") + private OSType osType; + + /** + * Get unique name of the master pool profile in the context of the subscription and resource group. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set unique name of the master pool profile in the context of the subscription and resource group. + * + * @param name the name value to set + * @return the OpenShiftManagedClusterMasterPoolProfile object itself. + */ + public OpenShiftManagedClusterMasterPoolProfile withName(String name) { + this.name = name; + return this; + } + + /** + * Get number of masters (VMs) to host docker containers. The default value is 3. + * + * @return the count value + */ + public int count() { + return this.count; + } + + /** + * Set number of masters (VMs) to host docker containers. The default value is 3. + * + * @param count the count value to set + * @return the OpenShiftManagedClusterMasterPoolProfile object itself. + */ + public OpenShiftManagedClusterMasterPoolProfile withCount(int count) { + this.count = count; + return this; + } + + /** + * Get size of agent VMs. Possible values include: 'Standard_D2s_v3', 'Standard_D4s_v3', 'Standard_D8s_v3', 'Standard_D16s_v3', 'Standard_D32s_v3', 'Standard_D64s_v3', 'Standard_DS4_v2', 'Standard_DS5_v2', 'Standard_F8s_v2', 'Standard_F16s_v2', 'Standard_F32s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8s', 'Standard_F16s', 'Standard_E4s_v3', 'Standard_E8s_v3', 'Standard_E16s_v3', 'Standard_E20s_v3', 'Standard_E32s_v3', 'Standard_E64s_v3', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS5', 'Standard_DS12_v2', 'Standard_DS13_v2', 'Standard_DS14_v2', 'Standard_DS15_v2', 'Standard_L4s', 'Standard_L8s', 'Standard_L16s', 'Standard_L32s'. + * + * @return the vmSize value + */ + public OpenShiftContainerServiceVMSize vmSize() { + return this.vmSize; + } + + /** + * Set size of agent VMs. Possible values include: 'Standard_D2s_v3', 'Standard_D4s_v3', 'Standard_D8s_v3', 'Standard_D16s_v3', 'Standard_D32s_v3', 'Standard_D64s_v3', 'Standard_DS4_v2', 'Standard_DS5_v2', 'Standard_F8s_v2', 'Standard_F16s_v2', 'Standard_F32s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8s', 'Standard_F16s', 'Standard_E4s_v3', 'Standard_E8s_v3', 'Standard_E16s_v3', 'Standard_E20s_v3', 'Standard_E32s_v3', 'Standard_E64s_v3', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS5', 'Standard_DS12_v2', 'Standard_DS13_v2', 'Standard_DS14_v2', 'Standard_DS15_v2', 'Standard_L4s', 'Standard_L8s', 'Standard_L16s', 'Standard_L32s'. + * + * @param vmSize the vmSize value to set + * @return the OpenShiftManagedClusterMasterPoolProfile object itself. + */ + public OpenShiftManagedClusterMasterPoolProfile withVmSize(OpenShiftContainerServiceVMSize vmSize) { + this.vmSize = vmSize; + return this; + } + + /** + * Get subnet CIDR for the peering. + * + * @return the subnetCidr value + */ + public String subnetCidr() { + return this.subnetCidr; + } + + /** + * Set subnet CIDR for the peering. + * + * @param subnetCidr the subnetCidr value to set + * @return the OpenShiftManagedClusterMasterPoolProfile object itself. + */ + public OpenShiftManagedClusterMasterPoolProfile withSubnetCidr(String subnetCidr) { + this.subnetCidr = subnetCidr; + return this; + } + + /** + * Get osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @return the osType value + */ + public OSType osType() { + return this.osType; + } + + /** + * Set osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @param osType the osType value to set + * @return the OpenShiftManagedClusterMasterPoolProfile object itself. + */ + public OpenShiftManagedClusterMasterPoolProfile withOsType(OSType osType) { + this.osType = osType; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusters.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusters.java new file mode 100644 index 000000000000..40061a758906 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftManagedClusters.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import com.microsoft.azure.arm.resources.collection.SupportsDeletingByResourceGroup; +import com.microsoft.azure.arm.resources.collection.SupportsBatchDeletion; +import com.microsoft.azure.arm.resources.collection.SupportsGettingByResourceGroup; +import rx.Observable; +import com.microsoft.azure.arm.resources.collection.SupportsListingByResourceGroup; +import com.microsoft.azure.arm.collection.SupportsListing; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.OpenShiftManagedClustersInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing OpenShiftManagedClusters. + */ +public interface OpenShiftManagedClusters extends SupportsCreating, SupportsDeletingByResourceGroup, SupportsBatchDeletion, SupportsGettingByResourceGroup, SupportsListingByResourceGroup, SupportsListing, HasInner { +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftRouterProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftRouterProfile.java new file mode 100644 index 000000000000..b3d740641f1d --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OpenShiftRouterProfile.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Represents an OpenShift router. + */ +public class OpenShiftRouterProfile { + /** + * Name of the router profile. + */ + @JsonProperty(value = "name") + private String name; + + /** + * DNS subdomain for OpenShift router. + */ + @JsonProperty(value = "publicSubdomain", access = JsonProperty.Access.WRITE_ONLY) + private String publicSubdomain; + + /** + * Auto-allocated FQDN for the OpenShift router. + */ + @JsonProperty(value = "fqdn", access = JsonProperty.Access.WRITE_ONLY) + private String fqdn; + + /** + * Get name of the router profile. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set name of the router profile. + * + * @param name the name value to set + * @return the OpenShiftRouterProfile object itself. + */ + public OpenShiftRouterProfile withName(String name) { + this.name = name; + return this; + } + + /** + * Get dNS subdomain for OpenShift router. + * + * @return the publicSubdomain value + */ + public String publicSubdomain() { + return this.publicSubdomain; + } + + /** + * Get auto-allocated FQDN for the OpenShift router. + * + * @return the fqdn value + */ + public String fqdn() { + return this.fqdn; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OperationValue.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OperationValue.java new file mode 100644 index 000000000000..ce5f90208da5 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OperationValue.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.OperationValueInner; + +/** + * Type representing OperationValue. + */ +public interface OperationValue extends HasInner, HasManager { + /** + * @return the description value. + */ + String description(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the operation value. + */ + String operation(); + + /** + * @return the origin value. + */ + String origin(); + + /** + * @return the provider value. + */ + String provider(); + + /** + * @return the resource value. + */ + String resource(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/Operations.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/Operations.java new file mode 100644 index 000000000000..f859cb23871a --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/Operations.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import rx.Observable; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.OperationsInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing Operations. + */ +public interface Operations extends HasInner { + /** + * Gets a list of compute operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listAsync(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorProfile.java new file mode 100644 index 000000000000..4d59cc6c9cb1 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorProfile.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Contains information about orchestrator. + */ +public class OrchestratorProfile { + /** + * Orchestrator type. + */ + @JsonProperty(value = "orchestratorType") + private String orchestratorType; + + /** + * Orchestrator version (major, minor, patch). + */ + @JsonProperty(value = "orchestratorVersion", required = true) + private String orchestratorVersion; + + /** + * Whether Kubernetes version is currently in preview. + */ + @JsonProperty(value = "isPreview") + private Boolean isPreview; + + /** + * Get orchestrator type. + * + * @return the orchestratorType value + */ + public String orchestratorType() { + return this.orchestratorType; + } + + /** + * Set orchestrator type. + * + * @param orchestratorType the orchestratorType value to set + * @return the OrchestratorProfile object itself. + */ + public OrchestratorProfile withOrchestratorType(String orchestratorType) { + this.orchestratorType = orchestratorType; + return this; + } + + /** + * Get orchestrator version (major, minor, patch). + * + * @return the orchestratorVersion value + */ + public String orchestratorVersion() { + return this.orchestratorVersion; + } + + /** + * Set orchestrator version (major, minor, patch). + * + * @param orchestratorVersion the orchestratorVersion value to set + * @return the OrchestratorProfile object itself. + */ + public OrchestratorProfile withOrchestratorVersion(String orchestratorVersion) { + this.orchestratorVersion = orchestratorVersion; + return this; + } + + /** + * Get whether Kubernetes version is currently in preview. + * + * @return the isPreview value + */ + public Boolean isPreview() { + return this.isPreview; + } + + /** + * Set whether Kubernetes version is currently in preview. + * + * @param isPreview the isPreview value to set + * @return the OrchestratorProfile object itself. + */ + public OrchestratorProfile withIsPreview(Boolean isPreview) { + this.isPreview = isPreview; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorVersionProfile.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorVersionProfile.java new file mode 100644 index 000000000000..a5ed50e3d0a6 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorVersionProfile.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The profile of an orchestrator and its available versions. + */ +public class OrchestratorVersionProfile { + /** + * Orchestrator type. + */ + @JsonProperty(value = "orchestratorType", required = true) + private String orchestratorType; + + /** + * Orchestrator version (major, minor, patch). + */ + @JsonProperty(value = "orchestratorVersion", required = true) + private String orchestratorVersion; + + /** + * Installed by default if version is not specified. + */ + @JsonProperty(value = "default") + private Boolean defaultProperty; + + /** + * Whether Kubernetes version is currently in preview. + */ + @JsonProperty(value = "isPreview") + private Boolean isPreview; + + /** + * The list of available upgrade versions. + */ + @JsonProperty(value = "upgrades") + private List upgrades; + + /** + * Get orchestrator type. + * + * @return the orchestratorType value + */ + public String orchestratorType() { + return this.orchestratorType; + } + + /** + * Set orchestrator type. + * + * @param orchestratorType the orchestratorType value to set + * @return the OrchestratorVersionProfile object itself. + */ + public OrchestratorVersionProfile withOrchestratorType(String orchestratorType) { + this.orchestratorType = orchestratorType; + return this; + } + + /** + * Get orchestrator version (major, minor, patch). + * + * @return the orchestratorVersion value + */ + public String orchestratorVersion() { + return this.orchestratorVersion; + } + + /** + * Set orchestrator version (major, minor, patch). + * + * @param orchestratorVersion the orchestratorVersion value to set + * @return the OrchestratorVersionProfile object itself. + */ + public OrchestratorVersionProfile withOrchestratorVersion(String orchestratorVersion) { + this.orchestratorVersion = orchestratorVersion; + return this; + } + + /** + * Get installed by default if version is not specified. + * + * @return the defaultProperty value + */ + public Boolean defaultProperty() { + return this.defaultProperty; + } + + /** + * Set installed by default if version is not specified. + * + * @param defaultProperty the defaultProperty value to set + * @return the OrchestratorVersionProfile object itself. + */ + public OrchestratorVersionProfile withDefaultProperty(Boolean defaultProperty) { + this.defaultProperty = defaultProperty; + return this; + } + + /** + * Get whether Kubernetes version is currently in preview. + * + * @return the isPreview value + */ + public Boolean isPreview() { + return this.isPreview; + } + + /** + * Set whether Kubernetes version is currently in preview. + * + * @param isPreview the isPreview value to set + * @return the OrchestratorVersionProfile object itself. + */ + public OrchestratorVersionProfile withIsPreview(Boolean isPreview) { + this.isPreview = isPreview; + return this; + } + + /** + * Get the list of available upgrade versions. + * + * @return the upgrades value + */ + public List upgrades() { + return this.upgrades; + } + + /** + * Set the list of available upgrade versions. + * + * @param upgrades the upgrades value to set + * @return the OrchestratorVersionProfile object itself. + */ + public OrchestratorVersionProfile withUpgrades(List upgrades) { + this.upgrades = upgrades; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorVersionProfileListResult.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorVersionProfileListResult.java new file mode 100644 index 000000000000..2c05209149b0 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/OrchestratorVersionProfileListResult.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.ContainerServiceManager; +import com.microsoft.azure.management.containerservice.v2019_08_01.implementation.OrchestratorVersionProfileListResultInner; +import java.util.List; + +/** + * Type representing OrchestratorVersionProfileListResult. + */ +public interface OrchestratorVersionProfileListResult extends HasInner, HasManager { + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the orchestrators value. + */ + List orchestrators(); + + /** + * @return the type value. + */ + String type(); + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/PurchasePlan.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/PurchasePlan.java new file mode 100644 index 000000000000..1c1cdb8210f3 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/PurchasePlan.java @@ -0,0 +1,123 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Used for establishing the purchase context of any 3rd Party artifact through + * MarketPlace. + */ +public class PurchasePlan { + /** + * The plan ID. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Specifies the product of the image from the marketplace. This is the + * same value as Offer under the imageReference element. + */ + @JsonProperty(value = "product") + private String product; + + /** + * The promotion code. + */ + @JsonProperty(value = "promotionCode") + private String promotionCode; + + /** + * The plan ID. + */ + @JsonProperty(value = "publisher") + private String publisher; + + /** + * Get the plan ID. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set the plan ID. + * + * @param name the name value to set + * @return the PurchasePlan object itself. + */ + public PurchasePlan withName(String name) { + this.name = name; + return this; + } + + /** + * Get specifies the product of the image from the marketplace. This is the same value as Offer under the imageReference element. + * + * @return the product value + */ + public String product() { + return this.product; + } + + /** + * Set specifies the product of the image from the marketplace. This is the same value as Offer under the imageReference element. + * + * @param product the product value to set + * @return the PurchasePlan object itself. + */ + public PurchasePlan withProduct(String product) { + this.product = product; + return this; + } + + /** + * Get the promotion code. + * + * @return the promotionCode value + */ + public String promotionCode() { + return this.promotionCode; + } + + /** + * Set the promotion code. + * + * @param promotionCode the promotionCode value to set + * @return the PurchasePlan object itself. + */ + public PurchasePlan withPromotionCode(String promotionCode) { + this.promotionCode = promotionCode; + return this; + } + + /** + * Get the plan ID. + * + * @return the publisher value + */ + public String publisher() { + return this.publisher; + } + + /** + * Set the plan ID. + * + * @param publisher the publisher value to set + * @return the PurchasePlan object itself. + */ + public PurchasePlan withPublisher(String publisher) { + this.publisher = publisher; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ResourceIdentityType.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ResourceIdentityType.java new file mode 100644 index 000000000000..3841dd4dc7c9 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ResourceIdentityType.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for ResourceIdentityType. + */ +public enum ResourceIdentityType { + /** Enum value SystemAssigned. */ + SYSTEM_ASSIGNED("SystemAssigned"), + + /** Enum value None. */ + NONE("None"); + + /** The actual serialized value for a ResourceIdentityType instance. */ + private String value; + + ResourceIdentityType(String value) { + this.value = value; + } + + /** + * Parses a serialized value to a ResourceIdentityType instance. + * + * @param value the serialized value to parse. + * @return the parsed ResourceIdentityType object, or null if unable to parse. + */ + @JsonCreator + public static ResourceIdentityType fromString(String value) { + ResourceIdentityType[] items = ResourceIdentityType.values(); + for (ResourceIdentityType item : items) { + if (item.toString().equalsIgnoreCase(value)) { + return item; + } + } + return null; + } + + @JsonValue + @Override + public String toString() { + return this.value; + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ResourceReference.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ResourceReference.java new file mode 100644 index 000000000000..e88fff982465 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ResourceReference.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A reference to an Azure resource. + */ +public class ResourceReference { + /** + * The fully qualified Azure resource id. + */ + @JsonProperty(value = "id") + private String id; + + /** + * Get the fully qualified Azure resource id. + * + * @return the id value + */ + public String id() { + return this.id; + } + + /** + * Set the fully qualified Azure resource id. + * + * @param id the id value to set + * @return the ResourceReference object itself. + */ + public ResourceReference withId(String id) { + this.id = id; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ScaleSetEvictionPolicy.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ScaleSetEvictionPolicy.java new file mode 100644 index 000000000000..5399e37e8ad7 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ScaleSetEvictionPolicy.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ScaleSetEvictionPolicy. + */ +public final class ScaleSetEvictionPolicy extends ExpandableStringEnum { + /** Static value Delete for ScaleSetEvictionPolicy. */ + public static final ScaleSetEvictionPolicy DELETE = fromString("Delete"); + + /** Static value Deallocate for ScaleSetEvictionPolicy. */ + public static final ScaleSetEvictionPolicy DEALLOCATE = fromString("Deallocate"); + + /** + * Creates or finds a ScaleSetEvictionPolicy from its string representation. + * @param name a name to look for + * @return the corresponding ScaleSetEvictionPolicy + */ + @JsonCreator + public static ScaleSetEvictionPolicy fromString(String name) { + return fromString(name, ScaleSetEvictionPolicy.class); + } + + /** + * @return known ScaleSetEvictionPolicy values + */ + public static Collection values() { + return values(ScaleSetEvictionPolicy.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ScaleSetPriority.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ScaleSetPriority.java new file mode 100644 index 000000000000..bef9422ab4b2 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/ScaleSetPriority.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ScaleSetPriority. + */ +public final class ScaleSetPriority extends ExpandableStringEnum { + /** Static value Low for ScaleSetPriority. */ + public static final ScaleSetPriority LOW = fromString("Low"); + + /** Static value Regular for ScaleSetPriority. */ + public static final ScaleSetPriority REGULAR = fromString("Regular"); + + /** + * Creates or finds a ScaleSetPriority from its string representation. + * @param name a name to look for + * @return the corresponding ScaleSetPriority + */ + @JsonCreator + public static ScaleSetPriority fromString(String name) { + return fromString(name, ScaleSetPriority.class); + } + + /** + * @return known ScaleSetPriority values + */ + public static Collection values() { + return values(ScaleSetPriority.class); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/TagsObject.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/TagsObject.java new file mode 100644 index 000000000000..94a13efa9728 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/TagsObject.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Tags object for patch operations. + */ +public class TagsObject { + /** + * Resource tags. + */ + @JsonProperty(value = "tags") + private Map tags; + + /** + * Get resource tags. + * + * @return the tags value + */ + public Map tags() { + return this.tags; + } + + /** + * Set resource tags. + * + * @param tags the tags value to set + * @return the TagsObject object itself. + */ + public TagsObject withTags(Map tags) { + this.tags = tags; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolAvailableVersionsImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolAvailableVersionsImpl.java new file mode 100644 index 000000000000..f67860dcdf90 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolAvailableVersionsImpl.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolAvailableVersions; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem; + +class AgentPoolAvailableVersionsImpl extends WrapperImpl implements AgentPoolAvailableVersions { + private final ContainerServiceManager manager; + AgentPoolAvailableVersionsImpl(AgentPoolAvailableVersionsInner inner, ContainerServiceManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public List agentPoolVersions() { + return this.inner().agentPoolVersions(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public String type() { + return this.inner().type(); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolAvailableVersionsInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolAvailableVersionsInner.java new file mode 100644 index 000000000000..4679b134d636 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolAvailableVersionsInner.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolAvailableVersionsPropertiesAgentPoolVersionsItem; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * The list of available versions for an agent pool. + */ +@JsonFlatten +public class AgentPoolAvailableVersionsInner { + /** + * Id of the agent pool available versions. + */ + @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY) + private String id; + + /** + * Name of the agent pool available versions. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * Type of the agent pool available versions. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * List of versions available for agent pool. + */ + @JsonProperty(value = "properties.agentPoolVersions") + private List agentPoolVersions; + + /** + * Get id of the agent pool available versions. + * + * @return the id value + */ + public String id() { + return this.id; + } + + /** + * Get name of the agent pool available versions. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get type of the agent pool available versions. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get list of versions available for agent pool. + * + * @return the agentPoolVersions value + */ + public List agentPoolVersions() { + return this.agentPoolVersions; + } + + /** + * Set list of versions available for agent pool. + * + * @param agentPoolVersions the agentPoolVersions value to set + * @return the AgentPoolAvailableVersionsInner object itself. + */ + public AgentPoolAvailableVersionsInner withAgentPoolVersions(List agentPoolVersions) { + this.agentPoolVersions = agentPoolVersions; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolImpl.java new file mode 100644 index 000000000000..3ae98ed95a30 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolImpl.java @@ -0,0 +1,281 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPool; +import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl; +import rx.Observable; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceVMSizeTypes; +import com.microsoft.azure.management.containerservice.v2019_08_01.OSType; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolType; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.ScaleSetPriority; +import com.microsoft.azure.management.containerservice.v2019_08_01.ScaleSetEvictionPolicy; + +class AgentPoolImpl extends CreatableUpdatableImpl implements AgentPool, AgentPool.Definition, AgentPool.Update { + private final ContainerServiceManager manager; + private String resourceGroupName; + private String resourceName; + private String agentPoolName; + + AgentPoolImpl(String name, ContainerServiceManager manager) { + super(name, new AgentPoolInner()); + this.manager = manager; + // Set resource name + this.agentPoolName = name; + // + } + + AgentPoolImpl(AgentPoolInner inner, ContainerServiceManager manager) { + super(inner.name(), inner); + this.manager = manager; + // Set resource name + this.agentPoolName = inner.name(); + // set resource ancestor and positional variables + this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups"); + this.resourceName = IdParsingUtils.getValueFromIdByName(inner.id(), "managedClusters"); + this.agentPoolName = IdParsingUtils.getValueFromIdByName(inner.id(), "agentPools"); + // + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public Observable createResourceAsync() { + AgentPoolsInner client = this.manager().inner().agentPools(); + return client.createOrUpdateAsync(this.resourceGroupName, this.resourceName, this.agentPoolName, this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + AgentPoolsInner client = this.manager().inner().agentPools(); + return client.createOrUpdateAsync(this.resourceGroupName, this.resourceName, this.agentPoolName, this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + AgentPoolsInner client = this.manager().inner().agentPools(); + return client.getAsync(this.resourceGroupName, this.resourceName, this.agentPoolName); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + + @Override + public AgentPoolType agentPoolType() { + return this.inner().agentPoolType(); + } + + @Override + public List availabilityZones() { + return this.inner().availabilityZones(); + } + + @Override + public int count() { + return this.inner().count(); + } + + @Override + public Boolean enableAutoScaling() { + return this.inner().enableAutoScaling(); + } + + @Override + public Boolean enableNodePublicIP() { + return this.inner().enableNodePublicIP(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public Integer maxCount() { + return this.inner().maxCount(); + } + + @Override + public Integer maxPods() { + return this.inner().maxPods(); + } + + @Override + public Integer minCount() { + return this.inner().minCount(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public List nodeTaints() { + return this.inner().nodeTaints(); + } + + @Override + public String orchestratorVersion() { + return this.inner().orchestratorVersion(); + } + + @Override + public Integer osDiskSizeGB() { + return this.inner().osDiskSizeGB(); + } + + @Override + public OSType osType() { + return this.inner().osType(); + } + + @Override + public String provisioningState() { + return this.inner().provisioningState(); + } + + @Override + public ScaleSetEvictionPolicy scaleSetEvictionPolicy() { + return this.inner().scaleSetEvictionPolicy(); + } + + @Override + public ScaleSetPriority scaleSetPriority() { + return this.inner().scaleSetPriority(); + } + + @Override + public String type() { + return this.inner().type(); + } + + @Override + public ContainerServiceVMSizeTypes vmSize() { + return this.inner().vmSize(); + } + + @Override + public String vnetSubnetID() { + return this.inner().vnetSubnetID(); + } + + @Override + public AgentPoolImpl withExistingManagedCluster(String resourceGroupName, String resourceName) { + this.resourceGroupName = resourceGroupName; + this.resourceName = resourceName; + return this; + } + + @Override + public AgentPoolImpl withCount(int count) { + this.inner().withCount(count); + return this; + } + + @Override + public AgentPoolImpl withVmSize(ContainerServiceVMSizeTypes vmSize) { + this.inner().withVmSize(vmSize); + return this; + } + + @Override + public AgentPoolImpl withAgentPoolType(AgentPoolType agentPoolType) { + this.inner().withAgentPoolType(agentPoolType); + return this; + } + + @Override + public AgentPoolImpl withAvailabilityZones(List availabilityZones) { + this.inner().withAvailabilityZones(availabilityZones); + return this; + } + + @Override + public AgentPoolImpl withEnableAutoScaling(Boolean enableAutoScaling) { + this.inner().withEnableAutoScaling(enableAutoScaling); + return this; + } + + @Override + public AgentPoolImpl withEnableNodePublicIP(Boolean enableNodePublicIP) { + this.inner().withEnableNodePublicIP(enableNodePublicIP); + return this; + } + + @Override + public AgentPoolImpl withMaxCount(Integer maxCount) { + this.inner().withMaxCount(maxCount); + return this; + } + + @Override + public AgentPoolImpl withMaxPods(Integer maxPods) { + this.inner().withMaxPods(maxPods); + return this; + } + + @Override + public AgentPoolImpl withMinCount(Integer minCount) { + this.inner().withMinCount(minCount); + return this; + } + + @Override + public AgentPoolImpl withNodeTaints(List nodeTaints) { + this.inner().withNodeTaints(nodeTaints); + return this; + } + + @Override + public AgentPoolImpl withOrchestratorVersion(String orchestratorVersion) { + this.inner().withOrchestratorVersion(orchestratorVersion); + return this; + } + + @Override + public AgentPoolImpl withOsDiskSizeGB(Integer osDiskSizeGB) { + this.inner().withOsDiskSizeGB(osDiskSizeGB); + return this; + } + + @Override + public AgentPoolImpl withOsType(OSType osType) { + this.inner().withOsType(osType); + return this; + } + + @Override + public AgentPoolImpl withScaleSetEvictionPolicy(ScaleSetEvictionPolicy scaleSetEvictionPolicy) { + this.inner().withScaleSetEvictionPolicy(scaleSetEvictionPolicy); + return this; + } + + @Override + public AgentPoolImpl withScaleSetPriority(ScaleSetPriority scaleSetPriority) { + this.inner().withScaleSetPriority(scaleSetPriority); + return this; + } + + @Override + public AgentPoolImpl withVnetSubnetID(String vnetSubnetID) { + this.inner().withVnetSubnetID(vnetSubnetID); + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolInner.java new file mode 100644 index 000000000000..58db15a020ad --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolInner.java @@ -0,0 +1,550 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceVMSizeTypes; +import com.microsoft.azure.management.containerservice.v2019_08_01.OSType; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolType; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.ScaleSetPriority; +import com.microsoft.azure.management.containerservice.v2019_08_01.ScaleSetEvictionPolicy; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.SubResource; + +/** + * Agent Pool. + */ +@JsonFlatten +public class AgentPoolInner extends SubResource { + /** + * Number of agents (VMs) to host docker containers. Allowed values must be + * in the range of 1 to 100 (inclusive). The default value is 1. + */ + @JsonProperty(value = "properties.count", required = true) + private int count; + + /** + * Size of agent VMs. Possible values include: 'Standard_A1', + * 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', + * 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', + * 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', + * 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', + * 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', + * 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', + * 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', + * 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', + * 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', + * 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', + * 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', + * 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', + * 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', + * 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', + * 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', + * 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', + * 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', + * 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', + * 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', + * 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', + * 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', + * 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', + * 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', + * 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', + * 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', + * 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', + * 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', + * 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', + * 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', + * 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', + * 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', + * 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', + * 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', + * 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', + * 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', + * 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', + * 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', + * 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', + * 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', + * 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', + * 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', + * 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', + * 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', + * 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', + * 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', + * 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', + * 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', + * 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', + * 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', + * 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', + * 'Standard_NV6'. + */ + @JsonProperty(value = "properties.vmSize", required = true) + private ContainerServiceVMSizeTypes vmSize; + + /** + * OS Disk Size in GB to be used to specify the disk size for every machine + * in this master/agent pool. If you specify 0, it will apply the default + * osDisk size according to the vmSize specified. + */ + @JsonProperty(value = "properties.osDiskSizeGB") + private Integer osDiskSizeGB; + + /** + * VNet SubnetID specifies the VNet's subnet identifier. + */ + @JsonProperty(value = "properties.vnetSubnetID") + private String vnetSubnetID; + + /** + * Maximum number of pods that can run on a node. + */ + @JsonProperty(value = "properties.maxPods") + private Integer maxPods; + + /** + * OsType to be used to specify os type. Choose from Linux and Windows. + * Default to Linux. Possible values include: 'Linux', 'Windows'. + */ + @JsonProperty(value = "properties.osType") + private OSType osType; + + /** + * Maximum number of nodes for auto-scaling. + */ + @JsonProperty(value = "properties.maxCount") + private Integer maxCount; + + /** + * Minimum number of nodes for auto-scaling. + */ + @JsonProperty(value = "properties.minCount") + private Integer minCount; + + /** + * Whether to enable auto-scaler. + */ + @JsonProperty(value = "properties.enableAutoScaling") + private Boolean enableAutoScaling; + + /** + * AgentPoolType represents types of an agent pool. Possible values + * include: 'VirtualMachineScaleSets', 'AvailabilitySet'. + */ + @JsonProperty(value = "properties.type") + private AgentPoolType agentPoolType; + + /** + * Version of orchestrator specified when creating the managed cluster. + */ + @JsonProperty(value = "properties.orchestratorVersion") + private String orchestratorVersion; + + /** + * The current deployment or provisioning state, which only appears in the + * response. + */ + @JsonProperty(value = "properties.provisioningState", access = JsonProperty.Access.WRITE_ONLY) + private String provisioningState; + + /** + * (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets + * AgentPoolType. + */ + @JsonProperty(value = "properties.availabilityZones") + private List availabilityZones; + + /** + * Enable public IP for nodes. + */ + @JsonProperty(value = "properties.enableNodePublicIP") + private Boolean enableNodePublicIP; + + /** + * ScaleSetPriority to be used to specify virtual machine scale set + * priority. Default to regular. Possible values include: 'Low', 'Regular'. + */ + @JsonProperty(value = "properties.scaleSetPriority") + private ScaleSetPriority scaleSetPriority; + + /** + * ScaleSetEvictionPolicy to be used to specify eviction policy for low + * priority virtual machine scale set. Default to Delete. Possible values + * include: 'Delete', 'Deallocate'. + */ + @JsonProperty(value = "properties.scaleSetEvictionPolicy") + private ScaleSetEvictionPolicy scaleSetEvictionPolicy; + + /** + * Taints added to new nodes during node pool create and scale. For + * example, key=value:NoSchedule. + */ + @JsonProperty(value = "properties.nodeTaints") + private List nodeTaints; + + /** + * The name of the resource that is unique within a resource group. This + * name can be used to access the resource. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * Resource type. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * Get number of agents (VMs) to host docker containers. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @return the count value + */ + public int count() { + return this.count; + } + + /** + * Set number of agents (VMs) to host docker containers. Allowed values must be in the range of 1 to 100 (inclusive). The default value is 1. + * + * @param count the count value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withCount(int count) { + this.count = count; + return this; + } + + /** + * Get size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @return the vmSize value + */ + public ContainerServiceVMSizeTypes vmSize() { + return this.vmSize; + } + + /** + * Set size of agent VMs. Possible values include: 'Standard_A1', 'Standard_A10', 'Standard_A11', 'Standard_A1_v2', 'Standard_A2', 'Standard_A2_v2', 'Standard_A2m_v2', 'Standard_A3', 'Standard_A4', 'Standard_A4_v2', 'Standard_A4m_v2', 'Standard_A5', 'Standard_A6', 'Standard_A7', 'Standard_A8', 'Standard_A8_v2', 'Standard_A8m_v2', 'Standard_A9', 'Standard_B2ms', 'Standard_B2s', 'Standard_B4ms', 'Standard_B8ms', 'Standard_D1', 'Standard_D11', 'Standard_D11_v2', 'Standard_D11_v2_Promo', 'Standard_D12', 'Standard_D12_v2', 'Standard_D12_v2_Promo', 'Standard_D13', 'Standard_D13_v2', 'Standard_D13_v2_Promo', 'Standard_D14', 'Standard_D14_v2', 'Standard_D14_v2_Promo', 'Standard_D15_v2', 'Standard_D16_v3', 'Standard_D16s_v3', 'Standard_D1_v2', 'Standard_D2', 'Standard_D2_v2', 'Standard_D2_v2_Promo', 'Standard_D2_v3', 'Standard_D2s_v3', 'Standard_D3', 'Standard_D32_v3', 'Standard_D32s_v3', 'Standard_D3_v2', 'Standard_D3_v2_Promo', 'Standard_D4', 'Standard_D4_v2', 'Standard_D4_v2_Promo', 'Standard_D4_v3', 'Standard_D4s_v3', 'Standard_D5_v2', 'Standard_D5_v2_Promo', 'Standard_D64_v3', 'Standard_D64s_v3', 'Standard_D8_v3', 'Standard_D8s_v3', 'Standard_DS1', 'Standard_DS11', 'Standard_DS11_v2', 'Standard_DS11_v2_Promo', 'Standard_DS12', 'Standard_DS12_v2', 'Standard_DS12_v2_Promo', 'Standard_DS13', 'Standard_DS13-2_v2', 'Standard_DS13-4_v2', 'Standard_DS13_v2', 'Standard_DS13_v2_Promo', 'Standard_DS14', 'Standard_DS14-4_v2', 'Standard_DS14-8_v2', 'Standard_DS14_v2', 'Standard_DS14_v2_Promo', 'Standard_DS15_v2', 'Standard_DS1_v2', 'Standard_DS2', 'Standard_DS2_v2', 'Standard_DS2_v2_Promo', 'Standard_DS3', 'Standard_DS3_v2', 'Standard_DS3_v2_Promo', 'Standard_DS4', 'Standard_DS4_v2', 'Standard_DS4_v2_Promo', 'Standard_DS5_v2', 'Standard_DS5_v2_Promo', 'Standard_E16_v3', 'Standard_E16s_v3', 'Standard_E2_v3', 'Standard_E2s_v3', 'Standard_E32-16s_v3', 'Standard_E32-8s_v3', 'Standard_E32_v3', 'Standard_E32s_v3', 'Standard_E4_v3', 'Standard_E4s_v3', 'Standard_E64-16s_v3', 'Standard_E64-32s_v3', 'Standard_E64_v3', 'Standard_E64s_v3', 'Standard_E8_v3', 'Standard_E8s_v3', 'Standard_F1', 'Standard_F16', 'Standard_F16s', 'Standard_F16s_v2', 'Standard_F1s', 'Standard_F2', 'Standard_F2s', 'Standard_F2s_v2', 'Standard_F32s_v2', 'Standard_F4', 'Standard_F4s', 'Standard_F4s_v2', 'Standard_F64s_v2', 'Standard_F72s_v2', 'Standard_F8', 'Standard_F8s', 'Standard_F8s_v2', 'Standard_G1', 'Standard_G2', 'Standard_G3', 'Standard_G4', 'Standard_G5', 'Standard_GS1', 'Standard_GS2', 'Standard_GS3', 'Standard_GS4', 'Standard_GS4-4', 'Standard_GS4-8', 'Standard_GS5', 'Standard_GS5-16', 'Standard_GS5-8', 'Standard_H16', 'Standard_H16m', 'Standard_H16mr', 'Standard_H16r', 'Standard_H8', 'Standard_H8m', 'Standard_L16s', 'Standard_L32s', 'Standard_L4s', 'Standard_L8s', 'Standard_M128-32ms', 'Standard_M128-64ms', 'Standard_M128ms', 'Standard_M128s', 'Standard_M64-16ms', 'Standard_M64-32ms', 'Standard_M64ms', 'Standard_M64s', 'Standard_NC12', 'Standard_NC12s_v2', 'Standard_NC12s_v3', 'Standard_NC24', 'Standard_NC24r', 'Standard_NC24rs_v2', 'Standard_NC24rs_v3', 'Standard_NC24s_v2', 'Standard_NC24s_v3', 'Standard_NC6', 'Standard_NC6s_v2', 'Standard_NC6s_v3', 'Standard_ND12s', 'Standard_ND24rs', 'Standard_ND24s', 'Standard_ND6s', 'Standard_NV12', 'Standard_NV24', 'Standard_NV6'. + * + * @param vmSize the vmSize value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withVmSize(ContainerServiceVMSizeTypes vmSize) { + this.vmSize = vmSize; + return this; + } + + /** + * Get oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @return the osDiskSizeGB value + */ + public Integer osDiskSizeGB() { + return this.osDiskSizeGB; + } + + /** + * Set oS Disk Size in GB to be used to specify the disk size for every machine in this master/agent pool. If you specify 0, it will apply the default osDisk size according to the vmSize specified. + * + * @param osDiskSizeGB the osDiskSizeGB value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withOsDiskSizeGB(Integer osDiskSizeGB) { + this.osDiskSizeGB = osDiskSizeGB; + return this; + } + + /** + * Get vNet SubnetID specifies the VNet's subnet identifier. + * + * @return the vnetSubnetID value + */ + public String vnetSubnetID() { + return this.vnetSubnetID; + } + + /** + * Set vNet SubnetID specifies the VNet's subnet identifier. + * + * @param vnetSubnetID the vnetSubnetID value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withVnetSubnetID(String vnetSubnetID) { + this.vnetSubnetID = vnetSubnetID; + return this; + } + + /** + * Get maximum number of pods that can run on a node. + * + * @return the maxPods value + */ + public Integer maxPods() { + return this.maxPods; + } + + /** + * Set maximum number of pods that can run on a node. + * + * @param maxPods the maxPods value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withMaxPods(Integer maxPods) { + this.maxPods = maxPods; + return this; + } + + /** + * Get osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @return the osType value + */ + public OSType osType() { + return this.osType; + } + + /** + * Set osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @param osType the osType value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withOsType(OSType osType) { + this.osType = osType; + return this; + } + + /** + * Get maximum number of nodes for auto-scaling. + * + * @return the maxCount value + */ + public Integer maxCount() { + return this.maxCount; + } + + /** + * Set maximum number of nodes for auto-scaling. + * + * @param maxCount the maxCount value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withMaxCount(Integer maxCount) { + this.maxCount = maxCount; + return this; + } + + /** + * Get minimum number of nodes for auto-scaling. + * + * @return the minCount value + */ + public Integer minCount() { + return this.minCount; + } + + /** + * Set minimum number of nodes for auto-scaling. + * + * @param minCount the minCount value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withMinCount(Integer minCount) { + this.minCount = minCount; + return this; + } + + /** + * Get whether to enable auto-scaler. + * + * @return the enableAutoScaling value + */ + public Boolean enableAutoScaling() { + return this.enableAutoScaling; + } + + /** + * Set whether to enable auto-scaler. + * + * @param enableAutoScaling the enableAutoScaling value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withEnableAutoScaling(Boolean enableAutoScaling) { + this.enableAutoScaling = enableAutoScaling; + return this; + } + + /** + * Get agentPoolType represents types of an agent pool. Possible values include: 'VirtualMachineScaleSets', 'AvailabilitySet'. + * + * @return the agentPoolType value + */ + public AgentPoolType agentPoolType() { + return this.agentPoolType; + } + + /** + * Set agentPoolType represents types of an agent pool. Possible values include: 'VirtualMachineScaleSets', 'AvailabilitySet'. + * + * @param agentPoolType the agentPoolType value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withAgentPoolType(AgentPoolType agentPoolType) { + this.agentPoolType = agentPoolType; + return this; + } + + /** + * Get version of orchestrator specified when creating the managed cluster. + * + * @return the orchestratorVersion value + */ + public String orchestratorVersion() { + return this.orchestratorVersion; + } + + /** + * Set version of orchestrator specified when creating the managed cluster. + * + * @param orchestratorVersion the orchestratorVersion value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withOrchestratorVersion(String orchestratorVersion) { + this.orchestratorVersion = orchestratorVersion; + return this; + } + + /** + * Get the current deployment or provisioning state, which only appears in the response. + * + * @return the provisioningState value + */ + public String provisioningState() { + return this.provisioningState; + } + + /** + * Get (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. + * + * @return the availabilityZones value + */ + public List availabilityZones() { + return this.availabilityZones; + } + + /** + * Set (PREVIEW) Availability zones for nodes. Must use VirtualMachineScaleSets AgentPoolType. + * + * @param availabilityZones the availabilityZones value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withAvailabilityZones(List availabilityZones) { + this.availabilityZones = availabilityZones; + return this; + } + + /** + * Get enable public IP for nodes. + * + * @return the enableNodePublicIP value + */ + public Boolean enableNodePublicIP() { + return this.enableNodePublicIP; + } + + /** + * Set enable public IP for nodes. + * + * @param enableNodePublicIP the enableNodePublicIP value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withEnableNodePublicIP(Boolean enableNodePublicIP) { + this.enableNodePublicIP = enableNodePublicIP; + return this; + } + + /** + * Get scaleSetPriority to be used to specify virtual machine scale set priority. Default to regular. Possible values include: 'Low', 'Regular'. + * + * @return the scaleSetPriority value + */ + public ScaleSetPriority scaleSetPriority() { + return this.scaleSetPriority; + } + + /** + * Set scaleSetPriority to be used to specify virtual machine scale set priority. Default to regular. Possible values include: 'Low', 'Regular'. + * + * @param scaleSetPriority the scaleSetPriority value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withScaleSetPriority(ScaleSetPriority scaleSetPriority) { + this.scaleSetPriority = scaleSetPriority; + return this; + } + + /** + * Get scaleSetEvictionPolicy to be used to specify eviction policy for low priority virtual machine scale set. Default to Delete. Possible values include: 'Delete', 'Deallocate'. + * + * @return the scaleSetEvictionPolicy value + */ + public ScaleSetEvictionPolicy scaleSetEvictionPolicy() { + return this.scaleSetEvictionPolicy; + } + + /** + * Set scaleSetEvictionPolicy to be used to specify eviction policy for low priority virtual machine scale set. Default to Delete. Possible values include: 'Delete', 'Deallocate'. + * + * @param scaleSetEvictionPolicy the scaleSetEvictionPolicy value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withScaleSetEvictionPolicy(ScaleSetEvictionPolicy scaleSetEvictionPolicy) { + this.scaleSetEvictionPolicy = scaleSetEvictionPolicy; + return this; + } + + /** + * Get taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule. + * + * @return the nodeTaints value + */ + public List nodeTaints() { + return this.nodeTaints; + } + + /** + * Set taints added to new nodes during node pool create and scale. For example, key=value:NoSchedule. + * + * @param nodeTaints the nodeTaints value to set + * @return the AgentPoolInner object itself. + */ + public AgentPoolInner withNodeTaints(List nodeTaints) { + this.nodeTaints = nodeTaints; + return this; + } + + /** + * Get the name of the resource that is unique within a resource group. This name can be used to access the resource. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get resource type. + * + * @return the type value + */ + public String type() { + return this.type; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolUpgradeProfileImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolUpgradeProfileImpl.java new file mode 100644 index 000000000000..b268e73755eb --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolUpgradeProfileImpl.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolUpgradeProfile; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.OSType; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolUpgradeProfilePropertiesUpgradesItem; + +class AgentPoolUpgradeProfileImpl extends WrapperImpl implements AgentPoolUpgradeProfile { + private final ContainerServiceManager manager; + AgentPoolUpgradeProfileImpl(AgentPoolUpgradeProfileInner inner, ContainerServiceManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String kubernetesVersion() { + return this.inner().kubernetesVersion(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public OSType osType() { + return this.inner().osType(); + } + + @Override + public String type() { + return this.inner().type(); + } + + @Override + public List upgrades() { + return this.inner().upgrades(); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolUpgradeProfileInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolUpgradeProfileInner.java new file mode 100644 index 000000000000..9a7a068de465 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolUpgradeProfileInner.java @@ -0,0 +1,146 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.OSType; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolUpgradeProfilePropertiesUpgradesItem; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * The list of available upgrades for an agent pool. + */ +@JsonFlatten +public class AgentPoolUpgradeProfileInner { + /** + * Id of the agent pool upgrade profile. + */ + @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY) + private String id; + + /** + * Name of the agent pool upgrade profile. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * Type of the agent pool upgrade profile. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * Kubernetes version (major, minor, patch). + */ + @JsonProperty(value = "properties.kubernetesVersion", required = true) + private String kubernetesVersion; + + /** + * OsType to be used to specify os type. Choose from Linux and Windows. + * Default to Linux. Possible values include: 'Linux', 'Windows'. + */ + @JsonProperty(value = "properties.osType", required = true) + private OSType osType; + + /** + * List of orchestrator types and versions available for upgrade. + */ + @JsonProperty(value = "properties.upgrades") + private List upgrades; + + /** + * Get id of the agent pool upgrade profile. + * + * @return the id value + */ + public String id() { + return this.id; + } + + /** + * Get name of the agent pool upgrade profile. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get type of the agent pool upgrade profile. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get kubernetes version (major, minor, patch). + * + * @return the kubernetesVersion value + */ + public String kubernetesVersion() { + return this.kubernetesVersion; + } + + /** + * Set kubernetes version (major, minor, patch). + * + * @param kubernetesVersion the kubernetesVersion value to set + * @return the AgentPoolUpgradeProfileInner object itself. + */ + public AgentPoolUpgradeProfileInner withKubernetesVersion(String kubernetesVersion) { + this.kubernetesVersion = kubernetesVersion; + return this; + } + + /** + * Get osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @return the osType value + */ + public OSType osType() { + return this.osType; + } + + /** + * Set osType to be used to specify os type. Choose from Linux and Windows. Default to Linux. Possible values include: 'Linux', 'Windows'. + * + * @param osType the osType value to set + * @return the AgentPoolUpgradeProfileInner object itself. + */ + public AgentPoolUpgradeProfileInner withOsType(OSType osType) { + this.osType = osType; + return this; + } + + /** + * Get list of orchestrator types and versions available for upgrade. + * + * @return the upgrades value + */ + public List upgrades() { + return this.upgrades; + } + + /** + * Set list of orchestrator types and versions available for upgrade. + * + * @param upgrades the upgrades value to set + * @return the AgentPoolUpgradeProfileInner object itself. + */ + public AgentPoolUpgradeProfileInner withUpgrades(List upgrades) { + this.upgrades = upgrades; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolsImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolsImpl.java new file mode 100644 index 000000000000..6f67a955bcd2 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolsImpl.java @@ -0,0 +1,111 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools; +import rx.Completable; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPool; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolUpgradeProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPoolAvailableVersions; + +class AgentPoolsImpl extends WrapperImpl implements AgentPools { + private final ContainerServiceManager manager; + + AgentPoolsImpl(ContainerServiceManager manager) { + super(manager.inner().agentPools()); + this.manager = manager; + } + + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public AgentPoolImpl define(String name) { + return wrapModel(name); + } + + private AgentPoolImpl wrapModel(AgentPoolInner inner) { + return new AgentPoolImpl(inner, manager()); + } + + private AgentPoolImpl wrapModel(String name) { + return new AgentPoolImpl(name, this.manager()); + } + + @Override + public Observable listAsync(final String resourceGroupName, final String resourceName) { + AgentPoolsInner client = this.inner(); + return client.listAsync(resourceGroupName, resourceName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public AgentPool call(AgentPoolInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Observable getAsync(String resourceGroupName, String resourceName, String agentPoolName) { + AgentPoolsInner client = this.inner(); + return client.getAsync(resourceGroupName, resourceName, agentPoolName) + .flatMap(new Func1>() { + @Override + public Observable call(AgentPoolInner inner) { + if (inner == null) { + return Observable.empty(); + } else { + return Observable.just((AgentPool)wrapModel(inner)); + } + } + }); + } + + @Override + public Completable deleteAsync(String resourceGroupName, String resourceName, String agentPoolName) { + AgentPoolsInner client = this.inner(); + return client.deleteAsync(resourceGroupName, resourceName, agentPoolName).toCompletable(); + } + + @Override + public Observable getUpgradeProfileAsync(String resourceGroupName, String resourceName, String agentPoolName) { + AgentPoolsInner client = this.inner(); + return client.getUpgradeProfileAsync(resourceGroupName, resourceName, agentPoolName) + .map(new Func1() { + @Override + public AgentPoolUpgradeProfile call(AgentPoolUpgradeProfileInner inner) { + return new AgentPoolUpgradeProfileImpl(inner, manager()); + } + }); + } + + @Override + public Observable getAvailableAgentPoolVersionsAsync(String resourceGroupName, String resourceName, String agentPoolName) { + AgentPoolsInner client = this.inner(); + return client.getAvailableAgentPoolVersionsAsync(resourceGroupName, resourceName, agentPoolName) + .map(new Func1() { + @Override + public AgentPoolAvailableVersions call(AgentPoolAvailableVersionsInner inner) { + return new AgentPoolAvailableVersionsImpl(inner, manager()); + } + }); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolsInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolsInner.java new file mode 100644 index 000000000000..2d49eb40a186 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/AgentPoolsInner.java @@ -0,0 +1,991 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in AgentPools. + */ +public class AgentPoolsInner { + /** The Retrofit service to perform REST calls. */ + private AgentPoolsService service; + /** The service client containing this operation class. */ + private ContainerServiceManagementClientImpl client; + + /** + * Initializes an instance of AgentPoolsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public AgentPoolsInner(Retrofit retrofit, ContainerServiceManagementClientImpl client) { + this.service = retrofit.create(AgentPoolsService.class); + this.client = client; + } + + /** + * The interface defining all the services for AgentPools to be + * used by Retrofit to perform actually REST calls. + */ + interface AgentPoolsService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools list" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools") + Observable> list(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools get" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}") + Observable> get(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("agentPoolName") String agentPoolName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("agentPoolName") String agentPoolName, @Query("api-version") String apiVersion, @Body AgentPoolInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools beginCreateOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}") + Observable> beginCreateOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("agentPoolName") String agentPoolName, @Query("api-version") String apiVersion, @Body AgentPoolInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("agentPoolName") String agentPoolName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools beginDelete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}", method = "DELETE", hasBody = true) + Observable> beginDelete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("agentPoolName") String agentPoolName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools getUpgradeProfile" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}/upgradeProfiles/default") + Observable> getUpgradeProfile(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("agentPoolName") String agentPoolName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools getAvailableAgentPoolVersions" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}/availableAgentPoolVersions") + Observable> getAvailableAgentPoolVersions(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("agentPoolName") String agentPoolName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools listNext" }) + @GET + Observable> listNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<AgentPoolInner> object if successful. + */ + public PagedList list(final String resourceGroupName, final String resourceName) { + ServiceResponse> response = listSinglePageAsync(resourceGroupName, resourceName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listAsync(final String resourceGroupName, final String resourceName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listSinglePageAsync(resourceGroupName, resourceName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<AgentPoolInner> object + */ + public Observable> listAsync(final String resourceGroupName, final String resourceName) { + return listWithServiceResponseAsync(resourceGroupName, resourceName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<AgentPoolInner> object + */ + public Observable>> listWithServiceResponseAsync(final String resourceGroupName, final String resourceName) { + return listSinglePageAsync(resourceGroupName, resourceName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + ServiceResponse> * @param resourceGroupName The name of the resource group. + ServiceResponse> * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<AgentPoolInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync(final String resourceGroupName, final String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.list(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets the agent pool. + * Gets the details of the agent pool by managed cluster and resource group. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the AgentPoolInner object if successful. + */ + public AgentPoolInner get(String resourceGroupName, String resourceName, String agentPoolName) { + return getWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).toBlocking().single().body(); + } + + /** + * Gets the agent pool. + * Gets the details of the agent pool by managed cluster and resource group. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAsync(String resourceGroupName, String resourceName, String agentPoolName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName), serviceCallback); + } + + /** + * Gets the agent pool. + * Gets the details of the agent pool by managed cluster and resource group. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolInner object + */ + public Observable getAsync(String resourceGroupName, String resourceName, String agentPoolName) { + return getWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).map(new Func1, AgentPoolInner>() { + @Override + public AgentPoolInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets the agent pool. + * Gets the details of the agent pool by managed cluster and resource group. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String resourceName, String agentPoolName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (agentPoolName == null) { + throw new IllegalArgumentException("Parameter agentPoolName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.get(this.client.subscriptionId(), resourceGroupName, resourceName, agentPoolName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the AgentPoolInner object if successful. + */ + public AgentPoolInner createOrUpdate(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName, parameters).toBlocking().last().body(); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName, parameters), serviceCallback); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable createOrUpdateAsync(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName, parameters).map(new Func1, AgentPoolInner>() { + @Override + public AgentPoolInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (agentPoolName == null) { + throw new IllegalArgumentException("Parameter agentPoolName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + Observable> observable = service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, resourceName, agentPoolName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the AgentPoolInner object if successful. + */ + public AgentPoolInner beginCreateOrUpdate(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName, parameters).toBlocking().single().body(); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginCreateOrUpdateAsync(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName, parameters), serviceCallback); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolInner object + */ + public Observable beginCreateOrUpdateAsync(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName, parameters).map(new Func1, AgentPoolInner>() { + @Override + public AgentPoolInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates an agent pool. + * Creates or updates an agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param parameters Parameters supplied to the Create or Update an agent pool operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolInner object + */ + public Observable> beginCreateOrUpdateWithServiceResponseAsync(String resourceGroupName, String resourceName, String agentPoolName, AgentPoolInner parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (agentPoolName == null) { + throw new IllegalArgumentException("Parameter agentPoolName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + return service.beginCreateOrUpdate(this.client.subscriptionId(), resourceGroupName, resourceName, agentPoolName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginCreateOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginCreateOrUpdateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(201, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String resourceName, String agentPoolName) { + deleteWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).toBlocking().last().body(); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String resourceName, String agentPoolName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName), serviceCallback); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable deleteAsync(String resourceGroupName, String resourceName, String agentPoolName) { + return deleteWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String resourceName, String agentPoolName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (agentPoolName == null) { + throw new IllegalArgumentException("Parameter agentPoolName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + Observable> observable = service.delete(this.client.subscriptionId(), resourceGroupName, resourceName, agentPoolName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginDelete(String resourceGroupName, String resourceName, String agentPoolName) { + beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).toBlocking().single().body(); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginDeleteAsync(String resourceGroupName, String resourceName, String agentPoolName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName), serviceCallback); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginDeleteAsync(String resourceGroupName, String resourceName, String agentPoolName) { + return beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes an agent pool. + * Deletes the agent pool in the specified managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginDeleteWithServiceResponseAsync(String resourceGroupName, String resourceName, String agentPoolName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (agentPoolName == null) { + throw new IllegalArgumentException("Parameter agentPoolName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.beginDelete(this.client.subscriptionId(), resourceGroupName, resourceName, agentPoolName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginDeleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginDeleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(202, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets upgrade profile for an agent pool. + * Gets the details of the upgrade profile for an agent pool with a specified resource group and managed cluster name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the AgentPoolUpgradeProfileInner object if successful. + */ + public AgentPoolUpgradeProfileInner getUpgradeProfile(String resourceGroupName, String resourceName, String agentPoolName) { + return getUpgradeProfileWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).toBlocking().single().body(); + } + + /** + * Gets upgrade profile for an agent pool. + * Gets the details of the upgrade profile for an agent pool with a specified resource group and managed cluster name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getUpgradeProfileAsync(String resourceGroupName, String resourceName, String agentPoolName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getUpgradeProfileWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName), serviceCallback); + } + + /** + * Gets upgrade profile for an agent pool. + * Gets the details of the upgrade profile for an agent pool with a specified resource group and managed cluster name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolUpgradeProfileInner object + */ + public Observable getUpgradeProfileAsync(String resourceGroupName, String resourceName, String agentPoolName) { + return getUpgradeProfileWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).map(new Func1, AgentPoolUpgradeProfileInner>() { + @Override + public AgentPoolUpgradeProfileInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets upgrade profile for an agent pool. + * Gets the details of the upgrade profile for an agent pool with a specified resource group and managed cluster name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolUpgradeProfileInner object + */ + public Observable> getUpgradeProfileWithServiceResponseAsync(String resourceGroupName, String resourceName, String agentPoolName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (agentPoolName == null) { + throw new IllegalArgumentException("Parameter agentPoolName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.getUpgradeProfile(this.client.subscriptionId(), resourceGroupName, resourceName, agentPoolName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getUpgradeProfileDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getUpgradeProfileDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of supported versions for the specified agent pool. + * Gets a list of supported versions for the specified agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the AgentPoolAvailableVersionsInner object if successful. + */ + public AgentPoolAvailableVersionsInner getAvailableAgentPoolVersions(String resourceGroupName, String resourceName, String agentPoolName) { + return getAvailableAgentPoolVersionsWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).toBlocking().single().body(); + } + + /** + * Gets a list of supported versions for the specified agent pool. + * Gets a list of supported versions for the specified agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAvailableAgentPoolVersionsAsync(String resourceGroupName, String resourceName, String agentPoolName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getAvailableAgentPoolVersionsWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName), serviceCallback); + } + + /** + * Gets a list of supported versions for the specified agent pool. + * Gets a list of supported versions for the specified agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolAvailableVersionsInner object + */ + public Observable getAvailableAgentPoolVersionsAsync(String resourceGroupName, String resourceName, String agentPoolName) { + return getAvailableAgentPoolVersionsWithServiceResponseAsync(resourceGroupName, resourceName, agentPoolName).map(new Func1, AgentPoolAvailableVersionsInner>() { + @Override + public AgentPoolAvailableVersionsInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a list of supported versions for the specified agent pool. + * Gets a list of supported versions for the specified agent pool. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param agentPoolName The name of the agent pool. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the AgentPoolAvailableVersionsInner object + */ + public Observable> getAvailableAgentPoolVersionsWithServiceResponseAsync(String resourceGroupName, String resourceName, String agentPoolName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (agentPoolName == null) { + throw new IllegalArgumentException("Parameter agentPoolName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.getAvailableAgentPoolVersions(this.client.subscriptionId(), resourceGroupName, resourceName, agentPoolName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getAvailableAgentPoolVersionsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getAvailableAgentPoolVersionsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<AgentPoolInner> object if successful. + */ + public PagedList listNext(final String nextPageLink) { + ServiceResponse> response = listNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<AgentPoolInner> object + */ + public Observable> listNextAsync(final String nextPageLink) { + return listNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<AgentPoolInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextPageLink) { + return listNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of agent pools in the specified managed cluster. + * Gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent pool. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<AgentPoolInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceImpl.java new file mode 100644 index 000000000000..7f52bb410d54 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceImpl.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.resources.models.implementation.GroupableResourceCoreImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerService; +import rx.Observable; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceOrchestratorProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceCustomProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceServicePrincipalProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceMasterProfile; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceAgentPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceWindowsProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceLinuxProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceDiagnosticsProfile; + +class ContainerServiceImpl extends GroupableResourceCoreImpl implements ContainerService, ContainerService.Definition, ContainerService.Update { + ContainerServiceImpl(String name, ContainerServiceInner inner, ContainerServiceManager manager) { + super(name, inner, manager); + } + + @Override + public Observable createResourceAsync() { + ContainerServicesInner client = this.manager().inner().containerServices(); + return client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + ContainerServicesInner client = this.manager().inner().containerServices(); + return client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + ContainerServicesInner client = this.manager().inner().containerServices(); + return client.getByResourceGroupAsync(this.resourceGroupName(), this.name()); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + + @Override + public List agentPoolProfiles() { + return this.inner().agentPoolProfiles(); + } + + @Override + public ContainerServiceCustomProfile customProfile() { + return this.inner().customProfile(); + } + + @Override + public ContainerServiceDiagnosticsProfile diagnosticsProfile() { + return this.inner().diagnosticsProfile(); + } + + @Override + public ContainerServiceLinuxProfile linuxProfile() { + return this.inner().linuxProfile(); + } + + @Override + public ContainerServiceMasterProfile masterProfile() { + return this.inner().masterProfile(); + } + + @Override + public ContainerServiceOrchestratorProfile orchestratorProfile() { + return this.inner().orchestratorProfile(); + } + + @Override + public String provisioningState() { + return this.inner().provisioningState(); + } + + @Override + public ContainerServiceServicePrincipalProfile servicePrincipalProfile() { + return this.inner().servicePrincipalProfile(); + } + + @Override + public ContainerServiceWindowsProfile windowsProfile() { + return this.inner().windowsProfile(); + } + + @Override + public ContainerServiceImpl withLinuxProfile(ContainerServiceLinuxProfile linuxProfile) { + this.inner().withLinuxProfile(linuxProfile); + return this; + } + + @Override + public ContainerServiceImpl withMasterProfile(ContainerServiceMasterProfile masterProfile) { + this.inner().withMasterProfile(masterProfile); + return this; + } + + @Override + public ContainerServiceImpl withOrchestratorProfile(ContainerServiceOrchestratorProfile orchestratorProfile) { + this.inner().withOrchestratorProfile(orchestratorProfile); + return this; + } + + @Override + public ContainerServiceImpl withAgentPoolProfiles(List agentPoolProfiles) { + this.inner().withAgentPoolProfiles(agentPoolProfiles); + return this; + } + + @Override + public ContainerServiceImpl withCustomProfile(ContainerServiceCustomProfile customProfile) { + this.inner().withCustomProfile(customProfile); + return this; + } + + @Override + public ContainerServiceImpl withDiagnosticsProfile(ContainerServiceDiagnosticsProfile diagnosticsProfile) { + this.inner().withDiagnosticsProfile(diagnosticsProfile); + return this; + } + + @Override + public ContainerServiceImpl withServicePrincipalProfile(ContainerServiceServicePrincipalProfile servicePrincipalProfile) { + this.inner().withServicePrincipalProfile(servicePrincipalProfile); + return this; + } + + @Override + public ContainerServiceImpl withWindowsProfile(ContainerServiceWindowsProfile windowsProfile) { + this.inner().withWindowsProfile(windowsProfile); + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceInner.java new file mode 100644 index 000000000000..50e68abeed0c --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceInner.java @@ -0,0 +1,255 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceOrchestratorProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceCustomProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceServicePrincipalProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceMasterProfile; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceAgentPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceWindowsProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceLinuxProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceDiagnosticsProfile; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.Resource; + +/** + * Container service. + */ +@JsonFlatten +public class ContainerServiceInner extends Resource { + /** + * The current deployment or provisioning state, which only appears in the + * response. + */ + @JsonProperty(value = "properties.provisioningState", access = JsonProperty.Access.WRITE_ONLY) + private String provisioningState; + + /** + * Profile for the container service orchestrator. + */ + @JsonProperty(value = "properties.orchestratorProfile", required = true) + private ContainerServiceOrchestratorProfile orchestratorProfile; + + /** + * Properties to configure a custom container service cluster. + */ + @JsonProperty(value = "properties.customProfile") + private ContainerServiceCustomProfile customProfile; + + /** + * Information about a service principal identity for the cluster to use + * for manipulating Azure APIs. Exact one of secret or keyVaultSecretRef + * need to be specified. + */ + @JsonProperty(value = "properties.servicePrincipalProfile") + private ContainerServiceServicePrincipalProfile servicePrincipalProfile; + + /** + * Profile for the container service master. + */ + @JsonProperty(value = "properties.masterProfile", required = true) + private ContainerServiceMasterProfile masterProfile; + + /** + * Properties of the agent pool. + */ + @JsonProperty(value = "properties.agentPoolProfiles") + private List agentPoolProfiles; + + /** + * Profile for Windows VMs in the container service cluster. + */ + @JsonProperty(value = "properties.windowsProfile") + private ContainerServiceWindowsProfile windowsProfile; + + /** + * Profile for Linux VMs in the container service cluster. + */ + @JsonProperty(value = "properties.linuxProfile", required = true) + private ContainerServiceLinuxProfile linuxProfile; + + /** + * Profile for diagnostics in the container service cluster. + */ + @JsonProperty(value = "properties.diagnosticsProfile") + private ContainerServiceDiagnosticsProfile diagnosticsProfile; + + /** + * Get the current deployment or provisioning state, which only appears in the response. + * + * @return the provisioningState value + */ + public String provisioningState() { + return this.provisioningState; + } + + /** + * Get profile for the container service orchestrator. + * + * @return the orchestratorProfile value + */ + public ContainerServiceOrchestratorProfile orchestratorProfile() { + return this.orchestratorProfile; + } + + /** + * Set profile for the container service orchestrator. + * + * @param orchestratorProfile the orchestratorProfile value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withOrchestratorProfile(ContainerServiceOrchestratorProfile orchestratorProfile) { + this.orchestratorProfile = orchestratorProfile; + return this; + } + + /** + * Get properties to configure a custom container service cluster. + * + * @return the customProfile value + */ + public ContainerServiceCustomProfile customProfile() { + return this.customProfile; + } + + /** + * Set properties to configure a custom container service cluster. + * + * @param customProfile the customProfile value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withCustomProfile(ContainerServiceCustomProfile customProfile) { + this.customProfile = customProfile; + return this; + } + + /** + * Get information about a service principal identity for the cluster to use for manipulating Azure APIs. Exact one of secret or keyVaultSecretRef need to be specified. + * + * @return the servicePrincipalProfile value + */ + public ContainerServiceServicePrincipalProfile servicePrincipalProfile() { + return this.servicePrincipalProfile; + } + + /** + * Set information about a service principal identity for the cluster to use for manipulating Azure APIs. Exact one of secret or keyVaultSecretRef need to be specified. + * + * @param servicePrincipalProfile the servicePrincipalProfile value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withServicePrincipalProfile(ContainerServiceServicePrincipalProfile servicePrincipalProfile) { + this.servicePrincipalProfile = servicePrincipalProfile; + return this; + } + + /** + * Get profile for the container service master. + * + * @return the masterProfile value + */ + public ContainerServiceMasterProfile masterProfile() { + return this.masterProfile; + } + + /** + * Set profile for the container service master. + * + * @param masterProfile the masterProfile value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withMasterProfile(ContainerServiceMasterProfile masterProfile) { + this.masterProfile = masterProfile; + return this; + } + + /** + * Get properties of the agent pool. + * + * @return the agentPoolProfiles value + */ + public List agentPoolProfiles() { + return this.agentPoolProfiles; + } + + /** + * Set properties of the agent pool. + * + * @param agentPoolProfiles the agentPoolProfiles value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withAgentPoolProfiles(List agentPoolProfiles) { + this.agentPoolProfiles = agentPoolProfiles; + return this; + } + + /** + * Get profile for Windows VMs in the container service cluster. + * + * @return the windowsProfile value + */ + public ContainerServiceWindowsProfile windowsProfile() { + return this.windowsProfile; + } + + /** + * Set profile for Windows VMs in the container service cluster. + * + * @param windowsProfile the windowsProfile value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withWindowsProfile(ContainerServiceWindowsProfile windowsProfile) { + this.windowsProfile = windowsProfile; + return this; + } + + /** + * Get profile for Linux VMs in the container service cluster. + * + * @return the linuxProfile value + */ + public ContainerServiceLinuxProfile linuxProfile() { + return this.linuxProfile; + } + + /** + * Set profile for Linux VMs in the container service cluster. + * + * @param linuxProfile the linuxProfile value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withLinuxProfile(ContainerServiceLinuxProfile linuxProfile) { + this.linuxProfile = linuxProfile; + return this; + } + + /** + * Get profile for diagnostics in the container service cluster. + * + * @return the diagnosticsProfile value + */ + public ContainerServiceDiagnosticsProfile diagnosticsProfile() { + return this.diagnosticsProfile; + } + + /** + * Set profile for diagnostics in the container service cluster. + * + * @param diagnosticsProfile the diagnosticsProfile value to set + * @return the ContainerServiceInner object itself. + */ + public ContainerServiceInner withDiagnosticsProfile(ContainerServiceDiagnosticsProfile diagnosticsProfile) { + this.diagnosticsProfile = diagnosticsProfile; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceManagementClientImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceManagementClientImpl.java new file mode 100644 index 000000000000..0efd97ac21c6 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceManagementClientImpl.java @@ -0,0 +1,239 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.AzureClient; +import com.microsoft.azure.AzureServiceClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; +import com.microsoft.rest.RestClient; + +/** + * Initializes a new instance of the ContainerServiceManagementClientImpl class. + */ +public class ContainerServiceManagementClientImpl extends AzureServiceClient { + /** the {@link AzureClient} used for long running operations. */ + private AzureClient azureClient; + + /** + * Gets the {@link AzureClient} used for long running operations. + * @return the azure client; + */ + public AzureClient getAzureClient() { + return this.azureClient; + } + + /** Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. */ + private String subscriptionId; + + /** + * Gets Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. + * + * @return the subscriptionId value. + */ + public String subscriptionId() { + return this.subscriptionId; + } + + /** + * Sets Subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID forms part of the URI for every service call. + * + * @param subscriptionId the subscriptionId value. + * @return the service client itself + */ + public ContainerServiceManagementClientImpl withSubscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /** The preferred language for the response. */ + private String acceptLanguage; + + /** + * Gets The preferred language for the response. + * + * @return the acceptLanguage value. + */ + public String acceptLanguage() { + return this.acceptLanguage; + } + + /** + * Sets The preferred language for the response. + * + * @param acceptLanguage the acceptLanguage value. + * @return the service client itself + */ + public ContainerServiceManagementClientImpl withAcceptLanguage(String acceptLanguage) { + this.acceptLanguage = acceptLanguage; + return this; + } + + /** The retry timeout in seconds for Long Running Operations. Default value is 30. */ + private int longRunningOperationRetryTimeout; + + /** + * Gets The retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @return the longRunningOperationRetryTimeout value. + */ + public int longRunningOperationRetryTimeout() { + return this.longRunningOperationRetryTimeout; + } + + /** + * Sets The retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @param longRunningOperationRetryTimeout the longRunningOperationRetryTimeout value. + * @return the service client itself + */ + public ContainerServiceManagementClientImpl withLongRunningOperationRetryTimeout(int longRunningOperationRetryTimeout) { + this.longRunningOperationRetryTimeout = longRunningOperationRetryTimeout; + return this; + } + + /** Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. */ + private boolean generateClientRequestId; + + /** + * Gets Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @return the generateClientRequestId value. + */ + public boolean generateClientRequestId() { + return this.generateClientRequestId; + } + + /** + * Sets Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @param generateClientRequestId the generateClientRequestId value. + * @return the service client itself + */ + public ContainerServiceManagementClientImpl withGenerateClientRequestId(boolean generateClientRequestId) { + this.generateClientRequestId = generateClientRequestId; + return this; + } + + /** + * The OpenShiftManagedClustersInner object to access its operations. + */ + private OpenShiftManagedClustersInner openShiftManagedClusters; + + /** + * Gets the OpenShiftManagedClustersInner object to access its operations. + * @return the OpenShiftManagedClustersInner object. + */ + public OpenShiftManagedClustersInner openShiftManagedClusters() { + return this.openShiftManagedClusters; + } + + /** + * The ContainerServicesInner object to access its operations. + */ + private ContainerServicesInner containerServices; + + /** + * Gets the ContainerServicesInner object to access its operations. + * @return the ContainerServicesInner object. + */ + public ContainerServicesInner containerServices() { + return this.containerServices; + } + + /** + * The OperationsInner object to access its operations. + */ + private OperationsInner operations; + + /** + * Gets the OperationsInner object to access its operations. + * @return the OperationsInner object. + */ + public OperationsInner operations() { + return this.operations; + } + + /** + * The ManagedClustersInner object to access its operations. + */ + private ManagedClustersInner managedClusters; + + /** + * Gets the ManagedClustersInner object to access its operations. + * @return the ManagedClustersInner object. + */ + public ManagedClustersInner managedClusters() { + return this.managedClusters; + } + + /** + * The AgentPoolsInner object to access its operations. + */ + private AgentPoolsInner agentPools; + + /** + * Gets the AgentPoolsInner object to access its operations. + * @return the AgentPoolsInner object. + */ + public AgentPoolsInner agentPools() { + return this.agentPools; + } + + /** + * Initializes an instance of ContainerServiceManagementClient client. + * + * @param credentials the management credentials for Azure + */ + public ContainerServiceManagementClientImpl(ServiceClientCredentials credentials) { + this("https://management.azure.com", credentials); + } + + /** + * Initializes an instance of ContainerServiceManagementClient client. + * + * @param baseUrl the base URL of the host + * @param credentials the management credentials for Azure + */ + public ContainerServiceManagementClientImpl(String baseUrl, ServiceClientCredentials credentials) { + super(baseUrl, credentials); + initialize(); + } + + /** + * Initializes an instance of ContainerServiceManagementClient client. + * + * @param restClient the REST client to connect to Azure. + */ + public ContainerServiceManagementClientImpl(RestClient restClient) { + super(restClient); + initialize(); + } + + protected void initialize() { + this.acceptLanguage = "en-US"; + this.longRunningOperationRetryTimeout = 30; + this.generateClientRequestId = true; + this.openShiftManagedClusters = new OpenShiftManagedClustersInner(restClient().retrofit(), this); + this.containerServices = new ContainerServicesInner(restClient().retrofit(), this); + this.operations = new OperationsInner(restClient().retrofit(), this); + this.managedClusters = new ManagedClustersInner(restClient().retrofit(), this); + this.agentPools = new AgentPoolsInner(restClient().retrofit(), this); + this.azureClient = new AzureClient(this); + } + + /** + * Gets the User-Agent header for the client. + * + * @return the user agent string. + */ + @Override + public String userAgent() { + return String.format("%s (%s, %s, auto-generated)", super.userAgent(), "ContainerServiceManagementClient", "2019-08-01"); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceManager.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceManager.java new file mode 100644 index 000000000000..1aeffc149fa1 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServiceManager.java @@ -0,0 +1,147 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.AzureResponseBuilder; +import com.microsoft.azure.credentials.AzureTokenCredentials; +import com.microsoft.azure.management.apigeneration.Beta; +import com.microsoft.azure.management.apigeneration.Beta.SinceVersion; +import com.microsoft.azure.arm.resources.AzureConfigurable; +import com.microsoft.azure.serializer.AzureJacksonAdapter; +import com.microsoft.rest.RestClient; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices; +import com.microsoft.azure.management.containerservice.v2019_08_01.Operations; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters; +import com.microsoft.azure.management.containerservice.v2019_08_01.AgentPools; +import com.microsoft.azure.arm.resources.implementation.AzureConfigurableCoreImpl; +import com.microsoft.azure.arm.resources.implementation.ManagerCore; + +/** + * Entry point to Azure ContainerService resource management. + */ +public final class ContainerServiceManager extends ManagerCore { + private OpenShiftManagedClusters openShiftManagedClusters; + private ContainerServices containerServices; + private Operations operations; + private ManagedClusters managedClusters; + private AgentPools agentPools; + /** + * Get a Configurable instance that can be used to create ContainerServiceManager with optional configuration. + * + * @return the instance allowing configurations + */ + public static Configurable configure() { + return new ContainerServiceManager.ConfigurableImpl(); + } + /** + * Creates an instance of ContainerServiceManager that exposes ContainerService resource management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the ContainerServiceManager + */ + public static ContainerServiceManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new ContainerServiceManager(new RestClient.Builder() + .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) + .withCredentials(credentials) + .withSerializerAdapter(new AzureJacksonAdapter()) + .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) + .build(), subscriptionId); + } + /** + * Creates an instance of ContainerServiceManager that exposes ContainerService resource management API entry points. + * + * @param restClient the RestClient to be used for API calls. + * @param subscriptionId the subscription UUID + * @return the ContainerServiceManager + */ + public static ContainerServiceManager authenticate(RestClient restClient, String subscriptionId) { + return new ContainerServiceManager(restClient, subscriptionId); + } + /** + * The interface allowing configurations to be set. + */ + public interface Configurable extends AzureConfigurable { + /** + * Creates an instance of ContainerServiceManager that exposes ContainerService management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the interface exposing ContainerService management API entry points that work across subscriptions + */ + ContainerServiceManager authenticate(AzureTokenCredentials credentials, String subscriptionId); + } + + /** + * @return Entry point to manage OpenShiftManagedClusters. + */ + public OpenShiftManagedClusters openShiftManagedClusters() { + if (this.openShiftManagedClusters == null) { + this.openShiftManagedClusters = new OpenShiftManagedClustersImpl(this); + } + return this.openShiftManagedClusters; + } + + /** + * @return Entry point to manage ContainerServices. + */ + public ContainerServices containerServices() { + if (this.containerServices == null) { + this.containerServices = new ContainerServicesImpl(this); + } + return this.containerServices; + } + + /** + * @return Entry point to manage Operations. + */ + public Operations operations() { + if (this.operations == null) { + this.operations = new OperationsImpl(this); + } + return this.operations; + } + + /** + * @return Entry point to manage ManagedClusters. + */ + public ManagedClusters managedClusters() { + if (this.managedClusters == null) { + this.managedClusters = new ManagedClustersImpl(this); + } + return this.managedClusters; + } + + /** + * @return Entry point to manage AgentPools. + */ + public AgentPools agentPools() { + if (this.agentPools == null) { + this.agentPools = new AgentPoolsImpl(this); + } + return this.agentPools; + } + + /** + * The implementation for Configurable interface. + */ + private static final class ConfigurableImpl extends AzureConfigurableCoreImpl implements Configurable { + public ContainerServiceManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return ContainerServiceManager.authenticate(buildRestClient(credentials), subscriptionId); + } + } + private ContainerServiceManager(RestClient restClient, String subscriptionId) { + super( + restClient, + subscriptionId, + new ContainerServiceManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServicesImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServicesImpl.java new file mode 100644 index 000000000000..65b24666e335 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServicesImpl.java @@ -0,0 +1,151 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * def + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.resources.collection.implementation.GroupableResourcesCoreImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerService; +import rx.Observable; +import rx.Completable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import com.microsoft.azure.arm.resources.ResourceUtilsCore; +import com.microsoft.azure.arm.utils.RXMapper; +import rx.functions.Func1; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.containerservice.v2019_08_01.OrchestratorVersionProfileListResult; + +class ContainerServicesImpl extends GroupableResourcesCoreImpl implements ContainerServices { + protected ContainerServicesImpl(ContainerServiceManager manager) { + super(manager.inner().containerServices(), manager); + } + + @Override + protected Observable getInnerAsync(String resourceGroupName, String name) { + ContainerServicesInner client = this.inner(); + return client.getByResourceGroupAsync(resourceGroupName, name); + } + + @Override + protected Completable deleteInnerAsync(String resourceGroupName, String name) { + ContainerServicesInner client = this.inner(); + return client.deleteAsync(resourceGroupName, name).toCompletable(); + } + + @Override + public Observable deleteByIdsAsync(Collection ids) { + if (ids == null || ids.isEmpty()) { + return Observable.empty(); + } + Collection> observables = new ArrayList<>(); + for (String id : ids) { + final String resourceGroupName = ResourceUtilsCore.groupFromResourceId(id); + final String name = ResourceUtilsCore.nameFromResourceId(id); + Observable o = RXMapper.map(this.inner().deleteAsync(resourceGroupName, name), id); + observables.add(o); + } + return Observable.mergeDelayError(observables); + } + + @Override + public Observable deleteByIdsAsync(String...ids) { + return this.deleteByIdsAsync(new ArrayList(Arrays.asList(ids))); + } + + @Override + public void deleteByIds(Collection ids) { + if (ids != null && !ids.isEmpty()) { + this.deleteByIdsAsync(ids).toBlocking().last(); + } + } + + @Override + public void deleteByIds(String...ids) { + this.deleteByIds(new ArrayList(Arrays.asList(ids))); + } + + @Override + public PagedList listByResourceGroup(String resourceGroupName) { + ContainerServicesInner client = this.inner(); + return this.wrapList(client.listByResourceGroup(resourceGroupName)); + } + + @Override + public Observable listByResourceGroupAsync(String resourceGroupName) { + ContainerServicesInner client = this.inner(); + return client.listByResourceGroupAsync(resourceGroupName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public ContainerService call(ContainerServiceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public PagedList list() { + ContainerServicesInner client = this.inner(); + return this.wrapList(client.list()); + } + + @Override + public Observable listAsync() { + ContainerServicesInner client = this.inner(); + return client.listAsync() + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public ContainerService call(ContainerServiceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public ContainerServiceImpl define(String name) { + return wrapModel(name); + } + + @Override + protected ContainerServiceImpl wrapModel(ContainerServiceInner inner) { + return new ContainerServiceImpl(inner.name(), inner, manager()); + } + + @Override + protected ContainerServiceImpl wrapModel(String name) { + return new ContainerServiceImpl(name, new ContainerServiceInner(), this.manager()); + } + + @Override + public Observable listOrchestratorsAsync(String location) { + ContainerServicesInner client = this.inner(); + return client.listOrchestratorsAsync(location) + .map(new Func1() { + @Override + public OrchestratorVersionProfileListResult call(OrchestratorVersionProfileListResultInner inner) { + return new OrchestratorVersionProfileListResultImpl(inner, manager()); + } + }); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServicesInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServicesInner.java new file mode 100644 index 000000000000..52f30a818234 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ContainerServicesInner.java @@ -0,0 +1,1152 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.collection.InnerSupportsGet; +import com.microsoft.azure.arm.collection.InnerSupportsDelete; +import com.microsoft.azure.arm.collection.InnerSupportsListing; +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in ContainerServices. + */ +public class ContainerServicesInner implements InnerSupportsGet, InnerSupportsDelete, InnerSupportsListing { + /** The Retrofit service to perform REST calls. */ + private ContainerServicesService service; + /** The service client containing this operation class. */ + private ContainerServiceManagementClientImpl client; + + /** + * Initializes an instance of ContainerServicesInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public ContainerServicesInner(Retrofit retrofit, ContainerServiceManagementClientImpl client) { + this.service = retrofit.create(ContainerServicesService.class); + this.client = client; + } + + /** + * The interface defining all the services for ContainerServices to be + * used by Retrofit to perform actually REST calls. + */ + interface ContainerServicesService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices list" }) + @GET("subscriptions/{subscriptionId}/providers/Microsoft.ContainerService/containerServices") + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}") + Observable> createOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("containerServiceName") String containerServiceName, @Path("subscriptionId") String subscriptionId, @Body ContainerServiceInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices beginCreateOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}") + Observable> beginCreateOrUpdate(@Path("resourceGroupName") String resourceGroupName, @Path("containerServiceName") String containerServiceName, @Path("subscriptionId") String subscriptionId, @Body ContainerServiceInner parameters, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices getByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}") + Observable> getByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("containerServiceName") String containerServiceName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("resourceGroupName") String resourceGroupName, @Path("containerServiceName") String containerServiceName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices beginDelete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}", method = "DELETE", hasBody = true) + Observable> beginDelete(@Path("resourceGroupName") String resourceGroupName, @Path("containerServiceName") String containerServiceName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices listByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices") + Observable> listByResourceGroup(@Path("resourceGroupName") String resourceGroupName, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices listOrchestrators" }) + @GET("subscriptions/{subscriptionId}/providers/Microsoft.ContainerService/locations/{location}/orchestrators") + Observable> listOrchestrators(@Path("subscriptionId") String subscriptionId, @Path("location") String location, @Query("api-version") String apiVersion, @Query("resource-type") String resourceType, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices listNext" }) + @GET + Observable> listNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServices listByResourceGroupNext" }) + @GET + Observable> listByResourceGroupNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ContainerServiceInner> object if successful. + */ + public PagedList list() { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ContainerServiceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String apiVersion = "2017-07-01"; + return service.list(this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ContainerServiceInner object if successful. + */ + public ContainerServiceInner createOrUpdate(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, containerServiceName, parameters).toBlocking().last().body(); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, containerServiceName, parameters), serviceCallback); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable createOrUpdateAsync(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, containerServiceName, parameters).map(new Func1, ContainerServiceInner>() { + @Override + public ContainerServiceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters) { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (containerServiceName == null) { + throw new IllegalArgumentException("Parameter containerServiceName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2017-07-01"; + Observable> observable = service.createOrUpdate(resourceGroupName, containerServiceName, this.client.subscriptionId(), parameters, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ContainerServiceInner object if successful. + */ + public ContainerServiceInner beginCreateOrUpdate(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, containerServiceName, parameters).toBlocking().single().body(); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginCreateOrUpdateAsync(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, containerServiceName, parameters), serviceCallback); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ContainerServiceInner object + */ + public Observable beginCreateOrUpdateAsync(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, containerServiceName, parameters).map(new Func1, ContainerServiceInner>() { + @Override + public ContainerServiceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a container service. + * Creates or updates a container service with the specified configuration of orchestrator, masters, and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param parameters Parameters supplied to the Create or Update a Container Service operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ContainerServiceInner object + */ + public Observable> beginCreateOrUpdateWithServiceResponseAsync(String resourceGroupName, String containerServiceName, ContainerServiceInner parameters) { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (containerServiceName == null) { + throw new IllegalArgumentException("Parameter containerServiceName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2017-07-01"; + return service.beginCreateOrUpdate(resourceGroupName, containerServiceName, this.client.subscriptionId(), parameters, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginCreateOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginCreateOrUpdateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(201, new TypeToken() { }.getType()) + .register(202, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets the properties of the specified container service. + * Gets the properties of the specified container service in the specified subscription and resource group. The operation returns the properties including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ContainerServiceInner object if successful. + */ + public ContainerServiceInner getByResourceGroup(String resourceGroupName, String containerServiceName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, containerServiceName).toBlocking().single().body(); + } + + /** + * Gets the properties of the specified container service. + * Gets the properties of the specified container service in the specified subscription and resource group. The operation returns the properties including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getByResourceGroupAsync(String resourceGroupName, String containerServiceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getByResourceGroupWithServiceResponseAsync(resourceGroupName, containerServiceName), serviceCallback); + } + + /** + * Gets the properties of the specified container service. + * Gets the properties of the specified container service in the specified subscription and resource group. The operation returns the properties including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ContainerServiceInner object + */ + public Observable getByResourceGroupAsync(String resourceGroupName, String containerServiceName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, containerServiceName).map(new Func1, ContainerServiceInner>() { + @Override + public ContainerServiceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets the properties of the specified container service. + * Gets the properties of the specified container service in the specified subscription and resource group. The operation returns the properties including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ContainerServiceInner object + */ + public Observable> getByResourceGroupWithServiceResponseAsync(String resourceGroupName, String containerServiceName) { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (containerServiceName == null) { + throw new IllegalArgumentException("Parameter containerServiceName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String apiVersion = "2017-07-01"; + return service.getByResourceGroup(resourceGroupName, containerServiceName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getByResourceGroupDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String containerServiceName) { + deleteWithServiceResponseAsync(resourceGroupName, containerServiceName).toBlocking().last().body(); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String containerServiceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, containerServiceName), serviceCallback); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable deleteAsync(String resourceGroupName, String containerServiceName) { + return deleteWithServiceResponseAsync(resourceGroupName, containerServiceName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String containerServiceName) { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (containerServiceName == null) { + throw new IllegalArgumentException("Parameter containerServiceName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String apiVersion = "2017-07-01"; + Observable> observable = service.delete(resourceGroupName, containerServiceName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginDelete(String resourceGroupName, String containerServiceName) { + beginDeleteWithServiceResponseAsync(resourceGroupName, containerServiceName).toBlocking().single().body(); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginDeleteAsync(String resourceGroupName, String containerServiceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginDeleteWithServiceResponseAsync(resourceGroupName, containerServiceName), serviceCallback); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginDeleteAsync(String resourceGroupName, String containerServiceName) { + return beginDeleteWithServiceResponseAsync(resourceGroupName, containerServiceName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes the specified container service. + * Deletes the specified container service in the specified subscription and resource group. The operation does not delete other resources created as part of creating a container service, including storage accounts, VMs, and availability sets. All the other resources created with the container service are part of the same resource group and can be deleted individually. + * + * @param resourceGroupName The name of the resource group. + * @param containerServiceName The name of the container service in the specified subscription and resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginDeleteWithServiceResponseAsync(String resourceGroupName, String containerServiceName) { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (containerServiceName == null) { + throw new IllegalArgumentException("Parameter containerServiceName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String apiVersion = "2017-07-01"; + return service.beginDelete(resourceGroupName, containerServiceName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginDeleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginDeleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(202, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ContainerServiceInner> object if successful. + */ + public PagedList listByResourceGroup(final String resourceGroupName) { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupSinglePageAsync(resourceGroupName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName) { + return listByResourceGroupSinglePageAsync(resourceGroupName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + ServiceResponse> * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ContainerServiceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName) { + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String apiVersion = "2017-07-01"; + return service.listByResourceGroup(resourceGroupName, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OrchestratorVersionProfileListResultInner object if successful. + */ + public OrchestratorVersionProfileListResultInner listOrchestrators(String location) { + return listOrchestratorsWithServiceResponseAsync(location).toBlocking().single().body(); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture listOrchestratorsAsync(String location, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(listOrchestratorsWithServiceResponseAsync(location), serviceCallback); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OrchestratorVersionProfileListResultInner object + */ + public Observable listOrchestratorsAsync(String location) { + return listOrchestratorsWithServiceResponseAsync(location).map(new Func1, OrchestratorVersionProfileListResultInner>() { + @Override + public OrchestratorVersionProfileListResultInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OrchestratorVersionProfileListResultInner object + */ + public Observable> listOrchestratorsWithServiceResponseAsync(String location) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (location == null) { + throw new IllegalArgumentException("Parameter location is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + final String resourceType = null; + return service.listOrchestrators(this.client.subscriptionId(), location, apiVersion, resourceType, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = listOrchestratorsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @param resourceType resource type for which the list of orchestrators needs to be returned + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OrchestratorVersionProfileListResultInner object if successful. + */ + public OrchestratorVersionProfileListResultInner listOrchestrators(String location, String resourceType) { + return listOrchestratorsWithServiceResponseAsync(location, resourceType).toBlocking().single().body(); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @param resourceType resource type for which the list of orchestrators needs to be returned + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture listOrchestratorsAsync(String location, String resourceType, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(listOrchestratorsWithServiceResponseAsync(location, resourceType), serviceCallback); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @param resourceType resource type for which the list of orchestrators needs to be returned + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OrchestratorVersionProfileListResultInner object + */ + public Observable listOrchestratorsAsync(String location, String resourceType) { + return listOrchestratorsWithServiceResponseAsync(location, resourceType).map(new Func1, OrchestratorVersionProfileListResultInner>() { + @Override + public OrchestratorVersionProfileListResultInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a list of supported orchestrators in the specified subscription. + * Gets a list of supported orchestrators in the specified subscription. The operation returns properties of each orchestrator including version, available upgrades and whether that version or upgrades are in preview. + * + * @param location The name of a supported Azure region. + * @param resourceType resource type for which the list of orchestrators needs to be returned + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OrchestratorVersionProfileListResultInner object + */ + public Observable> listOrchestratorsWithServiceResponseAsync(String location, String resourceType) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (location == null) { + throw new IllegalArgumentException("Parameter location is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.listOrchestrators(this.client.subscriptionId(), location, apiVersion, resourceType, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = listOrchestratorsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse listOrchestratorsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ContainerServiceInner> object if successful. + */ + public PagedList listNext(final String nextPageLink) { + ServiceResponse> response = listNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable> listNextAsync(final String nextPageLink) { + return listNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextPageLink) { + return listNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of container services in the specified subscription. + * Gets a list of container services in the specified subscription. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ContainerServiceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ContainerServiceInner> object if successful. + */ + public PagedList listByResourceGroupNext(final String nextPageLink) { + ServiceResponse> response = listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable> listByResourceGroupNextAsync(final String nextPageLink) { + return listByResourceGroupNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ContainerServiceInner> object + */ + public Observable>> listByResourceGroupNextWithServiceResponseAsync(final String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of container services in the specified resource group. + * Gets a list of container services in the specified subscription and resource group. The operation returns properties of each container service including state, orchestrator, number of masters and agents, and FQDNs of masters and agents. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ContainerServiceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByResourceGroupNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/CredentialResultsImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/CredentialResultsImpl.java new file mode 100644 index 000000000000..144684ef65bd --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/CredentialResultsImpl.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.CredentialResults; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.CredentialResult; + +class CredentialResultsImpl extends WrapperImpl implements CredentialResults { + private final ContainerServiceManager manager; + CredentialResultsImpl(CredentialResultsInner inner, ContainerServiceManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public List kubeconfigs() { + return this.inner().kubeconfigs(); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/CredentialResultsInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/CredentialResultsInner.java new file mode 100644 index 000000000000..f471226150b5 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/CredentialResultsInner.java @@ -0,0 +1,34 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.CredentialResult; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The list of credential result response. + */ +public class CredentialResultsInner { + /** + * Base64-encoded Kubernetes configuration file. + */ + @JsonProperty(value = "kubeconfigs", access = JsonProperty.Access.WRITE_ONLY) + private List kubeconfigs; + + /** + * Get base64-encoded Kubernetes configuration file. + * + * @return the kubeconfigs value + */ + public List kubeconfigs() { + return this.kubeconfigs; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/IdParsingUtils.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/IdParsingUtils.java new file mode 100644 index 000000000000..428c9011b978 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/IdParsingUtils.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; +import java.util.Arrays; +import java.util.Iterator; + +class IdParsingUtils { + public static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterable iterable = Arrays.asList(id.split("/")); + Iterator itr = iterable.iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && part.trim() != "") { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + public static String getValueFromIdByPosition(String id, int pos) { + if (id == null) { + return null; + } + Iterable iterable = Arrays.asList(id.split("/")); + Iterator itr = iterable.iterator(); + int index = 0; + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && part.trim() != "") { + if (index == pos) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + index++; + } + return null; + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterAccessProfileImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterAccessProfileImpl.java new file mode 100644 index 000000000000..ae8436bfe017 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterAccessProfileImpl.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAccessProfile; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.Map; + +class ManagedClusterAccessProfileImpl extends WrapperImpl implements ManagedClusterAccessProfile { + private final ContainerServiceManager manager; + ManagedClusterAccessProfileImpl(ManagedClusterAccessProfileInner inner, ContainerServiceManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public byte[] kubeConfig() { + return this.inner().kubeConfig(); + } + + @Override + public String location() { + return this.inner().location(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public Map tags() { + return this.inner().getTags(); + } + + @Override + public String type() { + return this.inner().type(); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterAccessProfileInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterAccessProfileInner.java new file mode 100644 index 000000000000..9453e5e1d79c --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterAccessProfileInner.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.Resource; + +/** + * Managed cluster Access Profile. + */ +@JsonFlatten +public class ManagedClusterAccessProfileInner extends Resource { + /** + * Base64-encoded Kubernetes configuration file. + */ + @JsonProperty(value = "properties.kubeConfig") + private byte[] kubeConfig; + + /** + * Get base64-encoded Kubernetes configuration file. + * + * @return the kubeConfig value + */ + public byte[] kubeConfig() { + return this.kubeConfig; + } + + /** + * Set base64-encoded Kubernetes configuration file. + * + * @param kubeConfig the kubeConfig value to set + * @return the ManagedClusterAccessProfileInner object itself. + */ + public ManagedClusterAccessProfileInner withKubeConfig(byte[] kubeConfig) { + this.kubeConfig = kubeConfig; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterImpl.java new file mode 100644 index 000000000000..f08a7c23aae7 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterImpl.java @@ -0,0 +1,226 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.resources.models.implementation.GroupableResourceCoreImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedCluster; +import rx.Observable; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAgentPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceLinuxProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterWindowsProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterServicePrincipalProfile; +import java.util.Map; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAddonProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceNetworkProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAADProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAPIServerAccessProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterIdentity; + +class ManagedClusterImpl extends GroupableResourceCoreImpl implements ManagedCluster, ManagedCluster.Definition, ManagedCluster.Update { + ManagedClusterImpl(String name, ManagedClusterInner inner, ContainerServiceManager manager) { + super(name, inner, manager); + } + + @Override + public Observable createResourceAsync() { + ManagedClustersInner client = this.manager().inner().managedClusters(); + return client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + ManagedClustersInner client = this.manager().inner().managedClusters(); + return client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + ManagedClustersInner client = this.manager().inner().managedClusters(); + return client.getByResourceGroupAsync(this.resourceGroupName(), this.name()); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + + @Override + public ManagedClusterAADProfile aadProfile() { + return this.inner().aadProfile(); + } + + @Override + public Map addonProfiles() { + return this.inner().addonProfiles(); + } + + @Override + public List agentPoolProfiles() { + return this.inner().agentPoolProfiles(); + } + + @Override + public ManagedClusterAPIServerAccessProfile apiServerAccessProfile() { + return this.inner().apiServerAccessProfile(); + } + + @Override + public String dnsPrefix() { + return this.inner().dnsPrefix(); + } + + @Override + public Boolean enablePodSecurityPolicy() { + return this.inner().enablePodSecurityPolicy(); + } + + @Override + public Boolean enableRBAC() { + return this.inner().enableRBAC(); + } + + @Override + public String fqdn() { + return this.inner().fqdn(); + } + + @Override + public ManagedClusterIdentity identity() { + return this.inner().identity(); + } + + @Override + public String kubernetesVersion() { + return this.inner().kubernetesVersion(); + } + + @Override + public ContainerServiceLinuxProfile linuxProfile() { + return this.inner().linuxProfile(); + } + + @Override + public Integer maxAgentPools() { + return this.inner().maxAgentPools(); + } + + @Override + public ContainerServiceNetworkProfile networkProfile() { + return this.inner().networkProfile(); + } + + @Override + public String nodeResourceGroup() { + return this.inner().nodeResourceGroup(); + } + + @Override + public String provisioningState() { + return this.inner().provisioningState(); + } + + @Override + public ManagedClusterServicePrincipalProfile servicePrincipalProfile() { + return this.inner().servicePrincipalProfile(); + } + + @Override + public ManagedClusterWindowsProfile windowsProfile() { + return this.inner().windowsProfile(); + } + + @Override + public ManagedClusterImpl withAadProfile(ManagedClusterAADProfile aadProfile) { + this.inner().withAadProfile(aadProfile); + return this; + } + + @Override + public ManagedClusterImpl withAddonProfiles(Map addonProfiles) { + this.inner().withAddonProfiles(addonProfiles); + return this; + } + + @Override + public ManagedClusterImpl withAgentPoolProfiles(List agentPoolProfiles) { + this.inner().withAgentPoolProfiles(agentPoolProfiles); + return this; + } + + @Override + public ManagedClusterImpl withApiServerAccessProfile(ManagedClusterAPIServerAccessProfile apiServerAccessProfile) { + this.inner().withApiServerAccessProfile(apiServerAccessProfile); + return this; + } + + @Override + public ManagedClusterImpl withDnsPrefix(String dnsPrefix) { + this.inner().withDnsPrefix(dnsPrefix); + return this; + } + + @Override + public ManagedClusterImpl withEnablePodSecurityPolicy(Boolean enablePodSecurityPolicy) { + this.inner().withEnablePodSecurityPolicy(enablePodSecurityPolicy); + return this; + } + + @Override + public ManagedClusterImpl withEnableRBAC(Boolean enableRBAC) { + this.inner().withEnableRBAC(enableRBAC); + return this; + } + + @Override + public ManagedClusterImpl withIdentity(ManagedClusterIdentity identity) { + this.inner().withIdentity(identity); + return this; + } + + @Override + public ManagedClusterImpl withKubernetesVersion(String kubernetesVersion) { + this.inner().withKubernetesVersion(kubernetesVersion); + return this; + } + + @Override + public ManagedClusterImpl withLinuxProfile(ContainerServiceLinuxProfile linuxProfile) { + this.inner().withLinuxProfile(linuxProfile); + return this; + } + + @Override + public ManagedClusterImpl withNetworkProfile(ContainerServiceNetworkProfile networkProfile) { + this.inner().withNetworkProfile(networkProfile); + return this; + } + + @Override + public ManagedClusterImpl withNodeResourceGroup(String nodeResourceGroup) { + this.inner().withNodeResourceGroup(nodeResourceGroup); + return this; + } + + @Override + public ManagedClusterImpl withServicePrincipalProfile(ManagedClusterServicePrincipalProfile servicePrincipalProfile) { + this.inner().withServicePrincipalProfile(servicePrincipalProfile); + return this; + } + + @Override + public ManagedClusterImpl withWindowsProfile(ManagedClusterWindowsProfile windowsProfile) { + this.inner().withWindowsProfile(windowsProfile); + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterInner.java new file mode 100644 index 000000000000..e7b1429b16b7 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterInner.java @@ -0,0 +1,442 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAgentPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceLinuxProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterWindowsProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterServicePrincipalProfile; +import java.util.Map; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAddonProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ContainerServiceNetworkProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAADProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAPIServerAccessProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterIdentity; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.Resource; + +/** + * Managed cluster. + */ +@JsonFlatten +public class ManagedClusterInner extends Resource { + /** + * The current deployment or provisioning state, which only appears in the + * response. + */ + @JsonProperty(value = "properties.provisioningState", access = JsonProperty.Access.WRITE_ONLY) + private String provisioningState; + + /** + * The max number of agent pools for the managed cluster. + */ + @JsonProperty(value = "properties.maxAgentPools", access = JsonProperty.Access.WRITE_ONLY) + private Integer maxAgentPools; + + /** + * Version of Kubernetes specified when creating the managed cluster. + */ + @JsonProperty(value = "properties.kubernetesVersion") + private String kubernetesVersion; + + /** + * DNS prefix specified when creating the managed cluster. + */ + @JsonProperty(value = "properties.dnsPrefix") + private String dnsPrefix; + + /** + * FQDN for the master pool. + */ + @JsonProperty(value = "properties.fqdn", access = JsonProperty.Access.WRITE_ONLY) + private String fqdn; + + /** + * Properties of the agent pool. + */ + @JsonProperty(value = "properties.agentPoolProfiles") + private List agentPoolProfiles; + + /** + * Profile for Linux VMs in the container service cluster. + */ + @JsonProperty(value = "properties.linuxProfile") + private ContainerServiceLinuxProfile linuxProfile; + + /** + * Profile for Windows VMs in the container service cluster. + */ + @JsonProperty(value = "properties.windowsProfile") + private ManagedClusterWindowsProfile windowsProfile; + + /** + * Information about a service principal identity for the cluster to use + * for manipulating Azure APIs. + */ + @JsonProperty(value = "properties.servicePrincipalProfile") + private ManagedClusterServicePrincipalProfile servicePrincipalProfile; + + /** + * Profile of managed cluster add-on. + */ + @JsonProperty(value = "properties.addonProfiles") + private Map addonProfiles; + + /** + * Name of the resource group containing agent pool nodes. + */ + @JsonProperty(value = "properties.nodeResourceGroup") + private String nodeResourceGroup; + + /** + * Whether to enable Kubernetes Role-Based Access Control. + */ + @JsonProperty(value = "properties.enableRBAC") + private Boolean enableRBAC; + + /** + * (PREVIEW) Whether to enable Kubernetes Pod security policy. + */ + @JsonProperty(value = "properties.enablePodSecurityPolicy") + private Boolean enablePodSecurityPolicy; + + /** + * Profile of network configuration. + */ + @JsonProperty(value = "properties.networkProfile") + private ContainerServiceNetworkProfile networkProfile; + + /** + * Profile of Azure Active Directory configuration. + */ + @JsonProperty(value = "properties.aadProfile") + private ManagedClusterAADProfile aadProfile; + + /** + * Access profile for managed cluster API server. + */ + @JsonProperty(value = "properties.apiServerAccessProfile") + private ManagedClusterAPIServerAccessProfile apiServerAccessProfile; + + /** + * The identity of the managed cluster, if configured. + */ + @JsonProperty(value = "identity") + private ManagedClusterIdentity identity; + + /** + * Get the current deployment or provisioning state, which only appears in the response. + * + * @return the provisioningState value + */ + public String provisioningState() { + return this.provisioningState; + } + + /** + * Get the max number of agent pools for the managed cluster. + * + * @return the maxAgentPools value + */ + public Integer maxAgentPools() { + return this.maxAgentPools; + } + + /** + * Get version of Kubernetes specified when creating the managed cluster. + * + * @return the kubernetesVersion value + */ + public String kubernetesVersion() { + return this.kubernetesVersion; + } + + /** + * Set version of Kubernetes specified when creating the managed cluster. + * + * @param kubernetesVersion the kubernetesVersion value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withKubernetesVersion(String kubernetesVersion) { + this.kubernetesVersion = kubernetesVersion; + return this; + } + + /** + * Get dNS prefix specified when creating the managed cluster. + * + * @return the dnsPrefix value + */ + public String dnsPrefix() { + return this.dnsPrefix; + } + + /** + * Set dNS prefix specified when creating the managed cluster. + * + * @param dnsPrefix the dnsPrefix value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withDnsPrefix(String dnsPrefix) { + this.dnsPrefix = dnsPrefix; + return this; + } + + /** + * Get fQDN for the master pool. + * + * @return the fqdn value + */ + public String fqdn() { + return this.fqdn; + } + + /** + * Get properties of the agent pool. + * + * @return the agentPoolProfiles value + */ + public List agentPoolProfiles() { + return this.agentPoolProfiles; + } + + /** + * Set properties of the agent pool. + * + * @param agentPoolProfiles the agentPoolProfiles value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withAgentPoolProfiles(List agentPoolProfiles) { + this.agentPoolProfiles = agentPoolProfiles; + return this; + } + + /** + * Get profile for Linux VMs in the container service cluster. + * + * @return the linuxProfile value + */ + public ContainerServiceLinuxProfile linuxProfile() { + return this.linuxProfile; + } + + /** + * Set profile for Linux VMs in the container service cluster. + * + * @param linuxProfile the linuxProfile value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withLinuxProfile(ContainerServiceLinuxProfile linuxProfile) { + this.linuxProfile = linuxProfile; + return this; + } + + /** + * Get profile for Windows VMs in the container service cluster. + * + * @return the windowsProfile value + */ + public ManagedClusterWindowsProfile windowsProfile() { + return this.windowsProfile; + } + + /** + * Set profile for Windows VMs in the container service cluster. + * + * @param windowsProfile the windowsProfile value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withWindowsProfile(ManagedClusterWindowsProfile windowsProfile) { + this.windowsProfile = windowsProfile; + return this; + } + + /** + * Get information about a service principal identity for the cluster to use for manipulating Azure APIs. + * + * @return the servicePrincipalProfile value + */ + public ManagedClusterServicePrincipalProfile servicePrincipalProfile() { + return this.servicePrincipalProfile; + } + + /** + * Set information about a service principal identity for the cluster to use for manipulating Azure APIs. + * + * @param servicePrincipalProfile the servicePrincipalProfile value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withServicePrincipalProfile(ManagedClusterServicePrincipalProfile servicePrincipalProfile) { + this.servicePrincipalProfile = servicePrincipalProfile; + return this; + } + + /** + * Get profile of managed cluster add-on. + * + * @return the addonProfiles value + */ + public Map addonProfiles() { + return this.addonProfiles; + } + + /** + * Set profile of managed cluster add-on. + * + * @param addonProfiles the addonProfiles value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withAddonProfiles(Map addonProfiles) { + this.addonProfiles = addonProfiles; + return this; + } + + /** + * Get name of the resource group containing agent pool nodes. + * + * @return the nodeResourceGroup value + */ + public String nodeResourceGroup() { + return this.nodeResourceGroup; + } + + /** + * Set name of the resource group containing agent pool nodes. + * + * @param nodeResourceGroup the nodeResourceGroup value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withNodeResourceGroup(String nodeResourceGroup) { + this.nodeResourceGroup = nodeResourceGroup; + return this; + } + + /** + * Get whether to enable Kubernetes Role-Based Access Control. + * + * @return the enableRBAC value + */ + public Boolean enableRBAC() { + return this.enableRBAC; + } + + /** + * Set whether to enable Kubernetes Role-Based Access Control. + * + * @param enableRBAC the enableRBAC value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withEnableRBAC(Boolean enableRBAC) { + this.enableRBAC = enableRBAC; + return this; + } + + /** + * Get (PREVIEW) Whether to enable Kubernetes Pod security policy. + * + * @return the enablePodSecurityPolicy value + */ + public Boolean enablePodSecurityPolicy() { + return this.enablePodSecurityPolicy; + } + + /** + * Set (PREVIEW) Whether to enable Kubernetes Pod security policy. + * + * @param enablePodSecurityPolicy the enablePodSecurityPolicy value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withEnablePodSecurityPolicy(Boolean enablePodSecurityPolicy) { + this.enablePodSecurityPolicy = enablePodSecurityPolicy; + return this; + } + + /** + * Get profile of network configuration. + * + * @return the networkProfile value + */ + public ContainerServiceNetworkProfile networkProfile() { + return this.networkProfile; + } + + /** + * Set profile of network configuration. + * + * @param networkProfile the networkProfile value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withNetworkProfile(ContainerServiceNetworkProfile networkProfile) { + this.networkProfile = networkProfile; + return this; + } + + /** + * Get profile of Azure Active Directory configuration. + * + * @return the aadProfile value + */ + public ManagedClusterAADProfile aadProfile() { + return this.aadProfile; + } + + /** + * Set profile of Azure Active Directory configuration. + * + * @param aadProfile the aadProfile value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withAadProfile(ManagedClusterAADProfile aadProfile) { + this.aadProfile = aadProfile; + return this; + } + + /** + * Get access profile for managed cluster API server. + * + * @return the apiServerAccessProfile value + */ + public ManagedClusterAPIServerAccessProfile apiServerAccessProfile() { + return this.apiServerAccessProfile; + } + + /** + * Set access profile for managed cluster API server. + * + * @param apiServerAccessProfile the apiServerAccessProfile value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withApiServerAccessProfile(ManagedClusterAPIServerAccessProfile apiServerAccessProfile) { + this.apiServerAccessProfile = apiServerAccessProfile; + return this; + } + + /** + * Get the identity of the managed cluster, if configured. + * + * @return the identity value + */ + public ManagedClusterIdentity identity() { + return this.identity; + } + + /** + * Set the identity of the managed cluster, if configured. + * + * @param identity the identity value to set + * @return the ManagedClusterInner object itself. + */ + public ManagedClusterInner withIdentity(ManagedClusterIdentity identity) { + this.identity = identity; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterUpgradeProfileImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterUpgradeProfileImpl.java new file mode 100644 index 000000000000..e4a1384e60da --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterUpgradeProfileImpl.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterUpgradeProfile; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterPoolUpgradeProfile; + +class ManagedClusterUpgradeProfileImpl extends WrapperImpl implements ManagedClusterUpgradeProfile { + private final ContainerServiceManager manager; + ManagedClusterUpgradeProfileImpl(ManagedClusterUpgradeProfileInner inner, ContainerServiceManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public List agentPoolProfiles() { + return this.inner().agentPoolProfiles(); + } + + @Override + public ManagedClusterPoolUpgradeProfile controlPlaneProfile() { + return this.inner().controlPlaneProfile(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public String type() { + return this.inner().type(); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterUpgradeProfileInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterUpgradeProfileInner.java new file mode 100644 index 000000000000..4a41fd0b7529 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClusterUpgradeProfileInner.java @@ -0,0 +1,118 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterPoolUpgradeProfile; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * The list of available upgrades for compute pools. + */ +@JsonFlatten +public class ManagedClusterUpgradeProfileInner { + /** + * Id of upgrade profile. + */ + @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY) + private String id; + + /** + * Name of upgrade profile. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * Type of upgrade profile. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * The list of available upgrade versions for the control plane. + */ + @JsonProperty(value = "properties.controlPlaneProfile", required = true) + private ManagedClusterPoolUpgradeProfile controlPlaneProfile; + + /** + * The list of available upgrade versions for agent pools. + */ + @JsonProperty(value = "properties.agentPoolProfiles", required = true) + private List agentPoolProfiles; + + /** + * Get id of upgrade profile. + * + * @return the id value + */ + public String id() { + return this.id; + } + + /** + * Get name of upgrade profile. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get type of upgrade profile. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get the list of available upgrade versions for the control plane. + * + * @return the controlPlaneProfile value + */ + public ManagedClusterPoolUpgradeProfile controlPlaneProfile() { + return this.controlPlaneProfile; + } + + /** + * Set the list of available upgrade versions for the control plane. + * + * @param controlPlaneProfile the controlPlaneProfile value to set + * @return the ManagedClusterUpgradeProfileInner object itself. + */ + public ManagedClusterUpgradeProfileInner withControlPlaneProfile(ManagedClusterPoolUpgradeProfile controlPlaneProfile) { + this.controlPlaneProfile = controlPlaneProfile; + return this; + } + + /** + * Get the list of available upgrade versions for agent pools. + * + * @return the agentPoolProfiles value + */ + public List agentPoolProfiles() { + return this.agentPoolProfiles; + } + + /** + * Set the list of available upgrade versions for agent pools. + * + * @param agentPoolProfiles the agentPoolProfiles value to set + * @return the ManagedClusterUpgradeProfileInner object itself. + */ + public ManagedClusterUpgradeProfileInner withAgentPoolProfiles(List agentPoolProfiles) { + this.agentPoolProfiles = agentPoolProfiles; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClustersImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClustersImpl.java new file mode 100644 index 000000000000..759e3566bf0d --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClustersImpl.java @@ -0,0 +1,203 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * def + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.resources.collection.implementation.GroupableResourcesCoreImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedCluster; +import rx.Observable; +import rx.Completable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import com.microsoft.azure.arm.resources.ResourceUtilsCore; +import com.microsoft.azure.arm.utils.RXMapper; +import rx.functions.Func1; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.containerservice.v2019_08_01.CredentialResults; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterServicePrincipalProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAADProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterUpgradeProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAccessProfile; + +class ManagedClustersImpl extends GroupableResourcesCoreImpl implements ManagedClusters { + protected ManagedClustersImpl(ContainerServiceManager manager) { + super(manager.inner().managedClusters(), manager); + } + + @Override + protected Observable getInnerAsync(String resourceGroupName, String name) { + ManagedClustersInner client = this.inner(); + return client.getByResourceGroupAsync(resourceGroupName, name); + } + + @Override + protected Completable deleteInnerAsync(String resourceGroupName, String name) { + ManagedClustersInner client = this.inner(); + return client.deleteAsync(resourceGroupName, name).toCompletable(); + } + + @Override + public Observable deleteByIdsAsync(Collection ids) { + if (ids == null || ids.isEmpty()) { + return Observable.empty(); + } + Collection> observables = new ArrayList<>(); + for (String id : ids) { + final String resourceGroupName = ResourceUtilsCore.groupFromResourceId(id); + final String name = ResourceUtilsCore.nameFromResourceId(id); + Observable o = RXMapper.map(this.inner().deleteAsync(resourceGroupName, name), id); + observables.add(o); + } + return Observable.mergeDelayError(observables); + } + + @Override + public Observable deleteByIdsAsync(String...ids) { + return this.deleteByIdsAsync(new ArrayList(Arrays.asList(ids))); + } + + @Override + public void deleteByIds(Collection ids) { + if (ids != null && !ids.isEmpty()) { + this.deleteByIdsAsync(ids).toBlocking().last(); + } + } + + @Override + public void deleteByIds(String...ids) { + this.deleteByIds(new ArrayList(Arrays.asList(ids))); + } + + @Override + public PagedList listByResourceGroup(String resourceGroupName) { + ManagedClustersInner client = this.inner(); + return this.wrapList(client.listByResourceGroup(resourceGroupName)); + } + + @Override + public Observable listByResourceGroupAsync(String resourceGroupName) { + ManagedClustersInner client = this.inner(); + return client.listByResourceGroupAsync(resourceGroupName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public ManagedCluster call(ManagedClusterInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public PagedList list() { + ManagedClustersInner client = this.inner(); + return this.wrapList(client.list()); + } + + @Override + public Observable listAsync() { + ManagedClustersInner client = this.inner(); + return client.listAsync() + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public ManagedCluster call(ManagedClusterInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public ManagedClusterImpl define(String name) { + return wrapModel(name); + } + + @Override + public Observable listClusterAdminCredentialsAsync(String resourceGroupName, String resourceName) { + ManagedClustersInner client = this.inner(); + return client.listClusterAdminCredentialsAsync(resourceGroupName, resourceName) + .map(new Func1() { + @Override + public CredentialResults call(CredentialResultsInner inner) { + return new CredentialResultsImpl(inner, manager()); + } + }); + } + + @Override + public Observable listClusterUserCredentialsAsync(String resourceGroupName, String resourceName) { + ManagedClustersInner client = this.inner(); + return client.listClusterUserCredentialsAsync(resourceGroupName, resourceName) + .map(new Func1() { + @Override + public CredentialResults call(CredentialResultsInner inner) { + return new CredentialResultsImpl(inner, manager()); + } + }); + } + + @Override + public Completable resetServicePrincipalProfileAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters) { + ManagedClustersInner client = this.inner(); + return client.resetServicePrincipalProfileAsync(resourceGroupName, resourceName, parameters).toCompletable(); + } + + @Override + public Completable resetAADProfileAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters) { + ManagedClustersInner client = this.inner(); + return client.resetAADProfileAsync(resourceGroupName, resourceName, parameters).toCompletable(); + } + + @Override + protected ManagedClusterImpl wrapModel(ManagedClusterInner inner) { + return new ManagedClusterImpl(inner.name(), inner, manager()); + } + + @Override + protected ManagedClusterImpl wrapModel(String name) { + return new ManagedClusterImpl(name, new ManagedClusterInner(), this.manager()); + } + + @Override + public Observable getUpgradeProfileAsync(String resourceGroupName, String resourceName) { + ManagedClustersInner client = this.inner(); + return client.getUpgradeProfileAsync(resourceGroupName, resourceName) + .map(new Func1() { + @Override + public ManagedClusterUpgradeProfile call(ManagedClusterUpgradeProfileInner inner) { + return new ManagedClusterUpgradeProfileImpl(inner, manager()); + } + }); + } + + @Override + public Observable getAccessProfileAsync(String resourceGroupName, String resourceName, String roleName) { + ManagedClustersInner client = this.inner(); + return client.getAccessProfileAsync(resourceGroupName, resourceName, roleName) + .map(new Func1() { + @Override + public ManagedClusterAccessProfile call(ManagedClusterAccessProfileInner inner) { + return new ManagedClusterAccessProfileImpl(inner, manager()); + } + }); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClustersInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClustersInner.java new file mode 100644 index 000000000000..901b6f03105f --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/ManagedClustersInner.java @@ -0,0 +1,2070 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.collection.InnerSupportsGet; +import com.microsoft.azure.arm.collection.InnerSupportsDelete; +import com.microsoft.azure.arm.collection.InnerSupportsListing; +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterAADProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusterServicePrincipalProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.TagsObject; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in ManagedClusters. + */ +public class ManagedClustersInner implements InnerSupportsGet, InnerSupportsDelete, InnerSupportsListing { + /** The Retrofit service to perform REST calls. */ + private ManagedClustersService service; + /** The service client containing this operation class. */ + private ContainerServiceManagementClientImpl client; + + /** + * Initializes an instance of ManagedClustersInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public ManagedClustersInner(Retrofit retrofit, ContainerServiceManagementClientImpl client) { + this.service = retrofit.create(ManagedClustersService.class); + this.client = client; + } + + /** + * The interface defining all the services for ManagedClusters to be + * used by Retrofit to perform actually REST calls. + */ + interface ManagedClustersService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters list" }) + @GET("subscriptions/{subscriptionId}/providers/Microsoft.ContainerService/managedClusters") + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters listByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters") + Observable> listByResourceGroup(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters getUpgradeProfile" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/upgradeProfiles/default") + Observable> getUpgradeProfile(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters getAccessProfile" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/accessProfiles/{roleName}/listCredential") + Observable> getAccessProfile(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Path("roleName") String roleName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters listClusterAdminCredentials" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterAdminCredential") + Observable> listClusterAdminCredentials(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters listClusterUserCredentials" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/listClusterUserCredential") + Observable> listClusterUserCredentials(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters getByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}") + Observable> getByResourceGroup(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body ManagedClusterInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters beginCreateOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}") + Observable> beginCreateOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body ManagedClusterInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters updateTags" }) + @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}") + Observable> updateTags(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body TagsObject parameters, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters beginUpdateTags" }) + @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}") + Observable> beginUpdateTags(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body TagsObject parameters, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters beginDelete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}", method = "DELETE", hasBody = true) + Observable> beginDelete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters resetServicePrincipalProfile" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/resetServicePrincipalProfile") + Observable> resetServicePrincipalProfile(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body ManagedClusterServicePrincipalProfile parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters beginResetServicePrincipalProfile" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/resetServicePrincipalProfile") + Observable> beginResetServicePrincipalProfile(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body ManagedClusterServicePrincipalProfile parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters resetAADProfile" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/resetAADProfile") + Observable> resetAADProfile(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body ManagedClusterAADProfile parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters beginResetAADProfile" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/resetAADProfile") + Observable> beginResetAADProfile(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body ManagedClusterAADProfile parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters listNext" }) + @GET + Observable> listNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.ManagedClusters listByResourceGroupNext" }) + @GET + Observable> listByResourceGroupNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ManagedClusterInner> object if successful. + */ + public PagedList list() { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.list(this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ManagedClusterInner> object if successful. + */ + public PagedList listByResourceGroup(final String resourceGroupName) { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupSinglePageAsync(resourceGroupName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName) { + return listByResourceGroupSinglePageAsync(resourceGroupName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + ServiceResponse> * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.listByResourceGroup(this.client.subscriptionId(), resourceGroupName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets upgrade profile for a managed cluster. + * Gets the details of the upgrade profile for a managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterUpgradeProfileInner object if successful. + */ + public ManagedClusterUpgradeProfileInner getUpgradeProfile(String resourceGroupName, String resourceName) { + return getUpgradeProfileWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Gets upgrade profile for a managed cluster. + * Gets the details of the upgrade profile for a managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getUpgradeProfileAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getUpgradeProfileWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Gets upgrade profile for a managed cluster. + * Gets the details of the upgrade profile for a managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterUpgradeProfileInner object + */ + public Observable getUpgradeProfileAsync(String resourceGroupName, String resourceName) { + return getUpgradeProfileWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, ManagedClusterUpgradeProfileInner>() { + @Override + public ManagedClusterUpgradeProfileInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets upgrade profile for a managed cluster. + * Gets the details of the upgrade profile for a managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterUpgradeProfileInner object + */ + public Observable> getUpgradeProfileWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.getUpgradeProfile(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getUpgradeProfileDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getUpgradeProfileDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets an access profile of a managed cluster. + * Gets the accessProfile for the specified role name of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param roleName The name of the role for managed cluster accessProfile resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterAccessProfileInner object if successful. + */ + public ManagedClusterAccessProfileInner getAccessProfile(String resourceGroupName, String resourceName, String roleName) { + return getAccessProfileWithServiceResponseAsync(resourceGroupName, resourceName, roleName).toBlocking().single().body(); + } + + /** + * Gets an access profile of a managed cluster. + * Gets the accessProfile for the specified role name of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param roleName The name of the role for managed cluster accessProfile resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAccessProfileAsync(String resourceGroupName, String resourceName, String roleName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getAccessProfileWithServiceResponseAsync(resourceGroupName, resourceName, roleName), serviceCallback); + } + + /** + * Gets an access profile of a managed cluster. + * Gets the accessProfile for the specified role name of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param roleName The name of the role for managed cluster accessProfile resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterAccessProfileInner object + */ + public Observable getAccessProfileAsync(String resourceGroupName, String resourceName, String roleName) { + return getAccessProfileWithServiceResponseAsync(resourceGroupName, resourceName, roleName).map(new Func1, ManagedClusterAccessProfileInner>() { + @Override + public ManagedClusterAccessProfileInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets an access profile of a managed cluster. + * Gets the accessProfile for the specified role name of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param roleName The name of the role for managed cluster accessProfile resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterAccessProfileInner object + */ + public Observable> getAccessProfileWithServiceResponseAsync(String resourceGroupName, String resourceName, String roleName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (roleName == null) { + throw new IllegalArgumentException("Parameter roleName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.getAccessProfile(this.client.subscriptionId(), resourceGroupName, resourceName, roleName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getAccessProfileDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getAccessProfileDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets cluster admin credential of a managed cluster. + * Gets cluster admin credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the CredentialResultsInner object if successful. + */ + public CredentialResultsInner listClusterAdminCredentials(String resourceGroupName, String resourceName) { + return listClusterAdminCredentialsWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Gets cluster admin credential of a managed cluster. + * Gets cluster admin credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture listClusterAdminCredentialsAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(listClusterAdminCredentialsWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Gets cluster admin credential of a managed cluster. + * Gets cluster admin credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CredentialResultsInner object + */ + public Observable listClusterAdminCredentialsAsync(String resourceGroupName, String resourceName) { + return listClusterAdminCredentialsWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, CredentialResultsInner>() { + @Override + public CredentialResultsInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets cluster admin credential of a managed cluster. + * Gets cluster admin credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CredentialResultsInner object + */ + public Observable> listClusterAdminCredentialsWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.listClusterAdminCredentials(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = listClusterAdminCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse listClusterAdminCredentialsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets cluster user credential of a managed cluster. + * Gets cluster user credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the CredentialResultsInner object if successful. + */ + public CredentialResultsInner listClusterUserCredentials(String resourceGroupName, String resourceName) { + return listClusterUserCredentialsWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Gets cluster user credential of a managed cluster. + * Gets cluster user credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture listClusterUserCredentialsAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(listClusterUserCredentialsWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Gets cluster user credential of a managed cluster. + * Gets cluster user credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CredentialResultsInner object + */ + public Observable listClusterUserCredentialsAsync(String resourceGroupName, String resourceName) { + return listClusterUserCredentialsWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, CredentialResultsInner>() { + @Override + public CredentialResultsInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets cluster user credential of a managed cluster. + * Gets cluster user credential of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CredentialResultsInner object + */ + public Observable> listClusterUserCredentialsWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.listClusterUserCredentials(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = listClusterUserCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse listClusterUserCredentialsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a managed cluster. + * Gets the details of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterInner object if successful. + */ + public ManagedClusterInner getByResourceGroup(String resourceGroupName, String resourceName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Gets a managed cluster. + * Gets the details of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getByResourceGroupAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getByResourceGroupWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Gets a managed cluster. + * Gets the details of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable getByResourceGroupAsync(String resourceGroupName, String resourceName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, ManagedClusterInner>() { + @Override + public ManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a managed cluster. + * Gets the details of the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable> getByResourceGroupWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.getByResourceGroup(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getByResourceGroupDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterInner object if successful. + */ + public ManagedClusterInner createOrUpdate(String resourceGroupName, String resourceName, ManagedClusterInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().last().body(); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String resourceName, ManagedClusterInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable createOrUpdateAsync(String resourceGroupName, String resourceName, ManagedClusterInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, ManagedClusterInner>() { + @Override + public ManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String resourceName, ManagedClusterInner parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + Observable> observable = service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterInner object if successful. + */ + public ManagedClusterInner beginCreateOrUpdate(String resourceGroupName, String resourceName, ManagedClusterInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().single().body(); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginCreateOrUpdateAsync(String resourceGroupName, String resourceName, ManagedClusterInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable beginCreateOrUpdateAsync(String resourceGroupName, String resourceName, ManagedClusterInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, ManagedClusterInner>() { + @Override + public ManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a managed cluster. + * Creates or updates a managed cluster with the specified configuration for agents and Kubernetes version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Create or Update a Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable> beginCreateOrUpdateWithServiceResponseAsync(String resourceGroupName, String resourceName, ManagedClusterInner parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + return service.beginCreateOrUpdate(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginCreateOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginCreateOrUpdateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(201, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterInner object if successful. + */ + public ManagedClusterInner updateTags(String resourceGroupName, String resourceName) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().last().body(); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateTagsAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateTagsWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable updateTagsAsync(String resourceGroupName, String resourceName) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, ManagedClusterInner>() { + @Override + public ManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> updateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + final Map tags = null; + TagsObject parameters = new TagsObject(); + parameters.withTags(null); + Observable> observable = service.updateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterInner object if successful. + */ + public ManagedClusterInner updateTags(String resourceGroupName, String resourceName, Map tags) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).toBlocking().last().body(); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateTagsAsync(String resourceGroupName, String resourceName, Map tags, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags), serviceCallback); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable updateTagsAsync(String resourceGroupName, String resourceName, Map tags) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).map(new Func1, ManagedClusterInner>() { + @Override + public ManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> updateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName, Map tags) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + Validator.validate(tags); + final String apiVersion = "2019-08-01"; + TagsObject parameters = new TagsObject(); + parameters.withTags(tags); + Observable> observable = service.updateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterInner object if successful. + */ + public ManagedClusterInner beginUpdateTags(String resourceGroupName, String resourceName) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginUpdateTagsAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable beginUpdateTagsAsync(String resourceGroupName, String resourceName) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, ManagedClusterInner>() { + @Override + public ManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable> beginUpdateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + final Map tags = null; + TagsObject parameters = new TagsObject(); + parameters.withTags(null); + return service.beginUpdateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginUpdateTagsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the ManagedClusterInner object if successful. + */ + public ManagedClusterInner beginUpdateTags(String resourceGroupName, String resourceName, Map tags) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).toBlocking().single().body(); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginUpdateTagsAsync(String resourceGroupName, String resourceName, Map tags, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags), serviceCallback); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable beginUpdateTagsAsync(String resourceGroupName, String resourceName, Map tags) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).map(new Func1, ManagedClusterInner>() { + @Override + public ManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on a managed cluster. + * Updates a managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the ManagedClusterInner object + */ + public Observable> beginUpdateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName, Map tags) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + Validator.validate(tags); + final String apiVersion = "2019-08-01"; + TagsObject parameters = new TagsObject(); + parameters.withTags(tags); + return service.beginUpdateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginUpdateTagsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginUpdateTagsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String resourceName) { + deleteWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().last().body(); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable deleteAsync(String resourceGroupName, String resourceName) { + return deleteWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + Observable> observable = service.delete(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginDelete(String resourceGroupName, String resourceName) { + beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginDeleteAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginDeleteAsync(String resourceGroupName, String resourceName) { + return beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a managed cluster. + * Deletes the managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginDeleteWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-08-01"; + return service.beginDelete(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginDeleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginDeleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(202, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void resetServicePrincipalProfile(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters) { + resetServicePrincipalProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().last().body(); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture resetServicePrincipalProfileAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(resetServicePrincipalProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable resetServicePrincipalProfileAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters) { + return resetServicePrincipalProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> resetServicePrincipalProfileWithServiceResponseAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + Observable> observable = service.resetServicePrincipalProfile(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginResetServicePrincipalProfile(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters) { + beginResetServicePrincipalProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().single().body(); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginResetServicePrincipalProfileAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginResetServicePrincipalProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginResetServicePrincipalProfileAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters) { + return beginResetServicePrincipalProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Reset Service Principal Profile of a managed cluster. + * Update the service principal Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset Service Principal Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginResetServicePrincipalProfileWithServiceResponseAsync(String resourceGroupName, String resourceName, ManagedClusterServicePrincipalProfile parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + return service.beginResetServicePrincipalProfile(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginResetServicePrincipalProfileDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginResetServicePrincipalProfileDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(202, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void resetAADProfile(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters) { + resetAADProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().last().body(); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture resetAADProfileAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(resetAADProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable resetAADProfileAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters) { + return resetAADProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> resetAADProfileWithServiceResponseAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + Observable> observable = service.resetAADProfile(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginResetAADProfile(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters) { + beginResetAADProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().single().body(); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginResetAADProfileAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginResetAADProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginResetAADProfileAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters) { + return beginResetAADProfileWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Reset AAD Profile of a managed cluster. + * Update the AAD Profile for a managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the managed cluster resource. + * @param parameters Parameters supplied to the Reset AAD Profile operation for a Managed Cluster. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginResetAADProfileWithServiceResponseAsync(String resourceGroupName, String resourceName, ManagedClusterAADProfile parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-08-01"; + return service.beginResetAADProfile(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginResetAADProfileDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginResetAADProfileDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(202, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ManagedClusterInner> object if successful. + */ + public PagedList listNext(final String nextPageLink) { + ServiceResponse> response = listNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable> listNextAsync(final String nextPageLink) { + return listNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextPageLink) { + return listNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of managed clusters in the specified subscription. + * Gets a list of managed clusters in the specified subscription. The operation returns properties of each managed cluster. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ManagedClusterInner> object if successful. + */ + public PagedList listByResourceGroupNext(final String nextPageLink) { + ServiceResponse> response = listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable> listByResourceGroupNextAsync(final String nextPageLink) { + return listByResourceGroupNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ManagedClusterInner> object + */ + public Observable>> listByResourceGroupNextWithServiceResponseAsync(final String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists managed clusters in the specified subscription and resource group. + * Lists managed clusters in the specified subscription and resource group. The operation returns properties of each managed cluster. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByResourceGroupNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClusterImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClusterImpl.java new file mode 100644 index 000000000000..3ee4d03ab946 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClusterImpl.java @@ -0,0 +1,150 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.resources.models.implementation.GroupableResourceCoreImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedCluster; +import rx.Observable; +import com.microsoft.azure.management.containerservice.v2019_08_01.PurchasePlan; +import com.microsoft.azure.management.containerservice.v2019_08_01.NetworkProfile; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftRouterProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusterMasterPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusterAgentPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusterAuthProfile; + +class OpenShiftManagedClusterImpl extends GroupableResourceCoreImpl implements OpenShiftManagedCluster, OpenShiftManagedCluster.Definition, OpenShiftManagedCluster.Update { + OpenShiftManagedClusterImpl(String name, OpenShiftManagedClusterInner inner, ContainerServiceManager manager) { + super(name, inner, manager); + } + + @Override + public Observable createResourceAsync() { + OpenShiftManagedClustersInner client = this.manager().inner().openShiftManagedClusters(); + return client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + OpenShiftManagedClustersInner client = this.manager().inner().openShiftManagedClusters(); + return client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + OpenShiftManagedClustersInner client = this.manager().inner().openShiftManagedClusters(); + return client.getByResourceGroupAsync(this.resourceGroupName(), this.name()); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + + @Override + public List agentPoolProfiles() { + return this.inner().agentPoolProfiles(); + } + + @Override + public OpenShiftManagedClusterAuthProfile authProfile() { + return this.inner().authProfile(); + } + + @Override + public String clusterVersion() { + return this.inner().clusterVersion(); + } + + @Override + public String fqdn() { + return this.inner().fqdn(); + } + + @Override + public OpenShiftManagedClusterMasterPoolProfile masterPoolProfile() { + return this.inner().masterPoolProfile(); + } + + @Override + public NetworkProfile networkProfile() { + return this.inner().networkProfile(); + } + + @Override + public String openShiftVersion() { + return this.inner().openShiftVersion(); + } + + @Override + public PurchasePlan plan() { + return this.inner().plan(); + } + + @Override + public String provisioningState() { + return this.inner().provisioningState(); + } + + @Override + public String publicHostname() { + return this.inner().publicHostname(); + } + + @Override + public List routerProfiles() { + return this.inner().routerProfiles(); + } + + @Override + public OpenShiftManagedClusterImpl withOpenShiftVersion(String openShiftVersion) { + this.inner().withOpenShiftVersion(openShiftVersion); + return this; + } + + @Override + public OpenShiftManagedClusterImpl withAgentPoolProfiles(List agentPoolProfiles) { + this.inner().withAgentPoolProfiles(agentPoolProfiles); + return this; + } + + @Override + public OpenShiftManagedClusterImpl withAuthProfile(OpenShiftManagedClusterAuthProfile authProfile) { + this.inner().withAuthProfile(authProfile); + return this; + } + + @Override + public OpenShiftManagedClusterImpl withMasterPoolProfile(OpenShiftManagedClusterMasterPoolProfile masterPoolProfile) { + this.inner().withMasterPoolProfile(masterPoolProfile); + return this; + } + + @Override + public OpenShiftManagedClusterImpl withNetworkProfile(NetworkProfile networkProfile) { + this.inner().withNetworkProfile(networkProfile); + return this; + } + + @Override + public OpenShiftManagedClusterImpl withPlan(PurchasePlan plan) { + this.inner().withPlan(plan); + return this; + } + + @Override + public OpenShiftManagedClusterImpl withRouterProfiles(List routerProfiles) { + this.inner().withRouterProfiles(routerProfiles); + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClusterInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClusterInner.java new file mode 100644 index 000000000000..2141f9c309e2 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClusterInner.java @@ -0,0 +1,271 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.PurchasePlan; +import com.microsoft.azure.management.containerservice.v2019_08_01.NetworkProfile; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftRouterProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusterMasterPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusterAgentPoolProfile; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusterAuthProfile; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.Resource; + +/** + * OpenShift Managed cluster. + */ +@JsonFlatten +public class OpenShiftManagedClusterInner extends Resource { + /** + * Define the resource plan as required by ARM for billing purposes. + */ + @JsonProperty(value = "plan") + private PurchasePlan plan; + + /** + * The current deployment or provisioning state, which only appears in the + * response. + */ + @JsonProperty(value = "properties.provisioningState", access = JsonProperty.Access.WRITE_ONLY) + private String provisioningState; + + /** + * Version of OpenShift specified when creating the cluster. + */ + @JsonProperty(value = "properties.openShiftVersion", required = true) + private String openShiftVersion; + + /** + * Version of OpenShift specified when creating the cluster. + */ + @JsonProperty(value = "properties.clusterVersion", access = JsonProperty.Access.WRITE_ONLY) + private String clusterVersion; + + /** + * Service generated FQDN for OpenShift API server. + */ + @JsonProperty(value = "properties.publicHostname", access = JsonProperty.Access.WRITE_ONLY) + private String publicHostname; + + /** + * Service generated FQDN for OpenShift API server loadbalancer internal + * hostname. + */ + @JsonProperty(value = "properties.fqdn", access = JsonProperty.Access.WRITE_ONLY) + private String fqdn; + + /** + * Configuration for OpenShift networking. + */ + @JsonProperty(value = "properties.networkProfile") + private NetworkProfile networkProfile; + + /** + * Configuration for OpenShift router(s). + */ + @JsonProperty(value = "properties.routerProfiles") + private List routerProfiles; + + /** + * Configuration for OpenShift master VMs. + */ + @JsonProperty(value = "properties.masterPoolProfile") + private OpenShiftManagedClusterMasterPoolProfile masterPoolProfile; + + /** + * Configuration of OpenShift cluster VMs. + */ + @JsonProperty(value = "properties.agentPoolProfiles") + private List agentPoolProfiles; + + /** + * Configures OpenShift authentication. + */ + @JsonProperty(value = "properties.authProfile") + private OpenShiftManagedClusterAuthProfile authProfile; + + /** + * Get define the resource plan as required by ARM for billing purposes. + * + * @return the plan value + */ + public PurchasePlan plan() { + return this.plan; + } + + /** + * Set define the resource plan as required by ARM for billing purposes. + * + * @param plan the plan value to set + * @return the OpenShiftManagedClusterInner object itself. + */ + public OpenShiftManagedClusterInner withPlan(PurchasePlan plan) { + this.plan = plan; + return this; + } + + /** + * Get the current deployment or provisioning state, which only appears in the response. + * + * @return the provisioningState value + */ + public String provisioningState() { + return this.provisioningState; + } + + /** + * Get version of OpenShift specified when creating the cluster. + * + * @return the openShiftVersion value + */ + public String openShiftVersion() { + return this.openShiftVersion; + } + + /** + * Set version of OpenShift specified when creating the cluster. + * + * @param openShiftVersion the openShiftVersion value to set + * @return the OpenShiftManagedClusterInner object itself. + */ + public OpenShiftManagedClusterInner withOpenShiftVersion(String openShiftVersion) { + this.openShiftVersion = openShiftVersion; + return this; + } + + /** + * Get version of OpenShift specified when creating the cluster. + * + * @return the clusterVersion value + */ + public String clusterVersion() { + return this.clusterVersion; + } + + /** + * Get service generated FQDN for OpenShift API server. + * + * @return the publicHostname value + */ + public String publicHostname() { + return this.publicHostname; + } + + /** + * Get service generated FQDN for OpenShift API server loadbalancer internal hostname. + * + * @return the fqdn value + */ + public String fqdn() { + return this.fqdn; + } + + /** + * Get configuration for OpenShift networking. + * + * @return the networkProfile value + */ + public NetworkProfile networkProfile() { + return this.networkProfile; + } + + /** + * Set configuration for OpenShift networking. + * + * @param networkProfile the networkProfile value to set + * @return the OpenShiftManagedClusterInner object itself. + */ + public OpenShiftManagedClusterInner withNetworkProfile(NetworkProfile networkProfile) { + this.networkProfile = networkProfile; + return this; + } + + /** + * Get configuration for OpenShift router(s). + * + * @return the routerProfiles value + */ + public List routerProfiles() { + return this.routerProfiles; + } + + /** + * Set configuration for OpenShift router(s). + * + * @param routerProfiles the routerProfiles value to set + * @return the OpenShiftManagedClusterInner object itself. + */ + public OpenShiftManagedClusterInner withRouterProfiles(List routerProfiles) { + this.routerProfiles = routerProfiles; + return this; + } + + /** + * Get configuration for OpenShift master VMs. + * + * @return the masterPoolProfile value + */ + public OpenShiftManagedClusterMasterPoolProfile masterPoolProfile() { + return this.masterPoolProfile; + } + + /** + * Set configuration for OpenShift master VMs. + * + * @param masterPoolProfile the masterPoolProfile value to set + * @return the OpenShiftManagedClusterInner object itself. + */ + public OpenShiftManagedClusterInner withMasterPoolProfile(OpenShiftManagedClusterMasterPoolProfile masterPoolProfile) { + this.masterPoolProfile = masterPoolProfile; + return this; + } + + /** + * Get configuration of OpenShift cluster VMs. + * + * @return the agentPoolProfiles value + */ + public List agentPoolProfiles() { + return this.agentPoolProfiles; + } + + /** + * Set configuration of OpenShift cluster VMs. + * + * @param agentPoolProfiles the agentPoolProfiles value to set + * @return the OpenShiftManagedClusterInner object itself. + */ + public OpenShiftManagedClusterInner withAgentPoolProfiles(List agentPoolProfiles) { + this.agentPoolProfiles = agentPoolProfiles; + return this; + } + + /** + * Get configures OpenShift authentication. + * + * @return the authProfile value + */ + public OpenShiftManagedClusterAuthProfile authProfile() { + return this.authProfile; + } + + /** + * Set configures OpenShift authentication. + * + * @param authProfile the authProfile value to set + * @return the OpenShiftManagedClusterInner object itself. + */ + public OpenShiftManagedClusterInner withAuthProfile(OpenShiftManagedClusterAuthProfile authProfile) { + this.authProfile = authProfile; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClustersImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClustersImpl.java new file mode 100644 index 000000000000..54b52a760d42 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClustersImpl.java @@ -0,0 +1,138 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * def + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.resources.collection.implementation.GroupableResourcesCoreImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters; +import com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedCluster; +import rx.Observable; +import rx.Completable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import com.microsoft.azure.arm.resources.ResourceUtilsCore; +import com.microsoft.azure.arm.utils.RXMapper; +import rx.functions.Func1; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.Page; + +class OpenShiftManagedClustersImpl extends GroupableResourcesCoreImpl implements OpenShiftManagedClusters { + protected OpenShiftManagedClustersImpl(ContainerServiceManager manager) { + super(manager.inner().openShiftManagedClusters(), manager); + } + + @Override + protected Observable getInnerAsync(String resourceGroupName, String name) { + OpenShiftManagedClustersInner client = this.inner(); + return client.getByResourceGroupAsync(resourceGroupName, name); + } + + @Override + protected Completable deleteInnerAsync(String resourceGroupName, String name) { + OpenShiftManagedClustersInner client = this.inner(); + return client.deleteAsync(resourceGroupName, name).toCompletable(); + } + + @Override + public Observable deleteByIdsAsync(Collection ids) { + if (ids == null || ids.isEmpty()) { + return Observable.empty(); + } + Collection> observables = new ArrayList<>(); + for (String id : ids) { + final String resourceGroupName = ResourceUtilsCore.groupFromResourceId(id); + final String name = ResourceUtilsCore.nameFromResourceId(id); + Observable o = RXMapper.map(this.inner().deleteAsync(resourceGroupName, name), id); + observables.add(o); + } + return Observable.mergeDelayError(observables); + } + + @Override + public Observable deleteByIdsAsync(String...ids) { + return this.deleteByIdsAsync(new ArrayList(Arrays.asList(ids))); + } + + @Override + public void deleteByIds(Collection ids) { + if (ids != null && !ids.isEmpty()) { + this.deleteByIdsAsync(ids).toBlocking().last(); + } + } + + @Override + public void deleteByIds(String...ids) { + this.deleteByIds(new ArrayList(Arrays.asList(ids))); + } + + @Override + public PagedList listByResourceGroup(String resourceGroupName) { + OpenShiftManagedClustersInner client = this.inner(); + return this.wrapList(client.listByResourceGroup(resourceGroupName)); + } + + @Override + public Observable listByResourceGroupAsync(String resourceGroupName) { + OpenShiftManagedClustersInner client = this.inner(); + return client.listByResourceGroupAsync(resourceGroupName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public OpenShiftManagedCluster call(OpenShiftManagedClusterInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public PagedList list() { + OpenShiftManagedClustersInner client = this.inner(); + return this.wrapList(client.list()); + } + + @Override + public Observable listAsync() { + OpenShiftManagedClustersInner client = this.inner(); + return client.listAsync() + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public OpenShiftManagedCluster call(OpenShiftManagedClusterInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public OpenShiftManagedClusterImpl define(String name) { + return wrapModel(name); + } + + @Override + protected OpenShiftManagedClusterImpl wrapModel(OpenShiftManagedClusterInner inner) { + return new OpenShiftManagedClusterImpl(inner.name(), inner, manager()); + } + + @Override + protected OpenShiftManagedClusterImpl wrapModel(String name) { + return new OpenShiftManagedClusterImpl(name, new OpenShiftManagedClusterInner(), this.manager()); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClustersInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClustersInner.java new file mode 100644 index 000000000000..40a9fd1fae0c --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OpenShiftManagedClustersInner.java @@ -0,0 +1,1328 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.collection.InnerSupportsGet; +import com.microsoft.azure.arm.collection.InnerSupportsDelete; +import com.microsoft.azure.arm.collection.InnerSupportsListing; +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.CloudException; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.containerservice.v2019_08_01.TagsObject; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in OpenShiftManagedClusters. + */ +public class OpenShiftManagedClustersInner implements InnerSupportsGet, InnerSupportsDelete, InnerSupportsListing { + /** The Retrofit service to perform REST calls. */ + private OpenShiftManagedClustersService service; + /** The service client containing this operation class. */ + private ContainerServiceManagementClientImpl client; + + /** + * Initializes an instance of OpenShiftManagedClustersInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public OpenShiftManagedClustersInner(Retrofit retrofit, ContainerServiceManagementClientImpl client) { + this.service = retrofit.create(OpenShiftManagedClustersService.class); + this.client = client; + } + + /** + * The interface defining all the services for OpenShiftManagedClusters to be + * used by Retrofit to perform actually REST calls. + */ + interface OpenShiftManagedClustersService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters list" }) + @GET("subscriptions/{subscriptionId}/providers/Microsoft.ContainerService/openShiftManagedClusters") + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters listByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters") + Observable> listByResourceGroup(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters getByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters/{resourceName}") + Observable> getByResourceGroup(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters/{resourceName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body OpenShiftManagedClusterInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters beginCreateOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters/{resourceName}") + Observable> beginCreateOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Body OpenShiftManagedClusterInner parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters updateTags" }) + @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters/{resourceName}") + Observable> updateTags(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body TagsObject parameters, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters beginUpdateTags" }) + @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters/{resourceName}") + Observable> beginUpdateTags(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body TagsObject parameters, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters/{resourceName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters beginDelete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/openShiftManagedClusters/{resourceName}", method = "DELETE", hasBody = true) + Observable> beginDelete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("resourceName") String resourceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters listNext" }) + @GET + Observable> listNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.OpenShiftManagedClusters listByResourceGroupNext" }) + @GET + Observable> listByResourceGroupNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<OpenShiftManagedClusterInner> object if successful. + */ + public PagedList list() { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<OpenShiftManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + final String apiVersion = "2019-04-30"; + return service.list(this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<OpenShiftManagedClusterInner> object if successful. + */ + public PagedList listByResourceGroup(final String resourceGroupName) { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupSinglePageAsync(resourceGroupName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName) { + return listByResourceGroupSinglePageAsync(resourceGroupName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + ServiceResponse> * @param resourceGroupName The name of the resource group. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<OpenShiftManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + final String apiVersion = "2019-04-30"; + return service.listByResourceGroup(this.client.subscriptionId(), resourceGroupName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a OpenShift managed cluster. + * Gets the details of the managed OpenShift cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OpenShiftManagedClusterInner object if successful. + */ + public OpenShiftManagedClusterInner getByResourceGroup(String resourceGroupName, String resourceName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Gets a OpenShift managed cluster. + * Gets the details of the managed OpenShift cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getByResourceGroupAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getByResourceGroupWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Gets a OpenShift managed cluster. + * Gets the details of the managed OpenShift cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable getByResourceGroupAsync(String resourceGroupName, String resourceName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, OpenShiftManagedClusterInner>() { + @Override + public OpenShiftManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a OpenShift managed cluster. + * Gets the details of the managed OpenShift cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable> getByResourceGroupWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-04-30"; + return service.getByResourceGroup(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getByResourceGroupDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getByResourceGroupDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OpenShiftManagedClusterInner object if successful. + */ + public OpenShiftManagedClusterInner createOrUpdate(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().last().body(); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable createOrUpdateAsync(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, OpenShiftManagedClusterInner>() { + @Override + public OpenShiftManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-04-30"; + Observable> observable = service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OpenShiftManagedClusterInner object if successful. + */ + public OpenShiftManagedClusterInner beginCreateOrUpdate(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).toBlocking().single().body(); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginCreateOrUpdateAsync(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters), serviceCallback); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable beginCreateOrUpdateAsync(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters) { + return beginCreateOrUpdateWithServiceResponseAsync(resourceGroupName, resourceName, parameters).map(new Func1, OpenShiftManagedClusterInner>() { + @Override + public OpenShiftManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates an OpenShift managed cluster. + * Creates or updates a OpenShift managed cluster with the specified configuration for agents and OpenShift version. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param parameters Parameters supplied to the Create or Update an OpenShift Managed Cluster operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable> beginCreateOrUpdateWithServiceResponseAsync(String resourceGroupName, String resourceName, OpenShiftManagedClusterInner parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + if (parameters == null) { + throw new IllegalArgumentException("Parameter parameters is required and cannot be null."); + } + Validator.validate(parameters); + final String apiVersion = "2019-04-30"; + return service.beginCreateOrUpdate(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginCreateOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginCreateOrUpdateDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(201, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OpenShiftManagedClusterInner object if successful. + */ + public OpenShiftManagedClusterInner updateTags(String resourceGroupName, String resourceName) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().last().body(); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateTagsAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateTagsWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable updateTagsAsync(String resourceGroupName, String resourceName) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, OpenShiftManagedClusterInner>() { + @Override + public OpenShiftManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> updateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-04-30"; + final Map tags = null; + TagsObject parameters = new TagsObject(); + parameters.withTags(null); + Observable> observable = service.updateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OpenShiftManagedClusterInner object if successful. + */ + public OpenShiftManagedClusterInner updateTags(String resourceGroupName, String resourceName, Map tags) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).toBlocking().last().body(); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateTagsAsync(String resourceGroupName, String resourceName, Map tags, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags), serviceCallback); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable updateTagsAsync(String resourceGroupName, String resourceName, Map tags) { + return updateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).map(new Func1, OpenShiftManagedClusterInner>() { + @Override + public OpenShiftManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> updateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName, Map tags) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + Validator.validate(tags); + final String apiVersion = "2019-04-30"; + TagsObject parameters = new TagsObject(); + parameters.withTags(tags); + Observable> observable = service.updateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()); + return client.getAzureClient().getPutOrPatchResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OpenShiftManagedClusterInner object if successful. + */ + public OpenShiftManagedClusterInner beginUpdateTags(String resourceGroupName, String resourceName) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginUpdateTagsAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable beginUpdateTagsAsync(String resourceGroupName, String resourceName) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, OpenShiftManagedClusterInner>() { + @Override + public OpenShiftManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable> beginUpdateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-04-30"; + final Map tags = null; + TagsObject parameters = new TagsObject(); + parameters.withTags(null); + return service.beginUpdateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginUpdateTagsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OpenShiftManagedClusterInner object if successful. + */ + public OpenShiftManagedClusterInner beginUpdateTags(String resourceGroupName, String resourceName, Map tags) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).toBlocking().single().body(); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginUpdateTagsAsync(String resourceGroupName, String resourceName, Map tags, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags), serviceCallback); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable beginUpdateTagsAsync(String resourceGroupName, String resourceName, Map tags) { + return beginUpdateTagsWithServiceResponseAsync(resourceGroupName, resourceName, tags).map(new Func1, OpenShiftManagedClusterInner>() { + @Override + public OpenShiftManagedClusterInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates tags on an OpenShift managed cluster. + * Updates an OpenShift managed cluster with the specified tags. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param tags Resource tags. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OpenShiftManagedClusterInner object + */ + public Observable> beginUpdateTagsWithServiceResponseAsync(String resourceGroupName, String resourceName, Map tags) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + Validator.validate(tags); + final String apiVersion = "2019-04-30"; + TagsObject parameters = new TagsObject(); + parameters.withTags(tags); + return service.beginUpdateTags(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), parameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginUpdateTagsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginUpdateTagsDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String resourceName) { + deleteWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().last().body(); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable deleteAsync(String resourceGroupName, String resourceName) { + return deleteWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-04-30"; + Observable> observable = service.delete(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginDelete(String resourceGroupName, String resourceName) { + beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName).toBlocking().single().body(); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginDeleteAsync(String resourceGroupName, String resourceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName), serviceCallback); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginDeleteAsync(String resourceGroupName, String resourceName) { + return beginDeleteWithServiceResponseAsync(resourceGroupName, resourceName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes an OpenShift managed cluster. + * Deletes the OpenShift managed cluster with a specified resource group and name. + * + * @param resourceGroupName The name of the resource group. + * @param resourceName The name of the OpenShift managed cluster resource. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginDeleteWithServiceResponseAsync(String resourceGroupName, String resourceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (resourceName == null) { + throw new IllegalArgumentException("Parameter resourceName is required and cannot be null."); + } + final String apiVersion = "2019-04-30"; + return service.beginDelete(this.client.subscriptionId(), resourceGroupName, resourceName, apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginDeleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginDeleteDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(202, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<OpenShiftManagedClusterInner> object if successful. + */ + public PagedList listNext(final String nextPageLink) { + ServiceResponse> response = listNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable> listNextAsync(final String nextPageLink) { + return listNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextPageLink) { + return listNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Gets a list of OpenShift managed clusters in the specified subscription. + * Gets a list of OpenShift managed clusters in the specified subscription. The operation returns properties of each OpenShift managed cluster. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<OpenShiftManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<OpenShiftManagedClusterInner> object if successful. + */ + public PagedList listByResourceGroupNext(final String nextPageLink) { + ServiceResponse> response = listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable> listByResourceGroupNextAsync(final String nextPageLink) { + return listByResourceGroupNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<OpenShiftManagedClusterInner> object + */ + public Observable>> listByResourceGroupNextWithServiceResponseAsync(final String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists OpenShift managed clusters in the specified subscription and resource group. + * Lists OpenShift managed clusters in the specified subscription and resource group. The operation returns properties of each OpenShift managed cluster. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<OpenShiftManagedClusterInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByResourceGroupNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupNextDelegate(Response response) throws CloudException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationValueImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationValueImpl.java new file mode 100644 index 000000000000..07eea73a4c69 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationValueImpl.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.OperationValue; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; + +class OperationValueImpl extends WrapperImpl implements OperationValue { + private final ContainerServiceManager manager; + OperationValueImpl(OperationValueInner inner, ContainerServiceManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public String description() { + return this.inner().description(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public String operation() { + return this.inner().operation(); + } + + @Override + public String origin() { + return this.inner().origin(); + } + + @Override + public String provider() { + return this.inner().provider(); + } + + @Override + public String resource() { + return this.inner().resource(); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationValueInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationValueInner.java new file mode 100644 index 000000000000..db8a8cfeec60 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationValueInner.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Describes the properties of a Compute Operation value. + */ +@JsonFlatten +public class OperationValueInner { + /** + * The origin of the compute operation. + */ + @JsonProperty(value = "origin", access = JsonProperty.Access.WRITE_ONLY) + private String origin; + + /** + * The name of the compute operation. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The display name of the compute operation. + */ + @JsonProperty(value = "display.operation", access = JsonProperty.Access.WRITE_ONLY) + private String operation; + + /** + * The display name of the resource the operation applies to. + */ + @JsonProperty(value = "display.resource", access = JsonProperty.Access.WRITE_ONLY) + private String resource; + + /** + * The description of the operation. + */ + @JsonProperty(value = "display.description", access = JsonProperty.Access.WRITE_ONLY) + private String description; + + /** + * The resource provider for the operation. + */ + @JsonProperty(value = "display.provider", access = JsonProperty.Access.WRITE_ONLY) + private String provider; + + /** + * Get the origin of the compute operation. + * + * @return the origin value + */ + public String origin() { + return this.origin; + } + + /** + * Get the name of the compute operation. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the display name of the compute operation. + * + * @return the operation value + */ + public String operation() { + return this.operation; + } + + /** + * Get the display name of the resource the operation applies to. + * + * @return the resource value + */ + public String resource() { + return this.resource; + } + + /** + * Get the description of the operation. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Get the resource provider for the operation. + * + * @return the provider value + */ + public String provider() { + return this.provider; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationsImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationsImpl.java new file mode 100644 index 000000000000..3ecf4c68e9e1 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationsImpl.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * abc + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.containerservice.v2019_08_01.Operations; +import rx.functions.Func1; +import rx.Observable; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.OperationValue; + +class OperationsImpl extends WrapperImpl implements Operations { + private final ContainerServiceManager manager; + + OperationsImpl(ContainerServiceManager manager) { + super(manager.inner().operations()); + this.manager = manager; + } + + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public Observable listAsync() { + OperationsInner client = this.inner(); + return client.listAsync() + .flatMap(new Func1, Observable>() { + @Override + public Observable call(List innerList) { + return Observable.from(innerList); + } + }) + .map(new Func1() { + @Override + public OperationValue call(OperationValueInner inner) { + return new OperationValueImpl(inner, manager()); + } + }); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationsInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationsInner.java new file mode 100644 index 000000000000..8f85d620fb1a --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OperationsInner.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.CloudException; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.Query; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in Operations. + */ +public class OperationsInner { + /** The Retrofit service to perform REST calls. */ + private OperationsService service; + /** The service client containing this operation class. */ + private ContainerServiceManagementClientImpl client; + + /** + * Initializes an instance of OperationsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public OperationsInner(Retrofit retrofit, ContainerServiceManagementClientImpl client) { + this.service = retrofit.create(OperationsService.class); + this.client = client; + } + + /** + * The interface defining all the services for Operations to be + * used by Retrofit to perform actually REST calls. + */ + interface OperationsService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.containerservice.v2019_08_01.Operations list" }) + @GET("providers/Microsoft.ContainerService/operations") + Observable> list(@Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Gets a list of compute operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws CloudException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the List<OperationValueInner> object if successful. + */ + public List list() { + return listWithServiceResponseAsync().toBlocking().single().body(); + } + + /** + * Gets a list of compute operations. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listAsync(final ServiceCallback> serviceCallback) { + return ServiceFuture.fromResponse(listWithServiceResponseAsync(), serviceCallback); + } + + /** + * Gets a list of compute operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the List<OperationValueInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync().map(new Func1>, List>() { + @Override + public List call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Gets a list of compute operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the List<OperationValueInner> object + */ + public Observable>> listWithServiceResponseAsync() { + final String apiVersion = "2019-08-01"; + return service.list(apiVersion, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + List items = null; + if (result.body() != null) { + items = result.body().items(); + } + ServiceResponse> clientResponse = new ServiceResponse>(items, result.response()); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws CloudException, IOException { + return this.client.restClient().responseBuilderFactory()., CloudException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(CloudException.class) + .build(response); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OrchestratorVersionProfileListResultImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OrchestratorVersionProfileListResultImpl.java new file mode 100644 index 000000000000..d049663917b4 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OrchestratorVersionProfileListResultImpl.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.microsoft.azure.management.containerservice.v2019_08_01.OrchestratorVersionProfileListResult; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.OrchestratorVersionProfile; + +class OrchestratorVersionProfileListResultImpl extends WrapperImpl implements OrchestratorVersionProfileListResult { + private final ContainerServiceManager manager; + OrchestratorVersionProfileListResultImpl(OrchestratorVersionProfileListResultInner inner, ContainerServiceManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public ContainerServiceManager manager() { + return this.manager; + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public List orchestrators() { + return this.inner().orchestrators(); + } + + @Override + public String type() { + return this.inner().type(); + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OrchestratorVersionProfileListResultInner.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OrchestratorVersionProfileListResultInner.java new file mode 100644 index 000000000000..59e7ab97b7b2 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/OrchestratorVersionProfileListResultInner.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import java.util.List; +import com.microsoft.azure.management.containerservice.v2019_08_01.OrchestratorVersionProfile; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * The list of versions for supported orchestrators. + */ +@JsonFlatten +public class OrchestratorVersionProfileListResultInner { + /** + * Id of the orchestrator version profile list result. + */ + @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY) + private String id; + + /** + * Name of the orchestrator version profile list result. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * Type of the orchestrator version profile list result. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * List of orchestrator version profiles. + */ + @JsonProperty(value = "properties.orchestrators", required = true) + private List orchestrators; + + /** + * Get id of the orchestrator version profile list result. + * + * @return the id value + */ + public String id() { + return this.id; + } + + /** + * Get name of the orchestrator version profile list result. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get type of the orchestrator version profile list result. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get list of orchestrator version profiles. + * + * @return the orchestrators value + */ + public List orchestrators() { + return this.orchestrators; + } + + /** + * Set list of orchestrator version profiles. + * + * @param orchestrators the orchestrators value to set + * @return the OrchestratorVersionProfileListResultInner object itself. + */ + public OrchestratorVersionProfileListResultInner withOrchestrators(List orchestrators) { + this.orchestrators = orchestrators; + return this; + } + +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/PageImpl.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/PageImpl.java new file mode 100644 index 000000000000..d291fbadd8de --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/PageImpl.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.Page; +import java.util.List; + +/** + * An instance of this class defines a page of Azure resources and a link to + * get the next page of resources, if any. + * + * @param type of Azure resource + */ +public class PageImpl implements Page { + /** + * The link to the next page. + */ + @JsonProperty("nextLink") + private String nextPageLink; + + /** + * The list of items. + */ + @JsonProperty("value") + private List items; + + /** + * Gets the link to the next page. + * + * @return the link to the next page. + */ + @Override + public String nextPageLink() { + return this.nextPageLink; + } + + /** + * Gets the list of items. + * + * @return the list of items in {@link List}. + */ + @Override + public List items() { + return items; + } + + /** + * Sets the link to the next page. + * + * @param nextPageLink the link to the next page. + * @return this Page object itself. + */ + public PageImpl setNextPageLink(String nextPageLink) { + this.nextPageLink = nextPageLink; + return this; + } + + /** + * Sets the list of items. + * + * @param items the list of items in {@link List}. + * @return this Page object itself. + */ + public PageImpl setItems(List items) { + this.items = items; + return this; + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/PageImpl1.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/PageImpl1.java new file mode 100644 index 000000000000..018f1453cce0 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/PageImpl1.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.Page; +import java.util.List; + +/** + * An instance of this class defines a page of Azure resources and a link to + * get the next page of resources, if any. + * + * @param type of Azure resource + */ +public class PageImpl1 implements Page { + /** + * The link to the next page. + */ + @JsonProperty("") + private String nextPageLink; + + /** + * The list of items. + */ + @JsonProperty("value") + private List items; + + /** + * Gets the link to the next page. + * + * @return the link to the next page. + */ + @Override + public String nextPageLink() { + return this.nextPageLink; + } + + /** + * Gets the list of items. + * + * @return the list of items in {@link List}. + */ + @Override + public List items() { + return items; + } + + /** + * Sets the link to the next page. + * + * @param nextPageLink the link to the next page. + * @return this Page object itself. + */ + public PageImpl1 setNextPageLink(String nextPageLink) { + this.nextPageLink = nextPageLink; + return this; + } + + /** + * Sets the list of items. + * + * @param items the list of items in {@link List}. + * @return this Page object itself. + */ + public PageImpl1 setItems(List items) { + this.items = items; + return this; + } +} diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/package-info.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/package-info.java new file mode 100644 index 000000000000..1caa785eb82b --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/implementation/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the implementation classes for ContainerServiceManagementClient. + * Container Service Client. + */ +package com.microsoft.azure.management.containerservice.v2019_08_01.implementation; diff --git a/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/package-info.java b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/package-info.java new file mode 100644 index 000000000000..947522c7a347 --- /dev/null +++ b/containerservice/resource-manager/v2019_08_01/src/main/java/com/microsoft/azure/management/containerservice/v2019_08_01/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the classes for ContainerServiceManagementClient. + * Container Service Client. + */ +package com.microsoft.azure.management.containerservice.v2019_08_01; diff --git a/cosmosdb/data-plane/.github/ISSUE_TEMPLATE/Bug_report.md b/cosmosdb/data-plane/.github/ISSUE_TEMPLATE/Bug_report.md deleted file mode 100644 index 7531bf124a13..000000000000 --- a/cosmosdb/data-plane/.github/ISSUE_TEMPLATE/Bug_report.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -name: "Bug report" -about: Create a report to help us improve - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior. - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Actual behavior** -Provide a description of the actual behavior observed. - -**Environment summary** -SDK Version: -Java JDK version: -OS Version (e.g. Windows, Linux, MacOSX) - -**Additional context** -Add any other context about the problem here. diff --git a/cosmosdb/data-plane/.gitignore b/cosmosdb/data-plane/.gitignore deleted file mode 100644 index bdb262af0bac..000000000000 --- a/cosmosdb/data-plane/.gitignore +++ /dev/null @@ -1,21 +0,0 @@ -*.class -target - -# Package Files # -*.jar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# MacOS files # -.DS_Store - -# IDE files # -.project -.settings -.classpath -.idea -*.iml - -doc -docs diff --git a/cosmosdb/data-plane/.travis.yml b/cosmosdb/data-plane/.travis.yml deleted file mode 100644 index 02ba5c532eaf..000000000000 --- a/cosmosdb/data-plane/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -language: java -sudo: false # faster builds - -matrix: - include: - - os: linux - jdk: oraclejdk8 -# - os: osx -# osx_image: xcode8 -script: -- mvn dependency:resolve -- mvn test -P fast -DargLine="-DACCOUNT_HOST=$ACCOUNT_HOST -DACCOUNT_KEY=$ACCOUNT_KEY" cobertura:cobertura -after_success: - - bash <(curl -s https://codecov.io/bash) - -cache: - directories: - - $HOME/.m2 diff --git a/cosmosdb/data-plane/CODEOWNERS b/cosmosdb/data-plane/CODEOWNERS deleted file mode 100644 index 26da20e9f2cf..000000000000 --- a/cosmosdb/data-plane/CODEOWNERS +++ /dev/null @@ -1,10 +0,0 @@ -# CODEOWNERS is a GitHub standard to specify who is automatically assigned pull requests to review. -# This helps to prevent pull requests from languishing without review. -# GitHub can also be configured to require review from code owners before a pull request can be merged. - -# Further reading is available from the following two URLs: -# https://blog.github.com/2017-07-06-introducing-code-owners/ -# https://help.github.com/articles/about-codeowners/ - -# Default owner for repo -* @moderakh @christopheranderson @kushagraThapar diff --git a/cosmosdb/data-plane/LICENSE b/cosmosdb/data-plane/LICENSE deleted file mode 100644 index 21071075c245..000000000000 --- a/cosmosdb/data-plane/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ - MIT License - - Copyright (c) Microsoft Corporation. All rights reserved. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE diff --git a/cosmosdb/data-plane/README.md b/cosmosdb/data-plane/README.md deleted file mode 100644 index 19399df1e3db..000000000000 --- a/cosmosdb/data-plane/README.md +++ /dev/null @@ -1,301 +0,0 @@ -## Java SDK for SQL API of Azure Cosmos DB -[![Maven Central](https://img.shields.io/maven-central/v/com.microsoft.azure/azure-cosmosdb.svg)](https://search.maven.org/artifact/com.microsoft.azure/azure-cosmosdb/2.4.3/jar) -[![Build Status](https://api.travis-ci.org/Azure/azure-cosmosdb-java.svg?branch=master)](https://travis-ci.org/Azure/azure-cosmosdb-java) -[![Known Vulnerabilities](https://snyk.io/test/github/Azure/azure-cosmosdb-java/badge.svg?targetFile=sdk%2Fpom.xml)](https://snyk.io/test/github/Azure/azure-cosmosdb-java?targetFile=sdk%2Fpom.xml) - - - - -- [Consuming the official Microsoft Azure Cosmos DB Java SDK](#consuming-the-official-microsoft-azure-cosmos-db-java-sdk) -- [Prerequisites](#prerequisites) -- [API Documentation](#api-documentation) -- [Usage Code Sample](#usage-code-sample) -- [Guide for Prod](#guide-for-prod) -- [Future, CompletableFuture, and ListenableFuture](#future-completablefuture-and-listenablefuture) -- [Checking out the Source Code](#checking-out-the-source-code) -- [FAQ](#faq) -- [Release changes](#release-changes) -- [Contribution and Feedback](#contribution-and-feedback) -- [License](#license) - - - - -## Consuming the official Microsoft Azure Cosmos DB Java SDK - -This project provides a SDK library in Java for interacting with [SQL API](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sql-query) of [Azure Cosmos DB -Database Service](https://azure.microsoft.com/en-us/services/cosmos-db/). This project also includes samples, tools, and utilities. - -Jar dependency binary information for maven and gradle can be found here at [maven]( https://mvnrepository.com/artifact/com.microsoft.azure/azure-cosmosdb/2.4.3). - -For example, using maven, you can add the following dependency to your maven pom file: - -```xml - - com.microsoft.azure - azure-cosmosdb - 2.4.3 - -``` - - - -Useful links: -- [Sample Get Started APP](https://github.com/Azure-Samples/azure-cosmos-db-sql-api-async-java-getting-started) -- [Introduction to Resource Model of Azure Cosmos DB Service]( https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-resources) -- [Introduction to SQL API of Azure Cosmos DB Service](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-sql-query) -- [SDK JavaDoc API](https://azure.github.io/azure-cosmosdb-java/2.4.0/com/microsoft/azure/cosmosdb/rx/AsyncDocumentClient.html) -- [RxJava Observable JavaDoc API](http://reactivex.io/RxJava/1.x/javadoc/rx/Observable.html) -- [SDK FAQ](faq/) - -## Prerequisites -* Java Development Kit 8 -* An active Azure account. If you don't have one, you can sign up for a [free account](https://azure.microsoft.com/free/). Alternatively, you can use the [Azure Cosmos DB Emulator](https://azure.microsoft.com/documentation/articles/documentdb-nosql-local-emulator) for development and testing. As emulator https certificate is self signed, you need to import its certificate to java trusted cert store as [explained here](https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator-export-ssl-certificates) -* (Optional) SLF4J is a logging facade. -* (Optional) [SLF4J binding](http://www.slf4j.org/manual.html) is used to associate a specific logging framework with SLF4J. -* (Optional) Maven - -SLF4J is only needed if you plan to use logging, please also download an SLF4J binding which will link the SLF4J API with the logging implementation of your choice. See the [SLF4J user manual](http://www.slf4j.org/manual.html) for more information. - - -## API Documentation -Javadoc is available [here](https://azure.github.io/azure-cosmosdb-java/2.4.0/com/microsoft/azure/cosmosdb/rx/AsyncDocumentClient.html). - -The SDK provide Reactive Extension Observable based async API. You can read more about RxJava and [Observable APIs here](http://reactivex.io/RxJava/1.x/javadoc/rx/Observable.html). - - -## Usage Code Sample - -Code Sample for creating a Document: -```java -import com.microsoft.azure.cosmosdb.rx.*; -import com.microsoft.azure.cosmosdb.*; - -ConnectionPolicy policy = new ConnectionPolicy(); -policy.setConnectionMode(ConnectionMode.Direct); - -AsyncDocumentClient asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(HOST) - .withMasterKeyOrResourceToken(MASTER_KEY) - .withConnectionPolicy(policy) - .withConsistencyLevel(ConsistencyLevel.Eventual) - .build(); - -Document doc = new Document(String.format("{ 'id': 'doc%d', 'counter': '%d'}", 1, 1)); - -Observable> createDocumentObservable = - asyncClient.createDocument(collectionLink, doc, null, false); - createDocumentObservable - .single() // we know there will be one response - .subscribe( - - documentResourceResponse -> { - System.out.println(documentResourceResponse.getRequestCharge()); - }, - - error -> { - System.err.println("an error happened: " + error.getMessage()); - }); -``` - -We have a get started sample app available [here](https://github.com/Azure-Samples/azure-cosmos-db-sql-api-async-java-getting-started). - -Also We have more examples in form of standalone unit tests in [examples project](examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples). - - -## Guide for Prod -To achieve better performance and higher throughput there are a few tips that are helpful to follow: - -### Use Appropriate Scheduler (Avoid stealing Eventloop IO Netty threads) -SDK uses [netty](https://netty.io/) for non-blocking IO. The SDK uses a fixed number of IO netty eventloop threads (as many CPU cores your machine has) for executing IO operations. - - The Observable returned by API emits the result on one of the shared IO eventloop netty threads. So it is important to not block the shared IO eventloop netty threads. Doing CPU intensive work or blocking operation on the IO eventloop netty thread may cause deadlock or significantly reduce SDK throughput. - -For example the following code executes a cpu intensive work on the eventloop IO netty thread: - - -```java -Observable> createDocObs = asyncDocumentClient.createDocument( - collectionLink, document, null, true); - -createDocObs.subscribe( - resourceResponse -> { - //this is executed on eventloop IO netty thread. - //the eventloop thread is shared and is meant to return back quickly. - // - // DON'T do this on eventloop IO netty thread. - veryCpuIntensiveWork(); - }); - -``` - -After result is received if you want to do CPU intensive work on the result you should avoid doing so on eventloop IO netty thread. You can instead provide your own Scheduler to provide your own thread for running your work. - -```java -import rx.schedulers; - -Observable> createDocObs = asyncDocumentClient.createDocument( - collectionLink, document, null, true); - -createDocObs.subscribeOn(Schedulers.computation()) -subscribe( - resourceResponse -> { - // this is executed on threads provided by Scheduler.computation() - // Schedulers.computation() should be used only the work is cpu intensive and you are not doing blocking IO, thread sleep, etc. in this thread against other resources. - veryCpuIntensiveWork(); - }); - -``` - -Based on the type of your work you should use the appropriate existing RxJava Scheduler for your work. Please read here -[``Schedulers``](http://reactivex.io/RxJava/1.x/javadoc/rx/schedulers/Schedulers.html). - - -### Disable netty's logging -Netty library logging is very chatty and need to be turned off (suppressing log in the configuration may not be enough) to avoid additional CPU costs. -If you are not in debugging mode disable netty's logging altogether. So if you are using log4j to remove the additional CPU costs incurred by ``org.apache.log4j.Category.callAppenders()`` from netty add the following line to your codebase: - -```java -org.apache.log4j.Logger.getLogger("io.netty").setLevel(org.apache.log4j.Level.OFF); -``` - -### OS Open files Resource Limit -Some Linux systems (like Redhat) have an upper limit on the number of open files and so the total number of connections. Run the following to view the current limits: - -```bash -ulimit -a -``` - -The number of open files (nofile) need to be large enough to have enough room for your configured connection pool size and other open files by the OS. It can be modified to allow for a larger connection pool size. - -Open the limits.conf file: - -```bash -vim /etc/security/limits.conf -``` -Add/modify the following lines: - -``` -* - nofile 100000 -``` - -### Use native SSL implementation for netty -Netty can use OpenSSL directly for SSL implementation stack to achieve better performance. -In the absence of this configuration netty will fall back to Java's default SSL implementation. - -on Ubuntu: -```bash -sudo apt-get install openssl -sudo apt-get install libapr1 -``` - -and add the following dependency to your project maven dependencies: -```xml - - io.netty - netty-tcnative - 2.0.20.Final - linux-x86_64 - -``` - -For other platforms (Redhat, Windows, Mac, etc) please refer to these instructions https://netty.io/wiki/forked-tomcat-native.html - -### Common Perf Tips -There is a set of common perf tips written for our sync SDK. The majority of them also apply to the async SDK. It is available [here](https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java). - -## Future, CompletableFuture, and ListenableFuture - -The SDK provide Reactive Extension (Rx) [Observable](http://reactivex.io/RxJava/1.x/javadoc/rx/Observable.html) based async API. - - -RX API has advantages over Future based APIs. But if you wish to use ``Future`` you can translate Observables to Java native Futures: - -```java -// You can convert an Observable to a ListenableFuture. -// ListenableFuture (part of google guava library) is a popular extension -// of Java's Future which allows registering listener callbacks: -// https://github.com/google/guava/wiki/ListenableFutureExplained - -import rx.observable.ListenableFutureObservable; - -Observable> createDocObservable = asyncClient.createDocument( - collectionLink, document, null, false); - -// NOTE: if you are going to do CPU intensive work -// on the result thread consider changing the scheduler see Use Proper Scheduler -// (Avoid Stealing Eventloop IO Netty threads) section -ListenableFuture> listenableFuture = - ListenableFutureObservable.to(createDocObservable); - -ResourceResponse rrd = listenableFuture.get(); -``` - -For this to work you will need [RxJava Guava library dependency ](https://mvnrepository.com/artifact/io.reactivex/rxjava-guava/1.0.3). More information available here https://github.com/ReactiveX/RxJavaGuava. - -You can see more details on how to convert Observables to Futures here: -https://dzone.com/articles/converting-between - -## Checking out the Source Code -The SDK is open source and is available here [sdk](sdk/). - - Clone the Repo -```bash -git clone https://github.com/Azure/azure-cosmosdb-java.git -cd azure-cosmosdb-java -``` - -### How to Build from Command Line - -* Run the following maven command to build: - -```bash -maven clean package -DskipTests -``` - -#### Running Tests from Command Line - -Running tests require Azure Cosmos DB Endpoint credentials: - -```bash -mvn test -DACCOUNT_HOST="https://REPLACE_ME_WITH_YOURS.documents.azure.com:443/" -DACCOUNT_KEY="REPLACE_ME_WITH_YOURS" -``` - -### Import into Intellij or Eclipse - -* Load the main parent project pom file in Intellij/Eclipse (That should automatically load examples). -* For running the samples you need a proper Azure Cosmos DB Endpoint. The endpoints are picked up from [TestConfigurations.java](examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/TestConfigurations.java). There is a similar endpoint config file for the sdk tests [here](sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestConfigurations.java). -* You can pass your endpoint credentials as VM Arguments in Eclipse JUnit Run Config: -```bash - -DACCOUNT_HOST="https://REPLACE_ME.documents.azure.com:443/" -DACCOUNT_KEY="REPLACE_ME" - ``` -* or you can simply put your endpoint credentials in TestConfigurations.java -* The SDK tests are written using TestNG framework, if you use Eclipse you may have to - add TestNG plugin to your eclipse IDE as explained [here](http://testng.org/doc/eclipse.html). - Intellij has builtin support for TestNG. -* Now you can run the tests in your Intellij/Eclipse IDE. - - -## FAQ -We have a frequently asked questions which is maintained [here](faq/). - -## Release changes -Release changelog is available [here](changelog/). - - -## Contribution and Feedback - -This is an open source project and we welcome contributions. - -If you would like to become an active contributor to this project please follow the instructions provided in [Azure Projects Contribution Guidelines](http://azure.github.io/guidelines/). - -We have [travis build CI](https://travis-ci.org/Azure/azure-cosmosdb-java) which should pass for any PR. - -If you encounter any bugs with the SDK please file an [issue](https://github.com/Azure/azure-cosmosdb-java/issues) in the Issues section of the project. - - -## License -MIT License -Copyright (c) 2018 Copyright (c) Microsoft Corporation diff --git a/cosmosdb/data-plane/benchmark/README.md b/cosmosdb/data-plane/benchmark/README.md deleted file mode 100644 index 4f7aadcc7796..000000000000 --- a/cosmosdb/data-plane/benchmark/README.md +++ /dev/null @@ -1,81 +0,0 @@ -# Benchmark tool - -## Build the benchmarking tool - -```bash -git clone https://github.com/Azure/azure-cosmosdb-java.git -cd azure-cosmosdb-java - -mvn clean package -DskipTests -``` - -and then the package will be generated. - -## Run the WriteLatency workload - -```bash -java -jar benchmark/target/azure-cosmosdb-benchmark-2.4.1-SNAPSHOT-jar-with-dependencies.jar \ - -serviceEndpoint $endpoint -masterKey $masterkey \ - -databaseId $dbname -collectionId $colname \ - -consistencyLevel Eventual -concurrency 10 -numberOfOperations 1000000 \ - -operation WriteLatency -connectionMode Direct -``` - -## Sample Report: - -``` -2/13/19 9:32:39 PM ============================================================= - --- Meters ---------------------------------------------------------------------- -#Successful Operations - count = 89934 - mean rate = 1798.56 events/second - 1-minute rate = 1718.45 events/second - 5-minute rate = 1630.17 events/second - 15-minute rate = 1610.01 events/second -#Unsuccessful Operations - count = 0 - mean rate = 0.00 events/second - 1-minute rate = 0.00 events/second - 5-minute rate = 0.00 events/second - 15-minute rate = 0.00 events/second - --- Timers ---------------------------------------------------------------------- -Latency - count = 89938 - mean rate = 1798.64 calls/second - 1-minute rate = 1718.65 calls/second - 5-minute rate = 1630.37 calls/second - 15-minute rate = 1610.21 calls/second - min = 3.97 milliseconds - max = 22.81 milliseconds - mean = 5.37 milliseconds - stddev = 0.96 milliseconds - median = 5.26 milliseconds - 75% <= 5.70 milliseconds - 95% <= 6.40 milliseconds - 98% <= 6.93 milliseconds - 99% <= 7.51 milliseconds - 99.9% <= 17.37 milliseconds -``` - -## Other Currently Supported Workloads - -* ReadLatency, -* WriteLatency, -* ReadThroughput, -* WriteThroughput, -* QueryCross, -* QuerySingle, -* QuerySingleMany, -* QueryParallel, -* QueryOrderby, -* QueryAggregate, -* QueryAggregateTopOrderby, -* QueryTopOrderby, -* Mixed -* ReadMyWrites - - -You can provide ``--help`` to the tool to see the list of other work loads (read, etc) and other options. - diff --git a/cosmosdb/data-plane/benchmark/pom.xml b/cosmosdb/data-plane/benchmark/pom.xml deleted file mode 100644 index 1bf6722f0281..000000000000 --- a/cosmosdb/data-plane/benchmark/pom.xml +++ /dev/null @@ -1,196 +0,0 @@ - - - - 4.0.0 - - com.microsoft.azure - azure-cosmosdb-parent - 2.4.5 - - - azure-cosmosdb-benchmark - Async SDK for SQL API of Azure Cosmos DB Service - Benchmarking tool - Benchmarking tool for Async SDK for SQL API of Azure Cosmos DB Service - - - UTF-8 - 1.7.6 - 1.2.17 - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - com.microsoft.azure.cosmosdb.benchmark.Main - - - - maven-assembly-plugin - 2.2 - - - jar-with-dependencies - - - - com.microsoft.azure.cosmosdb.benchmark.Main - - - - - - make-assembly - package - - single - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 - - - - - - - - - com.microsoft.azure - azure-cosmosdb - - - com.microsoft.azure - azure-cosmosdb-commons-test-utils - - - io.netty - netty-tcnative - 2.0.20.Final - linux-x86_64 - - - com.google.guava - guava - ${guava.version} - - - io.reactivex - rxjava-guava - 1.0.3 - - - org.mockito - mockito-core - ${mockito.version} - test - - - org.hamcrest - hamcrest-all - 1.3 - test - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - - - log4j - log4j - ${log4j.version} - - - io.dropwizard.metrics - metrics-core - ${metrics.version} - - - io.dropwizard.metrics - metrics-jvm - ${metrics.version} - - - io.dropwizard.metrics - metrics-graphite - ${metrics.version} - - - com.beust - jcommander - 1.58 - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.testng - testng - ${testng.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.mockito - mockito-all - ${mockito.version} - test - - - diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncBenchmark.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncBenchmark.java deleted file mode 100644 index 477118e3d51c..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncBenchmark.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.codahale.metrics.ConsoleReporter; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricFilter; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.ScheduledReporter; -import com.codahale.metrics.Timer; -import com.codahale.metrics.graphite.Graphite; -import com.codahale.metrics.graphite.GraphiteReporter; -import com.codahale.metrics.jvm.CachedThreadStatesGaugeSet; -import com.codahale.metrics.jvm.GarbageCollectorMetricSet; -import com.codahale.metrics.jvm.MemoryUsageGaugeSet; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.benchmark.Configuration.Operation; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.apache.commons.lang3.RandomStringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Subscriber; - -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -abstract class AsyncBenchmark { - private final MetricRegistry metricsRegistry = new MetricRegistry(); - private final ScheduledReporter reporter; - private final CountDownLatch operationCounterLatch; - private final String nameCollectionLink; - - private Meter successMeter; - private Meter failureMeter; - - final Logger logger; - final AsyncDocumentClient client; - final DocumentCollection collection; - final String partitionKey; - final Configuration configuration; - final List docsToRead; - final Semaphore concurrencyControlSemaphore; - Timer latency; - - AsyncBenchmark(Configuration cfg) { - client = new AsyncDocumentClient.Builder() - .withServiceEndpoint(cfg.getServiceEndpoint()) - .withMasterKeyOrResourceToken(cfg.getMasterKey()) - .withConnectionPolicy(cfg.getConnectionPolicy()) - .withConsistencyLevel(cfg.getConsistencyLevel()) - .build(); - - logger = LoggerFactory.getLogger(this.getClass()); - - Database database = DocDBUtils.getDatabase(client, cfg.getDatabaseId()); - collection = DocDBUtils.getCollection(client, database.getSelfLink(), cfg.getCollectionId()); - nameCollectionLink = String.format("dbs/%s/colls/%s", database.getId(), collection.getId()); - partitionKey = collection.getPartitionKey().getPaths().iterator().next().split("/")[1]; - concurrencyControlSemaphore = new Semaphore(cfg.getConcurrency()); - operationCounterLatch = new CountDownLatch(cfg.getNumberOfOperations()); - configuration = cfg; - - ArrayList> createDocumentObservables = new ArrayList<>(); - - if (configuration.getOperationType() != Operation.WriteLatency - && configuration.getOperationType() != Operation.WriteThroughput - && configuration.getOperationType() != Operation.ReadMyWrites) { - String dataFieldValue = RandomStringUtils.randomAlphabetic(cfg.getDocumentDataFieldSize()); - for (int i = 0; i < cfg.getNumberOfPreCreatedDocuments(); i++) { - String uuid = UUID.randomUUID().toString(); - Document newDoc = new Document(); - newDoc.setId(uuid); - newDoc.set(partitionKey, uuid); - newDoc.set("dataField1", dataFieldValue); - newDoc.set("dataField2", dataFieldValue); - newDoc.set("dataField3", dataFieldValue); - newDoc.set("dataField4", dataFieldValue); - newDoc.set("dataField5", dataFieldValue); - Observable obs = client.createDocument(collection.getSelfLink(), newDoc, null, false) - .map(ResourceResponse::getResource); - createDocumentObservables.add(obs); - } - } - - docsToRead = Observable.merge(createDocumentObservables, 100).toList().toBlocking().single(); - init(); - - if (configuration.isEnableJvmStats()) { - metricsRegistry.register("gc", new GarbageCollectorMetricSet()); - metricsRegistry.register("threads", new CachedThreadStatesGaugeSet(10, TimeUnit.SECONDS)); - metricsRegistry.register("memory", new MemoryUsageGaugeSet()); - } - - if (configuration.getGraphiteEndpoint() != null) { - final Graphite graphite = new Graphite(new InetSocketAddress(configuration.getGraphiteEndpoint(), configuration.getGraphiteEndpointPort())); - reporter = GraphiteReporter.forRegistry(metricsRegistry) - .prefixedWith(configuration.getOperationType().name()) - .convertRatesTo(TimeUnit.SECONDS) - .convertDurationsTo(TimeUnit.MILLISECONDS) - .filter(MetricFilter.ALL) - .build(graphite); - } else { - reporter = ConsoleReporter.forRegistry(metricsRegistry).convertRatesTo(TimeUnit.SECONDS) - .convertDurationsTo(TimeUnit.MILLISECONDS).build(); - } - } - - protected void init() { - } - - void shutdown() { - client.close(); - } - - protected void onSuccess() { - } - - protected void onError(Throwable throwable) { - } - - protected String getCollectionLink() { - if (configuration.isUseNameLink()) { - return this.nameCollectionLink; - } else { - return collection.getSelfLink(); - } - } - - protected String getDocumentLink(Document doc) { - if (configuration.isUseNameLink()) { - return this.nameCollectionLink + "/docs/" + doc.getId(); - } else { - return doc.getSelfLink(); - } - } - - protected abstract void performWorkload(Subscriber subs, long i) throws Exception; - - void run() throws Exception { - - successMeter = metricsRegistry.meter("#Successful Operations"); - failureMeter = metricsRegistry.meter("#Unsuccessful Operations"); - if (configuration.getOperationType() == Operation.ReadLatency - || configuration.getOperationType() == Operation.WriteLatency) - latency = metricsRegistry.timer("Latency"); - - reporter.start(configuration.getPrintingInterval(), TimeUnit.SECONDS); - - long startTime = System.currentTimeMillis(); - - for (long i = 1; i <= configuration.getNumberOfOperations(); i++) { - - Subscriber subs = new Subscriber() { - - @Override - public void onStart() { - } - - @Override - public void onCompleted() { - successMeter.mark(); - concurrencyControlSemaphore.release(); - operationCounterLatch.countDown(); - AsyncBenchmark.this.onSuccess(); - } - - @Override - public void onError(Throwable e) { - failureMeter.mark(); - logger.error("Encountered failure {} on thread {}" , - e.getMessage(), Thread.currentThread().getName(), e); - concurrencyControlSemaphore.release(); - operationCounterLatch.countDown(); - AsyncBenchmark.this.onError(e); - } - - @Override - public void onNext(T value) { - } - }; - - performWorkload(subs, i); - } - - operationCounterLatch.await(); - long endTime = System.currentTimeMillis(); - logger.info("[{}] operations performed in [{}] seconds.", - configuration.getNumberOfOperations(), (int) ((endTime - startTime) / 1000)); - - reporter.report(); - reporter.close(); - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncMixedBenchmark.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncMixedBenchmark.java deleted file mode 100644 index 9af6ddd21e59..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncMixedBenchmark.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import org.apache.commons.lang3.RandomStringUtils; -import rx.Observable; -import rx.Subscriber; -import rx.schedulers.Schedulers; - -import java.util.Random; -import java.util.UUID; - -class AsyncMixedBenchmark extends AsyncBenchmark { - - private final String uuid; - private final String dataFieldValue; - private final Random r; - - AsyncMixedBenchmark(Configuration cfg) { - super(cfg); - uuid = UUID.randomUUID().toString(); - dataFieldValue = RandomStringUtils.randomAlphabetic(configuration.getDocumentDataFieldSize()); - r = new Random(); - } - - @Override - protected void performWorkload(Subscriber subs, long i) throws InterruptedException { - Observable obs; - if (i % 10 == 0 && i % 100 != 0) { - - String idString = uuid + i; - Document newDoc = new Document(); - newDoc.setId(idString); - newDoc.set(partitionKey, idString); - newDoc.set("dataField1", dataFieldValue); - newDoc.set("dataField2", dataFieldValue); - newDoc.set("dataField3", dataFieldValue); - newDoc.set("dataField4", dataFieldValue); - newDoc.set("dataField5", dataFieldValue); - obs = client.createDocument(getCollectionLink(), newDoc, null, false).map(ResourceResponse::getResource); - - } else if (i % 100 == 0) { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(10); - options.setEnableCrossPartitionQuery(true); - - String sqlQuery = "Select top 100 * from c order by c._ts"; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options) - .map(frp -> frp.getResults().get(0)); - } else { - - int index = r.nextInt(1000); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(docsToRead.get(index).getId())); - - obs = client.readDocument(getDocumentLink(docsToRead.get(index)), options).map(ResourceResponse::getResource); - } - - concurrencyControlSemaphore.acquire(); - - obs.subscribeOn(Schedulers.computation()).subscribe(subs); - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncQueryBenchmark.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncQueryBenchmark.java deleted file mode 100644 index 73df9a4ab81d..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncQueryBenchmark.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import java.util.Random; - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.benchmark.Configuration.Operation; - -import rx.Observable; -import rx.Subscriber; -import rx.schedulers.Schedulers; - -import javax.net.ssl.SSLException; - -class AsyncQueryBenchmark extends AsyncBenchmark> { - - private int pageCount = 0; - - AsyncQueryBenchmark(Configuration cfg) { - super(cfg); - } - - @Override - protected void onSuccess() { - pageCount++; - if (pageCount % 10000 == 0) { - if (pageCount == 0) { - return; - } - logger.info("total pages so far: {}", pageCount); - } - } - - @Override - protected void performWorkload(Subscriber> subs, long i) throws InterruptedException { - - Observable> obs; - Random r = new Random(); - FeedOptions options = new FeedOptions(); - - if (configuration.getOperationType() == Operation.QueryCross) { - - int index = r.nextInt(1000); - options.setEnableCrossPartitionQuery(true); - String sqlQuery = "Select * from c where c._rid = \"" + docsToRead.get(index).getResourceId() + "\""; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options); - } else if (configuration.getOperationType() == Operation.QuerySingle) { - - int index = r.nextInt(1000); - String pk = docsToRead.get(index).getString("pk"); - options.setPartitionKey(new PartitionKey(pk)); - String sqlQuery = "Select * from c where c.pk = \"" + pk + "\""; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options); - } else if (configuration.getOperationType() == Operation.QueryParallel) { - - options.setMaxItemCount(10); - options.setEnableCrossPartitionQuery(true); - String sqlQuery = "Select * from c"; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options); - } else if (configuration.getOperationType() == Operation.QueryOrderby) { - - options.setMaxItemCount(10); - options.setEnableCrossPartitionQuery(true); - String sqlQuery = "Select * from c order by c._ts"; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options); - } else if (configuration.getOperationType() == Operation.QueryAggregate) { - - options.setMaxItemCount(10); - options.setEnableCrossPartitionQuery(true); - String sqlQuery = "Select value max(c._ts) from c"; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options); - } else if (configuration.getOperationType() == Operation.QueryAggregateTopOrderby) { - - options.setEnableCrossPartitionQuery(true); - String sqlQuery = "Select top 1 value count(c) from c order by c._ts"; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options); - } else if (configuration.getOperationType() == Operation.QueryTopOrderby) { - - options.setEnableCrossPartitionQuery(true); - String sqlQuery = "Select top 1000 * from c order by c._ts"; - obs = client.queryDocuments(getCollectionLink(), sqlQuery, options); - } else { - throw new IllegalArgumentException("Unsupported Operation: " + configuration.getOperationType()); - } - concurrencyControlSemaphore.acquire(); - - obs.subscribeOn(Schedulers.computation()).subscribe(subs); - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncQuerySinglePartitionMultiple.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncQuerySinglePartitionMultiple.java deleted file mode 100644 index 1d515226bea8..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncQuerySinglePartitionMultiple.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; - -import rx.Observable; -import rx.Subscriber; -import rx.schedulers.Schedulers; - -import javax.net.ssl.SSLException; - -class AsyncQuerySinglePartitionMultiple extends AsyncBenchmark> { - - private static final String SQL_QUERY = "Select * from c where c.pk = \"pk\""; - private FeedOptions options; - private int pageCount = 0; - - AsyncQuerySinglePartitionMultiple(Configuration cfg) { - super(cfg); - options = new FeedOptions(); - options.setPartitionKey(new PartitionKey("pk")); - options.setMaxItemCount(10); - } - - @Override - protected void onSuccess() { - pageCount++; - if (pageCount % 10000 == 0) { - if (pageCount == 0) { - return; - } - logger.info("total pages so far: {}", pageCount); - } - } - - @Override - protected void performWorkload(Subscriber> subs, long i) throws InterruptedException { - Observable> obs = client.queryDocuments(getCollectionLink(), SQL_QUERY, options); - - concurrencyControlSemaphore.acquire(); - - obs.subscribeOn(Schedulers.computation()).subscribe(subs); - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncReadBenchmark.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncReadBenchmark.java deleted file mode 100644 index bdf0454f3824..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncReadBenchmark.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.codahale.metrics.Timer; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.benchmark.Configuration.Operation; - -import rx.Observable; -import rx.Subscriber; -import rx.schedulers.Schedulers; - -import javax.net.ssl.SSLException; - -class AsyncReadBenchmark extends AsyncBenchmark> { - - class LatencySubscriber extends Subscriber { - - Timer.Context context; - Subscriber subscriber; - - LatencySubscriber(Subscriber subscriber) { - this.subscriber = subscriber; - } - - @Override - public void onCompleted() { - context.stop(); - subscriber.onCompleted(); - } - - @Override - public void onError(Throwable e) { - context.stop(); - subscriber.onError(e); - } - - @Override - public void onNext(T t) { - subscriber.onNext(t); - } - } - - AsyncReadBenchmark(Configuration cfg) { - super(cfg); - } - - @Override - protected void performWorkload(Subscriber> subs, long i) throws InterruptedException { - int index = (int) (i % docsToRead.size()); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(docsToRead.get(index).getId())); - - Observable> obs = client.readDocument(getDocumentLink(docsToRead.get(index)), options); - - concurrencyControlSemaphore.acquire(); - - if (configuration.getOperationType() == Operation.ReadThroughput) { - obs.subscribeOn(Schedulers.computation()).subscribe(subs); - } else { - LatencySubscriber> latencySubscriber = new LatencySubscriber<>( - subs); - latencySubscriber.context = latency.time(); - obs.subscribeOn(Schedulers.computation()).subscribe(latencySubscriber); - } - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncWriteBenchmark.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncWriteBenchmark.java deleted file mode 100644 index 8256e1c48cba..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/AsyncWriteBenchmark.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import java.util.UUID; - -import org.apache.commons.lang3.RandomStringUtils; - -import com.codahale.metrics.Timer; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.benchmark.Configuration.Operation; - -import rx.Observable; -import rx.Subscriber; -import rx.schedulers.Schedulers; - -import javax.net.ssl.SSLException; - -class AsyncWriteBenchmark extends AsyncBenchmark> { - - private final String uuid; - private final String dataFieldValue; - - class LatencySubscriber extends Subscriber { - - Timer.Context context; - Subscriber subscriber; - - LatencySubscriber(Subscriber subscriber) { - this.subscriber = subscriber; - } - - @Override - public void onCompleted() { - context.stop(); - subscriber.onCompleted(); - } - - @Override - public void onError(Throwable e) { - context.stop(); - subscriber.onError(e); - } - - @Override - public void onNext(T t) { - subscriber.onNext(t); - } - } - - AsyncWriteBenchmark(Configuration cfg) { - super(cfg); - uuid = UUID.randomUUID().toString(); - dataFieldValue = RandomStringUtils.randomAlphabetic(configuration.getDocumentDataFieldSize()); - } - - @Override - protected void performWorkload(Subscriber> subs, long i) throws InterruptedException { - - String idString = uuid + i; - Document newDoc = new Document(); - newDoc.setId(idString); - newDoc.set(partitionKey, idString); - newDoc.set("dataField1", dataFieldValue); - newDoc.set("dataField2", dataFieldValue); - newDoc.set("dataField3", dataFieldValue); - newDoc.set("dataField4", dataFieldValue); - newDoc.set("dataField5", dataFieldValue); - Observable> obs = client.createDocument(getCollectionLink(), newDoc, null, - false); - - concurrencyControlSemaphore.acquire(); - - if (configuration.getOperationType() == Operation.WriteThroughput) { - obs.subscribeOn(Schedulers.computation()).subscribe(subs); - } else { - LatencySubscriber> latencySubscriber = new LatencySubscriber<>( - subs); - latencySubscriber.context = latency.time(); - obs.subscribeOn(Schedulers.computation()).subscribe(latencySubscriber); - } - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/Configuration.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/Configuration.java deleted file mode 100644 index 915591f8b7c9..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/Configuration.java +++ /dev/null @@ -1,311 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import java.util.Arrays; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; - -import com.beust.jcommander.IStringConverter; -import com.beust.jcommander.Parameter; -import com.beust.jcommander.ParameterException; -import com.google.common.base.Strings; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.benchmark.Configuration.Operation.OperationTypeConverter; - -class Configuration { - private final static int GRAPHITE_SERVER_DEFAULT_PORT = 2003; - - @Parameter(names = "-serviceEndpoint", description = "Service Endpoint") - private String serviceEndpoint; - - @Parameter(names = "-masterKey", description = "Master Key") - private String masterKey; - - @Parameter(names = "-databaseId", description = "Database ID") - private String databaseId; - - @Parameter(names = "-collectionId", description = "Collection ID") - private String collectionId; - - @Parameter(names = "-useNameLink", description = "Use name Link") - private boolean useNameLink = false; - - @Parameter(names = "-documentDataFieldSize", description = "Length of a document data field in characters (16-bit)") - private int documentDataFieldSize = 20; - - @Parameter(names = "-maxConnectionPoolSize", description = "Max Connection Pool Size") - private Integer maxConnectionPoolSize = 1000; - - @Parameter(names = "-consistencyLevel", description = "Consistency Level", converter = ConsistencyLevelConverter.class) - private ConsistencyLevel consistencyLevel = ConsistencyLevel.Session; - - @Parameter(names = "-connectionMode", description = "Connection Mode") - private ConnectionMode connectionMode = ConnectionMode.Direct; - - @Parameter(names = "-graphiteEndpoint", description = "Graphite endpoint") - private String graphiteEndpoint; - - @Parameter(names = "-enableJvmStats", description = "Enables JVM Stats") - private boolean enableJvmStats; - - @Parameter(names = "-operation", description = "Type of Workload:\n" - + "\tReadThroughput- run a Read workload that prints only throughput *\n" - + "\tWriteThroughput - run a Write workload that prints only throughput\n" - + "\tReadLatency - run a Read workload that prints both throughput and latency *\n" - + "\tWriteLatency - run a Write workload that prints both throughput and latency\n" - + "\tQueryCross - run a 'Select * from c where c._rid = SOME_RID' workload that prints throughput\n" - + "\tQuerySingle - run a 'Select * from c where c.pk = SOME_PK' workload that prints throughput\n" - + "\tQuerySingleMany - run a 'Select * from c where c.pk = \"pk\"' workload that prints throughput\n" - + "\tQueryParallel - run a 'Select * from c' workload that prints throughput\n" - + "\tQueryOrderby - run a 'Select * from c order by c._ts' workload that prints throughput\n" - + "\tQueryAggregate - run a 'Select value max(c._ts) from c' workload that prints throughput\n" - + "\tQueryAggregateTopOrderby - run a 'Select top 1 value count(c) from c order by c._ts' workload that prints throughput\n" - + "\tQueryTopOrderby - run a 'Select top 1000 * from c order by c._ts' workload that prints throughput\n" - + "\tMixed - runa workload of 90 reads, 9 writes and 1 QueryTopOrderby per 100 operations *\n" - + "\tReadMyWrites - run a workflow of writes followed by reads and queries attempting to read the write.*\n" - + "\n\t* writes 10k documents initially, which are used in the reads", converter = OperationTypeConverter.class) - private Operation operation = Operation.WriteThroughput; - - @Parameter(names = "-concurrency", description = "Degree of Concurrency in Inserting Documents." - + " If this value is not specified, the max connection pool size will be used as the concurrency level.") - private Integer concurrency; - - @Parameter(names = "-numberOfOperations", description = "Total Number Of Documents To Insert") - private int numberOfOperations = 100000; - - @Parameter(names = "-printingInterval", description = "Interval of time after which Metrics should be printed (seconds)") - private int printingInterval = 10; - - @Parameter(names = "-numberOfPreCreatedDocuments", description = "Total Number Of Documents To pre create for a read workload to use") - private int numberOfPreCreatedDocuments = 1000; - - @Parameter(names = {"-h", "-help", "--help"}, description = "Help", help = true) - private boolean help = false; - - enum Operation { - ReadThroughput, - WriteThroughput, - ReadLatency, - WriteLatency, - QueryCross, - QuerySingle, - QuerySingleMany, - QueryParallel, - QueryOrderby, - QueryAggregate, - QueryAggregateTopOrderby, - QueryTopOrderby, - Mixed, - ReadMyWrites; - - static Operation fromString(String code) { - - for (Operation output : Operation.values()) { - if (output.toString().equalsIgnoreCase(code)) { - return output; - } - } - - return null; - } - - static class OperationTypeConverter implements IStringConverter { - - /* - * (non-Javadoc) - * - * @see com.beust.jcommander.IStringConverter#convert(java.lang.String) - */ - @Override - public Operation convert(String value) { - Operation ret = fromString(value); - if (ret == null) { - throw new ParameterException("Value " + value + " can not be converted to ClientType. " - + "Available values are: " + Arrays.toString(Operation.values())); - } - return ret; - } - } - } - - private static ConsistencyLevel fromString(String code) { - for (ConsistencyLevel output : ConsistencyLevel.values()) { - if (output.toString().equalsIgnoreCase(code)) { - return output; - } - } - return null; - } - - static class ConsistencyLevelConverter implements IStringConverter { - - /* - * (non-Javadoc) - * - * @see com.beust.jcommander.IStringConverter#convert(java.lang.String) - */ - @Override - public ConsistencyLevel convert(String value) { - ConsistencyLevel ret = fromString(value); - if (ret == null) { - throw new ParameterException("Value " + value + " can not be converted to ClientType. " - + "Available values are: " + Arrays.toString(Operation.values())); - } - return ret; - } - } - - Operation getOperationType() { - return operation; - } - - int getNumberOfOperations() { - return numberOfOperations; - } - - String getServiceEndpoint() { - return serviceEndpoint; - } - - String getMasterKey() { - return masterKey; - } - - boolean isHelp() { - return help; - } - - int getDocumentDataFieldSize() { - return documentDataFieldSize; - } - - ConnectionPolicy getConnectionPolicy() { - ConnectionPolicy policy = new ConnectionPolicy(); - policy.setConnectionMode(connectionMode); - policy.setMaxPoolSize(maxConnectionPoolSize); - return policy; - } - - ConsistencyLevel getConsistencyLevel() { - return consistencyLevel; - } - - String getDatabaseId() { - return databaseId; - } - - String getCollectionId() { - return collectionId; - } - - int getNumberOfPreCreatedDocuments() { - return numberOfPreCreatedDocuments; - } - - int getPrintingInterval() { - return printingInterval; - } - - int getConcurrency() { - if (this.concurrency != null) { - return concurrency; - } else { - return this.maxConnectionPoolSize; - } - } - - boolean isUseNameLink() { - return useNameLink; - } - - public boolean isEnableJvmStats() { - return enableJvmStats; - } - - public String getGraphiteEndpoint() { - if (graphiteEndpoint == null) { - return null; - } - - return StringUtils.substringBeforeLast(graphiteEndpoint, ":"); - } - - public int getGraphiteEndpointPort() { - if (graphiteEndpoint == null) { - return -1; - } - - String portAsString = Strings.emptyToNull(StringUtils.substringAfterLast(graphiteEndpoint, ":")); - if (portAsString == null) { - return GRAPHITE_SERVER_DEFAULT_PORT; - } else { - return Integer.parseInt(portAsString); - } - } - - public String toString() { - return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); - } - - void tryGetValuesFromSystem() { - serviceEndpoint = StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("SERVICE_END_POINT")), - serviceEndpoint); - - masterKey = StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("MASTER_KEY")), masterKey); - - databaseId = StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("DATABASE_ID")), databaseId); - - collectionId = StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("COLLECTION_ID")), - collectionId); - - documentDataFieldSize = Integer.parseInt( - StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("DOCUMENT_DATA_FIELD_SIZE")), - Integer.toString(documentDataFieldSize))); - - maxConnectionPoolSize = Integer.parseInt( - StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("MAX_CONNECTION_POOL_SIZE")), - Integer.toString(maxConnectionPoolSize))); - - ConsistencyLevelConverter consistencyLevelConverter = new ConsistencyLevelConverter(); - consistencyLevel = consistencyLevelConverter.convert(StringUtils - .defaultString(Strings.emptyToNull(System.getenv().get("CONSISTENCY_LEVEL")), consistencyLevel.name())); - - OperationTypeConverter operationTypeConverter = new OperationTypeConverter(); - operation = operationTypeConverter.convert( - StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("OPERATION")), operation.name())); - - String concurrencyValue = StringUtils.defaultString(Strings.emptyToNull(System.getenv().get("CONCURRENCY")), - concurrency == null ? null : Integer.toString(concurrency)); - concurrency = concurrencyValue == null ? null : Integer.parseInt(concurrencyValue); - - String numberOfOperationsValue = StringUtils.defaultString( - Strings.emptyToNull(System.getenv().get("NUMBER_OF_OPERATIONS")), Integer.toString(numberOfOperations)); - numberOfOperations = Integer.parseInt(numberOfOperationsValue); - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/DocDBUtils.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/DocDBUtils.java deleted file mode 100644 index 4d05fb177cc6..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/DocDBUtils.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.SqlParameter; -import com.microsoft.azure.cosmosdb.SqlParameterCollection; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -class DocDBUtils { - - private DocDBUtils() { - } - - static Database getDatabase(AsyncDocumentClient client, String databaseId) { - FeedResponse feedResponsePages = client - .queryDatabases(new SqlQuerySpec("SELECT * FROM root r WHERE r.id=@id", - new SqlParameterCollection(new SqlParameter("@id", databaseId))), null) - .toBlocking().single(); - - if (feedResponsePages.getResults().isEmpty()) { - throw new RuntimeException("cannot find datatbase " + databaseId); - } - return feedResponsePages.getResults().get(0); - } - - static DocumentCollection getCollection(AsyncDocumentClient client, String databaseLink, - String collectionId) { - FeedResponse feedResponsePages = client - .queryCollections(databaseLink, - new SqlQuerySpec("SELECT * FROM root r WHERE r.id=@id", - new SqlParameterCollection(new SqlParameter("@id", collectionId))), - null) - .toBlocking().single(); - - if (feedResponsePages.getResults().isEmpty()) { - throw new RuntimeException("cannot find collection " + collectionId); - } - return feedResponsePages.getResults().get(0); - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/Main.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/Main.java deleted file mode 100644 index 18c20c619faf..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/Main.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.beust.jcommander.JCommander; -import com.beust.jcommander.ParameterException; - -public class Main { - - private final static Logger LOGGER = LoggerFactory.getLogger(Main.class); - - public static void main(String[] args) throws Exception { - org.apache.log4j.Logger.getLogger("io.netty").setLevel(org.apache.log4j.Level.OFF); - - try { - LOGGER.debug("Parsing the arguments ..."); - Configuration cfg = new Configuration(); - cfg.tryGetValuesFromSystem(); - - JCommander jcommander = new JCommander(cfg, args); - if (cfg.isHelp()) { - // prints out the usage help - jcommander.usage(); - return; - } - - AsyncBenchmark benchmark; - switch (cfg.getOperationType()) { - case WriteThroughput: - case WriteLatency: - benchmark = new AsyncWriteBenchmark(cfg); - break; - - case ReadThroughput: - case ReadLatency: - benchmark = new AsyncReadBenchmark(cfg); - break; - - case QueryCross: - case QuerySingle: - case QueryParallel: - case QueryOrderby: - case QueryAggregate: - case QueryTopOrderby: - case QueryAggregateTopOrderby: - benchmark = new AsyncQueryBenchmark(cfg); - break; - - case Mixed: - benchmark = new AsyncMixedBenchmark(cfg); - break; - - case QuerySingleMany: - benchmark = new AsyncQuerySinglePartitionMultiple(cfg); - break; - - case ReadMyWrites: - benchmark = new ReadMyWriteWorkflow(cfg); - break; - - default: - throw new RuntimeException(cfg.getOperationType() + " is not supported"); - } - - benchmark.run(); - benchmark.shutdown(); - - } catch (ParameterException e) { - // if any error in parsing the cmd-line options print out the usage help - System.err.println("Invalid Usage: " + e.getMessage()); - System.err.println("Try '-help' for more information."); - System.exit(1); - } - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/ReadMyWriteWorkflow.java b/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/ReadMyWriteWorkflow.java deleted file mode 100644 index 5115dcfb0060..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/java/com/microsoft/azure/cosmosdb/benchmark/ReadMyWriteWorkflow.java +++ /dev/null @@ -1,419 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.SqlParameter; -import com.microsoft.azure.cosmosdb.SqlParameterCollection; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.RandomUtils; -import rx.Observable; -import rx.Subscriber; -import rx.schedulers.Schedulers; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -/** - * This workflow is intended for session and above consistency levels. - *

- * This workflow first will create some documents in cosmosdb and will store them all in its local cache. - * Then at each step will randomly will try to do a write, read its own write, or query for its own write. - */ -class ReadMyWriteWorkflow extends AsyncBenchmark { - private final static String QUERY_FIELD_NAME = "prop"; - private final static String ORDER_BY_FIELD_NAME = "_ts"; - private final static int MAX_TOP_QUERY_COUNT = 2000; - - private ConcurrentHashMap cache; - private int cacheSize; - - ReadMyWriteWorkflow(Configuration cfg) { - super(cfg); - } - - @Override - protected void init() { - this.cacheSize = configuration.getNumberOfPreCreatedDocuments(); - this.cache = new ConcurrentHashMap<>(); - this.populateCache(); - } - - @Override - protected void performWorkload(Subscriber subs, long i) throws Exception { - Observable obs; - boolean readyMyWrite = RandomUtils.nextBoolean(); - if (readyMyWrite) { - // will do a write and immediately upon success will either - // do a point read - // or single partition query - // or cross partition query to find the write. - int j = Math.toIntExact(Math.floorMod(i, 3)); - switch (j) { - case 0: - // write a random document to cosmodb and update the cache. - // then try to read the document which just was written - obs = writeDocument() - .flatMap(d -> readDocument(d)); - break; - case 1: - // write a random document to cosmodb and update the cache. - // then try to query for the document which just was written - obs = writeDocument() - .flatMap(d -> singlePartitionQuery(d) - .switchIfEmpty(Observable.error(new NotFoundException( - "couldn't find my write in a single partition query!")))); - break; - case 2: - // write a random document to cosmodb and update the cache. - // then try to query for the document which just was written - obs = writeDocument() - .flatMap(d -> xPartitionQuery(generateQuery(d)) - .switchIfEmpty(Observable.error(new NotFoundException( - "couldn't find my write in a cross partition query!")))); - break; - default: - assert false; - throw new IllegalStateException(); - } - } else { - // will either do - // a write - // a point read for a in memory cached document - // or single partition query for a in memory cached document - // or cross partition query for a in memory cached document - int j = Math.toIntExact(Math.floorMod(i, 4)); - switch (j) { - case 0: - // write a random document to cosmosdb and update the cache - obs = writeDocument(); - break; - case 1: - // randomly choose a document from the cache and do a single point read - obs = readDocument(cache.get(cacheKey())); - break; - case 2: - // randomly choose a document from the cache and do a single partition query - obs = singlePartitionQuery(cache.get(cacheKey())) - .switchIfEmpty(Observable.error(new NotFoundException( - "couldn't find my cached write in a single partition query!"))); - break; - case 3: - // randomly choose a document from the cache and do a cross partition query - obs = xPartitionQuery(generateRandomQuery()) - .switchIfEmpty(Observable.error(new NotFoundException( - "couldn't find my cached write in a cross partition query!"))); - break; - default: - assert false; - throw new IllegalStateException(); - } - } - - concurrencyControlSemaphore.acquire(); - - obs.subscribeOn(Schedulers.computation()).subscribe(subs); - } - - private void populateCache() { - ArrayList> list = new ArrayList<>(); - for (int i = 0; i < cacheSize; i++) { - Observable observable = writeDocument(i); - list.add(observable); - } - - logger.info("Pre-populating {} documents ....", cacheSize); - Observable.merge(list, configuration.getConcurrency()).toCompletable().await(); - logger.info("Finished pre-populating {} documents", cacheSize); - } - - /** - * Writes a random document to cosmosdb and store it in a random location in the cache. - * - * @return Observable of document - */ - private Observable writeDocument() { - return writeDocument(null); - } - - /** - * Writes a random document to cosmosdb and store it in the slot i-th in the cache. - * - * @return Observable of document - */ - private Observable writeDocument(Integer i) { - String idString = Utils.randomUUID().toString(); - String randomVal = Utils.randomUUID().toString(); - Document document = new Document(); - document.setId(idString); - document.set(partitionKey, idString); - document.set(QUERY_FIELD_NAME, randomVal); - document.set("dataField1", randomVal); - document.set("dataField2", randomVal); - document.set("dataField3", randomVal); - document.set("dataField4", randomVal); - - Integer key = i == null ? cacheKey() : i; - return client.createDocument(getCollectionLink(), document, null, false) - .doOnNext(r -> cache.put(key, r.getResource())) - .map(ResourceResponse::getResource); - } - - /** - * given a document tries to read it from cosmosdb - * - * @param d document to be read - * @return Observable of document - */ - private Observable readDocument(Document d) { - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(d.getString(partitionKey))); - - return client.readDocument(getDocumentLink(d), options) - .map(ResourceResponse::getResource); - } - - /** - * Generates a random query - * - * @return a randomly generated query - */ - private SqlQuerySpec generateRandomQuery() { - int docCount = RandomUtils.nextInt(1, 2); - Set keys = new HashSet<>(); - for (int i = 0; i < docCount; i++) { - int key = RandomUtils.nextInt(0, cacheSize); - keys.add(key); - } - List documentList = null; - if (RandomUtils.nextBoolean()) { - documentList = keys.stream().map(cache::get).collect(Collectors.toList()); - } - - int top = RandomUtils.nextInt(0, MAX_TOP_QUERY_COUNT); - boolean useOrderBy = RandomUtils.nextBoolean(); - - return generateQuery(documentList, top > 1000 ? top : null, useOrderBy); - } - - /** - * given a query returns the corresponding observable result - * - * @param query to find document - * @return Observable document - */ - private Observable xPartitionQuery(SqlQuerySpec query) { - FeedOptions options = new FeedOptions(); - options.setMaxDegreeOfParallelism(-1); - options.setEnableCrossPartitionQuery(true); - - return client.queryDocuments(getCollectionLink(), query, options) - .flatMap(p -> Observable.from(p.getResults())); - } - - /** - * given a document returns the corresponding observable result of issuing a single partition query - * for the document. - * - * @param d document to be queried for. - * @return Observable document - */ - private Observable singlePartitionQuery(Document d) { - FeedOptions options = new FeedOptions(); - options.setPartitionKey(new PartitionKey(d.get(partitionKey))); - - SqlQuerySpec sqlQuerySpec = new SqlQuerySpec(String.format("Select top 100 * from c where c.%s = '%s'", - QUERY_FIELD_NAME, - d.getString(QUERY_FIELD_NAME))); - return client.queryDocuments(getCollectionLink(), sqlQuerySpec, options) - .flatMap(p -> Observable.from(p.getResults())); - } - - /** - * Given a document list generates a randomly generated sql query which can find only and only the documents - *

- * The generated query may have a top, orderby, top and orderby. - * - * @param documentList list of documents to be queried for - * @return SqlQuerySpec - */ - private SqlQuerySpec generateQuery(Document... documentList) { - return generateQuery(Arrays.asList(documentList)); - } - - /** - * Given a document list generates a randomly generated sql query which can find only and only the documents - *

- * The generated query may have a top, orderby, top and orderby. - * - * @param documentList list of documents to be queried for - * @return SqlQuerySpec - */ - private SqlQuerySpec generateQuery(List documentList) { - int top = RandomUtils.nextInt(0, MAX_TOP_QUERY_COUNT); - boolean useOrderBy = RandomUtils.nextBoolean(); - - return generateQuery(documentList, top >= documentList.size() ? top : null, useOrderBy); - } - - /** - * Given a document list generates sql query which can find only and only the documents - * - * @param documentList lists of documents to find - * @param topCount if a valid top count, the query will have a top count - * @param withOrderBy if not null, the query will have an orderby clause - * @return SqlQuerySpec - */ - private SqlQuerySpec generateQuery(List documentList, Integer topCount, boolean withOrderBy) { - QueryBuilder queryBuilder = new QueryBuilder(); - if (withOrderBy) { - queryBuilder.orderBy(ORDER_BY_FIELD_NAME); - } - if (documentList != null && !documentList.isEmpty()) { - if (topCount != null) { - topCount = Math.max(topCount, documentList.size()); - } - - queryBuilder.whereClause(QueryBuilder.WhereClause.InWhereClause.asInWhereClause(QUERY_FIELD_NAME, documentList)); - } - - if ((documentList == null || documentList.isEmpty()) && (topCount == null || topCount <= 0)) { - topCount = 100; - } - - if (topCount != null) { - queryBuilder.top(topCount); - } - - return queryBuilder.toSqlQuerySpec(); - } - - private int cacheKey() { - return RandomUtils.nextInt(0, cacheSize); - } - - /** - * This is used for making random query generation with different terms (top, orderby) easier. - */ - static class QueryBuilder { - private String orderByFieldName; - private Integer topCount; - private WhereClause whereClause; - - QueryBuilder top(int top) { - this.topCount = top; - return this; - } - - QueryBuilder orderBy(String fieldName) { - this.orderByFieldName = fieldName; - return this; - } - - QueryBuilder whereClause(WhereClause whereClause) { - this.whereClause = whereClause; - return this; - } - - static abstract class WhereClause { - static class InWhereClause extends WhereClause { - private final List parameters; - private final String whereCondition; - - static InWhereClause asInWhereClause(String fieldName, List documentList) { - List parameters = new ArrayList<>(documentList.size()); - for (int i = 0; i < documentList.size(); i++) { - Object value = documentList.get(i).get(fieldName); - SqlParameter sqlParameter = new SqlParameter("@param" + i, value); - parameters.add(sqlParameter); - } - - return new InWhereClause(fieldName, parameters); - } - - InWhereClause(String fieldName, List parameters) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(fieldName); - stringBuilder.append(" IN ("); - List params = parameters.stream().map(SqlParameter::getName).collect(Collectors.toList()); - stringBuilder.append(String.join(", ", params)); - stringBuilder.append(")"); - - this.whereCondition = stringBuilder.toString(); - this.parameters = parameters; - } - - @Override - String getWhereCondition(String rootName) { - return rootName + "." + this.whereCondition; - } - - @Override - SqlParameterCollection getSqlParameterCollection() { - return new SqlParameterCollection(this.parameters); - } - } - - abstract String getWhereCondition(String rootName); - - abstract SqlParameterCollection getSqlParameterCollection(); - } - - SqlQuerySpec toSqlQuerySpec() { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("SELECT"); - - if (topCount != null) { - stringBuilder.append(" TOP ").append(topCount); - } - - stringBuilder.append(" * FROM root"); - if (whereClause != null) { - stringBuilder.append(" WHERE "); - stringBuilder.append(whereClause.getWhereCondition("root")); - - } - - if (orderByFieldName != null) { - stringBuilder.append(" ORDER BY ").append("root.").append(orderByFieldName); - } - - return whereClause == null ? - new SqlQuerySpec(stringBuilder.toString()) : - new SqlQuerySpec(stringBuilder.toString(), whereClause.getSqlParameterCollection()); - } - } -} diff --git a/cosmosdb/data-plane/benchmark/src/main/resources/log4j.properties b/cosmosdb/data-plane/benchmark/src/main/resources/log4j.properties deleted file mode 100644 index 92751a419201..000000000000 --- a/cosmosdb/data-plane/benchmark/src/main/resources/log4j.properties +++ /dev/null @@ -1,14 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -log4j.category.com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd=WARN -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p %c - %m%n \ No newline at end of file diff --git a/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/QueryBuilderTest.java b/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/QueryBuilderTest.java deleted file mode 100644 index d83d5505e1d3..000000000000 --- a/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/QueryBuilderTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.SqlParameter; -import org.testng.annotations.Test; - -import static com.microsoft.azure.cosmosdb.benchmark.ReadMyWriteWorkflow.QueryBuilder.WhereClause; -import static org.assertj.core.api.Assertions.assertThat; - -public class QueryBuilderTest { - - @Test(groups = {"unit"}) - public void basic() { - ReadMyWriteWorkflow.QueryBuilder queryBuilder = new ReadMyWriteWorkflow.QueryBuilder(); - assertThat(queryBuilder.toSqlQuerySpec().getQueryText()) - .isEqualTo("SELECT * FROM root"); - } - - @Test(groups = {"unit"}) - public void top() { - ReadMyWriteWorkflow.QueryBuilder queryBuilder = new ReadMyWriteWorkflow.QueryBuilder(); - queryBuilder.top(50); - assertThat(queryBuilder.toSqlQuerySpec().getQueryText()) - .isEqualTo("SELECT TOP 50 * FROM root"); - } - - @Test(groups = {"unit"}) - public void orderBy() { - ReadMyWriteWorkflow.QueryBuilder queryBuilder = new ReadMyWriteWorkflow.QueryBuilder(); - queryBuilder.orderBy("prop"); - assertThat(queryBuilder.toSqlQuerySpec().getQueryText()) - .isEqualTo("SELECT * FROM root ORDER BY root.prop"); - } - - @Test(groups = {"unit"}) - public void whereInClause() { - ReadMyWriteWorkflow.QueryBuilder queryBuilder = new ReadMyWriteWorkflow.QueryBuilder(); - - ImmutableList parameters = ImmutableList.of(new SqlParameter("@param1", 1), - new SqlParameter("@param2", 2)); - queryBuilder.whereClause(new WhereClause.InWhereClause("colName", - parameters)); - assertThat(queryBuilder.toSqlQuerySpec().getQueryText()) - .isEqualTo("SELECT * FROM root WHERE root.colName IN (@param1, @param2)"); - assertThat(queryBuilder.toSqlQuerySpec().getParameters()).containsExactlyElementsOf(parameters); - } - - @Test(groups = {"unit"}) - public void topOrderByWhereClause() { - ReadMyWriteWorkflow.QueryBuilder queryBuilder = new ReadMyWriteWorkflow.QueryBuilder(); - queryBuilder.orderBy("prop"); - queryBuilder.top(5); - - ImmutableList parameters = ImmutableList.of(new SqlParameter("@param1", 1), - new SqlParameter("@param2", 2)); - queryBuilder.whereClause(new WhereClause.InWhereClause("colName", - parameters)); - assertThat(queryBuilder.toSqlQuerySpec().getQueryText()) - .isEqualTo("SELECT TOP 5 * FROM root WHERE root.colName IN (@param1, @param2) ORDER BY root.prop"); - assertThat(queryBuilder.toSqlQuerySpec().getParameters()).containsExactlyElementsOf(parameters); - } -} diff --git a/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/Utils.java b/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/Utils.java deleted file mode 100644 index 49517fd05cb5..000000000000 --- a/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/Utils.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.RetryOptions; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import rx.Observable; - -public class Utils { - public static AsyncDocumentClient housekeepingClient() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - RetryOptions options = new RetryOptions(); - options.setMaxRetryAttemptsOnThrottledRequests(100); - options.setMaxRetryWaitTimeInSeconds(60); - connectionPolicy.setRetryOptions(options); - return new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - } - - public static String getCollectionLink(Database db, DocumentCollection collection) { - return "dbs/" + db.getId() + "/colls/" + collection; - } - - public static Database createDatabaseForTest(AsyncDocumentClient client) { - return DatabaseForTest.create(DatabaseManagerImpl.getInstance(client)).createdDatabase; - } - - public static void safeCleanDatabases(AsyncDocumentClient client) { - if (client != null) { - DatabaseForTest.cleanupStaleTestDatabases(DatabaseManagerImpl.getInstance(client)); - } - } - - public static void safeClean(AsyncDocumentClient client, Database database) { - if (database != null) { - safeClean(client, database.getId()); - } - } - - public static void safeClean(AsyncDocumentClient client, String databaseId) { - if (client != null) { - if (databaseId != null) { - try { - client.deleteDatabase("/dbs/" + databaseId, null).toBlocking().single(); - } catch (Exception e) { - } - } - } - } - - public static String generateDatabaseId() { - return DatabaseForTest.generateId(); - } - - public static void safeClose(AsyncDocumentClient client) { - if (client != null) { - client.close(); - } - } - - private static class DatabaseManagerImpl implements DatabaseForTest.DatabaseManager { - public static DatabaseManagerImpl getInstance(AsyncDocumentClient client) { - return new DatabaseManagerImpl(client); - } - - private final AsyncDocumentClient client; - - private DatabaseManagerImpl(AsyncDocumentClient client) { - this.client = client; - } - - @Override - public Observable> queryDatabases(SqlQuerySpec query) { - return client.queryDatabases(query, null); - } - - @Override - public Observable> createDatabase(Database databaseDefinition) { - return client.createDatabase(databaseDefinition, null); - } - - @Override - public Observable> deleteDatabase(String id) { - - return client.deleteDatabase("dbs/" + id, null); - } - } -} diff --git a/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/WorkflowTest.java b/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/WorkflowTest.java deleted file mode 100644 index 6490d47bcb6d..000000000000 --- a/cosmosdb/data-plane/benchmark/src/test/java/com/microsoft/azure/cosmosdb/benchmark/WorkflowTest.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.benchmark; - -import com.beust.jcommander.JCommander; -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import org.apache.commons.lang3.StringUtils; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.assertj.core.api.Assertions.assertThat; - -public class WorkflowTest { - private static final int TIMEOUT = 120000; - private Database database; - private DocumentCollection collection; - - @Test(groups = "simple", timeOut = TIMEOUT) - public void readMyWritesCLI() throws Exception { - String cmdFormat = "-serviceEndpoint %s -masterKey %s" + - " -databaseId %s -collectionId %s" + - " -consistencyLevel Session -concurrency 2 -numberOfOperations 123" + - " -operation ReadMyWrites -connectionMode Direct -numberOfPreCreatedDocuments 100"; - - String cmd = String.format(cmdFormat, - TestConfigurations.HOST, - TestConfigurations.MASTER_KEY, - database.getId(), - collection.getId()); - Main.main(StringUtils.split(cmd)); - } - - @Test(dataProvider = "collectionLinkTypeArgProvider", groups = "simple", timeOut = TIMEOUT) - public void readMyWrites(boolean useNameLink) throws Exception { - int numberOfOperations = 123; - String cmdFormat = "-serviceEndpoint %s -masterKey %s" + - " -databaseId %s -collectionId %s" + - " -consistencyLevel Session -concurrency 2 -numberOfOperations %s" + - " -operation ReadMyWrites -connectionMode Direct -numberOfPreCreatedDocuments 100"; - - String cmd = String.format(cmdFormat, - TestConfigurations.HOST, - TestConfigurations.MASTER_KEY, - database.getId(), - collection.getId(), - numberOfOperations) - + (useNameLink ? " -useNameLink" : ""); - - Configuration cfg = new Configuration(); - new JCommander(cfg, StringUtils.split(cmd)); - - AtomicInteger success = new AtomicInteger(); - AtomicInteger error = new AtomicInteger(); - - ReadMyWriteWorkflow wf = new ReadMyWriteWorkflow(cfg) { - @Override - protected void onError(Throwable throwable) { - error.incrementAndGet(); - } - - @Override - protected void onSuccess() { - success.incrementAndGet(); - } - }; - - wf.run(); - wf.shutdown(); - - assertThat(error).hasValue(0); - assertThat(success).hasValue(numberOfOperations); - } - - @Test(groups = "simple", timeOut = TIMEOUT) - public void writeLatencyCLI() throws Exception { - String cmdFormat = "-serviceEndpoint %s -masterKey %s" + - " -databaseId %s -collectionId %s" + - " -consistencyLevel Session -concurrency 2 -numberOfOperations 1000" + - " -operation WriteLatency -connectionMode Direct"; - - String cmd = String.format(cmdFormat, - TestConfigurations.HOST, - TestConfigurations.MASTER_KEY, - database.getId(), - collection.getId()); - Main.main(StringUtils.split(cmd)); - } - - @Test(dataProvider = "collectionLinkTypeArgProvider", groups = "simple", timeOut = TIMEOUT) - public void writeLatency(boolean useNameLink) throws Exception { - int numberOfOperations = 123; - String cmdFormat = "-serviceEndpoint %s -masterKey %s" + - " -databaseId %s -collectionId %s" + - " -consistencyLevel Session -concurrency 2 -numberOfOperations %s" + - " -operation WriteLatency -connectionMode Direct"; - - String cmd = String.format(cmdFormat, - TestConfigurations.HOST, - TestConfigurations.MASTER_KEY, - database.getId(), - collection.getId(), - numberOfOperations) - + (useNameLink ? " -useNameLink" : ""); - - Configuration cfg = new Configuration(); - new JCommander(cfg, StringUtils.split(cmd)); - - AtomicInteger success = new AtomicInteger(); - AtomicInteger error = new AtomicInteger(); - - AsyncWriteBenchmark wf = new AsyncWriteBenchmark(cfg) { - @Override - protected void onError(Throwable throwable) { - error.incrementAndGet(); - } - - @Override - protected void onSuccess() { - success.incrementAndGet(); - } - }; - - wf.run(); - wf.shutdown(); - - assertThat(error).hasValue(0); - assertThat(success).hasValue(numberOfOperations); - } - - @Test(dataProvider = "collectionLinkTypeArgProvider", groups = "simple", timeOut = TIMEOUT) - public void writeThroughput(boolean useNameLink) throws Exception { - int numberOfOperations = 123; - String cmdFormat = "-serviceEndpoint %s -masterKey %s" + - " -databaseId %s -collectionId %s" + - " -consistencyLevel Session -concurrency 2 -numberOfOperations %s" + - " -operation WriteThroughput -connectionMode Direct"; - - String cmd = String.format(cmdFormat, - TestConfigurations.HOST, - TestConfigurations.MASTER_KEY, - database.getId(), - collection.getId(), - numberOfOperations) - + (useNameLink ? " -useNameLink" : ""); - - Configuration cfg = new Configuration(); - new JCommander(cfg, StringUtils.split(cmd)); - - AtomicInteger success = new AtomicInteger(); - AtomicInteger error = new AtomicInteger(); - - AsyncWriteBenchmark wf = new AsyncWriteBenchmark(cfg) { - @Override - protected void onError(Throwable throwable) { - error.incrementAndGet(); - } - - @Override - protected void onSuccess() { - success.incrementAndGet(); - } - }; - - wf.run(); - wf.shutdown(); - - assertThat(error).hasValue(0); - assertThat(success).hasValue(numberOfOperations); - } - - @Test(dataProvider = "collectionLinkTypeArgProvider", groups = "simple", timeOut = TIMEOUT) - public void readLatency(boolean useNameLink) throws Exception { - int numberOfOperations = 123; - String cmdFormat = "-serviceEndpoint %s -masterKey %s" + - " -databaseId %s -collectionId %s" + - " -consistencyLevel Session -concurrency 2 -numberOfOperations %s" + - " -operation ReadLatency -connectionMode Direct"; - - String cmd = String.format(cmdFormat, - TestConfigurations.HOST, - TestConfigurations.MASTER_KEY, - database.getId(), - collection.getId(), - numberOfOperations) - + (useNameLink ? " -useNameLink" : ""); - - Configuration cfg = new Configuration(); - new JCommander(cfg, StringUtils.split(cmd)); - - AtomicInteger success = new AtomicInteger(); - AtomicInteger error = new AtomicInteger(); - - AsyncReadBenchmark wf = new AsyncReadBenchmark(cfg) { - @Override - protected void onError(Throwable throwable) { - error.incrementAndGet(); - } - - @Override - protected void onSuccess() { - success.incrementAndGet(); - } - }; - - wf.run(); - wf.shutdown(); - - assertThat(error).hasValue(0); - assertThat(success).hasValue(numberOfOperations); - } - - @Test(dataProvider = "collectionLinkTypeArgProvider", groups = "simple", timeOut = TIMEOUT) - public void readThroughput(boolean useNameLink) throws Exception { - int numberOfOperations = 123; - String cmdFormat = "-serviceEndpoint %s -masterKey %s" + - " -databaseId %s -collectionId %s" + - " -consistencyLevel Session -concurrency 2 -numberOfOperations %s" + - " -operation ReadThroughput -connectionMode Direct"; - - String cmd = String.format(cmdFormat, - TestConfigurations.HOST, - TestConfigurations.MASTER_KEY, - database.getId(), - collection.getId(), - numberOfOperations) - + (useNameLink ? " -useNameLink" : ""); - - Configuration cfg = new Configuration(); - new JCommander(cfg, StringUtils.split(cmd)); - - AtomicInteger success = new AtomicInteger(); - AtomicInteger error = new AtomicInteger(); - - AsyncReadBenchmark wf = new AsyncReadBenchmark(cfg) { - @Override - protected void onError(Throwable throwable) { - error.incrementAndGet(); - } - - @Override - protected void onSuccess() { - success.incrementAndGet(); - } - }; - - wf.run(); - wf.shutdown(); - - assertThat(error).hasValue(0); - assertThat(success).hasValue(numberOfOperations); - } - - @BeforeClass(groups = "simple", timeOut = TIMEOUT) - public void beforeClass() { - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(10000); - AsyncDocumentClient housekeepingClient = Utils.housekeepingClient(); - database = Utils.createDatabaseForTest(housekeepingClient); - collection = housekeepingClient.createCollection("dbs/"+ database.getId(), - getCollectionDefinitionWithRangeRangeIndex(), - options) - .toBlocking().single().getResource(); - housekeepingClient.close(); - } - - @DataProvider(name = "collectionLinkTypeArgProvider") - public Object[][] collectionLinkTypeArgProvider() { - return new Object[][]{ - // is namebased - {true}, - {false}, - }; - } - - @AfterClass(groups = "simple", timeOut = TIMEOUT) - public void afterClass() { - AsyncDocumentClient housekeepingClient = Utils.housekeepingClient(); - Utils.safeCleanDatabases(housekeepingClient); - Utils.safeClean(housekeepingClient, database); - Utils.safeClose(housekeepingClient); - } - - DocumentCollection getCollectionDefinitionWithRangeRangeIndex() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList<>(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection includedPaths = new ArrayList<>(); - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath("/*"); - Collection indexes = new ArrayList<>(); - Index stringIndex = Index.Range(DataType.String); - stringIndex.set("precision", -1); - indexes.add(stringIndex); - - Index numberIndex = Index.Range(DataType.Number); - numberIndex.set("precision", -1); - indexes.add(numberIndex); - includedPath.setIndexes(indexes); - includedPaths.add(includedPath); - indexingPolicy.setIncludedPaths(includedPaths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setIndexingPolicy(indexingPolicy); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } -} diff --git a/cosmosdb/data-plane/changelog/README.md b/cosmosdb/data-plane/changelog/README.md deleted file mode 100644 index f72d0684abc2..000000000000 --- a/cosmosdb/data-plane/changelog/README.md +++ /dev/null @@ -1,111 +0,0 @@ -## Changelog - -### 2.4.3 -* Fixed resource leak issue on closing client - -### 2.4.2 -* Fixed bugs in continuation token support for cross partition queries - -### 2.4.1 -* Fixed some bugs in Direct mode. -* Improved logging in Direct mode. -* Improved connection management. - -### 2.4.0 -* Direct GA. -* Added support for QueryMetrics. -* Changed the APIs accepting java.util.Collection for which order is important to accept java.util.List instead. Now ConnectionPolicy#getPreferredLocations(), JsonSerialization, and PartitionKey(.) accept List. - -### 2.4.0-beta1 - -* Added support for Direct Https. -* Changed the APIs accepting java.util.Collection for which order is important to accept java.util.List instead. - Now ConnectionPolicy#getPreferredLocations(), JsonSerialization, and PartitionKey(.) accept List. -* Fixed a Session bug for Document query in Gateway mode. -* Upgraded dependencies (netty 0.4.20 [github #79](https://github.com/Azure/azure-cosmosdb-java/issues/79), RxJava 1.3.8). - -### 2.3.1 - -* Fix handling very large query responses. -* Fix resource token handling when instantiating client ([github #78](https://github.com/Azure/azure-cosmosdb-java/issues/78)). -* Upgraded vulnerable dependency jackson-databind ([github #77](https://github.com/Azure/azure-cosmosdb-java/pull/77)). - -### 2.3.0 - -* Fixed a resource leak bug. -* Added support for MultiPolygon -* Added support for custom headers in RequestOptions. - -### 2.2.2 -* Fixed a packaging bug. - -### 2.2.1 -* Fixed a NPE bug in write retry path. -* Fixed a NPE bug in endpoint management. -* Upgraded vulnerable dependencies ([github #68](https://github.com/Azure/azure-cosmosdb-java/issues/68)). -* Added support for Netty network logging for troubleshooting. - -### 2.2.0 -* Added support for Multi-region write. - -### 2.1.0 -* Added support for Proxy. -* Added support for resource token authorization. -* Fixed a bug in handling large partition keys ([github #63](https://github.com/Azure/azure-cosmosdb-java/issues/63)). -* Documentation improved. -* SDK restructured into more granular modules. - -### 2.0.1 -- Fixed a bug for non-english locales ([github #51](https://github.com/Azure/azure-cosmosdb-java/issues/51)). -- Added helper methods for Conflict resource. - -### 2.0.0 -- Replaced org.json dependency by jackson due to performance reasons and licensing ([github #29](https://github.com/Azure/azure-cosmosdb-java/issues/29)). -- Removed deprecated OfferV2 class. -- Added accessor method to Offer class for throughput content. -- Any method in Document/Resource returning org.json types changed to return a jackson object type. -- getObject(.) method of classes extending JsonSerializable changed to return a jackson ObjectNode type. -- getCollection(.) method changed to return Collection of ObjectNode. -- Removed JsonSerializable subclasses' constructors with org.json.JSONObject arg. -- JsonSerializable.toJson (SerializationFormattingPolicy.Indented) now uses two spaces for indentation. - -### 1.0.2 -- Added support for Unique Index Policy. -- Added support for limiting response continuation token size in feed options. -- Added support for Partition Split in Cross Partition Query. -- Fixed a bug in Json timestamp serialization ([github #32](https://github.com/Azure/azure-cosmosdb-java/issues/32)). -- Fixed a bug in Json enum serialization. -- Fixed a bug in managing documents of 2MB size ([github #33](https://github.com/Azure/azure-cosmosdb-java/issues/33)). -- Dependency com.fasterxml.jackson.core:jackson-databind upgraded to 2.9.5 due to a bug ([jackson-databind: github #1599](https://github.com/FasterXML/jackson-databind/issues/1599)) -- Dependency on rxjava-extras upgraded to 0.8.0.17 due to a bug ([rxjava-extras: github #30](https://github.com/davidmoten/rxjava-extras/issues/30)). -- The metadata description in pom file updated to be inline with the rest of documentation. -- Syntax improvement ([github #41](https://github.com/Azure/azure-cosmosdb-java/issues/41)), ([github #40](https://github.com/Azure/azure-cosmosdb-java/issues/40)). - -### 1.0.1 -- Added back-pressure support in query. -- Added support for partition key range id in query. -- Changed to allow larger continuation token in request header (bugfix github #24). -- netty dependency upgraded to 4.1.22.Final to ensure JVM shuts down after main thread finishes. -- Changed to avoid passing session token when reading master resources. -- Added more examples. -- Added more benchmarking scenarios. -- Fixed java header files for proper javadoc generation. - -### 1.0.0 -- Release 1.0.0 has fully end to end support for non-blocking IO using netty library in Gateway mode. -- Dependency on ``azure-documentdb`` SDK removed. -- Artifact id changed to ``azure-cosmosdb`` from ``azure-documentdb-rx`` in 0.9.0-rc2. -- Java package name changed to ``com.microsoft.azure.cosmosdb`` from ``com.microsoft.azure.documentdb`` in 0.9.0-rc2. - -### 0.9.0-rc2 -- ``FeedResponsePage`` renamed to ``FeedReponse`` -- Some minor modifications to ``ConnectionPolicy`` configuration. -All time fields and methods in ConnectionPolicy suffixed with "InMillis" to be more precise of the time unit. -- ``ConnectionPolicy#setProxy()`` removed. -- ``FeedOptions#pageSize`` renamed to -``FeedOptions#maxItemCount`` -- Release 1.0.0 deprecates 0.9.x releases. - -### 0.9.0-rc1 -- First release of ``azure-documentdb-rx`` SDK. -- CRUD Document API fully non-blocking using netty. Query async API implemented as a wrapper using blocking SDK ``azure-documentdb``. diff --git a/cosmosdb/data-plane/commons-test-utils/pom.xml b/cosmosdb/data-plane/commons-test-utils/pom.xml deleted file mode 100644 index f06ce657bcb6..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/pom.xml +++ /dev/null @@ -1,135 +0,0 @@ - - - 4.0.0 - - com.microsoft.azure - azure-cosmosdb-parent - 2.4.5 - - azure-cosmosdb-commons-test-utils - Common Test Components for Testing Async SDK for SQL API of Azure Cosmos DB Service - Common Test Components for Testing Async SDK for SQL API of Azure Cosmos DB Service - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.22.0 - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - org.apache.maven.plugins - maven-jxr-plugin - 2.1 - - - - - - com.microsoft.azure - azure-cosmosdb-commons - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.testng - testng - ${testng.version} - - - org.assertj - assertj-core - ${assertj.version} - - - org.mockito - mockito-all - ${mockito.version} - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - - - log4j - log4j - ${log4j.version} - - - com.google.guava - guava - ${guava.version} - - - diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/BridgeUtils.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/BridgeUtils.java deleted file mode 100644 index f5e449b53fc9..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/BridgeUtils.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.List; - -/** - * This is a helper class for testing. - */ -public class BridgeUtils { - - public static DatabaseAccount createDatabaseAccount(List readLocations, - List writeLocations, - boolean useMultipleWriteLocations) { - DatabaseAccount dbAccount = new DatabaseAccount(); - dbAccount.setEnableMultipleWriteLocations(useMultipleWriteLocations); - - dbAccount.setReadableLocations(readLocations); - dbAccount.setWritableLocations(writeLocations); - - return dbAccount; - } - - public static DatabaseAccountLocation createDatabaseAccountLocation(String name, String endpoint) { - DatabaseAccountLocation dal = new DatabaseAccountLocation(); - dal.setName(name); - dal.setEndpoint(endpoint); - - return dal; - } - - public static ConflictResolutionPolicy createConflictResolutionPolicy() { - return new ConflictResolutionPolicy(); - } - - public static ConflictResolutionPolicy setMode(ConflictResolutionPolicy policy, ConflictResolutionMode mode) { - policy.setMode(mode); - return policy; - } - - public static ConflictResolutionPolicy setPath(ConflictResolutionPolicy policy, String path) { - policy.setConflictResolutionPath(path); - return policy; - } - - public static ConflictResolutionPolicy setStoredProc(ConflictResolutionPolicy policy, String storedProcLink) { - policy.setConflictResolutionProcedure(storedProcLink); - return policy; - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/ConfigsBuilder.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/ConfigsBuilder.java deleted file mode 100644 index ff8ec498a823..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/ConfigsBuilder.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import org.mockito.Mockito; - -/** - * This can be used for testing. - */ -public class ConfigsBuilder { - private Configs configs = Mockito.spy(new Configs()); - - public static ConfigsBuilder instance() { - return new ConfigsBuilder(); - } - - public ConfigsBuilder withProtocol(Protocol protocol) { - Mockito.doReturn(protocol).when(configs).getProtocol(); - return this; - } - - public Configs build() { - return configs; - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/DatabaseForTest.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/DatabaseForTest.java deleted file mode 100644 index 1e646d58e6eb..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/DatabaseForTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; - -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DatabaseForTest { - private static Logger logger = LoggerFactory.getLogger(DatabaseForTest.class); - public static final String SHARED_DB_ID_PREFIX = "RxJava.SDKTest.SharedDatabase"; - private static final Duration CLEANUP_THRESHOLD_DURATION = Duration.ofHours(1); - private static final String DELIMITER = "_"; - private static DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss"); - - public LocalDateTime createdTime; - public Database createdDatabase; - - private DatabaseForTest(Database db, LocalDateTime createdTime) { - this.createdDatabase = db; - this.createdTime = createdTime; - } - - private boolean isStale() { - return isOlderThan(CLEANUP_THRESHOLD_DURATION); - } - - private boolean isOlderThan(Duration dur) { - return createdTime.isBefore(LocalDateTime.now().minus(dur)); - } - - public static String generateId() { - return SHARED_DB_ID_PREFIX + DELIMITER + TIME_FORMATTER.format(LocalDateTime.now()) + DELIMITER + RandomStringUtils.randomAlphabetic(3); - } - - private static DatabaseForTest from(Database db) { - if (db == null || db.getId() == null || db.getSelfLink() == null) { - return null; - } - - String id = db.getId(); - if (id == null) { - return null; - } - - String[] parts = StringUtils.split(id, DELIMITER); - if (parts.length != 3) { - return null; - } - if (!StringUtils.equals(parts[0], SHARED_DB_ID_PREFIX)) { - return null; - } - - try { - LocalDateTime parsedTime = LocalDateTime.parse(parts[1], TIME_FORMATTER); - return new DatabaseForTest(db, parsedTime); - } catch (Exception e) { - return null; - } - } - - public static DatabaseForTest create(DatabaseManager client) { - Database dbDef = new Database(); - dbDef.setId(generateId()); - - Database db = client.createDatabase(dbDef).toBlocking().single().getResource(); - DatabaseForTest dbForTest = DatabaseForTest.from(db); - assertThat(dbForTest).isNotNull(); - return dbForTest; - } - - public static void cleanupStaleTestDatabases(DatabaseManager client) { - logger.info("Cleaning stale test databases ..."); - List dbs = client.queryDatabases( - new SqlQuerySpec("SELECT * FROM c WHERE STARTSWITH(c.id, @PREFIX)", - new SqlParameterCollection(new SqlParameter("@PREFIX", DatabaseForTest.SHARED_DB_ID_PREFIX)))) - .flatMap(page -> Observable.from(page.getResults())).toList().toBlocking().single(); - - for (Database db : dbs) { - assertThat(db.getId()).startsWith(DatabaseForTest.SHARED_DB_ID_PREFIX); - - DatabaseForTest dbForTest = DatabaseForTest.from(db); - - if (db != null && dbForTest.isStale()) { - logger.info("Deleting database {}", db.getId()); - client.deleteDatabase(db.getId()).toBlocking().single(); - } - } - } - - public interface DatabaseManager { - Observable> queryDatabases(SqlQuerySpec query); - Observable> createDatabase(Database databaseDefinition); - Observable> deleteDatabase(String id); - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientUnderTestWrapper.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientUnderTestWrapper.java deleted file mode 100644 index ffb118d8d852..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientUnderTestWrapper.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.mockito.Mockito.doAnswer; - -/** - * This is a helper class for capturing requests sent over a httpClient. - */ -public class HttpClientUnderTestWrapper { - final private CompositeHttpClient origHttpClient; - final private CompositeHttpClient spyHttpClient; - - public final List> capturedRequest = Collections.synchronizedList(new ArrayList<>()); - - public HttpClientUnderTestWrapper(CompositeHttpClient origHttpClient) { - this.origHttpClient = origHttpClient; - this.spyHttpClient = Mockito.spy(origHttpClient); - - initRequestCapture(spyHttpClient); - } - - public CompositeHttpClient getSpyHttpClient() { - return spyHttpClient; - } - - void initRequestCapture(CompositeHttpClient spyClient) { - - doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - RxClient.ServerInfo serverInfo = invocationOnMock.getArgumentAt(0, RxClient.ServerInfo.class); - HttpClientRequest httpReq = invocationOnMock.getArgumentAt(1, HttpClientRequest.class); - capturedRequest.add(httpReq); - return origHttpClient.submit(serverInfo, httpReq); - } - }).when(spyClient).submit(Mockito.any(RxClient.ServerInfo.class), Mockito.any(HttpClientRequest.class)); - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseBuilder.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseBuilder.java deleted file mode 100644 index 5a1c1900d920..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseBuilder.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -import java.math.BigDecimal; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class StoreResponseBuilder { - private int status; - private List> headerEntries; - private String content; - - public static StoreResponseBuilder create() { - return new StoreResponseBuilder(); - } - - public StoreResponseBuilder() { - headerEntries = new ArrayList<>(); - } - - public StoreResponseBuilder withHeader(String key, String value) { - headerEntries.add(new AbstractMap.SimpleEntry(key, value)); - return this; - } - - public StoreResponseBuilder withLSN(long lsn) { - headerEntries.add(new AbstractMap.SimpleEntry(WFConstants.BackendHeaders.LSN, Long.toString(lsn))); - return this; - } - - public StoreResponseBuilder withRequestCharge(BigDecimal requestCharge) { - withRequestCharge(requestCharge.doubleValue()); - return this; - } - - public StoreResponseBuilder withRequestCharge(double requestCharge) { - headerEntries.add(new AbstractMap.SimpleEntry(HttpConstants.HttpHeaders.REQUEST_CHARGE, Double.toString(requestCharge))); - return this; - } - - public StoreResponseBuilder withLocalLSN(long localLsn) { - headerEntries.add(new AbstractMap.SimpleEntry(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(localLsn))); - return this; - } - - public StoreResponseBuilder withPartitionKeyRangeId(String partitionKeyRangeId) { - headerEntries.add(new AbstractMap.SimpleEntry(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId)); - return this; - } - - public StoreResponseBuilder withItemLocalLSN(long itemLocalLsn) { - headerEntries.add(new AbstractMap.SimpleEntry(WFConstants.BackendHeaders.ITEM_LOCAL_LSN, Long.toString(itemLocalLsn))); - return this; - } - - public StoreResponseBuilder withQuorumAckecdLsn(long quorumAckecdLsn) { - headerEntries.add(new AbstractMap.SimpleEntry(WFConstants.BackendHeaders.QUORUM_ACKED_LSN, Long.toString(quorumAckecdLsn))); - return this; - } - - public StoreResponseBuilder withQuorumAckecdLocalLsn(long quorumAckecdLocalLsn) { - headerEntries.add(new AbstractMap.SimpleEntry(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long.toString(quorumAckecdLocalLsn))); - return this; - } - - public StoreResponseBuilder withGlobalCommittedLsn(long globalCommittedLsn) { - headerEntries.add(new AbstractMap.SimpleEntry(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn))); - return this; - } - - public StoreResponseBuilder withSessionToken(String sessionToken) { - headerEntries.add(new AbstractMap.SimpleEntry(HttpConstants.HttpHeaders.SESSION_TOKEN, sessionToken)); - return this; - } - - public StoreResponseBuilder withStatus(int status) { - this.status = status; - return this; - } - - public StoreResponseBuilder withContent(String content) { - this.content = content; - return this; - } - - public StoreResponse build() { - return new StoreResponse(status, headerEntries, content); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/DocumentServiceRequestContextValidator.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/DocumentServiceRequestContextValidator.java deleted file mode 100644 index 5458c36929b9..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/DocumentServiceRequestContextValidator.java +++ /dev/null @@ -1,97 +0,0 @@ - -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public interface DocumentServiceRequestContextValidator { - - static Builder builder() { - return new Builder(); - } - - void validate(T v); - - class Builder { - private List> validators = new ArrayList<>(); - - public DocumentServiceRequestContextValidator build() { - return new DocumentServiceRequestContextValidator() { - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void validate(T v) { - for (DocumentServiceRequestContextValidator validator : validators) { - validator.validate(v); - } - } - }; - } - - - public Builder add(DocumentServiceRequestContextValidator validator) { - validators.add(validator); - return this; - } - - public Builder qurorumSelectedLSN(long quoriumSelectedLSN) { - add(new DocumentServiceRequestContextValidator() { - @Override - public void validate(DocumentServiceRequestContext v) { - assertThat(v.quorumSelectedLSN).isEqualTo(quoriumSelectedLSN); - } - }); - return this; - } - - public Builder globalCommittedSelectedLSN(long globalCommittedSelectedLSN) { - add(new DocumentServiceRequestContextValidator() { - @Override - public void validate(DocumentServiceRequestContext v) { - assertThat(v.globalCommittedSelectedLSN).isEqualTo(globalCommittedSelectedLSN); - } - }); - return this; - } - - public Builder storeResponses(List storeResponses) { - add(new DocumentServiceRequestContextValidator() { - @Override - public void validate(DocumentServiceRequestContext v) { - assertThat(v.storeResponses).isEqualTo(storeResponses); - } - }); - return this; - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/DocumentServiceRequestValidator.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/DocumentServiceRequestValidator.java deleted file mode 100644 index d26d13cd3c57..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/DocumentServiceRequestValidator.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public interface DocumentServiceRequestValidator { - - static Builder builder() { - return new Builder(); - } - - void validate(T v); - - class Builder { - private List> validators = new ArrayList<>(); - - public DocumentServiceRequestValidator build() { - return new DocumentServiceRequestValidator() { - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void validate(T v) { - for (DocumentServiceRequestValidator validator : validators) { - validator.validate(v); - } - } - }; - } - - public Builder add(DocumentServiceRequestValidator validator) { - validators.add(validator); - return this; - } - - public Builder withResourceType(ResourceType resourceType) { - add(new DocumentServiceRequestValidator() { - @Override - public void validate(T v) { - assertThat(v.getResourceType()).isEqualTo(resourceType); - } - }); - return this; - } - - public Builder withOperationType(OperationType operationType) { - add(new DocumentServiceRequestValidator() { - @Override - public void validate(T v) { - assertThat(v.getOperationType()).isEqualTo(operationType); - } - }); - return this; - } - - public Builder resourceTypeIn(ResourceType... resourceType) { - add(new DocumentServiceRequestValidator() { - @Override - public void validate(T v) { - assertThat(v.getResourceType()).isIn((Object[]) resourceType); - } - }); - return this; - } - - public Builder resourceTypeNotIn(ResourceType... resourceType) { - add(new DocumentServiceRequestValidator() { - @Override - public void validate(T v) { - assertThat(v.getResourceType()).isNotIn((Object[]) resourceType); - } - }); - return this; - } - - public Builder add(DocumentServiceRequestContextValidator validator) { - add(new DocumentServiceRequestValidator() { - @Override - public void validate(RxDocumentServiceRequest request) { - validator.validate(request.requestContext); - } - }); - return this; - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FailureValidator.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FailureValidator.java deleted file mode 100644 index 2ad5ec534aa6..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FailureValidator.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public interface FailureValidator { - - static Builder builder() { - return new Builder(); - } - - void validate(Throwable t); - - class Builder { - private List validators = new ArrayList<>(); - - public FailureValidator build() { - return new FailureValidator() { - @Override - public void validate(Throwable t) { - for (FailureValidator validator : validators) { - validator.validate(t); - } - } - }; - } - - public Builder statusCode(int statusCode) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(((DocumentClientException) t).getStatusCode()).isEqualTo(statusCode); - } - }); - return this; - } - - public Builder lsnGreaterThan(long quorumAckedLSN) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(BridgeInternal.getLSN((DocumentClientException) t) > quorumAckedLSN).isTrue(); - } - }); - return this; - } - - public Builder lsnGreaterThanEqualsTo(long quorumAckedLSN) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(BridgeInternal.getLSN((DocumentClientException) t) >= quorumAckedLSN).isTrue(); - } - }); - return this; - } - - public Builder exceptionQuorumAckedLSNInNotNull() { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - DocumentClientException documentClientException = (DocumentClientException) t; - long exceptionQuorumAckedLSN = -1; - if (documentClientException.getResponseHeaders().get(WFConstants.BackendHeaders.QUORUM_ACKED_LSN) != null) { - exceptionQuorumAckedLSN = Long.parseLong((String) documentClientException.getResponseHeaders().get(WFConstants.BackendHeaders.QUORUM_ACKED_LSN)); - - } - assertThat(exceptionQuorumAckedLSN).isNotEqualTo(-1); - } - }); - return this; - } - - public Builder errorMessageContains(String errorMsg) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t.getMessage()).contains(errorMsg); - } - }); - return this; - } - - public Builder notNullActivityId() { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(((DocumentClientException) t).getActivityId()).isNotNull(); - } - }); - return this; - } - - public Builder error(Error error) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(((DocumentClientException) t).getError().toJson()).isEqualTo(error.toJson()); - } - }); - return this; - } - - public Builder subStatusCode(Integer substatusCode) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(((DocumentClientException) t).getSubStatusCode()).isEqualTo(substatusCode); - } - }); - return this; - } - - public Builder unknownSubStatusCode() { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(((DocumentClientException) t).getSubStatusCode()).isEqualTo(HttpConstants.SubStatusCodes.UNKNOWN); - } - }); - return this; - } - - public Builder responseHeader(String key, String value) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - assertThat(((DocumentClientException) t).getResponseHeaders().get(key)).isEqualTo(value); - } - }); - return this; - } - - public Builder lsn(long lsn) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - DocumentClientException ex = (DocumentClientException) t; - assertThat(BridgeInternal.getLSN(ex)).isEqualTo(lsn); - } - }); - return this; - } - - public Builder partitionKeyRangeId(String pkrid) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - DocumentClientException ex = (DocumentClientException) t; - assertThat(BridgeInternal.getPartitionKeyRangeId(ex)).isEqualTo(pkrid); - } - }); - return this; - } - - public Builder resourceAddress(String resourceAddress) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - DocumentClientException ex = (DocumentClientException) t; - assertThat(BridgeInternal.getResourceAddress(ex)).isEqualTo(resourceAddress); - } - }); - return this; - } - - public Builder instanceOf(Class cls) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(cls); - } - }); - return this; - } - - public Builder sameAs(Exception exception) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isSameAs(exception); - } - }); - return this; - } - - public Builder resourceNotFound() { - - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - DocumentClientException ex = (DocumentClientException) t; - assertThat(ex.getStatusCode()).isEqualTo(404); - - } - }); - return this; - } - - public Builder resourceTokenNotFound() { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(IllegalArgumentException.class); - IllegalArgumentException ex = (IllegalArgumentException) t; - assertThat(ex.getMessage()).isEqualTo(RMResources.ResourceTokenNotFound); - } - }); - return this; - } - - public Builder resourceAlreadyExists() { - - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - DocumentClientException ex = (DocumentClientException) t; - assertThat(ex.getStatusCode()).isEqualTo(409); - - } - }); - return this; - } - - public Builder causeInstanceOf(Class cls) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t.getCause()).isNotNull(); - assertThat(t.getCause()).isInstanceOf(cls); - } - }); - return this; - } - - public Builder causeOfCauseInstanceOf(Class cls) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t.getCause()).isNotNull(); - assertThat(t.getCause().getCause()).isNotNull(); - assertThat(t.getCause().getCause()).isInstanceOf(cls); - } - }); - return this; - } - - public Builder documentClientExceptionHeaderRequestContainsEntry(String key, String value) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(DocumentClientException.class); - DocumentClientException ex = (DocumentClientException) t; - assertThat(BridgeInternal.getRequestHeaders(ex)).containsEntry(key, value); - } - }); - return this; - } - - public Builder withRuntimeExceptionMessage(String message) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(RuntimeException.class); - assertThat(t.getMessage()).isEqualTo(message); - } - }); - return this; - } - - public Builder withRuntimeExceptionClass(Class k) { - validators.add(new FailureValidator() { - @Override - public void validate(Throwable t) { - assertThat(t).isNotNull(); - assertThat(t).isInstanceOf(RuntimeException.class); - assertThat(t).isInstanceOf(k); - } - }); - return this; - } - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FeedResponseListValidator.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FeedResponseListValidator.java deleted file mode 100644 index 6356f1363fff..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FeedResponseListValidator.java +++ /dev/null @@ -1,305 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.microsoft.azure.cosmosdb.CompositePath; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.QueryMetrics; -import com.microsoft.azure.cosmosdb.Resource; - -public interface FeedResponseListValidator { - - void validate(List> feedList); - - class Builder { - private List> validators = new ArrayList<>(); - - public FeedResponseListValidator build() { - return new FeedResponseListValidator() { - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void validate(List> feedList) { - for (FeedResponseListValidator validator : validators) { - validator.validate(feedList); - } - } - }; - } - - public Builder totalSize(final int expectedCount) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - int resultCount = feedList.stream().mapToInt(f -> f.getResults().size()).sum(); - assertThat(resultCount) - .describedAs("total number of results").isEqualTo(expectedCount); - } - }); - return this; - } - - public Builder containsExactly(List expectedIds) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - List actualIds = feedList - .stream() - .flatMap(f -> f.getResults().stream()) - .map(r -> r.getResourceId()) - .collect(Collectors.toList()); - assertThat(actualIds) - .describedAs("Resource IDs of results") - .containsExactlyElementsOf(expectedIds); - } - }); - return this; - } - - public Builder validateAllResources(Map> resourceIDToValidator) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - List resources = feedList - .stream() - .flatMap(f -> f.getResults().stream()) - .collect(Collectors.toList()); - - for(T r: resources) { - ResourceValidator validator = resourceIDToValidator.get(r.getResourceId()); - assertThat(validator).isNotNull(); - validator.validate(r); - } - } - }); - return this; - } - - public Builder exactlyContainsInAnyOrder(List expectedIds) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - List actualIds = feedList - .stream() - .flatMap(f -> f.getResults().stream()) - .map(r -> r.getResourceId()) - .collect(Collectors.toList()); - assertThat(actualIds) - .describedAs("Resource IDs of results") - .containsOnlyElementsOf(expectedIds); - } - }); - return this; - } - - public Builder numberOfPages(int expectedNumberOfPages) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - assertThat(feedList) - .describedAs("number of pages") - .hasSize(expectedNumberOfPages); - } - }); - return this; - } - - public Builder numberOfPagesIsGreaterThanOrEqualTo(int leastNumber) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - assertThat(feedList.size()) - .describedAs("number of pages") - .isGreaterThanOrEqualTo(leastNumber); - } - }); - return this; - } - - public Builder totalRequestChargeIsAtLeast(double minimumCharge) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - assertThat(feedList.stream().mapToDouble(p -> p.getRequestCharge()).sum()) - .describedAs("total request charge") - .isGreaterThanOrEqualTo(minimumCharge); - } - }); - return this; - } - - public Builder pageSatisfy(int pageNumber, FeedResponseValidator pageValidator) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - assertThat(feedList.size()).isGreaterThan(pageNumber); - pageValidator.validate(feedList.get(pageNumber)); - } - }); - return this; - } - - public Builder allPagesSatisfy(FeedResponseValidator pageValidator) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - - for(FeedResponse fp: feedList) { - pageValidator.validate(fp); - } - } - }); - return this; - } - - public Builder withAggregateValue(Object value) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - List list = feedList.get(0).getResults(); - Document result = list.size() > 0 ? list.get(0) : null; - - if (result != null) { - if (value instanceof Double) { - - Double d = result.getDouble("_aggregate"); - assertThat(d).isEqualTo(value); - } else if (value instanceof Integer) { - - Integer d = result.getInt("_aggregate"); - assertThat(d).isEqualTo(value); - } else if (value instanceof String) { - - String d = result.getString("_aggregate"); - assertThat(d).isEqualTo(value); - } else if (value instanceof Document){ - - assertThat(result.toString()).isEqualTo(value.toString()); - } else { - - assertThat(result.get("_aggregate")).isNull(); - assertThat(value).isNull(); - } - } else { - - assertThat(value).isNull(); - } - - } - }); - return this; - } - - public Builder withOrderedResults(ArrayList expectedOrderedList, - ArrayList compositeIndex) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - - List resultOrderedList = feedList.stream() - .flatMap(f -> f.getResults().stream()) - .collect(Collectors.toList()); - assertThat(expectedOrderedList.size()).isEqualTo(resultOrderedList.size()); - - ArrayList paths = new ArrayList(); - Iterator compositeIndexIterator = compositeIndex.iterator(); - while (compositeIndexIterator.hasNext()) { - paths.add(compositeIndexIterator.next().getPath().replace("/", "")); - } - for (int i = 0; i < resultOrderedList.size(); i ++) { - ArrayNode resultValues = (ArrayNode) resultOrderedList.get(i).get("$1"); - assertThat(resultValues.size()).isEqualTo(paths.size()); - for (int j = 0; j < paths.size(); j++) { - if (paths.get(j).contains("number")) { - assertThat(expectedOrderedList.get(i).getInt(paths.get(j))).isEqualTo(resultValues.get(j).intValue()); - } else if (paths.get(j).toLowerCase().contains("string")) { - assertThat(expectedOrderedList.get(i).getString(paths.get(j))).isEqualTo(resultValues.get(j).asText()); - } else if (paths.get(j).contains("bool")) { - assertThat(expectedOrderedList.get(i).getBoolean(paths.get(j))).isEqualTo(resultValues.get(j).asBoolean()); - } else { - assertThat(resultValues.get(j).isNull()).isTrue(); - assertThat(expectedOrderedList.get(i).get("nullField")).isNull(); - } - } - } - - } - }); - return this; - } - - public Builder pageLengths(int[] pageLengths) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - assertThat(feedList).hasSize(pageLengths.length); - for (int i = 0; i < pageLengths.length; i++) - assertThat(feedList.get(i).getResults().size()).isEqualTo(pageLengths[i]); - } - }); - return this; - } - - public Builder hasValidQueryMetrics(boolean shouldHaveMetrics) { - validators.add(new FeedResponseListValidator() { - @Override - public void validate(List> feedList) { - for(FeedResponse feedPage: feedList) { - if (shouldHaveMetrics) { - QueryMetrics queryMetrics = BridgeInternal.createQueryMetricsFromCollection(feedPage.getQueryMetrics().values()); - assertThat(queryMetrics.getIndexHitDocumentCount()).isGreaterThanOrEqualTo(0); - assertThat(queryMetrics.getRetrievedDocumentSize()).isGreaterThan(0); - assertThat(queryMetrics.getTotalQueryExecutionTime().compareTo(Duration.ZERO)).isGreaterThan(0); - assertThat(queryMetrics.getOutputDocumentCount()).isGreaterThan(0); - assertThat(queryMetrics.getRetrievedDocumentCount()).isGreaterThan(0); - assertThat(queryMetrics.getDocumentLoadTime().compareTo(Duration.ZERO)).isGreaterThan(0); - assertThat(queryMetrics.getDocumentWriteTime().compareTo(Duration.ZERO)).isGreaterThanOrEqualTo(0); - assertThat(queryMetrics.getVMExecutionTime().compareTo(Duration.ZERO)).isGreaterThan(0); - assertThat(queryMetrics.getQueryPreparationTimes().getLogicalPlanBuildTime().compareTo(Duration.ZERO)).isGreaterThan(0); - assertThat(queryMetrics.getQueryPreparationTimes().getPhysicalPlanBuildTime().compareTo(Duration.ZERO)).isGreaterThanOrEqualTo(0); - assertThat(queryMetrics.getQueryPreparationTimes().getQueryCompilationTime().compareTo(Duration.ZERO)).isGreaterThan(0); - assertThat(queryMetrics.getRuntimeExecutionTimes().getQueryEngineExecutionTime().compareTo(Duration.ZERO)).isGreaterThanOrEqualTo(0); - assertThat(BridgeInternal.getClientSideMetrics(queryMetrics).getRequestCharge()).isGreaterThan(0); - } else { - assertThat(feedPage.getQueryMetrics().isEmpty()); - } - } - } - }); - return this; - } - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FeedResponseValidator.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FeedResponseValidator.java deleted file mode 100644 index d245f6f49593..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/FeedResponseValidator.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -public interface FeedResponseValidator { - - void validate(FeedResponse feedList); - - public class Builder { - private List> validators = new ArrayList<>(); - - public FeedResponseValidator build() { - return new FeedResponseValidator() { - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void validate(FeedResponse feedPage) { - for (FeedResponseValidator validator : validators) { - validator.validate(feedPage); - } - } - }; - } - - public Builder pageSizeIsLessThanOrEqualTo(final int maxPageSize) { - - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage.getResults().size()).isLessThanOrEqualTo(maxPageSize); - } - }); - return this; - } - - public Builder pageSizeOf(final int expectedCount) { - - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage.getResults()).hasSize(expectedCount); - } - }); - return this; - } - - public Builder positiveRequestCharge() { - - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage.getRequestCharge()).isPositive(); - } - }); - return this; - } - - public Builder requestChargeGreaterThanOrEqualTo(double minRequestCharge) { - - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage.getRequestCharge()).isGreaterThanOrEqualTo(minRequestCharge); - } - }); - return this; - } - - public Builder requestChargeLessThanOrEqualTo(double maxRequestCharge) { - - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage.getRequestCharge()).isLessThanOrEqualTo(maxRequestCharge); - } - }); - return this; - } - - public Builder hasHeader(String headerKey) { - - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage.getResponseHeaders()).containsKey(headerKey); - } - }); - return this; - } - - public Builder hasRequestChargeHeader() { - - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage.getResponseHeaders()).containsKey(HttpConstants.HttpHeaders.REQUEST_CHARGE); - } - }); - return this; - } - - public Builder idsExactlyAre(final List expectedIds) { - validators.add(new FeedResponseValidator() { - @Override - public void validate(FeedResponse feedPage) { - assertThat(feedPage - .getResults().stream() - .map(r -> r.getResourceId()) - .collect(Collectors.toList())) - .containsExactlyElementsOf(expectedIds); - } - }); - return this; - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/ResourceResponseValidator.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/ResourceResponseValidator.java deleted file mode 100644 index 0686e7df1336..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/ResourceResponseValidator.java +++ /dev/null @@ -1,379 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; - -import org.assertj.core.api.Condition; - -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.CompositePath; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.IndexingMode; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.PermissionMode; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.SpatialSpec; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.TriggerOperation; -import com.microsoft.azure.cosmosdb.TriggerType; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.SpatialType; - -public interface ResourceResponseValidator { - - static Builder builder() { - return new Builder(); - } - - void validate(ResourceResponse resourceResponse); - - class Builder { - private List> validators = new ArrayList<>(); - - public ResourceResponseValidator build() { - return new ResourceResponseValidator() { - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void validate(ResourceResponse resourceResponse) { - for (ResourceResponseValidator validator : validators) { - validator.validate(resourceResponse); - } - } - }; - } - - public Builder withId(final String resourceId) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().getId()).as("check Resource Id").isEqualTo(resourceId); - } - }); - return this; - } - - public Builder nullResource() { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNull(); - } - }); - return this; - } - - public Builder withProperty(String propertyName, Condition validatingCondition) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().get(propertyName)).is(validatingCondition); - - } - }); - return this; - } - - public Builder withProperty(String propertyName, Object value) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().get(propertyName)).isEqualTo(value); - - } - }); - return this; - } - - - public Builder withTimestampIsAfterOrEqualTo(Instant time) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().getTimestamp()).isNotNull(); - Date d = resourceResponse.getResource().getTimestamp(); - System.out.println(d.toString()); - assertThat(d.toInstant()).isAfterOrEqualTo(time); - } - }); - return this; - } - - public Builder withTimestampIsBeforeOrEqualTo(Instant time) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().getTimestamp()).isNotNull(); - Date d = resourceResponse.getResource().getTimestamp(); - assertThat(d.toInstant()).isBeforeOrEqualTo(time); - } - }); - return this; - } - - public Builder withPermissionMode(PermissionMode mode) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getPermissionMode()).isEqualTo(mode); - } - }); - return this; - } - - public Builder withPermissionResourceLink(String link) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getResourceLink()).isEqualTo(link); - } - }); - return this; - } - - public Builder indexingMode(IndexingMode mode) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().getIndexingPolicy()).isNotNull(); - assertThat(resourceResponse.getResource().getIndexingPolicy().getIndexingMode()).isEqualTo(mode); - } - }); - return this; - } - - public Builder withStoredProcedureBody(String functionBody) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getBody()).isEqualTo(functionBody); - } - }); - return this; - } - - public Builder withUserDefinedFunctionBody(String functionBody) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getBody()).isEqualTo(functionBody); - } - }); - return this; - } - - - public Builder withTriggerBody(String functionBody) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getBody()).isEqualTo(functionBody); - } - }); - return this; - } - - public Builder notNullEtag() { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().getETag()).isNotNull(); - } - }); - return this; - } - - public Builder notEmptySelfLink() { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().getSelfLink()).isNotEmpty(); - } - }); - return this; - } - - public Builder withTriggerInternals(TriggerType type, TriggerOperation op) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getTriggerType()).isEqualTo(type); - assertThat(resourceResponse.getResource().getTriggerOperation()).isEqualTo(op); - } - }); - return this; - } - - public Builder withContentType(final String contentType) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getContentType()).isEqualTo(contentType); - } - }); - return this; - } - - public Builder withOfferThroughput(int throughput) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource().getThroughput()) - .isEqualTo(throughput); - } - }); - return this; - } - - public Builder validatePropertyCondition(String key, Condition condition) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - assertThat(resourceResponse.getResource()).isNotNull(); - assertThat(resourceResponse.getResource().get(key)).is(condition); - - } - }); - return this; - } - - public Builder withCompositeIndexes(Collection> compositeIndexesWritten) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - Iterator> compositeIndexesReadIterator = resourceResponse.getResource() - .getIndexingPolicy().getCompositeIndexes().iterator(); - Iterator> compositeIndexesWrittenIterator = compositeIndexesWritten.iterator(); - - ArrayList readIndexesStrings = new ArrayList(); - ArrayList writtenIndexesStrings = new ArrayList(); - - while (compositeIndexesReadIterator.hasNext() && compositeIndexesWrittenIterator.hasNext()) { - Iterator compositeIndexReadIterator = compositeIndexesReadIterator.next().iterator(); - Iterator compositeIndexWrittenIterator = compositeIndexesWrittenIterator.next().iterator(); - - StringBuilder readIndexesString = new StringBuilder(); - StringBuilder writtenIndexesString = new StringBuilder(); - - while (compositeIndexReadIterator.hasNext() && compositeIndexWrittenIterator.hasNext()) { - CompositePath compositePathRead = compositeIndexReadIterator.next(); - CompositePath compositePathWritten = compositeIndexWrittenIterator.next(); - - readIndexesString.append(compositePathRead.getPath() + ":" + compositePathRead.getOrder() + ";"); - writtenIndexesString.append(compositePathWritten.getPath() + ":" + compositePathRead.getOrder() + ";"); - } - - readIndexesStrings.add(readIndexesString.toString()); - writtenIndexesStrings.add(writtenIndexesString.toString()); - } - - assertThat(readIndexesStrings).containsExactlyInAnyOrderElementsOf(writtenIndexesStrings); - } - }); - return this; - } - - public Builder withSpatialIndexes(Collection spatialIndexes) { - validators.add(new ResourceResponseValidator() { - - @Override - public void validate(ResourceResponse resourceResponse) { - Iterator spatialIndexesReadIterator = resourceResponse.getResource() - .getIndexingPolicy().getSpatialIndexes().iterator(); - Iterator spatialIndexesWrittenIterator = spatialIndexes.iterator(); - - HashMap> readIndexMap = new HashMap>(); - HashMap> writtenIndexMap = new HashMap>(); - - while (spatialIndexesReadIterator.hasNext() && spatialIndexesWrittenIterator.hasNext()) { - SpatialSpec spatialSpecRead = spatialIndexesReadIterator.next(); - SpatialSpec spatialSpecWritten = spatialIndexesWrittenIterator.next(); - - String readPath = spatialSpecRead.getPath() + ":"; - String writtenPath = spatialSpecWritten.getPath() + ":"; - - ArrayList readSpatialTypes = new ArrayList(); - ArrayList writtenSpatialTypes = new ArrayList(); - - Iterator spatialTypesReadIterator = spatialSpecRead.getSpatialTypes().iterator(); - Iterator spatialTypesWrittenIterator = spatialSpecWritten.getSpatialTypes().iterator(); - - while (spatialTypesReadIterator.hasNext() && spatialTypesWrittenIterator.hasNext()) { - readSpatialTypes.add(spatialTypesReadIterator.next()); - writtenSpatialTypes.add(spatialTypesWrittenIterator.next()); - } - - readIndexMap.put(readPath, readSpatialTypes); - writtenIndexMap.put(writtenPath, writtenSpatialTypes); - } - - for (Entry> entry : readIndexMap.entrySet()) { - assertThat(entry.getValue()) - .containsExactlyInAnyOrderElementsOf(writtenIndexMap.get(entry.getKey())); - } - } - }); - return this; - } - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/ResourceValidator.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/ResourceValidator.java deleted file mode 100644 index a95a6346089c..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/ResourceValidator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; - -import com.microsoft.azure.cosmosdb.Resource; - -interface ResourceValidator { - - void validate(T v); - - class Builder { - private List> validators = new ArrayList<>(); - - public ResourceValidator build() { - return new ResourceValidator() { - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public void validate(T v) { - for (ResourceValidator validator : validators) { - validator.validate(v); - } - } - }; - } - - public Builder areEqual(T expectedValue) { - validators.add(new ResourceValidator() { - @Override - public void validate(T v) { - - assertThat(v.getHashMap().keySet()) - .describedAs("number of fields"). - hasSize(expectedValue.getHashMap().keySet().size()); - expectedValue.getHashMap().keySet(); - for(String key: expectedValue.getHashMap().keySet()) { - assertThat(expectedValue.get(key)) - .describedAs("value for " + key) - .isEqualTo(expectedValue.get(key)); - } - } - }); - return this; - } - - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/TestConfigurations.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/TestConfigurations.java deleted file mode 100644 index a6f115439e9e..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/TestConfigurations.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import org.apache.commons.lang3.StringUtils; - -import com.google.common.base.Strings; - -/** - * Contains the configurations for tests. - * - * For running tests, you can pass a customized endpoint configuration in one of the following - * ways: - *
    - *
  • -DACCOUNT_KEY="[your-key]" -ACCOUNT_HOST="[your-endpoint]" as JVM - * command-line option.
  • - *
  • You can set ACCOUNT_KEY and ACCOUNT_HOST as environment variables.
  • - *
- * - * If none of the above is set, emulator endpoint will be used. - */ -public final class TestConfigurations { - // Replace MASTER_KEY and HOST with values from your Azure Cosmos DB account. - // The default values are credentials of the local emulator, which are not used in any production environment. - // - public static String MASTER_KEY = - System.getProperty("ACCOUNT_KEY", - StringUtils.defaultString(Strings.emptyToNull( - System.getenv().get("ACCOUNT_KEY")), - "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==")); - - public static String HOST = - System.getProperty("ACCOUNT_HOST", - StringUtils.defaultString(Strings.emptyToNull( - System.getenv().get("ACCOUNT_HOST")), - "https://localhost:443/")); - - public static String CONSISTENCY = - System.getProperty("ACCOUNT_CONSISTENCY", - StringUtils.defaultString(Strings.emptyToNull( - System.getenv().get("ACCOUNT_CONSISTENCY")), "Strong")); - - public static String PREFERRED_LOCATIONS = - System.getProperty("PREFERRED_LOCATIONS", - StringUtils.defaultString(Strings.emptyToNull( - System.getenv().get("PREFERRED_LOCATIONS")), null)); -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/Utils.java b/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/Utils.java deleted file mode 100644 index 9bc18381d95d..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/java/com/microsoft/azure/cosmosdb/rx/Utils.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.Database; - -public class Utils { - private static final String DATABASES_PATH_SEGMENT = "dbs"; - private static final String COLLECTIONS_PATH_SEGMENT = "colls"; - private static final String DOCUMENTS_PATH_SEGMENT = "docs"; - private static final String USERS_PATH_SEGMENT = "users"; - - public static String getDatabaseLink(Database database, boolean isNameBased) { - if (isNameBased) { - return getDatabaseNameLink(database.getId()); - } else { - return database.getSelfLink(); - } - } - - public static String getDatabaseNameLink(String databaseId) { - return DATABASES_PATH_SEGMENT + "/" + databaseId; - } - - public static String getCollectionNameLink(String databaseId, String collectionId) { - - return DATABASES_PATH_SEGMENT + "/" + databaseId + "/" + COLLECTIONS_PATH_SEGMENT + "/" + collectionId; - } - - public static String getDocumentNameLink(String databaseId, String collectionId, String docId) { - - return DATABASES_PATH_SEGMENT + "/" + databaseId + "/" + COLLECTIONS_PATH_SEGMENT + "/" +collectionId + "/" + DOCUMENTS_PATH_SEGMENT + "/" + docId; - } - - public static String getUserNameLink(String databaseId, String userId) { - - return DATABASES_PATH_SEGMENT + "/" + databaseId + "/" + USERS_PATH_SEGMENT + "/" + userId; - } - - private Utils() { - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/tests/java/com/microsoft/azure/cosmosdb/ConfigsBuilderTest.java b/cosmosdb/data-plane/commons-test-utils/src/main/tests/java/com/microsoft/azure/cosmosdb/ConfigsBuilderTest.java deleted file mode 100644 index cf49065ef5bf..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/tests/java/com/microsoft/azure/cosmosdb/ConfigsBuilderTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConfigsBuilderTest { - - @Test(groups = { "unit" }) - public void defaultProtocol() { - Configs config = ConfigsBuilder.instance().build(); - assertThat(config.getProtocol()).isEqualTo(Protocol.Https); - } - - @Test(groups = { "unit" }) - public void tcp() { - Configs config = ConfigsBuilder.instance().withProtocol(Protocol.Tcp).build(); - assertThat(config.getProtocol()).isEqualTo(Protocol.Tcp); - } - - @Test(groups = { "unit" }) - public void https() { - Configs config = ConfigsBuilder.instance().withProtocol(Protocol.Https).build(); - assertThat(config.getProtocol()).isEqualTo(Protocol.Https); - } -} diff --git a/cosmosdb/data-plane/commons-test-utils/src/main/tests/resources/log4j.properties b/cosmosdb/data-plane/commons-test-utils/src/main/tests/resources/log4j.properties deleted file mode 100644 index 1f3287c67a55..000000000000 --- a/cosmosdb/data-plane/commons-test-utils/src/main/tests/resources/log4j.properties +++ /dev/null @@ -1,15 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -# Set HTTP components' logger to INFO - -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p %c - %m%n diff --git a/cosmosdb/data-plane/commons/pom.xml b/cosmosdb/data-plane/commons/pom.xml deleted file mode 100644 index 103f302b51ba..000000000000 --- a/cosmosdb/data-plane/commons/pom.xml +++ /dev/null @@ -1,204 +0,0 @@ - - - 4.0.0 - - com.microsoft.azure - azure-cosmosdb-parent - 2.4.5 - - azure-cosmosdb-commons - Common Components for Async SDK for SQL API of Azure Cosmos DB Service - Common Components for Async SDK for SQL API of Azure Cosmos DB Service - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.22.0 - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - org.apache.maven.plugins - maven-jxr-plugin - 2.1 - - - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind.version} - - - com.fasterxml.uuid - java-uuid-generator - ${java-uuid-generator.version} - - - commons-io - commons-io - ${commons-io.version} - - - commons-validator - commons-validator - ${commons-validator.version} - - - com.github.davidmoten - rxjava-extras - ${rxjava-extras.version} - - - io.reactivex - rxjava - ${rxjava.version} - - - io.reactivex - rxjava-string - ${rxjava-string.version} - - - io.reactivex - rxnetty - ${rxnetty.version} - - - io.netty - netty-transport-native-epoll - - - - - io.netty - netty-codec-http - ${netty.version} - - - io.netty - netty-handler - ${netty.version} - - - io.netty - netty-transport - ${netty.version} - - - io.netty - netty-handler-proxy - ${netty.version} - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.apache.commons - commons-collections4 - 4.2 - - - org.apache.commons - commons-text - ${commons-text.version} - - - org.testng - testng - ${testng.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.mockito - mockito-all - ${mockito.version} - test - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - test - - - log4j - log4j - ${log4j.version} - test - - - com.google.guava - guava - ${guava.version} - test - - - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/AccessCondition.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/AccessCondition.java deleted file mode 100644 index ecf664d5795a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/AccessCondition.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Represents a set of access conditions to be used for operations against the Azure Cosmos DB database service. - */ -public final class AccessCondition { - - private AccessConditionType type = AccessConditionType.IfMatch; - private String condition; - - /** - * Gets the condition type. - * - * @return the condition type. - */ - public AccessConditionType getType() { - return this.type; - } - - /** - * Sets the condition type. - * - * @param type the condition type to use. - */ - public void setType(AccessConditionType type) { - this.type = type; - } - - /** - * Gets the value of the condition - for AccessConditionType IfMatchs and IfNotMatch, this is the ETag that has to - * be compared to. - * - * @return the condition. - */ - public String getCondition() { - return this.condition; - } - - /** - * Sets the value of the condition - for AccessConditionType IfMatchs and IfNotMatch, this is the ETag that has to - * be compared to. - * - * @param condition the condition to use. - */ - public void setCondition(String condition) { - this.condition = condition; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/AccessConditionType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/AccessConditionType.java deleted file mode 100644 index 1366079dfe2a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/AccessConditionType.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Specifies the set of access condition types that can be used for operations in the Azure Cosmos DB database service. - */ -public enum AccessConditionType { - /** - * Check if the resource's ETag value matches the ETag value performed. - */ - IfMatch, - - /** - * Check if the resource's ETag value does not match ETag value performed. - */ - IfNoneMatch -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Attachment.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Attachment.java deleted file mode 100644 index 203c778242d3..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Attachment.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a document attachment in the Azure Cosmos DB database service. - *

- * Each document may contain zero or more attachments. Attachments can be of any MIME type - text, image, binary data. - * These are stored externally in Azure Blob storage. Attachments are automatically deleted when the parent document - * is deleted. - */ -public class Attachment extends Resource { - /** - * Initialize an attachment object. - */ - public Attachment() { - super(); - } - - /** - * Initialize an attachment object from json string. - * - * @param source the json string representation of the Attachment. - */ - public Attachment(String source) { - super(source); - } - - /** - * Gets the MIME content type of the attachment. - * - * @return the content type. - */ - public String getContentType() { - return super.getString(Constants.Properties.CONTENT_TYPE); - } - - /** - * Sets the MIME content type of the attachment. - * - * @param contentType the content type to use. - */ - public void setContentType(String contentType) { - super.set(Constants.Properties.CONTENT_TYPE, contentType); - } - - /** - * Gets the media link associated with the attachment content. - * - * @return the media link. - */ - public String getMediaLink() { - return super.getString(Constants.Properties.MEDIA_LINK); - } - - /** - * Sets the media link associated with the attachment content. - * - * @param mediaLink the media link to use. - */ - public void setMediaLink(String mediaLink) { - super.set(Constants.Properties.MEDIA_LINK, mediaLink); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/BridgeInternal.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/BridgeInternal.java deleted file mode 100644 index e0bc79144077..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/BridgeInternal.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.query.metrics.ClientSideMetrics; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -import java.net.URI; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentMap; - -import static com.microsoft.azure.cosmosdb.internal.Constants.QueryExecutionContext.INCREMENTAL_FEED_HEADER_VALUE; - - -/** - * This is meant to be used only internally as a bridge access to classes in - * com.microsoft.azure.cosmosdb - **/ -public class BridgeInternal { - - public static Error createError(ObjectNode objectNode) { - return new Error(objectNode); - } - - public static Document documentFromObject(Object document, ObjectMapper mapper) { - return Document.FromObject(document, mapper); - } - - public static ResourceResponse toResourceResponse(RxDocumentServiceResponse response, - Class cls) { - return new ResourceResponse(response, cls); - } - - public static MediaResponse toMediaResponse(RxDocumentServiceResponse response, boolean willBuffer) { - return new MediaResponse(response, willBuffer); - } - - public static FeedResponse toFeedResponsePage(RxDocumentServiceResponse response, - Class cls) { - return new FeedResponse(response.getQueryResponse(cls), response.getResponseHeaders()); - } - - public static FeedResponse toChaneFeedResponsePage(RxDocumentServiceResponse response, - Class cls) { - return new FeedResponse(noChanges(response) ? Collections.emptyList(): response.getQueryResponse(cls), response.getResponseHeaders(), noChanges(response)); - } - - public static StoredProcedureResponse toStoredProcedureResponse(RxDocumentServiceResponse response) { - return new StoredProcedureResponse(response); - } - - public static DatabaseAccount toDatabaseAccount(RxDocumentServiceResponse response) { - DatabaseAccount account = response.getResource(DatabaseAccount.class); - - // read the headers and set to the account - Map responseHeader = response.getResponseHeaders(); - - account.setMaxMediaStorageUsageInMB( - Long.valueOf(responseHeader.get(HttpConstants.HttpHeaders.MAX_MEDIA_STORAGE_USAGE_IN_MB))); - account.setMediaStorageUsageInMB( - Long.valueOf(responseHeader.get(HttpConstants.HttpHeaders.CURRENT_MEDIA_STORAGE_USAGE_IN_MB))); - - return account; - } - - public static Map getFeedHeaders(FeedOptionsBase options) { - - if (options == null) - return new HashMap<>(); - - Map headers = new HashMap<>(); - - if (options.getMaxItemCount() != null) { - headers.put(HttpConstants.HttpHeaders.PAGE_SIZE, options.getMaxItemCount().toString()); - } - - if (options instanceof ChangeFeedOptions) { - ChangeFeedOptions changeFeedOptions = (ChangeFeedOptions) options; - - String ifNoneMatchValue = null; - if (changeFeedOptions.getRequestContinuation() != null) { - ifNoneMatchValue = changeFeedOptions.getRequestContinuation(); - } else if (!changeFeedOptions.isStartFromBeginning()) { - ifNoneMatchValue = "*"; - } - // On REST level, change feed is using IfNoneMatch/ETag instead of - // continuation. - if (ifNoneMatchValue != null) { - headers.put(HttpConstants.HttpHeaders.IF_NONE_MATCH, ifNoneMatchValue); - } - - headers.put(HttpConstants.HttpHeaders.A_IM, INCREMENTAL_FEED_HEADER_VALUE); - } else if (options.getRequestContinuation() != null) { - headers.put(HttpConstants.HttpHeaders.CONTINUATION, options.getRequestContinuation()); - } - - FeedOptions feedOptions = options instanceof FeedOptions ? (FeedOptions) options : null; - if (feedOptions != null) { - if (feedOptions.getSessionToken() != null) { - headers.put(HttpConstants.HttpHeaders.SESSION_TOKEN, feedOptions.getSessionToken()); - } - - if (feedOptions.getEnableScanInQuery() != null) { - headers.put(HttpConstants.HttpHeaders.ENABLE_SCAN_IN_QUERY, - feedOptions.getEnableScanInQuery().toString()); - } - - if (feedOptions.getEmitVerboseTracesInQuery() != null) { - headers.put(HttpConstants.HttpHeaders.EMIT_VERBOSE_TRACES_IN_QUERY, - feedOptions.getEmitVerboseTracesInQuery().toString()); - } - - if (feedOptions.getEnableCrossPartitionQuery() != null) { - headers.put(HttpConstants.HttpHeaders.ENABLE_CROSS_PARTITION_QUERY, - feedOptions.getEnableCrossPartitionQuery().toString()); - } - - if (feedOptions.getMaxDegreeOfParallelism() != 0) { - headers.put(HttpConstants.HttpHeaders.PARALLELIZE_CROSS_PARTITION_QUERY, Boolean.TRUE.toString()); - } - - if (feedOptions.getResponseContinuationTokenLimitInKb() > 0) { - headers.put(HttpConstants.HttpHeaders.RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB, - Strings.toString(feedOptions.getResponseContinuationTokenLimitInKb())); - } - - if(feedOptions.getPopulateQueryMetrics()){ - headers.put(HttpConstants.HttpHeaders.POPULATE_QUERY_METRICS, String.valueOf(feedOptions.getPopulateQueryMetrics())); - } - } - - return headers; - } - - public static boolean noChanges(FeedResponse page) { - return page.nochanges; - } - - public static boolean noChanges(RxDocumentServiceResponse rsp) { - return rsp.getStatusCode() == HttpConstants.StatusCodes.NOT_MODIFIED; - } - - public static FeedResponse createFeedResponse(List results, Map headers) { - return new FeedResponse<>(results, headers); - } - - public static FeedResponse createFeedResponseWithQueryMetrics(List results, Map headers, ConcurrentMap queryMetricsMap) { - return new FeedResponse<>(results, headers, queryMetricsMap); - } - - public static E setResourceAddress(E e, String resourceAddress) { - e.resourceAddress = resourceAddress; - return e; - } - - public static long getLSN(E e) { - return e.lsn; - } - - public static String getPartitionKeyRangeId(E e) { - return e.partitionKeyRangeId; - } - - public static String getResourceAddress(E e) { - return e.resourceAddress; - } - - public static E setLSN(E e, long lsn) { - e.lsn = lsn; - return e; - } - - public static E setPartitionKeyRangeId(E e, String partitionKeyRangeId) { - e.partitionKeyRangeId = partitionKeyRangeId; - return e; - } - - public static boolean isEnableMultipleWriteLocations(DatabaseAccount account) { - return account.isEnableMultipleWriteLocations(); - } - - public static boolean getUseMultipleWriteLocations(ConnectionPolicy policy) { - return policy.isUsingMultipleWriteLocations(); - } - - public static void setUseMultipleWriteLocations(ConnectionPolicy policy, boolean value) { - policy.setUsingMultipleWriteLocations(value); - } - - public static URI getRequestUri(DocumentClientException documentClientException) { - return documentClientException.requestUri; - } - - public static void setRequestHeaders(DocumentClientException documentClientException, Map requestHeaders) { - documentClientException.requestHeaders = requestHeaders; - } - - public static Map getRequestHeaders(DocumentClientException documentClientException) { - return documentClientException.requestHeaders; - } - - public static Map getQueryEngineConfiuration(DatabaseAccount databaseAccount) { - return databaseAccount.getQueryEngineConfiuration(); - } - - public static ReplicationPolicy getReplicationPolicy(DatabaseAccount databaseAccount) { - return databaseAccount.getReplicationPolicy(); - } - - public static ReplicationPolicy getSystemReplicationPolicy(DatabaseAccount databaseAccount) { - return databaseAccount.getSystemReplicationPolicy(); - } - - public static ConsistencyPolicy getConsistencyPolicy(DatabaseAccount databaseAccount) { - return databaseAccount.getConsistencyPolicy(); - } - - public static String getAltLink(Resource resource) { - return resource.getAltLink(); - } - - public static void setAltLink(Resource resource, String altLink) { - resource.setAltLink(altLink); - } - - public static void setMaxReplicaSetSize(ReplicationPolicy replicationPolicy, int value) { - replicationPolicy.setMaxReplicaSetSize(value); - } - - public static void putQueryMetricsIntoMap(FeedResponse response, - String partitionKeyRangeId, - QueryMetrics queryMetrics){ - response.getQueryMetricsMap().put(partitionKeyRangeId, queryMetrics); - } - - public static QueryMetrics createQueryMetricsFromDelimitedStringAndClientSideMetrics(String queryMetricsDelimitedString, - ClientSideMetrics clientSideMetrics, - String activityId) { - return QueryMetrics.createFromDelimitedStringAndClientSideMetrics(queryMetricsDelimitedString, clientSideMetrics, activityId); - } - - public static QueryMetrics createQueryMetricsFromCollection(Collection queryMetricsCollection) { - return QueryMetrics.createFromCollection(queryMetricsCollection); - } - - public static ClientSideMetrics getClientSideMetrics(QueryMetrics queryMetrics){ - return queryMetrics.getClientSideMetrics(); - } - - public static String getInnerErrorMessage(DocumentClientException documentClientException) { - if (documentClientException == null) { - return null; - } - return documentClientException.getInnerErrorMessage(); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ChangeFeedOptions.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ChangeFeedOptions.java deleted file mode 100644 index a52595d59443..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ChangeFeedOptions.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.time.ZonedDateTime; - -/** - * Specifies the options associated with change feed methods (enumeration operations) in the Azure Cosmos DB database service. - */ -public final class ChangeFeedOptions extends FeedOptionsBase { - private String partitionKeyRangeId; - private boolean startFromBeginning; - private ZonedDateTime startDateTime; - - public ChangeFeedOptions() {} - - public ChangeFeedOptions(ChangeFeedOptions options) { - super(options); - this.partitionKeyRangeId = options.partitionKeyRangeId; - this.startFromBeginning = options.startFromBeginning; - this.startDateTime = options.startDateTime; - } - - /** - * Get the partition key range id for the current request - *

- * ChangeFeed requests can be executed against specific partition key ranges. - * This is used to process the change feed in parallel across multiple consumers. - *

- * - * @return a string indicating the partition key range ID - * @see PartitionKeyRange - */ - public String getPartitionKeyRangeId() { - return partitionKeyRangeId; - } - - /** - * Set the partition key range id for the current request - *

- * ChangeFeed requests can be executed against specific partition key ranges. - * This is used to process the change feed in parallel across multiple consumers. - *

- * - * @param partitionKeyRangeId a string indicating the partition key range ID - * @see PartitionKeyRange - */ - public void setPartitionKeyRangeId(String partitionKeyRangeId) { - this.partitionKeyRangeId = partitionKeyRangeId; - } - - /** - * Get whether change feed should start from beginning (true) or from current (false). - * By default it's start from current (false). - * - * @return a boolean value indicating change feed should start from beginning or not - */ - public boolean isStartFromBeginning() { - return startFromBeginning; - } - - /** - * Set whether change feed should start from beginning (true) or from current (false). - * By default it's start from current (false). - * - * @param startFromBeginning a boolean value indicating change feed should start from beginning or not - */ - public void setStartFromBeginning(boolean startFromBeginning) { - this.startFromBeginning = startFromBeginning; - } - - /** - * Gets the zoned date time to start looking for changes after. - * @return a zoned date time to start looking for changes after, if set or null otherwise - */ - public ZonedDateTime getStartDateTime() { - return startDateTime; - } - - /** - * Sets the zoned date time (exclusive) to start looking for changes after. - * If this is specified, startFromBeginning is ignored. - * @param startDateTime a zoned date time to start looking for changes after. - */ - public void setStartDateTime(ZonedDateTime startDateTime) { - this.startDateTime = startDateTime; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ClientSideRequestStatistics.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ClientSideRequestStatistics.java deleted file mode 100644 index cc71e6b391f5..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ClientSideRequestStatistics.java +++ /dev/null @@ -1,275 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import java.net.URI; -import java.net.URISyntaxException; -import java.time.Duration; -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResult; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.apache.commons.lang3.StringUtils; - -public class ClientSideRequestStatistics { - - private final static int MAX_SUPPLEMENTAL_REQUESTS_FOR_TO_STRING = 10; - - private final static DateTimeFormatter responseTimeFormatter = DateTimeFormatter.ofPattern("dd MMM yyyy HH:mm:ss.SSS").withLocale(Locale.US); - - private ZonedDateTime requestStartTime; - private ZonedDateTime requestEndTime; - - private List responseStatisticsList; - private List supplementalResponseStatisticsList; - private Map addressResolutionStatistics; - - private List contactedReplicas; - private Set failedReplicas; - private Set regionsContacted; - - public ClientSideRequestStatistics() { - this.requestStartTime = ZonedDateTime.now(ZoneOffset.UTC); - this.requestEndTime = ZonedDateTime.now(ZoneOffset.UTC); - this.responseStatisticsList = new ArrayList<>(); - this.supplementalResponseStatisticsList = new ArrayList<>(); - this.addressResolutionStatistics = new HashMap<>(); - this.contactedReplicas = new ArrayList<>(); - this.failedReplicas = new HashSet<>(); - this.regionsContacted = new HashSet<>(); - } - - public Duration getRequestLatency() { - return Duration.between(requestStartTime, requestEndTime); - } - - private boolean isCPUOverloaded() { - // NOTE: CPUMonitor and CPULoadHistory is not implemented in async SDK yet. - return false; - } - - public void recordResponse(RxDocumentServiceRequest request, StoreResult storeResult) { - ZonedDateTime responseTime = ZonedDateTime.now(ZoneOffset.UTC); - - StoreResponseStatistics storeResponseStatistics = new StoreResponseStatistics(); - storeResponseStatistics.requestResponseTime = responseTime; - storeResponseStatistics.storeResult = storeResult; - storeResponseStatistics.requestOperationType = request.getOperationType(); - storeResponseStatistics.requestResourceType = request.getResourceType(); - - URI locationEndPoint = null; - if (request.requestContext.locationEndpointToRoute != null) { - try { - locationEndPoint = request.requestContext.locationEndpointToRoute.toURI(); - } catch (URISyntaxException e) { - throw new IllegalArgumentException(e); - } - } - - synchronized (this) { - if (responseTime.isAfter(this.requestEndTime)) { - this.requestEndTime = responseTime; - } - - if (locationEndPoint != null) { - this.regionsContacted.add(locationEndPoint); - } - - if (storeResponseStatistics.requestOperationType == OperationType.Head || - storeResponseStatistics.requestOperationType == OperationType.HeadFeed) { - this.supplementalResponseStatisticsList.add(storeResponseStatistics); - } else { - this.responseStatisticsList.add(storeResponseStatistics); - } - } - } - - public String recordAddressResolutionStart(URI targetEndpoint) { - String identifier = Utils.randomUUID().toString(); - - AddressResolutionStatistics resolutionStatistics = new AddressResolutionStatistics(); - resolutionStatistics.startTime = ZonedDateTime.now(ZoneOffset.UTC); - // Very far in the future - resolutionStatistics.endTime = ZonedDateTime.of(LocalDateTime.MAX, ZoneOffset.UTC); - resolutionStatistics.targetEndpoint = targetEndpoint == null ? "" : targetEndpoint.toString(); - - synchronized (this) { - this.addressResolutionStatistics.put(identifier, resolutionStatistics); - } - - return identifier; - } - - public void recordAddressResolutionEnd(String identifier) { - if (StringUtils.isEmpty(identifier)) { - return; - } - ZonedDateTime responseTime = ZonedDateTime.now(ZoneOffset.UTC); - - synchronized (this) { - if (!this.addressResolutionStatistics.containsKey(identifier)) { - throw new IllegalArgumentException("Identifier " + identifier + " does not exist. Please call start before calling end"); - } - - if (responseTime.isAfter(this.requestEndTime)) { - this.requestEndTime = responseTime; - } - - AddressResolutionStatistics resolutionStatistics = this.addressResolutionStatistics.get(identifier); - resolutionStatistics.endTime = responseTime; - } - } - - @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - - // need to lock in case of concurrent operations. this should be extremely rare since toString() - // should only be called at the end of request. - synchronized (this) { - - // first trace request start time, as well as total non-head/headfeed requests made. - stringBuilder.append("RequestStartTime: ") - .append("\"").append(this.requestStartTime.format(responseTimeFormatter)).append("\"") - .append(", ") - .append("RequestEndTime: ") - .append("\"").append(this.requestEndTime.format(responseTimeFormatter)).append("\"") - .append(", ") - .append("Duration: ") - .append(Duration.between(requestStartTime, requestEndTime).toMillis()) - .append(" ms, ") - .append("Number of regions attempted: ") - .append(this.regionsContacted.isEmpty() ? 1 : this.regionsContacted.size()) - .append(System.lineSeparator()); - - // take all responses here - this should be limited in number and each one contains relevant information. - for (StoreResponseStatistics storeResponseStatistics : this.responseStatisticsList) { - stringBuilder.append(storeResponseStatistics.toString()).append(System.lineSeparator()); - } - - // take all responses here - this should be limited in number and each one is important. - for (AddressResolutionStatistics value : this.addressResolutionStatistics.values()) { - stringBuilder.append(value.toString()).append(System.lineSeparator()); - } - - // only take last 10 responses from this list - this has potential of having large number of entries. - // since this is for establishing consistency, we can make do with the last responses to paint a meaningful picture. - int supplementalResponseStatisticsListCount = this.supplementalResponseStatisticsList.size(); - int initialIndex = Math.max(supplementalResponseStatisticsListCount - MAX_SUPPLEMENTAL_REQUESTS_FOR_TO_STRING, 0); - if (initialIndex != 0) { - stringBuilder.append(" -- Displaying only the last ") - .append(MAX_SUPPLEMENTAL_REQUESTS_FOR_TO_STRING) - .append(" head/headfeed requests. Total head/headfeed requests: ") - .append(supplementalResponseStatisticsListCount); - } - for (int i = initialIndex; i < supplementalResponseStatisticsListCount; i++) { - stringBuilder.append(this.supplementalResponseStatisticsList.get(i).toString()).append(System.lineSeparator()); - } - } - String requestStatsString = stringBuilder.toString(); - if (!requestStatsString.isEmpty()) { - return System.lineSeparator() + requestStatsString; - } - return StringUtils.EMPTY; - } - - public List getContactedReplicas() { - return contactedReplicas; - } - - public void setContactedReplicas(List contactedReplicas) { - this.contactedReplicas = contactedReplicas; - } - - public Set getFailedReplicas() { - return failedReplicas; - } - - public void setFailedReplicas(Set failedReplicas) { - this.failedReplicas = failedReplicas; - } - - public Set getRegionsContacted() { - return regionsContacted; - } - - public void setRegionsContacted(Set regionsContacted) { - this.regionsContacted = regionsContacted; - } - - private static String formatDateTime(ZonedDateTime dateTime) { - if (dateTime == null) { - return null; - } - return dateTime.format(responseTimeFormatter); - } - - private class StoreResponseStatistics { - - private ZonedDateTime requestResponseTime; - private StoreResult storeResult; - private ResourceType requestResourceType; - private OperationType requestOperationType; - - @Override - public String toString() { - return "StoreResponseStatistics{" + - "requestResponseTime=\"" + formatDateTime(requestResponseTime) + "\"" + - ", storeResult=" + storeResult + - ", requestResourceType=" + requestResourceType + - ", requestOperationType=" + requestOperationType + - '}'; - } - } - - private class AddressResolutionStatistics { - private ZonedDateTime startTime; - private ZonedDateTime endTime; - private String targetEndpoint; - - AddressResolutionStatistics() { - } - - @Override - public String toString() { - return "AddressResolutionStatistics{" + - "startTime=\"" + formatDateTime(startTime) + "\"" + - ", endTime=\"" + formatDateTime(endTime) + "\"" + - ", targetEndpoint='" + targetEndpoint + '\'' + - '}'; - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CommonsBridgeInternal.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CommonsBridgeInternal.java deleted file mode 100644 index 20009de704a8..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CommonsBridgeInternal.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -public class CommonsBridgeInternal { - public static boolean isV2(PartitionKeyDefinition pkd) { - return pkd.getVersion() != null && PartitionKeyDefinitionVersion.V2.val == pkd.getVersion().val; - } - - public static void setV2(PartitionKeyDefinition pkd) { - pkd.setVersion(PartitionKeyDefinitionVersion.V2); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CompositePath.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CompositePath.java deleted file mode 100644 index ea9fcb67b175..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CompositePath.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import org.apache.commons.text.WordUtils; - -/** - * Represents a composite path of the IndexingPolicy in the Azure Cosmos DB database service. - * A composite path is used in a composite index. For example if you want to run a query like - * "SELECT * FROM c ORDER BY c.age, c.height", then you need to add "/age" and "/height" - * as composite paths to your composite index. - */ -public class CompositePath extends JsonSerializable { - /** - * Constructor. - */ - public CompositePath() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the included path. - */ - public CompositePath(String jsonString) { - super(jsonString); - } - - /** - * Gets path. - * - * @return the path. - */ - public String getPath() { - return super.getString(Constants.Properties.PATH); - } - - /** - * Sets path. - * - * @param path the path. - */ - public void setPath(String path) { - super.set(Constants.Properties.PATH, path); - } - - /** - * Gets the sort order for the composite path. - * - * For example if you want to run the query "SELECT * FROM c ORDER BY c.age asc, c.height desc", - * then you need to make the order for "/age" "ascending" and the order for "/height" "descending". - * - * @return the sort order. - */ - public CompositePathSortOrder getOrder() { - String strValue = super.getString(Constants.Properties.ORDER); - if (!StringUtils.isEmpty(strValue)) { - try { - return CompositePathSortOrder.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.ORDER))); - } catch (IllegalArgumentException e) { - this.getLogger().warn("Invalid indexingMode value {}.", super.getString(Constants.Properties.ORDER)); - return CompositePathSortOrder.Ascending; - } - } - return CompositePathSortOrder.Ascending; - } - - /** - * Gets the sort order for the composite path. - * - * For example if you want to run the query "SELECT * FROM c ORDER BY c.age asc, c.height desc", - * then you need to make the order for "/age" "ascending" and the order for "/height" "descending". - * - * @param order the sort order. - */ - public void setOrder(CompositePathSortOrder order) { - super.set(Constants.Properties.ORDER, order.toString()); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CompositePathSortOrder.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CompositePathSortOrder.java deleted file mode 100644 index fdb123abb0f8..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CompositePathSortOrder.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Represents the sorting order for a path in a composite index, for a - * collection in the Azure Cosmos DB database service. - */ -public enum CompositePathSortOrder { - /** - * Ascending sort order for composite paths. - */ - Ascending { - public String toString() { - return "ascending"; - } - }, - - /** - * Descending sort order for composite paths. - */ - Descending { - public String toString() { - return "descending"; - } - }, -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Conflict.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Conflict.java deleted file mode 100644 index 21650fe6331a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Conflict.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -import java.lang.reflect.InvocationTargetException; - -/** - * Represents a conflict in the version of a particular resource in the Azure Cosmos DB database service. - *

- * During rare failure scenarios, conflicts are generated for the documents in transit. Clients can inspect the - * respective conflict instances for resources and operations in conflict. - */ -public final class Conflict extends Resource { - /** - * Initialize a conflict object. - */ - public Conflict() { - super(); - } - - /** - * Initialize a conflict object from json string. - * - * @param jsonString the json string that represents the conflict. - */ - public Conflict(String jsonString) { - super(jsonString); - } - - /** - * Gets the operation kind. - * - * @return the operation kind. - */ - public String getOperationKind() { - return super.getString(Constants.Properties.OPERATION_TYPE); - } - - /** - * Gets the type of the conflicting resource. - * - * @return the resource type. - */ - public String getResouceType() { - return super.getString(Constants.Properties.RESOURCE_TYPE); - } - - /** - * Gets the resource ID for the conflict in the Azure Cosmos DB service. - * @return resource Id for the conflict. - */ - public String getSourceResourceId() { - return super.getString(Constants.Properties.SOURCE_RESOURCE_ID); - } - - /** - * Gets the conflicting resource in the Azure Cosmos DB service. - * @param the type of the object. - * @param klass The returned type of conflicting resource. - * @return The conflicting resource. - */ - public T getResource(Class klass) { - String resourceAsString = super.getString(Constants.Properties.CONTENT); - - if (!Strings.isNullOrEmpty(resourceAsString)) { - try { - return klass.getConstructor(String.class).newInstance(resourceAsString); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to instantiate class object.", e); - } - } else { - return null; - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConflictResolutionMode.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConflictResolutionMode.java deleted file mode 100644 index 8e605c5a0951..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConflictResolutionMode.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -public enum ConflictResolutionMode { - /** - * Last writer wins conflict resolution mode - * - * Setting the ConflictResolutionMode to "LastWriterWins" indicates that conflict resolution should be done by inspecting a field in the conflicting documents - * and picking the document which has the higher value in that path. See {@link ConflictResolutionPolicy#getConflictResolutionPath()} for details on how to specify the path - * to be checked for conflict resolution. Also note that Deletes win. - */ - LastWriterWins, - - /** - * Custom conflict resolution mode - * - * Setting the ConflictResolutionMode to "Custom" indicates that conflict resolution is custom handled by a user. - * The user could elect to register a user specified {@link StoredProcedure} for handling conflicting resources. - * Should the user not register a user specified StoredProcedure, conflicts will default to being made available as {@link Conflict} resources, - * which the user can inspect and manually resolve. - * See {@link ConflictResolutionPolicy#getConflictResolutionProcedure()} for details on how to specify the stored procedure - * to run for conflict resolution. - */ - Custom, - - /** - * Invalid or unknown mode. - */ - Invalid -} - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConflictResolutionPolicy.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConflictResolutionPolicy.java deleted file mode 100644 index 291b24d326b9..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConflictResolutionPolicy.java +++ /dev/null @@ -1,221 +0,0 @@ -package com.microsoft.azure.cosmosdb; - - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.apache.commons.text.WordUtils; - - -/** - * Represents the conflict resolution policy configuration for specifying how to resolve conflicts - * in case writes from different regions result in conflicts on documents in the collection in the Azure Cosmos DB service. - * - * A collection with custom conflict resolution with no user-registered stored procedure. - *

{@code
- * DocumentCollection collectionSpec = new DocumentCollection();
- * collectionSpec.setId("Multi-master collection");
- *
- * ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy();
- * collectionSpec.setConflictResolutionPolicy(policy);
- *
- * DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null)
- *         .toBlocking().single().getResource();
- *
- * }
- * 
- * - * A collection with custom conflict resolution with a user-registered stored procedure. - *
{@code
- * DocumentCollection collectionSpec = new DocumentCollection();
- * collectionSpec.setId("Multi-master collection");
- *
- * ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy(conflictResolutionSprocName);
- * collectionSpec.setConflictResolutionPolicy(policy);
- *
- * DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null)
- *         .toBlocking().single().getResource();
- *
- * }
- * 
- * - * A collection with last writer wins conflict resolution, based on a path in the conflicting documents. - * A collection with custom conflict resolution with a user-registered stored procedure. - *
{@code
- * DocumentCollection collectionSpec = new DocumentCollection();
- * collectionSpec.setId("Multi-master collection");
- *
- * ConflictResolutionPolicy policy = ConflictResolutionPolicy.createLastWriterWinsPolicy("/path/for/conflict/resolution");
- * collectionSpec.setConflictResolutionPolicy(policy);
- *
- * DocumentCollection collection = client.createCollection(databaseLink, collectionSpec, null)
- *         .toBlocking().single().getResource();
- *
- * }
- * 
- */ -public class ConflictResolutionPolicy extends JsonSerializable { - - /** - * Creates a LastWriterWins {@link ConflictResolutionPolicy} with "/_ts" as the resolution path. - * - * In case of a conflict occurring on a document, the document with the higher integer value in the default path - * {@link Resource#getTimestamp()}, i.e., "/_ts" will be used. - * - * @return ConflictResolutionPolicy. - */ - public static ConflictResolutionPolicy createLastWriterWinsPolicy() { - ConflictResolutionPolicy policy = new ConflictResolutionPolicy(); - policy.setMode(ConflictResolutionMode.LastWriterWins); - return policy; - } - - /** - * - * Creates a LastWriterWins {@link ConflictResolutionPolicy} with path as the resolution path. - * - * The specified path must be present in each document and must be an integer value. - * In case of a conflict occurring on a document, the document with the higher integer value in the specified path - * will be picked. - * - * @param conflictResolutionPath The path to check values for last-writer wins conflict resolution. - * That path is a rooted path of the property in the document, such as "/name/first". - * @return ConflictResolutionPolicy. - */ - public static ConflictResolutionPolicy createLastWriterWinsPolicy(String conflictResolutionPath) { - ConflictResolutionPolicy policy = new ConflictResolutionPolicy(); - policy.setMode(ConflictResolutionMode.LastWriterWins); - if (conflictResolutionPath != null) { - policy.setConflictResolutionPath(conflictResolutionPath); - } - return policy; - } - - /** - * Creates a Custom {@link ConflictResolutionPolicy} which uses the specified stored procedure - * to perform conflict resolution - * - * This stored procedure may be created after the {@link DocumentCollection} is created and can be changed as required. - * - *
    - *
  • In case the stored procedure fails or throws an exception, - * the conflict resolution will default to registering conflicts in the conflicts feed
  • - *
  • The user can provide the stored procedure @see {@link Resource#getId()}
  • - *
- * @param conflictResolutionSprocName stored procedure to perform conflict resolution. - * @return ConflictResolutionPolicy. - */ - public static ConflictResolutionPolicy createCustomPolicy(String conflictResolutionSprocName) { - ConflictResolutionPolicy policy = new ConflictResolutionPolicy(); - policy.setMode(ConflictResolutionMode.Custom); - if (conflictResolutionSprocName != null) { - policy.setConflictResolutionProcedure(conflictResolutionSprocName); - } - return policy; - } - - /** - * Creates a Custom {@link ConflictResolutionPolicy} without any {@link StoredProcedure}. User manually - * should resolve conflicts. - * - * The conflicts will be registered in the conflicts feed and the user should manually resolve them. - * - * @return ConflictResolutionPolicy. - */ - public static ConflictResolutionPolicy createCustomPolicy() { - ConflictResolutionPolicy policy = new ConflictResolutionPolicy(); - policy.setMode(ConflictResolutionMode.Custom); - return policy; - } - - /** - * Initializes a new instance of the {@link ConflictResolutionPolicy} class for the Azure Cosmos DB service. - */ - ConflictResolutionPolicy() {} - - public ConflictResolutionPolicy(String jsonString) { - super(jsonString); - } - - /** - * Gets the {@link ConflictResolutionMode} in the Azure Cosmos DB service. - * By default it is {@link ConflictResolutionMode#LastWriterWins}. - * - * @return ConflictResolutionMode. - */ - public ConflictResolutionMode getConflictResolutionMode() { - - String strValue = super.getString(Constants.Properties.MODE); - - if (!Strings.isNullOrEmpty(strValue)) { - try { - return ConflictResolutionMode.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.MODE))); - } catch (IllegalArgumentException e) { - this.getLogger().warn("Invalid ConflictResolutionMode value {}.", super.getString(Constants.Properties.MODE)); - return ConflictResolutionMode.Invalid; - } - } - - return ConflictResolutionMode.Invalid; - } - - /** - * Sets the {@link ConflictResolutionMode} in the Azure Cosmos DB service. - * By default it is {@link ConflictResolutionMode#LastWriterWins}. - * - * @param mode One of the values of the {@link ConflictResolutionMode} enum. - */ - void setMode(ConflictResolutionMode mode) { - super.set(Constants.Properties.MODE, mode.name()); - } - - /** - * Gets the path which is present in each document in the Azure Cosmos DB service for last writer wins conflict-resolution. - * This path must be present in each document and must be an integer value. - * In case of a conflict occurring on a document, the document with the higher integer value in the specified path will be picked. - * If the path is unspecified, by default the {@link Resource#getTimestamp()} path will be used. - * - * This value should only be set when using {@link ConflictResolutionMode#LastWriterWins} - * - * @return The path to check values for last-writer wins conflict resolution. - * That path is a rooted path of the property in the document, such as "/name/first". - */ - public String getConflictResolutionPath() { - return super.getString(Constants.Properties.CONFLICT_RESOLUTION_PATH); - } - - /** - * Sets the path which is present in each document in the Azure Cosmos DB service for last writer wins conflict-resolution. - * This path must be present in each document and must be an integer value. - * In case of a conflict occurring on a document, the document with the higher integer value in the specified path will be picked. - * If the path is unspecified, by default the {@link Resource#getTimestamp()} path will be used. - * - * This value should only be set when using {@link ConflictResolutionMode#LastWriterWins} - * - * @param value The path to check values for last-writer wins conflict resolution. - * That path is a rooted path of the property in the document, such as "/name/first". - */ - void setConflictResolutionPath(String value) { - super.set(Constants.Properties.CONFLICT_RESOLUTION_PATH, value); - } - - /** - * Gets the {@link StoredProcedure} which is used for conflict resolution in the Azure Cosmos DB service. - * This stored procedure may be created after the {@link DocumentCollection} is created and can be changed as required. - * - *
    - *
  • This value should only be set when using {@link ConflictResolutionMode#Custom}
  • - *
  • In case the stored procedure fails or throws an exception, - * the conflict resolution will default to registering conflicts in the conflicts feed
  • - *
  • The user can provide the stored procedure @see {@link Resource#getId()}
  • - *
- ** - * @return the stored procedure to perform conflict resolution.] - */ - public String getConflictResolutionProcedure() { - return super.getString(Constants.Properties.CONFLICT_RESOLUTION_PROCEDURE); - } - - void setConflictResolutionProcedure(String value) { - super.set(Constants.Properties.CONFLICT_RESOLUTION_PROCEDURE, value); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConnectionMode.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConnectionMode.java deleted file mode 100644 index c534ef3394b7..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConnectionMode.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Represents the connection mode to be used by the client in the Azure Cosmos DB database service. - *

- * Direct and Gateway connectivity modes are supported. Gateway is the default. - * Refer to <see>http://azure.microsoft.com/documentation/articles/documentdb- - * interactions-with-resources/#connectivity-options</see> for additional - * details. - *

- */ -public enum ConnectionMode { - - /** - * Specifies that requests to server resources are made through a gateway proxy using HTTPS. - *

- * In Gateway mode, all requests are made through a gateway proxy. - *

- */ - Gateway, - - /** - * Specifies that requests to server resources are made directly to the data nodes. - *

- * In Direct mode, all requests to server resources within a collection, such as documents, stored procedures - * and user-defined functions, etc., are made directly to the data nodes within the target Cosmos DB cluster - * using either the HTTPS or TCP/SSL transport protocol. - *

- * Certain operations on account or database level resources, such as databases, collections and users, etc., - * are always routed through the gateway using HTTPS. - *

- */ - Direct -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConnectionPolicy.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConnectionPolicy.java deleted file mode 100644 index 6409218e0515..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConnectionPolicy.java +++ /dev/null @@ -1,400 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.net.InetSocketAddress; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -/** - * Represents the Connection policy associated with a DocumentClient in the Azure Cosmos DB database service. - */ -public final class ConnectionPolicy { - - private static final int DEFAULT_REQUEST_TIMEOUT_IN_MILLIS = 60 * 1000; - // defaultMediaRequestTimeout is based upon the blob client timeout and the - // retry policy. - private static final int DEFAULT_MEDIA_REQUEST_TIMEOUT_IN_MILLIS = 300 * 1000; - private static final int DEFAULT_IDLE_CONNECTION_TIMEOUT_IN_MILLIS = 60 * 1000; - - private static final int DEFAULT_MAX_POOL_SIZE = 1000; - - private static ConnectionPolicy default_policy = null; - private int requestTimeoutInMillis; - private int mediaRequestTimeoutInMillis; - private ConnectionMode connectionMode; - private MediaReadMode mediaReadMode; - private int maxPoolSize; - private int idleConnectionTimeoutInMillis; - private String userAgentSuffix; - private RetryOptions retryOptions; - private boolean enableEndpointDiscovery = true; - private List preferredLocations; - private boolean usingMultipleWriteLocations; - private InetSocketAddress inetSocketProxyAddress; - private Boolean enableReadRequestsFallback; - - /** - * Constructor. - */ - public ConnectionPolicy() { - this.connectionMode = ConnectionMode.Gateway; - this.enableReadRequestsFallback = null; - this.idleConnectionTimeoutInMillis = DEFAULT_IDLE_CONNECTION_TIMEOUT_IN_MILLIS; - this.maxPoolSize = DEFAULT_MAX_POOL_SIZE; - this.mediaReadMode = MediaReadMode.Buffered; - this.mediaRequestTimeoutInMillis = ConnectionPolicy.DEFAULT_MEDIA_REQUEST_TIMEOUT_IN_MILLIS; - this.requestTimeoutInMillis = ConnectionPolicy.DEFAULT_REQUEST_TIMEOUT_IN_MILLIS; - this.retryOptions = new RetryOptions(); - this.userAgentSuffix = ""; - } - - /** - * Gets the default connection policy. - * - * @return the default connection policy. - */ - public static ConnectionPolicy GetDefault() { - if (ConnectionPolicy.default_policy == null) { - ConnectionPolicy.default_policy = new ConnectionPolicy(); - } - return ConnectionPolicy.default_policy; - } - - /** - * Gets the request timeout (time to wait for response from network peer) in - * milliseconds. - * - * @return the request timeout in milliseconds. - */ - public int getRequestTimeoutInMillis() { - return this.requestTimeoutInMillis; - } - - /** - * Sets the request timeout (time to wait for response from network peer) in - * milliseconds. The default is 60 seconds. - * - * @param requestTimeoutInMillis the request timeout in milliseconds. - */ - public void setRequestTimeoutInMillis(int requestTimeoutInMillis) { - this.requestTimeoutInMillis = requestTimeoutInMillis; - } - - /** - * Gets or sets time to wait for response from network peer for attachment - * content (aka media) operations. - * - * @return the media request timeout in milliseconds. - */ - public int getMediaRequestTimeoutInMillis() { - return this.mediaRequestTimeoutInMillis; - } - - /** - * Gets or sets Time to wait for response from network peer for attachment - * content (aka media) operations. - * - * @param mediaRequestTimeoutInMillis the media request timeout in milliseconds. - */ - public void setMediaRequestTimeoutInMillis(int mediaRequestTimeoutInMillis) { - this.mediaRequestTimeoutInMillis = mediaRequestTimeoutInMillis; - } - - /** - * Gets the connection mode used in the client. - * - * @return the connection mode. - */ - public ConnectionMode getConnectionMode() { - return this.connectionMode; - } - - /** - * Sets the connection mode used in the client. - * - * @param connectionMode the connection mode. - */ - public void setConnectionMode(ConnectionMode connectionMode) { - this.connectionMode = connectionMode; - } - - /** - * Gets the attachment content (aka media) download mode. - * - * @return the media read mode. - */ - public MediaReadMode getMediaReadMode() { - return this.mediaReadMode; - } - - /** - * Sets the attachment content (aka media) download mode. - * - * @param mediaReadMode the media read mode. - */ - public void setMediaReadMode(MediaReadMode mediaReadMode) { - this.mediaReadMode = mediaReadMode; - } - - /** - * Gets the value of the connection pool size the client is using. - * - * @return connection pool size. - */ - public int getMaxPoolSize() { - return this.maxPoolSize; - } - - /** - * Sets the value of the connection pool size, the default - * is 1000. - * - * @param maxPoolSize The value of the connection pool size. - */ - public void setMaxPoolSize(int maxPoolSize) { - this.maxPoolSize = maxPoolSize; - } - - /** - * Gets the value of the timeout for an idle connection, the default is 60 - * seconds. - * - * @return Idle connection timeout. - */ - public int getIdleConnectionTimeoutInMillis() { - return this.idleConnectionTimeoutInMillis; - } - - /** - * sets the value of the timeout for an idle connection. After that time, - * the connection will be automatically closed. - * - * @param idleConnectionTimeoutInMillis the timeout for an idle connection in seconds. - */ - public void setIdleConnectionTimeoutInMillis(int idleConnectionTimeoutInMillis) { - this.idleConnectionTimeoutInMillis = idleConnectionTimeoutInMillis; - } - - /** - * Gets the value of user-agent suffix. - * - * @return the value of user-agent suffix. - */ - public String getUserAgentSuffix() { - return this.userAgentSuffix; - } - - /** - * sets the value of the user-agent suffix. - * - * @param userAgentSuffix The value to be appended to the user-agent header, this is - * used for monitoring purposes. - */ - public void setUserAgentSuffix(String userAgentSuffix) { - this.userAgentSuffix = userAgentSuffix; - } - - /** - * Gets the retry policy options associated with the DocumentClient instance. - * - * @return the RetryOptions instance. - */ - public RetryOptions getRetryOptions() { - return this.retryOptions; - } - - /** - * Sets the retry policy options associated with the DocumentClient instance. - *

- * Properties in the RetryOptions class allow application to customize the built-in - * retry policies. This property is optional. When it's not set, the SDK uses the - * default values for configuring the retry policies. See RetryOptions class for - * more details. - * - * @param retryOptions the RetryOptions instance. - */ - public void setRetryOptions(RetryOptions retryOptions) { - if (retryOptions == null) { - throw new IllegalArgumentException("retryOptions value must not be null."); - } - - this.retryOptions = retryOptions; - } - - /** - * Gets the flag to enable endpoint discovery for geo-replicated database accounts. - * - * @return whether endpoint discovery is enabled. - */ - public boolean getEnableEndpointDiscovery() { - return this.enableEndpointDiscovery; - } - - /** - * Sets the flag to enable endpoint discovery for geo-replicated database accounts. - *

- * When EnableEndpointDiscovery is true, the SDK will automatically discover the - * current write and read regions to ensure requests are sent to the correct region - * based on the capability of the region and the user's preference. - *

- * The default value for this property is true indicating endpoint discovery is enabled. - * - * @param enableEndpointDiscovery true if EndpointDiscovery is enabled. - */ - public void setEnableEndpointDiscovery(boolean enableEndpointDiscovery) { - this.enableEndpointDiscovery = enableEndpointDiscovery; - } - - /** - * Gets the flag to enable writes on any locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service. - * - * When the value of this property is true, the SDK will direct write operations to - * available writable locations of geo-replicated database account. Writable locations - * are ordered by PreferredLocations property. Setting the property value - * to true has no effect until EnableMultipleWriteLocations in DatabaseAccount - * is also set to true. - * - * Default value is false indicating that writes are only directed to - * first region in PreferredLocations property. - * - * @return flag to enable writes on any locations (regions) for geo-replicated database accounts. - */ - public boolean isUsingMultipleWriteLocations() { - return this.usingMultipleWriteLocations; - } - - /** - * Gets whether to allow for reads to go to multiple regions configured on an account of Azure Cosmos DB service. - * - * Default value is null. - * - * If this property is not set, the default is true for all Consistency Levels other than Bounded Staleness, - * The default is false for Bounded Staleness. - * 1. {@link #enableEndpointDiscovery} is true - * 2. the Azure Cosmos DB account has more than one region - * - * @return flag to allow for reads to go to multiple regions configured on an account of Azure Cosmos DB service. - */ - public Boolean isEnableReadRequestsFallback() { - return this.enableReadRequestsFallback; - } - - /** - * Sets the flag to enable writes on any locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service. - * - * When the value of this property is true, the SDK will direct write operations to - * available writable locations of geo-replicated database account. Writable locations - * are ordered by PreferredLocations property. Setting the property value - * to true has no effect until EnableMultipleWriteLocations in DatabaseAccount - * is also set to true. - * - * Default value is false indicating that writes are only directed to - * first region in PreferredLocations property. - * - * @param usingMultipleWriteLocations flag to enable writes on any locations (regions) for geo-replicated database accounts. - */ - public void setUsingMultipleWriteLocations(boolean usingMultipleWriteLocations) { - this.usingMultipleWriteLocations = usingMultipleWriteLocations; - } - - /** - * Sets whether to allow for reads to go to multiple regions configured on an account of Azure Cosmos DB service. - * - * Default value is null. - * - * If this property is not set, the default is true for all Consistency Levels other than Bounded Staleness, - * The default is false for Bounded Staleness. - * 1. {@link #enableEndpointDiscovery} is true - * 2. the Azure Cosmos DB account has more than one region - * - * @param enableReadRequestsFallback flag to enable reads to go to multiple regions configured on an account of Azure Cosmos DB service. - */ - public void setEnableReadRequestsFallback(Boolean enableReadRequestsFallback) { - this.enableReadRequestsFallback = enableReadRequestsFallback; - } - - /** - * Gets the preferred locations for geo-replicated database accounts - * - * @return the list of preferred location. - */ - public List getPreferredLocations() { - return this.preferredLocations != null ? preferredLocations : Collections.emptyList(); - } - - /** - * Sets the preferred locations for geo-replicated database accounts. For example, - * "East US" as the preferred location. - *

- * When EnableEndpointDiscovery is true and PreferredRegions is non-empty, - * the SDK will prefer to use the locations in the collection in the order - * they are specified to perform operations. - *

- * If EnableEndpointDiscovery is set to false, this property is ignored. - * - * @param preferredLocations the list of preferred locations. - */ - public void setPreferredLocations(List preferredLocations) { - this.preferredLocations = preferredLocations; - } - - /** - * Gets the InetSocketAddress of proxy server. - * - * @return the value of proxyHost. - */ - public InetSocketAddress getProxy() { - return this.inetSocketProxyAddress; - } - - /** - * This will create the InetSocketAddress for proxy server, - * all the requests to cosmoDB will route from this address. - * @param proxyHost The proxy server host. - * @param proxyPort The proxy server port. - */ - public void setProxy(String proxyHost, int proxyPort) { - this.inetSocketProxyAddress = new InetSocketAddress(proxyHost, proxyPort); - } - - @Override - public String toString() { - return "ConnectionPolicy{" + - "requestTimeoutInMillis=" + requestTimeoutInMillis + - ", mediaRequestTimeoutInMillis=" + mediaRequestTimeoutInMillis + - ", connectionMode=" + connectionMode + - ", mediaReadMode=" + mediaReadMode + - ", maxPoolSize=" + maxPoolSize + - ", idleConnectionTimeoutInMillis=" + idleConnectionTimeoutInMillis + - ", userAgentSuffix='" + userAgentSuffix + '\'' + - ", retryOptions=" + retryOptions + - ", enableEndpointDiscovery=" + enableEndpointDiscovery + - ", preferredLocations=" + preferredLocations + - ", usingMultipleWriteLocations=" + usingMultipleWriteLocations + - ", inetSocketProxyAddress=" + inetSocketProxyAddress + - '}'; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConsistencyLevel.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConsistencyLevel.java deleted file mode 100644 index a7da6d28eb8a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConsistencyLevel.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Represents the consistency levels supported for Cosmos DB client operations in the Azure Cosmos DB database service. - *

- * The requested ConsistencyLevel must match or be weaker than that provisioned for the database account. Consistency - * levels by order of strength are Strong, BoundedStaleness, Session and Eventual. - */ -public enum ConsistencyLevel { - - /** - * Strong Consistency guarantees that read operations always return the value that was last written. - */ - Strong, - - /** - * Bounded Staleness guarantees that reads are not too out-of-date. This can be configured based on number of - * operations (MaxStalenessPrefix) or time (MaxStalenessIntervalInSeconds) - */ - BoundedStaleness, - - /** - * Session Consistency guarantees monotonic reads (you never read old data, then new, then old again), monotonic - * writes (writes are ordered) and read your writes (your writes are immediately visible to your reads) within - * any single session. - */ - Session, - - /** - * Eventual Consistency guarantees that reads will return a subset of writes. All writes will be eventually be - * available for reads. - */ - Eventual, - - /** - * ConsistentPrefix Consistency guarantees that reads will return some prefix of all writes with no gaps. All writes - * will be eventually be available for reads. - */ - ConsistentPrefix -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConsistencyPolicy.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConsistencyPolicy.java deleted file mode 100644 index 141a6b196795..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ConsistencyPolicy.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - - -import org.apache.commons.text.WordUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Encapsulates the settings for consistency policy in the Azure Cosmos DB database service. - */ -public final class ConsistencyPolicy extends JsonSerializable { - private static final ConsistencyLevel DEFAULT_DEFAULT_CONSISTENCY_LEVEL = - ConsistencyLevel.Session; - - private static final int DEFAULT_MAX_STALENESS_INTERVAL = 5; - private static final int DEFAULT_MAX_STALENESS_PREFIX = 100; - - - /** - * Constructor. - */ - ConsistencyPolicy() { - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the consistency policy. - */ - public ConsistencyPolicy(String jsonString) { - super(jsonString); - } - - /** - * Get the name of the resource. - * - * @return the default consistency level. - */ - public ConsistencyLevel getDefaultConsistencyLevel() { - - ConsistencyLevel result = ConsistencyPolicy.DEFAULT_DEFAULT_CONSISTENCY_LEVEL; - try { - result = ConsistencyLevel.valueOf( - WordUtils.capitalize(super.getString(Constants.Properties.DEFAULT_CONSISTENCY_LEVEL))); - } catch (IllegalArgumentException e) { - // ignore the exception and return the default - this.getLogger().warn("Unknown consistency level {}, value ignored.", super.getString(Constants.Properties.DEFAULT_CONSISTENCY_LEVEL)); - } - return result; - } - - /** - * Set the name of the resource. - * - * @param level the consistency level. - */ - public void setDefaultConsistencyLevel(ConsistencyLevel level) { - super.set(Constants.Properties.DEFAULT_CONSISTENCY_LEVEL, level.name()); - } - - /** - * Gets the bounded staleness consistency, the maximum allowed staleness in terms difference in sequence numbers - * (aka version). - * - * @return the max staleness prefix. - */ - public int getMaxStalenessPrefix() { - Integer value = super.getInt(Constants.Properties.MAX_STALENESS_PREFIX); - if (value == null) { - return ConsistencyPolicy.DEFAULT_MAX_STALENESS_PREFIX; - } - return value; - } - - /** - * Sets the bounded staleness consistency, the maximum allowed staleness in terms difference in sequence numbers - * (aka version). - * - * @param maxStalenessPrefix the max staleness prefix. - */ - public void setMaxStalenessPrefix(int maxStalenessPrefix) { - super.set(Constants.Properties.MAX_STALENESS_PREFIX, maxStalenessPrefix); - } - - /** - * Gets the in bounded staleness consistency, the maximum allowed staleness in terms time interval. - * - * @return the max staleness prefix. - */ - public int getMaxStalenessIntervalInSeconds() { - Integer value = super.getInt(Constants.Properties.MAX_STALENESS_INTERVAL_IN_SECONDS); - if (value == null) { - return ConsistencyPolicy.DEFAULT_MAX_STALENESS_INTERVAL; - } - return value; - } - - /** - * Sets the in bounded staleness consistency, the maximum allowed staleness in terms time interval. - * - * @param maxStalenessIntervalInSeconds the max staleness interval in seconds. - */ - public void setMaxStalenessIntervalInSeconds(int maxStalenessIntervalInSeconds) { - super.set(Constants.Properties.MAX_STALENESS_INTERVAL_IN_SECONDS, maxStalenessIntervalInSeconds); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CosmosResourceType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CosmosResourceType.java deleted file mode 100644 index 11029c770a91..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/CosmosResourceType.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Resource types in the Azure Cosmos DB database service. - */ -public enum CosmosResourceType { - - System(-100), - Attachment(3), - DocumentCollection(1), - Conflict(107), - Database(0), - Document(2), - Index(104), - Offer(113), - Permission(5), - StoredProcedure(109), - Trigger(110), - User(4), - UserDefinedFunction(111); - - final private int value; - - CosmosResourceType(int value) { - this.value = value; - } - - public int value() { - return this.value; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DataType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DataType.java deleted file mode 100644 index 9ff43f876835..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DataType.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Data types in the Azure Cosmos DB database service. - */ -public enum DataType { - /** - * Represents a numeric data type. - */ - Number, - - /** - * Represents a string data type. - */ - String, - - /** - * Represent a point data type. - */ - Point, - - /** - * Represents a line string data type. - */ - LineString, - - /** - * Represent a polygon data type. - */ - Polygon, - - /** - * Represent a multi-polygon data type. - */ - MultiPolygon -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Database.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Database.java deleted file mode 100644 index 118eef88cf38..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Database.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a Database in the Azure Cosmos DB database service. A database manages users, permissions and a set of collections - *

- * Each Azure Cosmos DB Service is able to support multiple independent named databases, with the database being the - * logical container for data. Each Database consists of one or more collections, each of which in turn contain one or - * more documents. Since databases are an an administrative resource and the Service Master Key will be required in - * order to access and successfully complete any action using the User APIs. - */ -public final class Database extends Resource { - - /** - * Initialize a database object. - */ - public Database() { - super(); - } - - /** - * Initialize a database object from json string. - * - * @param jsonString the json string. - */ - public Database(String jsonString) { - super(jsonString); - } - - /** - * Gets the self-link for collections in the database - * - * @return the collections link. - */ - public String getCollectionsLink() { - return String.format("%s/%s", - StringUtils.stripEnd(super.getSelfLink(), "/"), - super.getString(Constants.Properties.COLLECTIONS_LINK)); - } - - /** - * Gets the self-link for users in the database. - * - * @return the users link. - */ - public String getUsersLink() { - return String.format("%s/%s", - StringUtils.stripEnd(super.getSelfLink(), "/"), - super.getString(Constants.Properties.USERS_LINK)); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccount.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccount.java deleted file mode 100644 index a8ce58bb977a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccount.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.Utils; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; - -/** - * Represents a database account in the Azure Cosmos DB database service. - */ -public class DatabaseAccount extends Resource { - private ConsistencyPolicy consistencyPolicy; - - private long maxMediaStorageUsageInMB; - private long mediaStorageUsageInMB; - private ReplicationPolicy replicationPolicy; - private ReplicationPolicy systemReplicationPolicy; - private Map queryEngineConfiguration; - - /** - * Constructor. - */ - DatabaseAccount() { - this.setSelfLink(""); - } - - /** - * Initialize a database account object from json string. - * - * @param jsonString the json string that represents the database account. - */ - public DatabaseAccount(String jsonString) { - super(jsonString); - } - - /** - * Get the databases link of the databaseAccount. - * - * @return the databases link. - */ - public String getDatabasesLink() { - return super.getString(Constants.Properties.DATABASES_LINK); - } - - /** - * Set the databases of the databaseAccount. - * - * @param databasesLink the databases link. - */ - void setDatabasesLink(String databasesLink) { - super.set(Constants.Properties.DATABASES_LINK, databasesLink); - } - - /** - * Get the medialink of the databaseAccount. - * - * @return the media link. - */ - public String getMediaLink() { - return super.getString(Constants.Properties.MEDIA_LINK); - } - - /** - * Set the medialink of the databaseAccount. - * - * @param medialink the media link. - */ - void setMediaLink(String medialink) { - super.set(Constants.Properties.MEDIA_LINK, medialink); - } - - /** - * Get the addresseslink of the databaseAccount. - * - * @return the addresses link. - */ - public String getAddressesLink() { - return super.getString(Constants.Properties.ADDRESS_LINK); - } - - /** - * Set the addresseslink of the databaseAccount. - * - * @param addresseslink the addresses link. - */ - void setAddressesLink(String addresseslink) { - super.set(Constants.Properties.ADDRESS_LINK, addresseslink); - } - - /** - * Attachment content (media) storage quota in MBs Retrieved from gateway. - * - * @return the max media storage usage in MB. - */ - public long getMaxMediaStorageUsageInMB() { - return this.maxMediaStorageUsageInMB; - } - - void setMaxMediaStorageUsageInMB(long value) { - this.maxMediaStorageUsageInMB = value; - } - - /** - * Current attachment content (media) usage in MBs. - *

- * Retrieved from gateway. Value is returned from cached information updated - * periodically and is not guaranteed to be real time. - * - * @return the media storage usage in MB. - */ - public long getMediaStorageUsageInMB() { - return this.mediaStorageUsageInMB; - } - - void setMediaStorageUsageInMB(long value) { - this.mediaStorageUsageInMB = value; - } - - /** - * Gets the ConsistencyPolicy settings. - * - * @return the consistency policy. - */ - public ConsistencyPolicy getConsistencyPolicy() { - if (this.consistencyPolicy == null) { - this.consistencyPolicy = super.getObject(Constants.Properties.USER_CONSISTENCY_POLICY, - ConsistencyPolicy.class); - - if (this.consistencyPolicy == null) { - this.consistencyPolicy = new ConsistencyPolicy(); - } - } - return this.consistencyPolicy; - } - - /** - * Gets the ReplicationPolicy settings. - * - * @return the replication policy. - */ - public ReplicationPolicy getReplicationPolicy() { - if (this.replicationPolicy == null) { - this.replicationPolicy = super.getObject(Constants.Properties.USER_REPLICATION_POLICY, - ReplicationPolicy.class); - - if (this.replicationPolicy == null) { - this.replicationPolicy = new ReplicationPolicy(); - } - } - - return this.replicationPolicy; - } - - /** - * Gets the SystemReplicationPolicy settings. - * - * @return the system replication policy. - */ - ReplicationPolicy getSystemReplicationPolicy() { - if (this.systemReplicationPolicy == null) { - this.systemReplicationPolicy = super.getObject(Constants.Properties.SYSTEM_REPLICATION_POLICY, - ReplicationPolicy.class); - - if (this.systemReplicationPolicy == null) { - this.systemReplicationPolicy = new ReplicationPolicy(); - } - } - - return this.systemReplicationPolicy; - } - - /** - * Gets the QueryEngineConfiuration settings. - * - * @return the query engine configuration. - */ - Map getQueryEngineConfiuration() { - if (this.queryEngineConfiguration == null) { - String queryEngineConfigurationJsonString = super.getObject(Constants.Properties.QUERY_ENGINE_CONFIGURATION, - String.class); - if (StringUtils.isNotEmpty(queryEngineConfigurationJsonString)) { - TypeReference> typeRef = new TypeReference>() { - }; - try { - this.queryEngineConfiguration = Utils.getSimpleObjectMapper() - .readValue(queryEngineConfigurationJsonString, typeRef); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - if (this.queryEngineConfiguration == null) { - this.queryEngineConfiguration = new HashMap<>(); - } - } - } - - return this.queryEngineConfiguration; - } - - /** - * Gets the list of writable locations for this database account. - * - * @return the list of writable locations. - */ - public Iterable getWritableLocations() { - return super.getCollection(Constants.Properties.WRITABLE_LOCATIONS, DatabaseAccountLocation.class); - } - - /** - * Sets the list of writable locations for this database account. - *

- * The list of writable locations are returned by the service. - * - * @param locations the list of writable locations. - */ - void setWritableLocations(Iterable locations) { - super.set(Constants.Properties.WRITABLE_LOCATIONS, locations); - } - - /** - * Gets the list of readable locations for this database account. - * - * @return the list of readable locations. - */ - public Iterable getReadableLocations() { - return super.getCollection(Constants.Properties.READABLE_LOCATIONS, DatabaseAccountLocation.class); - } - - /** - * Sets the list of readable locations for this database account. - *

- * The list of readable locations are returned by the service. - * - * @param locations the list of readable locations. - */ - void setReadableLocations(Iterable locations) { - super.set(Constants.Properties.READABLE_LOCATIONS, locations); - } - - boolean isEnableMultipleWriteLocations() { - return ObjectUtils.defaultIfNull(super.getBoolean(Constants.Properties.ENABLE_MULTIPLE_WRITE_LOCATIONS), false); - } - - void setEnableMultipleWriteLocations(boolean value) { - super.set(Constants.Properties.ENABLE_MULTIPLE_WRITE_LOCATIONS, value); - } - - @Override - void populatePropertyBag() { - if (this.consistencyPolicy != null) { - this.consistencyPolicy.populatePropertyBag(); - super.set(Constants.Properties.USER_CONSISTENCY_POLICY, this.consistencyPolicy); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccountLocation.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccountLocation.java deleted file mode 100644 index 2ee1cca92a09..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccountLocation.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents the location of a database account in the Azure Cosmos DB database service. - */ -public class DatabaseAccountLocation extends JsonSerializable { - - /** - * Default Constructor. Creates a new instance of the - * DatabaseAccountLocation object. - */ - DatabaseAccountLocation() { - super(); - } - - /** - * Creates a new instance of the DatabaseAccountLocation object from a JSON - * string. - * - * @param jsonString the JSON string that represents the DatabaseAccountLocation object. - */ - public DatabaseAccountLocation(String jsonString) { - super(jsonString); - } - - /** - * Gets The name of the database account location. - * - * @return the name of the database account location. - */ - public String getName() { - return super.getString(Constants.Properties.Name); - } - - /** - * Sets the name of the database account location. - * - * @param name the name of the database account location. - */ - public void setName(String name) { - super.set(Constants.Properties.Name, name); - } - - /** - * Gets The endpoint (the URI) of the database account location. - * - * @return the endpoint of the database account location. - */ - public String getEndpoint() { - return super.getString(Constants.Properties.DATABASE_ACCOUNT_ENDPOINT); - } - - /** - * Sets the endpoint (the URI) of the database account location. - * - * @param endpoint the endpoint of the database account location. - */ - public void setEndpoint(String endpoint) { - super.set(Constants.Properties.DATABASE_ACCOUNT_ENDPOINT, endpoint); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Document.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Document.java deleted file mode 100644 index 31922b93adba..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Document.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.io.IOException; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a document in the Azure Cosmos DB database service. - *

- * A document is a structured JSON document. There is no set schema for the JSON documents, and a document may contain - * any number of custom properties as well as an optional list of attachments. Document is an application resource and - * can be authorized using the master key or resource keys. - */ -public class Document extends Resource { - - /** - * Initialize a document object. - */ - public Document() { - super(); - } - - /** - * Initialize a document object from json string. - * - * @param jsonString the json string that represents the document object. - * @param objectMapper the custom object mapper - */ - public Document(String jsonString, ObjectMapper objectMapper) { - super(jsonString, objectMapper); - } - - /** - * Initialize a document object from json string. - * - * @param jsonString the json string that represents the document object. - */ - public Document(String jsonString) { - super(jsonString); - } - - static Document FromObject(Object document, ObjectMapper objectMapper) { - Document typedDocument; - if (document instanceof Document) { - typedDocument = (Document) document; - } else { - try { - return new Document(objectMapper.writeValueAsString(document)); - } catch (IOException e) { - throw new IllegalArgumentException("Can't serialize the object into the json string", e); - } - } - return typedDocument; - } - - /** - * Gets the document's time-to-live value. - * - * @return the document's time-to-live value in seconds. - */ - public Integer getTimeToLive() { - if (super.has(Constants.Properties.TTL)) { - return super.getInt(Constants.Properties.TTL); - } - - return null; - } - - /** - * Sets the document's time-to-live value. - *

- * A document's time-to-live value is an optional property. If set, the document expires after the specified number - * of seconds since its last write time. The value of this property should be one of the following: - *

- * null - indicates the time-to-live value for this document inherits from the parent collection's default time-to-live value. - *

- * nonzero positive integer - indicates the number of seconds before the document expires. It overrides the default time-to-live - * value specified on the parent collection, unless the parent collection's default time-to-live is null. - *

- * -1 - indicates the document never expires. It overrides the default time-to-live - * value specified on the parent collection, unless the parent collection's default time-to-live is null. - * - * @param timeToLive the document's time-to-live value in seconds. - */ - public void setTimeToLive(Integer timeToLive) { - // a "null" value is represented as a missing element on the wire. - // setting timeToLive to null should remove the property from the property bag. - if (timeToLive != null) { - super.set(Constants.Properties.TTL, timeToLive); - } else if (super.has(Constants.Properties.TTL)) { - super.remove(Constants.Properties.TTL); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DocumentClientException.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DocumentClientException.java deleted file mode 100644 index c9b6d4a99fd9..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DocumentClientException.java +++ /dev/null @@ -1,302 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.net.URI; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -/** - * This class defines a custom exception type for all operations on - * DocumentClient in the Azure Cosmos DB database service. Applications are expected to catch DocumentClientException - * and handle errors as appropriate when calling methods on DocumentClient. - *

- * Errors coming from the service during normal execution are converted to - * DocumentClientException before returning to the application with the following exception: - *

- * When a BE error is encountered during a QueryIterable<T> iteration, an IllegalStateException - * is thrown instead of DocumentClientException. - *

- * When a transport level error happens that request is not able to reach the service, - * an IllegalStateException is thrown instead of DocumentClientException. - */ -public class DocumentClientException extends Exception { - private static final long serialVersionUID = 1L; - - private Error error; - private final int statusCode; - private final Map responseHeaders; - private ClientSideRequestStatistics clientSideRequestStatistics; - String resourceAddress; - String partitionKeyRangeId; - URI requestUri; - long lsn; - Map requestHeaders; - - /** - * Creates a new instance of the DocumentClientException class. - * - * @param statusCode the http status code of the response. - */ - public DocumentClientException(int statusCode) { - this.statusCode = statusCode; - this.responseHeaders = new HashMap<>(); - } - - /** - * Creates a new instance of the DocumentClientException class. - * - * @param statusCode the http status code of the response. - * @param errorMessage the error message. - */ - public DocumentClientException(int statusCode, String errorMessage) { - Error error = new Error(); - error.set(Constants.Properties.MESSAGE, errorMessage); - this.statusCode = statusCode; - this.error = error; - this.responseHeaders = new HashMap<>(); - } - - /** - * Creates a new instance of the DocumentClientException class. - * - * @param statusCode the http status code of the response. - * @param innerException the original exception. - */ - public DocumentClientException(int statusCode, Exception innerException) { - super(innerException); - this.statusCode = statusCode; - this.responseHeaders = new HashMap<>(); - } - - /** - * Creates a new instance of the DocumentClientException class. - * - * @param statusCode the http status code of the response. - * @param errorResource the error resource object. - * @param responseHeaders the response headers. - */ - public DocumentClientException(int statusCode, Error errorResource, Map responseHeaders) { - this(null, statusCode, errorResource, responseHeaders); - } - - /** - * Creates a new instance of the DocumentClientException class. - * - * @param resourceAddress the address of the resource the request is associated with. - * @param statusCode the http status code of the response. - * @param errorResource the error resource object. - * @param responseHeaders the response headers. - */ - - public DocumentClientException(String resourceAddress, int statusCode, Error errorResource, Map responseHeaders) { - - super(errorResource == null ? null : errorResource.getMessage()); - - this.responseHeaders = safeResponseHeaders(responseHeaders); - this.resourceAddress = resourceAddress; - this.statusCode = statusCode; - this.error = errorResource; - } - - /** Creates a new instance of the DocumentClientException class. - * @param message the string message. - * @param statusCode the http status code of the response. - * @param exception the exception object. - * @param responseHeaders the response headers. - * @param resourceAddress the address of the resource the request is associated with. - */ - public DocumentClientException(String message, Exception exception, Map responseHeaders, int statusCode, String resourceAddress) { - - super(message, exception); - - this.responseHeaders = safeResponseHeaders(responseHeaders); - this.resourceAddress = resourceAddress; - this.statusCode = statusCode; - } - - @Override - public String getMessage() { - if (clientSideRequestStatistics == null) { - return getInnerErrorMessage(); - } - return getInnerErrorMessage() + ", " + clientSideRequestStatistics.toString(); - } - - /** - * Gets the activity ID associated with the request. - * - * @return the activity ID. - */ - public String getActivityId() { - if (this.responseHeaders != null) { - return this.responseHeaders.get(HttpConstants.HttpHeaders.ACTIVITY_ID); - } - - return null; - } - - /** - * Gets the http status code. - * - * @return the status code. - */ - public int getStatusCode() { - return this.statusCode; - } - - /** - * Gets the sub status code. - * - * @return the status code. - */ - public int getSubStatusCode() { - int code = HttpConstants.SubStatusCodes.UNKNOWN; - if (this.responseHeaders != null) { - String subStatusString = this.responseHeaders.get(HttpConstants.HttpHeaders.SUB_STATUS); - if (StringUtils.isNotEmpty(subStatusString)) { - try { - code = Integer.parseInt(subStatusString); - } catch (NumberFormatException e) { - // If value cannot be parsed as Integer, return Unknown. - } - } - } - - return code; - } - - /** - * Gets the error code associated with the exception. - * - * @return the error. - */ - public Error getError() { - return this.error; - } - - /** - * Gets the recommended time interval after which the client can retry - * failed requests - * - * @return the recommended time interval after which the client can retry - * failed requests. - */ - public long getRetryAfterInMilliseconds() { - long retryIntervalInMilliseconds = 0; - - if (this.responseHeaders != null) { - String header = this.responseHeaders.get(HttpConstants.HttpHeaders.RETRY_AFTER_IN_MILLISECONDS); - - if (StringUtils.isNotEmpty(header)) { - try { - retryIntervalInMilliseconds = Long.parseLong(header); - } catch (NumberFormatException e) { - // If the value cannot be parsed as long, return 0. - } - } - } - - // - // In the absence of explicit guidance from the backend, don't introduce - // any unilateral retry delays here. - return retryIntervalInMilliseconds; - } - - /** - * Gets the response headers as key-value pairs - * - * @return the response headers - */ - public Map getResponseHeaders() { - return this.responseHeaders; - } - - /** - * Gets the resource address associated with this exception. - * - * @return the resource address associated with this exception. - */ - String getResourceAddress() { - return this.resourceAddress; - } - - /** - * Gets the Client side request statistics associated with this exception. - * - * @return Client side request statistics associated with this exception. - */ - public ClientSideRequestStatistics getClientSideRequestStatistics() { - return clientSideRequestStatistics; - } - - public void setClientSideRequestStatistics(ClientSideRequestStatistics clientSideRequestStatistics) { - this.clientSideRequestStatistics = clientSideRequestStatistics; - } - - @Override - public String toString() { - return getClass().getSimpleName() + "{" + - "error=" + error + - ", resourceAddress='" + resourceAddress + '\'' + - ", statusCode=" + statusCode + - ", message=" + getMessage() + - ", getCauseInfo=" + getCauseInfo() + - ", responseHeaders=" + responseHeaders + - ", requestHeaders=" + requestHeaders + - '}'; - } - - String getInnerErrorMessage() { - String innerErrorMessage = super.getMessage(); - if (error != null) { - innerErrorMessage = error.getMessage(); - if (innerErrorMessage == null) { - innerErrorMessage = String.valueOf(error.get("Errors")); - } - } - return innerErrorMessage; - } - - private String getCauseInfo() { - Throwable cause = getCause(); - if (cause != null) { - return String.format("[class: %s, message: %s]", cause.getClass(), cause.getMessage()); - } - return null; - } - - private Map safeResponseHeaders(Map map) { - if (map != null) { - return new HashMap<>(map); - } else { - return new HashMap<>(); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DocumentCollection.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DocumentCollection.java deleted file mode 100644 index 351b483e0dc5..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/DocumentCollection.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import org.apache.commons.lang3.StringUtils; - -/** - * Represents a document collection in the Azure Cosmos DB database service. A collection is a named logical container - * for documents. - *

- * A database may contain zero or more named collections and each collection consists of zero or more JSON documents. - * Being schema-free, the documents in a collection do not need to share the same structure or fields. Since collections - * are application resources, they can be authorized using either the master key or resource keys. - */ -public final class DocumentCollection extends Resource { - private IndexingPolicy indexingPolicy; - private UniqueKeyPolicy uniqueKeyPolicy; - private PartitionKeyDefinition partitionKeyDefinition; - - /** - * Initialize a document collection object. - */ - public DocumentCollection() { - super(); - } - - /** - * Initialize a document collection object from json string. - * - * @param jsonString the json string that represents the document collection. - */ - public DocumentCollection(String jsonString) { - super(jsonString); - } - - /** - * Gets the indexing policy. - * - * @return the indexing policy. - */ - public IndexingPolicy getIndexingPolicy() { - if (this.indexingPolicy == null) { - if (super.has(Constants.Properties.INDEXING_POLICY)) { - this.indexingPolicy = super.getObject(Constants.Properties.INDEXING_POLICY, IndexingPolicy.class); - } else { - this.indexingPolicy = new IndexingPolicy(); - } - } - - return this.indexingPolicy; - } - - /** - * Sets the indexing policy. - * - * @param indexingPolicy the indexing policy. - */ - public void setIndexingPolicy(IndexingPolicy indexingPolicy) { - if (indexingPolicy == null) { - throw new IllegalArgumentException("IndexingPolicy cannot be null."); - } - - this.indexingPolicy = indexingPolicy; - } - - /** - * Gets the collection's partition key definition. - * - * @return the partition key definition. - */ - public PartitionKeyDefinition getPartitionKey() { - if (this.partitionKeyDefinition == null) { - - if (super.has(Constants.Properties.PARTITION_KEY)) { - this.partitionKeyDefinition = super.getObject(Constants.Properties.PARTITION_KEY, PartitionKeyDefinition.class); - } else { - this.partitionKeyDefinition = new PartitionKeyDefinition(); - } - } - - return this.partitionKeyDefinition; - } - - /** - * Sets the collection's partition key definition. - * - * @param partitionKey the partition key definition. - */ - public void setPartitionKey(PartitionKeyDefinition partitionKey) { - if (partitionKey == null) { - throw new IllegalArgumentException("partitionKey cannot be null."); - } - - this.partitionKeyDefinition = partitionKey; - } - - /** - * Gets the collection's default time-to-live value. - * - * @return the default time-to-live value in seconds. - */ - public Integer getDefaultTimeToLive() { - if (super.has(Constants.Properties.DEFAULT_TTL)) { - return super.getInt(Constants.Properties.DEFAULT_TTL); - } - - return null; - } - - /** - * Sets the collection's default time-to-live value. - *

- * The default time-to-live value on a collection is an optional property. If set, the documents within the collection - * expires after the specified number of seconds since their last write time. The value of this property should be one of the following: - *

- * null - indicates evaluation of time-to-live is disabled and documents within the collection will never expire, regardless whether - * individual documents have their time-to-live set. - *

- * nonzero positive integer - indicates the default time-to-live value for all documents within the collection. This value can be overridden - * by individual documents' time-to-live value. - *

- * -1 - indicates by default all documents within the collection never expire. This value can be overridden by individual documents' - * time-to-live value. - * - * @param timeToLive the default time-to-live value in seconds. - */ - public void setDefaultTimeToLive(Integer timeToLive) { - // a "null" value is represented as a missing element on the wire. - // setting timeToLive to null should remove the property from the property bag. - if (timeToLive != null) { - super.set(Constants.Properties.DEFAULT_TTL, timeToLive); - } else if (super.has(Constants.Properties.DEFAULT_TTL)) { - super.remove(Constants.Properties.DEFAULT_TTL); - } - } - - /** - * Sets the Uni that guarantees uniqueness of documents in collection in the Azure Cosmos DB service. - * @return UniqueKeyPolicy - */ - public UniqueKeyPolicy getUniqueKeyPolicy() { - - // Thread safe lazy initialization for case when collection is cached (and is basically readonly). - if (this.uniqueKeyPolicy == null) { - this.uniqueKeyPolicy = super.getObject(Constants.Properties.UNIQUE_KEY_POLICY, UniqueKeyPolicy.class); - - if (this.uniqueKeyPolicy == null) { - this.uniqueKeyPolicy = new UniqueKeyPolicy(); - } - } - - return this.uniqueKeyPolicy; - } - - public void setUniqueKeyPolicy(UniqueKeyPolicy uniqueKeyPolicy) { - if (uniqueKeyPolicy == null) { - throw new IllegalArgumentException("uniqueKeyPolicy cannot be null."); - } - - this.uniqueKeyPolicy = uniqueKeyPolicy; - super.set(Constants.Properties.UNIQUE_KEY_POLICY, uniqueKeyPolicy); - } - - /** - * Gets the conflictResolutionPolicy that is used for resolving conflicting writes - * on documents in different regions, in a collection in the Azure Cosmos DB service. - * - * @return ConflictResolutionPolicy - */ - public ConflictResolutionPolicy getConflictResolutionPolicy() { - return super.getObject(Constants.Properties.CONFLICT_RESOLUTION_POLICY, ConflictResolutionPolicy.class); - } - - /** - * Sets the conflictResolutionPolicy that is used for resolving conflicting writes - * on documents in different regions, in a collection in the Azure Cosmos DB service. - * - * @param value ConflictResolutionPolicy to be used. - */ - public void setConflictResolutionPolicy(ConflictResolutionPolicy value) { - if (value == null) { - throw new IllegalArgumentException("CONFLICT_RESOLUTION_POLICY cannot be null."); - } - - super.set(Constants.Properties.CONFLICT_RESOLUTION_POLICY, value); - } - - - /** - * Gets the self-link for documents in a collection. - * - * @return the document link. - */ - public String getDocumentsLink() { - return String.format("%s/%s", - StringUtils.stripEnd(super.getSelfLink(), "/"), - super.getString(Constants.Properties.DOCUMENTS_LINK)); - } - - /** - * Gets the self-link for stored procedures in a collection. - * - * @return the stored procedures link. - */ - public String getStoredProceduresLink() { - return String.format("%s/%s", - StringUtils.stripEnd(super.getSelfLink(), "/"), - super.getString(Constants.Properties.STORED_PROCEDURES_LINK)); - } - - /** - * Gets the self-link for triggers in a collection. - * - * @return the trigger link. - */ - public String getTriggersLink() { - return StringUtils.removeEnd(this.getSelfLink(), "/") + - "/" + super.getString(Constants.Properties.TRIGGERS_LINK); - } - - /** - * Gets the self-link for user defined functions in a collection. - * - * @return the user defined functions link. - */ - public String getUserDefinedFunctionsLink() { - return StringUtils.removeEnd(this.getSelfLink(), "/") + - "/" + super.getString(Constants.Properties.USER_DEFINED_FUNCTIONS_LINK); - } - - /** - * Gets the self-link for conflicts in a collection. - * - * @return the conflicts link. - */ - public String getConflictsLink() { - return StringUtils.removeEnd(this.getSelfLink(), "/") + - "/" + super.getString(Constants.Properties.CONFLICTS_LINK); - } - - @Override - void populatePropertyBag() { - if (this.indexingPolicy == null) { - this.getIndexingPolicy(); - } - if (this.uniqueKeyPolicy == null) { - this.getUniqueKeyPolicy(); - } - - if (this.partitionKeyDefinition != null) { - this.partitionKeyDefinition.populatePropertyBag(); - super.set(Constants.Properties.PARTITION_KEY, this.partitionKeyDefinition); - } - - this.indexingPolicy.populatePropertyBag(); - this.uniqueKeyPolicy.populatePropertyBag(); - super.set(Constants.Properties.INDEXING_POLICY, this.indexingPolicy); - super.set(Constants.Properties.UNIQUE_KEY_POLICY, this.uniqueKeyPolicy); - } - - @Override - public boolean equals(Object obj) { - if (obj == null || !DocumentCollection.class.isAssignableFrom(obj.getClass())) { - return false; - } - - DocumentCollection typedObj = (DocumentCollection) obj; - return typedObj.getResourceId().equals(this.getResourceId()); - } - - @Override - public int hashCode() { - return this.getResourceId().hashCode(); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Error.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Error.java deleted file mode 100644 index 8923700be3c2..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Error.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Encapsulates error related details in the Azure Cosmos DB database service. - */ -public class Error extends Resource { - /** - * Initialize a new instance of the Error object. - */ - public Error() { - super(); - } - - /** - * Initialize a new instance of the Error object from a JSON string. - * - * @param objectNode the {@link ObjectNode} that represents the error. - */ - Error(ObjectNode objectNode) { - super(objectNode); - } - - /** - * Initialize a new instance of the Error object from a JSON string. - * - * @param jsonString the jsonString that represents the error. - */ - public Error(String jsonString) { - super(jsonString); - } - - /** - * Initialize a new instance of the Error object. - * - * @param errorCode the error code. - * @param message the error message. - */ - public Error(String errorCode, String message) { - this(errorCode, message, null); - } - - /** - * Initialize a new instance of the Error object. - * - * @param errorCode - * the error code. - * @param message - * the error message. - * @param additionalErrorInfo - * additional error info. - */ - public Error(String errorCode, String message, String additionalErrorInfo) { - super(); - this.setCode(errorCode); - this.setMessage(message); - this.setAdditionalErrorInfo(additionalErrorInfo); - } - - /** - * Gets the error code. - * - * @return the error code. - */ - public String getCode() { - return super.getString(Constants.Properties.CODE); - } - - /** - * Sets the error code. - * - * @param code the error code. - */ - private void setCode(String code) { - super.set(Constants.Properties.CODE, code); - } - - /** - * Gets the error message. - * - * @return the error message. - */ - public String getMessage() { - return super.getString(Constants.Properties.MESSAGE); - } - - /** - * Sets the error message. - * - * @param message the error message. - */ - private void setMessage(String message) { - super.set(Constants.Properties.MESSAGE, message); - } - - /** - * Gets the error details. - * - * @return the error details. - */ - public String getErrorDetails() { - return super.getString(Constants.Properties.ERROR_DETAILS); - } - - /** - * Sets the partitioned query execution info. - * - * @param additionalErrorInfo - * the partitioned query execution info. - */ - private void setAdditionalErrorInfo(String additionalErrorInfo) { - super.set(Constants.Properties.ADDITIONAL_ERROR_INFO, additionalErrorInfo); - } - - /** - * Gets the partitioned query execution info. - * - * @return the partitioned query execution info. - */ - public String getPartitionedQueryExecutionInfo() { - return super.getString(Constants.Properties.ADDITIONAL_ERROR_INFO); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ExcludedPath.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ExcludedPath.java deleted file mode 100644 index 58cb1835d70d..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ExcludedPath.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents an excluded path of the IndexingPolicy in the Azure Cosmos DB database service. - */ -public class ExcludedPath extends JsonSerializable { - - /** - * Constructor. - */ - public ExcludedPath() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the excluded path. - */ - public ExcludedPath(String jsonString) { - super(jsonString); - } - - /** - * Gets path. - * - * @return the path. - */ - public String getPath() { - return super.getString(Constants.Properties.PATH); - } - - /** - * Sets path. - * - * @param path the path. - */ - public void setPath(String path) { - super.set(Constants.Properties.PATH, path); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedOptions.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedOptions.java deleted file mode 100644 index d0fd538ade3b..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedOptions.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Specifies the options associated with feed methods (enumeration operations) in the Azure Cosmos DB database service. - */ -public final class FeedOptions extends FeedOptionsBase { - private String sessionToken; - private String partitionKeyRangeId; - private Boolean enableScanInQuery; - private Boolean emitVerboseTracesInQuery; - private Boolean enableCrossPartitionQuery; - private int maxDegreeOfParallelism; - private int maxBufferedItemCount; - private int responseContinuationTokenLimitInKb; - - public FeedOptions() {} - - public FeedOptions(FeedOptions options) { - super(options); - this.sessionToken = options.sessionToken; - this.partitionKeyRangeId = options.partitionKeyRangeId; - this.enableScanInQuery = options.enableScanInQuery; - this.emitVerboseTracesInQuery = options.emitVerboseTracesInQuery; - this.enableCrossPartitionQuery = options.enableCrossPartitionQuery; - this.maxDegreeOfParallelism = options.maxDegreeOfParallelism; - this.maxBufferedItemCount = options.maxBufferedItemCount; - this.responseContinuationTokenLimitInKb = options.responseContinuationTokenLimitInKb; - } - - /** - * Gets the partitionKeyRangeId. - * - * @return the partitionKeyRangeId. - */ - public String getPartitionKeyRangeIdInternal() { - return this.partitionKeyRangeId; - } - - /** - * Sets the partitionKeyRangeId. - * - * @param partitionKeyRangeId - * the partitionKeyRangeId. - */ - public void setPartitionKeyRangeIdInternal(String partitionKeyRangeId) { - this.partitionKeyRangeId = partitionKeyRangeId; - } - - /** - * Gets the session token for use with session consistency. - * - * @return the session token. - */ - public String getSessionToken() { - return this.sessionToken; - } - - /** - * Sets the session token for use with session consistency. - * - * @param sessionToken - * the session token. - */ - public void setSessionToken(String sessionToken) { - this.sessionToken = sessionToken; - } - - /** - * Gets the option to allow scan on the queries which couldn't be served as - * indexing was opted out on the requested paths. - * - * @return the option of enable scan in query. - */ - public Boolean getEnableScanInQuery() { - return this.enableScanInQuery; - } - - /** - * Sets the option to allow scan on the queries which couldn't be served as - * indexing was opted out on the requested paths. - * - * @param enableScanInQuery - * the option of enable scan in query. - */ - public void setEnableScanInQuery(Boolean enableScanInQuery) { - this.enableScanInQuery = enableScanInQuery; - } - - /** - * Gets the option to allow queries to emit out verbose traces for - * investigation. - * - * @return the emit verbose traces in query. - */ - public Boolean getEmitVerboseTracesInQuery() { - return this.emitVerboseTracesInQuery; - } - - /** - * Sets the option to allow queries to emit out verbose traces for - * investigation. - * - * @param emitVerboseTracesInQuery - * the emit verbose traces in query. - */ - public void setEmitVerboseTracesInQuery(Boolean emitVerboseTracesInQuery) { - this.emitVerboseTracesInQuery = emitVerboseTracesInQuery; - } - - /** - * Gets the option to allow queries to run across all partitions of the - * collection. - * - * @return whether to allow queries to run across all partitions of the - * collection. - */ - public Boolean getEnableCrossPartitionQuery() { - return this.enableCrossPartitionQuery; - } - - /** - * Sets the option to allow queries to run across all partitions of the - * collection. - * - * @param enableCrossPartitionQuery - * whether to allow queries to run across all partitions of the - * collection. - */ - public void setEnableCrossPartitionQuery(Boolean enableCrossPartitionQuery) { - this.enableCrossPartitionQuery = enableCrossPartitionQuery; - } - - /** - * Gets the number of concurrent operations run client side during parallel - * query execution. - * - * @return number of concurrent operations run client side during parallel - * query execution. - */ - public int getMaxDegreeOfParallelism() { - return maxDegreeOfParallelism; - } - - /** - * Sets the number of concurrent operations run client side during parallel - * query execution. - * - * @param maxDegreeOfParallelism - * number of concurrent operations. - */ - public void setMaxDegreeOfParallelism(int maxDegreeOfParallelism) { - this.maxDegreeOfParallelism = maxDegreeOfParallelism; - } - - /** - * Gets the maximum number of items that can be buffered client side during - * parallel query execution. - * - * @return maximum number of items that can be buffered client side during - * parallel query execution. - */ - public int getMaxBufferedItemCount() { - return maxBufferedItemCount; - } - - /** - * Sets the maximum number of items that can be buffered client side during - * parallel query execution. - * - * @param maxBufferedItemCount - * maximum number of items. - */ - public void setMaxBufferedItemCount(int maxBufferedItemCount) { - this.maxBufferedItemCount = maxBufferedItemCount; - } - - /** - * Sets the ResponseContinuationTokenLimitInKb request option for document query requests - * in the Azure Cosmos DB service. - * - * ResponseContinuationTokenLimitInKb is used to limit the length of continuation token in the query response. - * Valid values are >= 1. - * - * The continuation token contains both required and optional fields. - * The required fields are necessary for resuming the execution from where it was stooped. - * The optional fields may contain serialized index lookup work that was done but not yet utilized. - * This avoids redoing the work again in subsequent continuations and hence improve the query performance. - * Setting the maximum continuation size to 1KB, the Azure Cosmos DB service will only serialize required fields. - * Starting from 2KB, the Azure Cosmos DB service would serialize as much as it could fit till it reaches the maximum specified size. - * - * @param limitInKb continuation token size limit. - */ - public void setResponseContinuationTokenLimitInKb(int limitInKb) { - this.responseContinuationTokenLimitInKb = limitInKb; - } - - /** - * Gets the ResponseContinuationTokenLimitInKb request option for document query requests - * in the Azure Cosmos DB service. If not already set returns 0. - * - * ResponseContinuationTokenLimitInKb is used to limit the length of continuation token in the query response. - * Valid values are >= 1. - * - * @return return set ResponseContinuationTokenLimitInKb, or 0 if not set - */ - public int getResponseContinuationTokenLimitInKb() { - return responseContinuationTokenLimitInKb; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedOptionsBase.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedOptionsBase.java deleted file mode 100644 index d2edb4cf433f..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedOptionsBase.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.Map; - -/** - * Specifies the common options associated with feed methods (enumeration operations) in the Azure Cosmos DB database service. - */ -public abstract class FeedOptionsBase { - private Integer maxItemCount; - private String requestContinuation; - private PartitionKey partitionkey; - private boolean populateQueryMetrics; - private Map properties; - - protected FeedOptionsBase() {} - - FeedOptionsBase(FeedOptionsBase options) { - this.maxItemCount = options.maxItemCount; - this.requestContinuation = options.requestContinuation; - this.partitionkey = options.partitionkey; - this.populateQueryMetrics = options.populateQueryMetrics; - } - - /** - * Gets the maximum number of items to be returned in the enumeration - * operation. - * - * @return the max number of items. - */ - public Integer getMaxItemCount() { - return this.maxItemCount; - } - - /** - * Sets the maximum number of items to be returned in the enumeration - * operation. - * - * @param maxItemCount the max number of items. - */ - public void setMaxItemCount(Integer maxItemCount) { - this.maxItemCount = maxItemCount; - } - - /** - * Gets the request continuation token. - * - * @return the request continuation. - */ - public String getRequestContinuation() { - return this.requestContinuation; - } - - /** - * Sets the request continuation token. - * - * @param requestContinuation - * the request continuation. - */ - public void setRequestContinuation(String requestContinuation) { - this.requestContinuation = requestContinuation; - } - - /** - * Gets the partition key used to identify the current request's target - * partition. - * - * @return the partition key. - */ - public PartitionKey getPartitionKey() { - return this.partitionkey; - } - - /** - * Sets the partition key used to identify the current request's target - * partition. - * - * @param partitionkey - * the partition key value. - */ - public void setPartitionKey(PartitionKey partitionkey) { - this.partitionkey = partitionkey; - } - - /** - * Gets the option to enable populate query metrics - * @return whether to enable populate query metrics - */ - public boolean getPopulateQueryMetrics() { - return populateQueryMetrics; - } - - /** - * Sets the option to enable/disable getting metrics relating to query execution on document query requests - * @param populateQueryMetrics whether to enable or disable query metrics - */ - public void setPopulateQueryMetrics(boolean populateQueryMetrics) { - this.populateQueryMetrics = populateQueryMetrics; - } - - /** - * Gets the properties - * - * @return Map of request options properties - */ - public Map getProperties() { - return properties; - } - - /** - * Sets the properties used to identify the request token. - * - * @param properties the properties. - */ - public void setProperties(Map properties) { - this.properties = properties; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedResponse.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedResponse.java deleted file mode 100644 index 3ce9c19ed4ec..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/FeedResponse.java +++ /dev/null @@ -1,401 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -public class FeedResponse { - - private final List results; - private final Map header; - private final HashMap usageHeaders; - private final HashMap quotaHeaders; - private final boolean useEtagAsContinuation; - boolean nochanges; - private final ConcurrentMap queryMetricsMap; - private final String DefaultPartition = "0"; - - FeedResponse(List results, Map headers) { - this(results, headers, false, false, new ConcurrentHashMap<>()); - } - - FeedResponse(List results, Map headers, ConcurrentMap queryMetricsMap) { - this(results, headers, false, false, queryMetricsMap); - } - - FeedResponse(List results, Map header, boolean nochanges) { - this(results, header, true, nochanges, new ConcurrentHashMap<>()); - } - - // TODO: need to more sure the query metrics can round trip just from the headers. - // We can then remove it as a parameter. - private FeedResponse( - List results, - Map header, - boolean useEtagAsContinuation, - boolean nochanges, - ConcurrentMap queryMetricsMap) { - this.results = results; - this.header = header; - this.usageHeaders = new HashMap<>(); - this.quotaHeaders = new HashMap<>(); - this.useEtagAsContinuation = useEtagAsContinuation; - this.nochanges = nochanges; - this.queryMetricsMap = new ConcurrentHashMap<>(queryMetricsMap); - } - - /** - * Results. - * - * @return the list of results. - */ - public List getResults() { - return results; - } - - /** - * Gets the maximum quota for database resources within the account from the Azure Cosmos DB service. - * - * @return The maximum quota for the account. - */ - public long getDatabaseQuota() { - return this.getMaxQuotaHeader(Constants.Quota.DATABASE); - } - - /** - * Gets the current number of database resources within the account from the Azure Cosmos DB service. - * - * @return The current number of databases. - */ - public long getDatabaseUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.DATABASE); - } - - /** - * Gets the maximum quota for collection resources within an account from the Azure Cosmos DB service. - * - * @return The maximum quota for the account. - */ - public long getCollectionQuota() { - return this.getMaxQuotaHeader(Constants.Quota.COLLECTION); - } - - /** - * Gets the current number of collection resources within the account from the Azure Cosmos DB service. - * - * @return The current number of collections. - */ - public long getCollectionUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.COLLECTION); - } - - /** - * Gets the maximum quota for user resources within an account from the Azure Cosmos DB service. - * - * @return The maximum quota for the account. - */ - public long getUserQuota() { - return this.getMaxQuotaHeader(Constants.Quota.USER); - } - - /** - * Gets the current number of user resources within the account from the Azure Cosmos DB service. - * - * @return The current number of users. - */ - public long getUserUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.USER); - } - - /** - * Gets the maximum quota for permission resources within an account from the Azure Cosmos DB service. - * - * @return The maximum quota for the account. - */ - public long getPermissionQuota() { - return this.getMaxQuotaHeader(Constants.Quota.PERMISSION); - } - - /** - * Gets the current number of permission resources within the account from the Azure Cosmos DB service. - * - * @return The current number of permissions. - */ - public long getPermissionUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.PERMISSION); - } - - /** - * Gets the maximum size of a collection in kilobytes from the Azure Cosmos DB service. - * - * @return The maximum quota in kilobytes. - */ - public long getCollectionSizeQuota() { - return this.getMaxQuotaHeader(Constants.Quota.COLLECTION_SIZE); - } - - /** - * Gets the current size of a collection in kilobytes from the Azure Cosmos DB service. - * - * @return The current size of a collection in kilobytes. - */ - public long getCollectionSizeUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.COLLECTION_SIZE); - } - - /** - * Gets the maximum quota of stored procedures for a collection from the Azure Cosmos DB service. - * - * @return The maximum stored procedure quota. - */ - public long getStoredProceduresQuota() { - return this.getMaxQuotaHeader(Constants.Quota.STORED_PROCEDURE); - } - - /** - * Gets the current number of stored procedures for a collection from the Azure Cosmos DB service. - * - * @return The current number of stored procedures. - */ - public long getStoredProceduresUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.STORED_PROCEDURE); - } - - /** - * Gets the maximum quota of triggers for a collection from the Azure Cosmos DB service. - * - * @return The maximum triggers quota. - */ - public long getTriggersQuota() { - return this.getMaxQuotaHeader(Constants.Quota.TRIGGER); - } - - /** - * Get the current number of triggers for a collection from the Azure Cosmos DB service. - * - * @return The current number of triggers. - */ - public long getTriggersUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.TRIGGER); - } - - /** - * Gets the maximum quota of user defined functions for a collection from the Azure Cosmos DB service. - * - * @return The maximum user defined functions quota. - */ - public long getUserDefinedFunctionsQuota() { - return this.getMaxQuotaHeader(Constants.Quota.USER_DEFINED_FUNCTION); - } - - /** - * Gets the current number of user defined functions for a collection from the Azure Cosmos DB service. - * - * @return the current number of user defined functions. - */ - public long getUserDefinedFunctionsUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.USER_DEFINED_FUNCTION); - } - - /** - * Gets the maximum size limit for this entity from the Azure Cosmos DB service. - * - * @return the maximum size limit for this entity. - * Measured in kilobytes for document resources and in counts for other resources. - */ - public String getMaxResourceQuota() { - return getValueOrNull(header, - HttpConstants.HttpHeaders.MAX_RESOURCE_QUOTA); - } - - /** - * Gets the current size of this entity from the Azure Cosmos DB service. - * - * @return the current size for this entity. Measured in kilobytes for document resources - * and in counts for other resources. - */ - public String getCurrentResourceQuotaUsage() { - return getValueOrNull(header, - HttpConstants.HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE); - } - - /** - * Gets the number of index paths (terms) generated by the operation. - * - * @return the request charge. - */ - public double getRequestCharge() { - String value = getValueOrNull(header, - HttpConstants.HttpHeaders.REQUEST_CHARGE); - if (StringUtils.isEmpty(value)) { - return 0; - } - return Double.valueOf(value); - } - - /** - * Gets the activity ID for the request. - * - * @return the activity id. - */ - public String getActivityId() { - return getValueOrNull(header, HttpConstants.HttpHeaders.ACTIVITY_ID); - } - - /** - * Gets the continuation token to be used for continuing the enumeration. - * - * @return the response continuation. - */ - public String getResponseContinuation() { - String headerName = useEtagAsContinuation - ? HttpConstants.HttpHeaders.E_TAG - : HttpConstants.HttpHeaders.CONTINUATION; - return getValueOrNull(header, headerName); - } - - /** - * Gets the session token for use in session consistency. - * - * @return the session token. - */ - public String getSessionToken() { - return getValueOrNull(header, HttpConstants.HttpHeaders.SESSION_TOKEN); - } - - /** - * Gets the response headers. - * - * @return the response headers. - */ - public Map getResponseHeaders() { - return header; - } - - private String getQueryMetricsString(){ - return getValueOrNull(getResponseHeaders(), - HttpConstants.HttpHeaders.QUERY_METRICS); - } - - /** - * Gets the QueryMetrics for each partition. - * - * @return the QueryMetrics for each partition. - */ - public ConcurrentMap getQueryMetrics() { - if (queryMetricsMap != null && !queryMetricsMap.isEmpty()) { - return queryMetricsMap; - } - - //We parse query metrics for un-partitioned collection here - if (!StringUtils.isEmpty(getQueryMetricsString())) { - String qm = getQueryMetricsString(); - qm += String.format(";%s=%.2f", QueryMetricsConstants.RequestCharge, getRequestCharge()); - queryMetricsMap.put(DefaultPartition, QueryMetrics.createFromDelimitedString(qm)); - } - return queryMetricsMap; - } - - ConcurrentMap getQueryMetricsMap(){ - return queryMetricsMap; - } - - private long getCurrentQuotaHeader(String headerName) { - if (this.usageHeaders.size() == 0 && !StringUtils.isEmpty(this.getMaxResourceQuota()) && - !StringUtils.isEmpty(this.getCurrentResourceQuotaUsage())) { - this.populateQuotaHeader(this.getMaxResourceQuota(), this.getCurrentResourceQuotaUsage()); - } - - if (this.usageHeaders.containsKey(headerName)) { - return this.usageHeaders.get(headerName); - } - - return 0; - } - - private long getMaxQuotaHeader(String headerName) { - if (this.quotaHeaders.size() == 0 && - !StringUtils.isEmpty(this.getMaxResourceQuota()) && - !StringUtils.isEmpty(this.getCurrentResourceQuotaUsage())) { - this.populateQuotaHeader(this.getMaxResourceQuota(), this.getCurrentResourceQuotaUsage()); - } - - if (this.quotaHeaders.containsKey(headerName)) { - return this.quotaHeaders.get(headerName); - } - - return 0; - } - - private void populateQuotaHeader(String headerMaxQuota, - String headerCurrentUsage) { - String[] headerMaxQuotaWords = headerMaxQuota.split(Constants.Quota.DELIMITER_CHARS, -1); - String[] headerCurrentUsageWords = headerCurrentUsage.split(Constants.Quota.DELIMITER_CHARS, -1); - - for (int i = 0; i < headerMaxQuotaWords.length; ++i) { - if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.DATABASE)) { - this.quotaHeaders.put(Constants.Quota.DATABASE, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.DATABASE, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.COLLECTION)) { - this.quotaHeaders.put(Constants.Quota.COLLECTION, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.COLLECTION, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.USER)) { - this.quotaHeaders.put(Constants.Quota.USER, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.USER, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.PERMISSION)) { - this.quotaHeaders.put(Constants.Quota.PERMISSION, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.PERMISSION, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.COLLECTION_SIZE)) { - this.quotaHeaders.put(Constants.Quota.COLLECTION_SIZE, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.COLLECTION_SIZE, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.STORED_PROCEDURE)) { - this.quotaHeaders.put(Constants.Quota.STORED_PROCEDURE, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.STORED_PROCEDURE, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.TRIGGER)) { - this.quotaHeaders.put(Constants.Quota.TRIGGER, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.TRIGGER, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.USER_DEFINED_FUNCTION)) { - this.quotaHeaders.put(Constants.Quota.USER_DEFINED_FUNCTION, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.USER_DEFINED_FUNCTION, - Long.valueOf(headerCurrentUsageWords[i + 1])); - } - } - } - - private static String getValueOrNull(Map map, String key) { - if (map != null) { - return map.get(key); - } - return null; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/HashIndex.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/HashIndex.java deleted file mode 100644 index 2c351733dec8..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/HashIndex.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.text.WordUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a hash index in the Azure Cosmos DB database service. - */ -public final class HashIndex extends Index { - - /** - * Specifies an instance of HashIndex class with specified DataType. - *

- * Here is an example to instantiate HashIndex class passing in the DataType: - *

-     * {@code
-     *
-     * HashIndex hashIndex = new HashIndex(DataType.String);
-     *
-     * }
-     * 
- * - * @param dataType the data type. - */ - public HashIndex(DataType dataType) { - super(IndexKind.Hash); - this.setDataType(dataType); - } - - /** - * Initializes a new instance of the HashIndex class with specified DataType and precision. - *

- * Here is an example to instantiate HashIndex class passing in the DataType: - *

-     * {@code
-     *
-     * HashIndex hashIndex = new HashIndex(DataType.String, 3);
-     *
-     * }
-     * 
- * - * @param dataType the data type. - * @param precision the precision. - */ - public HashIndex(DataType dataType, int precision) { - super(IndexKind.Hash); - this.setDataType(dataType); - this.setPrecision(precision); - } - - /** - * Initializes a new instance of the HashIndex class with json string. - * - * @param jsonString the json string that represents the index. - */ - public HashIndex(String jsonString) { - super(jsonString, IndexKind.Hash); - if (this.getDataType() == null) { - throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'."); - } - } - - /** - * Gets data type. - * - * @return the data type. - */ - public DataType getDataType() { - DataType result = null; - try { - result = DataType.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.DATA_TYPE))); - } catch (IllegalArgumentException e) { - // Ignore exception and let the caller handle null value. - this.getLogger().warn("Invalid index dataType value {}.", super.getString(Constants.Properties.DATA_TYPE)); - } - return result; - } - - /** - * Sets data type. - * - * @param dataType the data type. - */ - public void setDataType(DataType dataType) { - super.set(Constants.Properties.DATA_TYPE, dataType.name()); - } - - /** - * Gets precision. - * - * @return the precision. - */ - public int getPrecision() { - return super.getInt(Constants.Properties.PRECISION); - } - - /** - * Sets precision. - * - * @param precision the precision. - */ - public void setPrecision(int precision) { - super.set(Constants.Properties.PRECISION, precision); - } - - boolean hasPrecision() { - return super.has(Constants.Properties.PRECISION); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IncludedPath.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IncludedPath.java deleted file mode 100644 index 3a630102fde8..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IncludedPath.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.ArrayList; -import java.util.Collection; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import org.apache.commons.text.WordUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents an included path of the IndexingPolicy in the Azure Cosmos DB database service. - */ -public class IncludedPath extends JsonSerializable { - - private Collection indexes; - - /** - * Constructor. - */ - public IncludedPath() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the included path. - */ - public IncludedPath(String jsonString) { - super(jsonString); - } - - /** - * Gets path. - * - * @return the path. - */ - public String getPath() { - return super.getString(Constants.Properties.PATH); - } - - /** - * Sets path. - * - * @param path the path. - */ - public void setPath(String path) { - super.set(Constants.Properties.PATH, path); - } - - /** - * Gets the paths that are chosen to be indexed by the user. - * - * @return the included paths. - */ - public Collection getIndexes() { - if (this.indexes == null) { - this.indexes = this.getIndexCollection(); - - if (this.indexes == null) { - this.indexes = new ArrayList(); - } - } - - return this.indexes; - } - - public void setIndexes(Collection indexes) { - this.indexes = indexes; - } - - private Collection getIndexCollection() { - if (this.propertyBag != null && this.propertyBag.has(Constants.Properties.INDEXES)) { - ArrayNode jsonArray = (ArrayNode) this.propertyBag.get(Constants.Properties.INDEXES); - Collection result = new ArrayList(); - - for (int i = 0; i < jsonArray.size(); i++) { - JsonNode jsonObject = jsonArray.get(i); - - IndexKind indexKind = IndexKind.valueOf(WordUtils.capitalize( - jsonObject.get(Constants.Properties.INDEX_KIND).asText())); - switch (indexKind) { - case Hash: - result.add(new HashIndex(jsonObject.toString())); - break; - case Range: - result.add(new RangeIndex(jsonObject.toString())); - break; - case Spatial: - result.add(new SpatialIndex(jsonObject.toString())); - break; - } - } - - return result; - } - - return null; - } - - @Override - void populatePropertyBag() { - if (this.indexes != null) { - for (Index index : this.indexes) { - index.populatePropertyBag(); - } - - super.set(Constants.Properties.INDEXES, this.indexes); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Index.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Index.java deleted file mode 100644 index 7a3b00a6dc97..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Index.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.text.WordUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents the index of a collection in the Azure Cosmos DB database service. - */ -public abstract class Index extends JsonSerializable { - - /** - * Constructor. - * - * @param indexKind the kind of the index - */ - protected Index(IndexKind indexKind) { - super(); - this.setKind(indexKind); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the index. - * @param indexKind the kind of the index - */ - protected Index(String jsonString, IndexKind indexKind) { - super(jsonString); - this.setKind(indexKind); - } - - /** - * Returns an instance of RangeIndex class with specified DataType. - *

- * Here is an example to create RangeIndex instance passing in the DataType: - *

-     * {@code
-     *
-     * RangeIndex rangeIndex = Index.Range(DataType.Number);
-     *
-     * }
-     * 
- * - * @param dataType the data type. - * @return an instance of RangeIndex type. - */ - public static RangeIndex Range(DataType dataType) { - return new RangeIndex(dataType); - } - - /** - * Returns an instance of RangeIndex class with specified DataType and precision. - *

- * Here is an example to create RangeIndex instance passing in the DataType and precision: - *

-     * {@code
-     *
-     * RangeIndex rangeIndex = Index.Range(DataType.Number, -1);
-     *
-     * }
-     * 
- * - * @param dataType specifies the target data type for the index path specification. - * @param precision specifies the precision to be used for the data type associated with this index. - * @return an instance of RangeIndex type. - */ - public static RangeIndex Range(DataType dataType, int precision) { - return new RangeIndex(dataType, precision); - } - - /** - * Returns an instance of HashIndex class with specified DataType. - *

- * Here is an example to create HashIndex instance passing in the DataType: - *

-     * {@code
-     *
-     * HashIndex hashIndex = Index.Hash(DataType.String);
-     * }
-     * 
- * - * @param dataType specifies the target data type for the index path specification. - * @return an instance of HashIndex type. - */ - public static HashIndex Hash(DataType dataType) { - return new HashIndex(dataType); - } - - /** - * Returns an instance of HashIndex class with specified DataType and precision. - *

- * Here is an example to create HashIndex instance passing in the DataType and precision: - *

- * HashIndex hashIndex = Index.Hash(DataType.String, 3); - * - * @param dataType specifies the target data type for the index path specification. - * @param precision specifies the precision to be used for the data type associated with this index. - * @return an instance of HashIndex type. - */ - public static HashIndex Hash(DataType dataType, int precision) { - return new HashIndex(dataType, precision); - } - - /** - * Returns an instance of SpatialIndex class with specified DataType. - *

- * Here is an example to create SpatialIndex instance passing in the DataType: - *

- * SpatialIndex spatialIndex = Index.Spatial(DataType.Point); - * - * @param dataType specifies the target data type for the index path specification. - * @return an instance of SpatialIndex type. - */ - public static SpatialIndex Spatial(DataType dataType) { - return new SpatialIndex(dataType); - } - - /** - * Gets index kind. - * - * @return the index kind. - */ - public IndexKind getKind() { - IndexKind result = null; - try { - result = IndexKind.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.INDEX_KIND))); - } catch (IllegalArgumentException e) { - this.getLogger().warn("Invalid index kind value %s.", super.getString(Constants.Properties.INDEX_KIND)); - } - - return result; - } - - /** - * Sets index kind. - * - * @param indexKind the index kind. - */ - private void setKind(IndexKind indexKind) { - super.set(Constants.Properties.INDEX_KIND, indexKind.name()); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexKind.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexKind.java deleted file mode 100644 index 4e63ba467972..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexKind.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * These are the indexing types available for indexing a path in the Azure Cosmos DB database service. - * For additional details, refer to - * http://azure.microsoft.com/documentation/articles/documentdb-indexing-policies/#ConfigPolicy. - */ -public enum IndexKind { - // The index entries are hashed to serve point look up queries. - // Can be used to serve queries like: SELECT * FROM docs d WHERE d.prop = 5 - Hash, - - // The index entries are ordered. Range indexes are optimized for inequality predicate queries with efficient range - // scans. - // Can be used to serve queries like: SELECT * FROM docs d WHERE d.prop > 5 - Range, - - // The index entries are indexed to serve spatial queries like below: - // SELECT * FROM Root r WHERE ST_DISTANCE({"type":"Point","coordinates":[71.0589,42.3601]}, r.location) $LE 10000 - Spatial -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingDirective.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingDirective.java deleted file mode 100644 index 603191cc05c8..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingDirective.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Specifies whether or not the resource is to be indexed in the Azure Cosmos DB database service. - */ -public enum IndexingDirective { - - /** - * Use any pre-defined/pre-configured defaults. - */ - Default, - - /** - * Index the resource. - */ - Include, - - /** - * Do not index the resource. - */ - Exclude -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingMode.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingMode.java deleted file mode 100644 index 54bd9b96a99e..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingMode.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Specifies the supported indexing modes in the Azure Cosmos DB database service. - */ -public enum IndexingMode { - /** - * Index is updated synchronously with a create or update operation. - *

- * With consistent indexing, query behavior is the same as the default consistency level for the collection. The - * index is always kept up to date with the data. - */ - Consistent, - - /** - * Index is updated asynchronously with respect to a create or update operation. - *

- * With lazy indexing, queries are eventually consistent. The index is updated when the collection is idle. - */ - Lazy, - - /** - * No index is provided. - *

- * Setting IndexingMode to "None" drops the index. Use this if you don't want to maintain the index for a document - * collection, to save the storage cost or improve the write throughput. Your queries will degenerate to scans of - * the entire collection. - */ - None -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingPolicy.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingPolicy.java deleted file mode 100644 index 41650c03a562..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/IndexingPolicy.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.microsoft.azure.cosmosdb.internal.Constants; -import org.apache.commons.text.WordUtils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; - -/** - * Represents the indexing policy configuration for a collection in the Azure Cosmos DB database service. - */ -public final class IndexingPolicy extends JsonSerializable { - - private static final String DEFAULT_PATH = "/*"; - - private Collection includedPaths; - private Collection excludedPaths; - private Collection> compositeIndexes; - private Collection spatialIndexes; - - /** - * Constructor. - */ - public IndexingPolicy() { - this.setAutomatic(true); - this.setIndexingMode(IndexingMode.Consistent); - } - - /** - * Initializes a new instance of the IndexingPolicy class with the specified set of indexes as - * default index specifications for the root path. - *

- * The following example shows how to override the default indexingPolicy for root path: - *

-     * {@code
-     * HashIndex hashIndexOverride = Index.Hash(DataType.String, 5);
-     * RangeIndex rangeIndexOverride = Index.Range(DataType.Number, 2);
-     * SpatialIndex spatialIndexOverride = Index.Spatial(DataType.Point);
-     *
-     * IndexingPolicy indexingPolicy = new IndexingPolicy(hashIndexOverride, rangeIndexOverride, spatialIndexOverride);
-     * }
-     * 
- *

- * If you would like to just override the indexingPolicy for Numbers you can specify just that: - *

-     * {@code
-     * RangeIndex rangeIndexOverride = Index.Range(DataType.Number, 2);
-     *
-     * IndexingPolicy indexingPolicy = new IndexingPolicy(rangeIndexOverride);
-     * }
-     * 
- * - * @param defaultIndexOverrides comma separated set of indexes that serve as default index specifications for the root path. - */ - public IndexingPolicy(Index[] defaultIndexOverrides) { - this(); - - if (defaultIndexOverrides == null) { - throw new IllegalArgumentException("defaultIndexOverrides is null."); - } - - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath(IndexingPolicy.DEFAULT_PATH); - includedPath.setIndexes(new ArrayList(Arrays.asList(defaultIndexOverrides))); - this.getIncludedPaths().add(includedPath); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the indexing policy. - */ - public IndexingPolicy(String jsonString) { - super(jsonString); - } - - /** - * Gets whether automatic indexing is enabled for a collection. - *

- * In automatic indexing, documents can be explicitly excluded from indexing using RequestOptions. In manual - * indexing, documents can be explicitly included. - * - * @return the automatic - */ - public Boolean getAutomatic() { - return super.getBoolean(Constants.Properties.AUTOMATIC); - } - - /** - * Sets whether automatic indexing is enabled for a collection. - *

- * In automatic indexing, documents can be explicitly excluded from indexing using RequestOptions. In manual - * indexing, documents can be explicitly included. - * - * @param automatic the automatic - */ - public void setAutomatic(boolean automatic) { - super.set(Constants.Properties.AUTOMATIC, automatic); - } - - /** - * Gets the indexing mode (consistent or lazy). - * - * @return the indexing mode. - */ - public IndexingMode getIndexingMode() { - IndexingMode result = IndexingMode.Lazy; - try { - result = IndexingMode.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.INDEXING_MODE))); - } catch (IllegalArgumentException e) { - this.getLogger().warn("Invalid indexingMode value {}.", super.getString(Constants.Properties.INDEXING_MODE)); - } - return result; - } - - /** - * Sets the indexing mode (consistent or lazy). - * - * @param indexingMode the indexing mode. - */ - public void setIndexingMode(IndexingMode indexingMode) { - super.set(Constants.Properties.INDEXING_MODE, indexingMode.name()); - } - - /** - * Gets the paths that are chosen to be indexed by the user. - * - * @return the included paths. - */ - public Collection getIncludedPaths() { - if (this.includedPaths == null) { - this.includedPaths = super.getCollection(Constants.Properties.INCLUDED_PATHS, IncludedPath.class); - - if (this.includedPaths == null) { - this.includedPaths = new ArrayList(); - } - } - - return this.includedPaths; - } - - public void setIncludedPaths(Collection includedPaths) { - this.includedPaths = includedPaths; - } - - /** - * Gets the paths that are not indexed. - * - * @return the excluded paths. - */ - public Collection getExcludedPaths() { - if (this.excludedPaths == null) { - this.excludedPaths = super.getCollection(Constants.Properties.EXCLUDED_PATHS, ExcludedPath.class); - - if (this.excludedPaths == null) { - this.excludedPaths = new ArrayList(); - } - } - - return this.excludedPaths; - } - - public void setExcludedPaths(Collection excludedPaths) { - this.excludedPaths = excludedPaths; - } - - /** - * Gets the composite indexes for additional indexes. - * - * @return the composite indexes. - */ - public Collection> getCompositeIndexes() { - if (this.compositeIndexes == null) { - this.compositeIndexes = new ArrayList>(); - ArrayNode compositeIndexes = (ArrayNode) super.get(Constants.Properties.COMPOSITE_INDEXES); - for (int i = 0; i < compositeIndexes.size(); i ++) { - ArrayNode compositeIndex = (ArrayNode) compositeIndexes.get(i); - ArrayList compositePaths = new ArrayList(); - for (int j = 0; j < compositeIndex.size(); j ++) { - CompositePath candidateCompositePath = new CompositePath(compositeIndex.get(j).toString()); - compositePaths.add(candidateCompositePath); - } - this.compositeIndexes.add(compositePaths); - } - } - - return this.compositeIndexes; - } - - /** - * Sets the composite indexes for additional indexes. - * - * @param compositeIndexes the composite indexes. - */ - public void setCompositeIndexes(Collection> compositeIndexes) { - this.compositeIndexes = compositeIndexes; - super.set(Constants.Properties.COMPOSITE_INDEXES, this.compositeIndexes); - } - - /** - * Sets the spatial indexes for additional indexes. - * - * @return the spatial indexes. - */ - public Collection getSpatialIndexes() { - if (this.spatialIndexes == null) { - this.spatialIndexes = super.getCollection(Constants.Properties.SPATIAL_INDEXES, SpatialSpec.class); - - if (this.spatialIndexes == null) { - this.spatialIndexes = new ArrayList(); - } - } - - return this.spatialIndexes; - } - - /** - * Sets the spatial indexes for additional indexes. - * - * @param spatialIndexes the spatial indexes. - */ - public void setSpatialIndexes(Collection spatialIndexes) { - this.spatialIndexes = spatialIndexes; - super.set(Constants.Properties.SPATIAL_INDEXES, this.spatialIndexes); - } - - @Override - void populatePropertyBag() { - // If indexing mode is not 'none' and not paths are set, set them to the defaults - if (this.getIndexingMode() != IndexingMode.None && this.getIncludedPaths().size() == 0 && - this.getExcludedPaths().size() == 0) { - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath(IndexingPolicy.DEFAULT_PATH); - this.getIncludedPaths().add(includedPath); - } - - if (this.includedPaths != null) { - for (IncludedPath includedPath : this.includedPaths) { - includedPath.populatePropertyBag(); - } - super.set(Constants.Properties.INCLUDED_PATHS, this.includedPaths); - } - - if (this.excludedPaths != null) { - for (ExcludedPath excludedPath : this.excludedPaths) { - excludedPath.populatePropertyBag(); - } - super.set(Constants.Properties.EXCLUDED_PATHS, this.excludedPaths); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/JsonSerializable.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/JsonSerializable.java deleted file mode 100644 index 27b52d80d51b..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/JsonSerializable.java +++ /dev/null @@ -1,581 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.internal.Utils; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.ObjectMapper; - -/** - * Represents a base resource that can be serialized to JSON in the Azure Cosmos DB database service. - */ -public class JsonSerializable { - private final static Logger logger = LoggerFactory.getLogger(JsonSerializable.class); - private final static ObjectMapper OBJECT_MAPPER = Utils.getSimpleObjectMapper(); - private ObjectMapper om; - transient ObjectNode propertyBag = null; - - protected JsonSerializable() { - this.propertyBag = OBJECT_MAPPER.createObjectNode(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the JsonSerializable. - * @param objectMapper the custom object mapper - */ - protected JsonSerializable(String jsonString, ObjectMapper objectMapper) { - this.propertyBag = fromJson(jsonString); - this.om = objectMapper; - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the JsonSerializable. - */ - protected JsonSerializable(String jsonString) { - this.propertyBag = fromJson(jsonString); - } - - /** - * Constructor. - * - * @param objectNode the {@link ObjectNode} that represent the {@link JsonSerializable} - */ - JsonSerializable(ObjectNode objectNode) { - this.propertyBag = objectNode; - } - - protected ObjectMapper getMapper() { - if (this.om != null) { return this.om; } - return OBJECT_MAPPER; - } - - private static void checkForValidPOJO(Class c) { - if (c.isAnonymousClass() || c.isLocalClass()) { - throw new IllegalArgumentException( - String.format("%s can't be an anonymous or local class.", c.getName())); - } - if (c.isMemberClass() && !Modifier.isStatic(c.getModifiers())) { - throw new IllegalArgumentException( - String.format("%s must be static if it's a member class.", c.getName())); - } - } - - protected Logger getLogger() { - return logger; - } - - void populatePropertyBag() { - } - - /** - * Returns the propertybag(JSONObject) in a hashMap - * - * @return the HashMap. - */ - public HashMap getHashMap() { - return getMapper().convertValue(this.propertyBag, HashMap.class); - } - - /** - * Checks whether a property exists. - * - * @param propertyName the property to look up. - * @return true if the property exists. - */ - public boolean has(String propertyName) { - return this.propertyBag.has(propertyName); - } - - /** - * Removes a value by propertyName. - * - * @param propertyName the property to remove. - */ - public void remove(String propertyName) { - this.propertyBag.remove(propertyName); - } - - /** - * Sets the value of a property. - * - * @param the type of the object. - * @param propertyName the property to set. - * @param value the value of the property. - */ - @SuppressWarnings({"unchecked", "rawtypes"}) - public void set(String propertyName, T value) { - if (value == null) { - // Sets null. - this.propertyBag.putNull(propertyName); - } else if (value instanceof Collection) { - // Collection. - ArrayNode jsonArray = propertyBag.arrayNode(); - this.internalSetCollection(propertyName, (Collection) value, jsonArray); - this.propertyBag.set(propertyName, jsonArray); - } else if (value instanceof JsonNode) { - this.propertyBag.set(propertyName, (JsonNode) value); - } else if (value instanceof JsonSerializable) { - // JsonSerializable - JsonSerializable castedValue = (JsonSerializable) value; - if (castedValue != null) { - castedValue.populatePropertyBag(); - } - this.propertyBag.set(propertyName, castedValue != null ? castedValue.propertyBag : null); - } else { - // POJO, ObjectNode, number (includes int, float, double etc), boolean, - // and string. - this.propertyBag.set(propertyName, getMapper().valueToTree(value)); - } - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private void internalSetCollection(String propertyName, Collection collection, ArrayNode targetArray) { - for (T childValue : collection) { - if (childValue == null) { - // Sets null. - targetArray.addNull(); - } else if (childValue instanceof Collection) { - // When T is also a Collection, use recursion. - ArrayNode childArray = targetArray.addArray(); - this.internalSetCollection(propertyName, (Collection) childValue, childArray); - } else if (childValue instanceof JsonNode) { - targetArray.add((JsonNode) childValue); - } else if (childValue instanceof JsonSerializable) { - // JsonSerializable - JsonSerializable castedValue = (JsonSerializable) childValue; - castedValue.populatePropertyBag(); - targetArray.add(castedValue.propertyBag != null ? castedValue.propertyBag : this.getMapper().createObjectNode()); - } else { - // POJO, JSONObject, Number (includes Int, Float, Double etc), - // Boolean, and String. - targetArray.add(this.getMapper().valueToTree(childValue)); - } - } - } - - /** - * Gets a property value as Object. - * - * @param propertyName the property to get. - * @return the value of the property. - */ - public Object get(String propertyName) { - if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - return getValue(this.propertyBag.get(propertyName)); - } else { - return null; - } - } - - /** - * Gets a string value. - * - * @param propertyName the property to get. - * @return the string value. - */ - public String getString(String propertyName) { - if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - return this.propertyBag.get(propertyName).asText(); - } else { - return null; - } - } - - /** - * Gets a boolean value. - * - * @param propertyName the property to get. - * @return the boolean value. - */ - public Boolean getBoolean(String propertyName) { - if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - return this.propertyBag.get(propertyName).asBoolean(); - } else { - return null; - } - } - - /** - * Gets an integer value. - * - * @param propertyName the property to get. - * @return the boolean value - */ - public Integer getInt(String propertyName) { - if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - return Integer.valueOf(this.propertyBag.get(propertyName).asInt()); - } else { - return null; - } - } - - /** - * Gets a long value. - * - * @param propertyName the property to get. - * @return the long value - */ - public Long getLong(String propertyName) { - if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - return Long.valueOf(this.propertyBag.get(propertyName).asLong()); - } else { - return null; - } - } - - /** - * Gets a double value. - * - * @param propertyName the property to get. - * @return the double value. - */ - public Double getDouble(String propertyName) { - if (this.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - return new Double(this.propertyBag.get(propertyName).asDouble()); - } else { - return null; - } - } - - /** - * Gets an object value. - * - * @param the type of the object. - * @param propertyName the property to get. - * @param c the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) - * and a static one. - * @return the object value. - */ - public T getObject(String propertyName, Class c) { - if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - JsonNode jsonObj = propertyBag.get(propertyName); - if (Number.class.isAssignableFrom(c) || String.class.isAssignableFrom(c) - || Boolean.class.isAssignableFrom(c) || Object.class == c) { - // Number, String, Boolean - return c.cast(getValue(jsonObj)); - } else if (Enum.class.isAssignableFrom(c)) { - try { - return c.cast(c.getMethod("valueOf", String.class).invoke(null, String.class.cast(getValue(jsonObj)))); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to create enum.", e); - } - } else if (JsonSerializable.class.isAssignableFrom(c)) { - try { - return c.getConstructor(String.class).newInstance(toJson(jsonObj)); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to instantiate class object.", e); - } - } else { - // POJO - JsonSerializable.checkForValidPOJO(c); - try { - return this.getMapper().treeToValue(jsonObj, c); - } catch (IOException e) { - throw new IllegalStateException("Failed to get POJO.", e); - } - } - } - - return null; - } - - /** - * Gets an object List. - * - * @param the type of the objects in the List. - * @param propertyName the property to get - * @param c the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) - * and a static one. - * @return the object collection. - */ - public List getList(String propertyName, Class c) { - if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - ArrayNode jsonArray = (ArrayNode) this.propertyBag.get(propertyName); - ArrayList result = new ArrayList(); - - boolean isBaseClass = false; - boolean isEnumClass = false; - boolean isJsonSerializable = false; - - // Check once. - if (Number.class.isAssignableFrom(c) || String.class.isAssignableFrom(c) - || Boolean.class.isAssignableFrom(c) || Object.class == c) { - isBaseClass = true; - } else if (Enum.class.isAssignableFrom(c)) { - isEnumClass = true; - } else if (JsonSerializable.class.isAssignableFrom(c)) { - isJsonSerializable = true; - } else { - JsonSerializable.checkForValidPOJO(c); - } - - for (JsonNode n : jsonArray) { - if (isBaseClass) { - // Number, String, Boolean - result.add(c.cast(getValue(n))); - } else if (isEnumClass) { - try { - result.add(c.cast(c.getMethod("valueOf", String.class).invoke(null, - String.class.cast(getValue(n))))); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to create enum.", e); - } - } else if (isJsonSerializable) { - // JsonSerializable - try { - result.add(c.getConstructor(String.class).newInstance(toJson(n))); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to instantiate class object.", e); - } - } else { - // POJO - try { - result.add(this.getMapper().treeToValue(n, c)); - } catch (IOException e) { - throw new IllegalStateException("Failed to get POJO.", e); - } - } - } - return result; - } - return null; - } - - /** - * Gets an object collection. - * - * @param the type of the objects in the collection. - * @param propertyName the property to get - * @param c the class of the object. If c is a POJO class, it must be a member (and not an anonymous or local) - * and a static one. - * @return the object collection. - */ - public Collection getCollection(String propertyName, Class c) { - return getList(propertyName, c); - } - - /** - * Gets a JSONObject. - * - * @param propertyName the property to get. - * @return the JSONObject. - */ - public ObjectNode getObject(String propertyName) { - if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - ObjectNode jsonObj = (ObjectNode) this.propertyBag.get(propertyName); - return jsonObj; - } - return null; - } - - /** - * Gets a JSONObject collection. - * - * @param propertyName the property to get. - * @return the JSONObject collection. - */ - public Collection getCollection(String propertyName) { - Collection result = null; - if (this.propertyBag.has(propertyName) && this.propertyBag.hasNonNull(propertyName)) { - result = new ArrayList(); - - for (JsonNode n : this.propertyBag.findValues(propertyName)) { - result.add((ObjectNode) n); - } - } - - return result; - } - - /** - * Gets the value of a property identified by an array of property names that forms the path. - * - * @param propertyNames that form the path to the property to get. - * @return the value of the property. - */ - public Object getObjectByPath(List propertyNames) { - ObjectNode propBag = this.propertyBag; - JsonNode value = null; - String propertyName = null; - Integer matchedProperties = 0; - Iterator iterator = propertyNames.iterator(); - if (iterator.hasNext()) { - do { - propertyName = iterator.next(); - if (propBag.has(propertyName)) { - matchedProperties++; - value = propBag.get(propertyName); - if (!value.isObject()) { - break; - } - propBag = (ObjectNode) value; - } else { - break; - } - } while (iterator.hasNext()); - - if (value != null && matchedProperties == propertyNames.size()) { - return getValue(value); - } - } - - return null; - } - - static Object getValue(JsonNode value) { - if (value.isValueNode()) { - switch (value.getNodeType()) { - case BOOLEAN: - return value.asBoolean(); - case NUMBER: - if (value.isInt()) { - return value.asInt(); - } else if (value.isLong()) { - return value.asLong(); - } else if (value.isDouble()) { - return value.asDouble(); - } - case STRING : - return value.asText(); - } - } - return value; - } - - private ObjectNode fromJson(String json){ - try { - return (ObjectNode) getMapper().readTree(json); - } catch (IOException e) { - throw new IllegalArgumentException(String.format("Unable to parse JSON %s", json), e); - } - } - - private String toJson(Object object){ - try { - return getMapper().writeValueAsString(object); - } catch (JsonProcessingException e) { - throw new IllegalStateException("Unable to convert JSON to String", e); - } - } - - private String toPrettyJson(Object object){ - try { - return getMapper().writerWithDefaultPrettyPrinter().writeValueAsString(object); - } catch (JsonProcessingException e) { - throw new IllegalStateException("Unable to convert JSON to String", e); - } - } - - /** - * Converts to an Object (only POJOs and JSONObject are supported). - * - * @param the type of the object. - * @param c the class of the object, either a POJO class or JSONObject. If c is a POJO class, it must be a member - * (and not an anonymous or local) and a static one. - * @return the POJO. - */ - public T toObject(Class c) { - if (JsonSerializable.class.isAssignableFrom(c) || String.class.isAssignableFrom(c) - || Number.class.isAssignableFrom(c) || Boolean.class.isAssignableFrom(c)) { - throw new IllegalArgumentException("c can only be a POJO class or JSONObject"); - } - if (ObjectNode.class.isAssignableFrom(c)) { - // JSONObject - if (ObjectNode.class != c) { - throw new IllegalArgumentException("We support JSONObject but not its sub-classes."); - } - return c.cast(this.propertyBag); - } else { - // POJO - JsonSerializable.checkForValidPOJO(c); - try { - return this.getMapper().readValue(this.toJson(), c); - } catch (IOException e) { - throw new IllegalStateException("Failed to get POJO.", e); - } - } - } - - /** - * Converts to a JSON string. - * - * @return the JSON string. - */ - public String toJson() { - return this.toJson(SerializationFormattingPolicy.None); - } - - /** - * Converts to a JSON string. - * - * @param formattingPolicy the formatting policy to be used. - * @return the JSON string. - */ - public String toJson(SerializationFormattingPolicy formattingPolicy) { - this.populatePropertyBag(); - if (SerializationFormattingPolicy.Indented.equals(formattingPolicy) ) { - return toPrettyJson(propertyBag); - } else { - return toJson(propertyBag); - } - } - - /** - * Gets Simple String representation of property bag. - * - * For proper conversion to json and inclusion of the default values - * use {@link #toJson()}. - * - * @return string representation of property bag. - */ - public String toString() { - return toJson(propertyBag); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaOptions.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaOptions.java deleted file mode 100644 index 43d38ee187d2..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaOptions.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Options used with attachment content (aka media) creation in the Azure Cosmos DB database service. - */ -public final class MediaOptions { - private String slug; - private String contentType; - - /** - * Gets the HTTP Slug header value. - * - * @return the slug. - */ - public String getSlug() { - return this.slug; - } - - /** - * Sets the HTTP Slug header value. - * - * @param slug the slug. - */ - public void setSlug(String slug) { - this.slug = slug; - } - - /** - * Gets the HTTP ContentType header value. - * - * @return the content type. - */ - public String getContentType() { - return this.contentType; - } - - /** - * Sets the HTTP ContentType header value. - * - * @param contentType the content type. - */ - public void setContentType(String contentType) { - this.contentType = contentType; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaReadMode.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaReadMode.java deleted file mode 100644 index 00b318ea7f58..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaReadMode.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Represents the mode for use with downloading attachment content (aka media) from the Azure Cosmos DB database service. - */ -public enum MediaReadMode { - - /** - * Content is buffered at the client and not directly streamed from the - * content store. Use Buffered to reduce the time taken to read and write - * media files. - */ - Buffered, - - /** - * Content is directly streamed from the content store without any buffering - * at the client. Use Streamed to reduce the client memory overhead of - * reading and writing media files. - */ - Streamed -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaResponse.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaResponse.java deleted file mode 100644 index cc4e1dcf3075..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/MediaResponse.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.util.Map; - -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; - -/** - * Response associated with retrieving attachment content in the Azure Cosmos DB database service. - */ -public final class MediaResponse { - private InputStream media = null; - private Map responseHeaders = null; - - MediaResponse(RxDocumentServiceResponse response, boolean willBuffer) { - this.media = response.getContentStream(); - if (willBuffer) { - this.media = new BufferedInputStream(this.media); - } - - this.responseHeaders = response.getResponseHeaders(); - } - - /** - * Gets the attachment content stream. - * - * @return the attachment content stream. - */ - public InputStream getMedia() { - return this.media; - } - - /** - * Gets the headers associated with the response. - * - * @return the response headers. - */ - public Map getResponseHeaders() { - return this.responseHeaders; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Offer.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Offer.java deleted file mode 100644 index 0e450510340e..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Offer.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.fasterxml.jackson.databind.node.ObjectNode; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.Utils; - -/** - * Represents an offer in the Azure Cosmos DB database service. - */ -public class Offer extends Resource { - - /** - * Initialize an new instance of the Offer object. - * - * @param offerThroughput the throughput value for this offer. - */ - public Offer(int offerThroughput) { - super(); - this.setOfferVersion(Constants.Properties.OFFER_VERSION_V2); - this.setOfferType(""); - ObjectNode content = Utils.getSimpleObjectMapper().createObjectNode(); - content.put(Constants.Properties.OFFER_THROUGHPUT, offerThroughput); - this.setContent(content); - } - - /** - * Initialize an offer object from json string. - * - * @param jsonString the json string that represents the offer. - */ - public Offer(String jsonString) { - super(jsonString); - } - - /** - * Gets the self-link of a resource to which the resource offer applies. - * - * @return the resource link. - */ - public String getResourceLink() { - return super.getString(Constants.Properties.RESOURCE_LINK); - } - - /** - * Sets the self-link of a resource to which the resource offer applies. - * - * @param resourceLink the resource link. - */ - void setResourceLink(String resourceLink) { - super.set(Constants.Properties.RESOURCE_LINK, resourceLink); - } - - /** - * Sets the target resource id of a resource to which this offer applies. - * - * @return the resource id. - */ - public String getOfferResourceId() { - return super.getString(Constants.Properties.OFFER_RESOURCE_ID); - } - - /** - * Sets the target resource id of a resource to which this offer applies. - * - * @param resourceId the resource id. - */ - void setOfferResourceId(String resourceId) { - super.set(Constants.Properties.OFFER_RESOURCE_ID, resourceId); - } - - /** - * Gets the OfferType for the resource offer. - * - * @return the offer type. - */ - public String getOfferType() { - return super.getString(Constants.Properties.OFFER_TYPE); - } - - /** - * Sets the OfferType for the resource offer. - * - * @param offerType the offer type. - */ - public void setOfferType(String offerType) { - super.set(Constants.Properties.OFFER_TYPE, offerType); - } - - /** - * Gets the version of the current offer. - * - * @return the offer version. - */ - public String getOfferVersion() { - return super.getString(Constants.Properties.OFFER_VERSION); - } - - /** - * Sets the offer version. - * - * @param offerVersion the version of the offer. - */ - public void setOfferVersion(String offerVersion) { - super.set(Constants.Properties.OFFER_VERSION, offerVersion); - } - - /** - * Gets the offer throughput for this offer. - * - * @return the offer throughput. - */ - public int getThroughput() { - return this.getContent().get(Constants.Properties.OFFER_THROUGHPUT).asInt(); - } - - /** - * Sets the offer throughput for this offer. - * - * @param throughput the throughput of this offer. - */ - public void setThroughput(int throughput) { - this.getContent().put(Constants.Properties.OFFER_THROUGHPUT, throughput); - } - - private ObjectNode getContent() { - return super.getObject(Constants.Properties.OFFER_CONTENT); - } - - private void setContent(ObjectNode offerContent) { - super.set(Constants.Properties.OFFER_CONTENT, offerContent); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKey.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKey.java deleted file mode 100644 index 8defae8237b4..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKey.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -/** - * Represents a partition key value in the Azure Cosmos DB database service. A partition key identifies the partition - * where the document is stored in. - */ -public class PartitionKey { - - private PartitionKeyInternal internalPartitionKey; - - PartitionKey(PartitionKeyInternal partitionKeyInternal) { - this.internalPartitionKey = partitionKeyInternal; - } - - /** - * Constructor. Create a new instance of the PartitionKey object. - * - * @param key the value of the partition key. - */ - @SuppressWarnings("serial") - public PartitionKey(final Object key) { - this.internalPartitionKey = PartitionKeyInternal.fromObjectArray(new Object[] {key}, true); - } - - /** - * Create a new instance of the PartitionKey object from a serialized JSON partition key. - * - * @param jsonString the JSON string representation of this PartitionKey object. - * @return the PartitionKey instance. - */ - public static PartitionKey FromJsonString(String jsonString) { - return new PartitionKey(PartitionKeyInternal.fromJsonString(jsonString)); - } - - /** - * Serialize the PartitionKey object to a JSON string. - * - * @return the string representation of this PartitionKey object. - */ - public String toString() { - return this.internalPartitionKey.toJson(); - } - - public PartitionKeyInternal getInternalPartitionKey() { - return internalPartitionKey; - } - - /** - * Overrides the Equal operator for object comparisons between two instances of {@link PartitionKey} - * @param other The object to compare with. - * @return True if two object instance are considered equal. - */ - @Override - public boolean equals(Object other) { - if (other == null) { - return false; - } - - if (this == other) { - return true; - } - - PartitionKey otherKey = Utils.as(other, PartitionKey.class); - return otherKey != null && this.internalPartitionKey.equals(otherKey.internalPartitionKey); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyDefinition.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyDefinition.java deleted file mode 100644 index e9f71e9928b0..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyDefinition.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.WordUtils; - -/** - * Represents a partition key definition in the Azure Cosmos DB database service. A partition key definition specifies which - * document property is used as the partition key in a collection that has multiple partitions. - */ -public final class PartitionKeyDefinition extends JsonSerializable { - private List paths; - private PartitionKind kind; - private PartitionKeyDefinitionVersion version; - - /** - * Constructor. Creates a new instance of the PartitionKeyDefinition object. - */ - public PartitionKeyDefinition() { - this.setKind(PartitionKind.Hash); - } - - /** - * Constructor. Creates a new instance of the PartitionKeyDefinition object from a - * JSON string. - * - * @param jsonString the JSON string that represents the partition key definition. - */ - public PartitionKeyDefinition(String jsonString) { - super(jsonString); - } - - /** - * Sets the partition algorithm used to calculate the partition id given a partition key. - * - * @return the partition algorithm. - */ - public PartitionKind getKind() { - if (this.kind == null) { - this.kind = super.getObject(Constants.Properties.PARTITION_KIND, PartitionKind.class); - } - - return this.kind; - } - - /** - * Sets the partition algorithm used to calculate the partition id given a partition key. - * - * @param kind the partition algorithm. - */ - public void setKind(PartitionKind kind) { - this.kind = kind; - } - - public PartitionKeyDefinitionVersion getVersion() { - if (this.version == null) { - Object versionObject = super.getObject(Constants.Properties.PARTITION_KEY_DEFINITION_VERSION, Object.class); - if (versionObject == null) { - this.version = null; - } else { - String versionStr = String.valueOf(versionObject); - if (StringUtils.isNumeric(versionStr)) { - this.version = PartitionKeyDefinitionVersion.valueOf(String.format("V%d", Integer.parseInt(versionStr))); - } else { - this.version = !Strings.isNullOrEmpty(versionStr) - ? PartitionKeyDefinitionVersion.valueOf(WordUtils.capitalize(versionStr)) - : null; - } - } - } - - return this.version; - } - - public void setVersion(PartitionKeyDefinitionVersion version) { - this.version = version; - } - - /** - * Gets the document property paths for the partition key. - * - * @return the paths to the document properties that form the partition key. - */ - public List getPaths() { - if (this.paths == null) { - if (super.has(Constants.Properties.PARTITION_KEY_PATHS)) { - paths = super.getList(Constants.Properties.PARTITION_KEY_PATHS, String.class); - } else { - paths = new ArrayList<>(); - } - } - - return paths; - } - - /** - * Sets the document property paths for the partition key. - * - * @param paths the paths to document properties that form the partition key. - */ - public void setPaths(List paths) { - if (paths == null || paths.size() == 0) { - throw new IllegalArgumentException("paths must not be null or empty."); - } - - this.paths = paths; - } - - @Override - void populatePropertyBag() { - if (this.kind != null) { - super.set(Constants.Properties.PARTITION_KIND, kind.name()); - } - if (this.paths != null) { - super.set(Constants.Properties.PARTITION_KEY_PATHS, paths); - } - - if (this.version != null) { - super.set(Constants.Properties.PARTITION_KEY_DEFINITION_VERSION, version.name()); - } - super.populatePropertyBag(); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyDefinitionVersion.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyDefinitionVersion.java deleted file mode 100644 index 096f2dc054f9..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyDefinitionVersion.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Partitioning version. - */ -public enum PartitionKeyDefinitionVersion { - - /** - * Original version of hash partitioning. - */ - V1(1), - - /** - * Enhanced version of hash partitioning - offers better distribution of long partition keys and uses less storage. - * - * This version should be used for any practical purpose, but it is available in newer SDKs only. - */ - V2(2); - - int val; - - private PartitionKeyDefinitionVersion(int val) { - this.val = val; - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyRange.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyRange.java deleted file mode 100644 index f74e3146a8bf..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKeyRange.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.List; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.routing.Range; - -/** - * Represent a partition key range in the Azure Cosmos DB database service. - */ -public class PartitionKeyRange extends Resource { - public static final String MINIMUM_INCLUSIVE_EFFECTIVE_PARTITION_KEY = ""; - public static final String MAXIMUM_EXCLUSIVE_EFFECTIVE_PARTITION_KEY = "FF"; - public static final String MASTER_PARTITION_KEY_RANGE_ID = "M"; - - /** - * Initialize a partition key range object. - */ - public PartitionKeyRange() { - super(); - } - - /** - * Initialize a partition key range object from json string. - * - * @param jsonString - * the json string that represents the partition key range - * object. - */ - public PartitionKeyRange(String jsonString) { - super(jsonString); - } - - public PartitionKeyRange(String id, String minInclusive, String maxExclusive) { - super(); - this.setId(id); - this.setMinInclusive(minInclusive); - this.setMaxExclusive(maxExclusive); - } - - public PartitionKeyRange(String id, String minInclusive, String maxExclusive, List parents) { - super(); - this.setId(id); - this.setMinInclusive(minInclusive); - this.setMaxExclusive(maxExclusive); - this.setParents(parents); - } - - public String getMinInclusive() { - return super.getString("minInclusive"); - } - - public void setMinInclusive(String minInclusive) { - super.set("minInclusive", minInclusive); - } - - public String getMaxExclusive() { - return super.getString("maxExclusive"); - } - - public void setMaxExclusive(String maxExclusive) { - super.set("maxExclusive", maxExclusive); - } - - public Range toRange() { - return new Range(this.getMinInclusive(), this.getMaxExclusive(), true, false); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof PartitionKeyRange)) { - return false; - } - - PartitionKeyRange otherRange = (PartitionKeyRange) obj; - - return this.getId().compareTo(otherRange.getId()) == 0 - && this.getMinInclusive().compareTo(otherRange.getMinInclusive()) == 0 - && this.getMaxExclusive().compareTo(otherRange.getMaxExclusive()) == 0; - } - - @Override - public int hashCode() { - int hash = 0; - hash = (hash * 397) ^ this.getId().hashCode(); - hash = (hash * 397) ^ this.getMinInclusive().hashCode(); - hash = (hash * 397) ^ this.getMaxExclusive().hashCode(); - return hash; - } - - void setParents(List parents) { - this.set(Constants.Properties.PARENTS, parents); - } - - /** - * Used internally to indicate the ID of the parent range - * @return a list partition key range ID - */ - public List getParents() { return this.getList(Constants.Properties.PARENTS, String.class); } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKind.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKind.java deleted file mode 100644 index 4c5c94c35cd2..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PartitionKind.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Specifies the partition scheme for an multiple-partitioned collection in the Azure Cosmos DB database service. - */ -public enum PartitionKind { - /** - * The Partition of a document is calculated based on the hash value of the PartitionKey. - */ - Hash -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Permission.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Permission.java deleted file mode 100644 index a72b653582ec..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Permission.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.fasterxml.jackson.databind.node.ArrayNode; -import org.apache.commons.text.WordUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a per-User Permission to access a specific resource e.g. Document or Collection in the Azure Cosmos DB database service. - */ -public class Permission extends Resource { - /** - * Initialize a permission object. - */ - public Permission() { - super(); - } - - /** - * Initialize a permission object from json string. - * - * @param jsonString the json string that represents the permission. - */ - public Permission(String jsonString) { - super(jsonString); - } - - /** - * Gets the self-link of resource to which the permission applies. - * - * @return the resource link. - */ - public String getResourceLink() { - return super.getString(Constants.Properties.RESOURCE_LINK); - } - - /** - * Sets the self-link of resource to which the permission applies. - * - * @param resourceLink the resource link. - */ - public void setResourceLink(String resourceLink) { - super.set(Constants.Properties.RESOURCE_LINK, resourceLink); - } - - /** - * Gets the permission mode. - * - * @return the permission mode. - */ - public PermissionMode getPermissionMode() { - String value = super.getString(Constants.Properties.PERMISSION_MODE); - return PermissionMode.valueOf(WordUtils.capitalize(value)); - } - - /** - * Sets the permission mode. - * - * @param permissionMode the permission mode. - */ - public void setPermissionMode(PermissionMode permissionMode) { - this.set(Constants.Properties.PERMISSION_MODE, - permissionMode.name().toLowerCase()); - } - - /** - * Gets the access token granting the defined permission. - * - * @return the access token. - */ - public String getToken() { - return super.getString(Constants.Properties.TOKEN); - } - - /** - * Gets the resource partition key associated with this permission object. - * - * @return the partition key. - */ - public PartitionKey getResourcePartitionKey() { - PartitionKey key = null; - Object value = super.get(Constants.Properties.RESOURCE_PARTITION_KEY); - if (value != null) { - ArrayNode arrayValue = (ArrayNode) value; - key = new PartitionKey(getValue(arrayValue.get(0))); - } - - return key; - } - - /** - * Sets the resource partition key associated with this permission object. - * - * @param partitionkey the partition key. - */ - public void setResourcePartitionKey(PartitionKey partitionkey) { - super.set(Constants.Properties.RESOURCE_PARTITION_KEY, partitionkey.getInternalPartitionKey().toJson()); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PermissionMode.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PermissionMode.java deleted file mode 100644 index ef514dcf4573..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/PermissionMode.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Enumeration specifying applicability of permission in the Azure Cosmos DB database service. - */ -public enum PermissionMode { - /** - * Permission applicable for read operations only. - */ - Read(0x1), - - /** - * Permission applicable for all operations. - */ - All(0x2); - - private int value; - - PermissionMode(int value) { - this.value = value; - } - - /** - * Gets the numerical value of the permission mode. - * - * @return the numerical value. - */ - public int getValue() { - return value; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetrics.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetrics.java deleted file mode 100644 index c333c6a757a6..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetrics.java +++ /dev/null @@ -1,315 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.query.metrics.ClientSideMetrics; -import com.microsoft.azure.cosmosdb.internal.query.metrics.FetchExecutionRange; -import com.microsoft.azure.cosmosdb.internal.query.metrics.QueryMetricsTextWriter; -import com.microsoft.azure.cosmosdb.internal.query.metrics.SchedulingTimeSpan; -import org.apache.commons.lang3.tuple.ImmutablePair; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - -/** - * Query metrics in the Azure Cosmos database service. - * This metric represents a moving average for a set of queries whose metrics have been aggregated together. - */ -public final class QueryMetrics { - public static QueryMetrics ZERO = new QueryMetrics( - new ArrayList<>(), /* */ - 0, /* retrievedDocumentCount */ - 0, /* retrievedDocumentSize */ - 0, /* outputDocumentCount */ - 0, /* outputDocumentSize */ - 0, /* indexHitCount */ - Duration.ZERO, - QueryPreparationTimes.ZERO, - Duration.ZERO, - Duration.ZERO, - Duration.ZERO, - RuntimeExecutionTimes.ZERO, - Duration.ZERO, - ClientSideMetrics.ZERO); - private final long retrievedDocumentCount; - private final long retrievedDocumentSize; - private final long outputDocumentCount; - private final long outputDocumentSize; - private final long indexHitDocumentCount; - private final Duration totalQueryExecutionTime; - private final QueryPreparationTimes queryPreparationTimes; - private final Duration indexLookupTime; - private final Duration documentLoadTime; - private final Duration vmExecutionTime; - private final RuntimeExecutionTimes runtimeExecutionTimes; - private final Duration documentWriteTime; - private final ClientSideMetrics clientSideMetrics; - private final List activityIds; - - public QueryMetrics(List activities, long retrievedDocumentCount, long retrievedDocumentSize, long outputDocumentCount, - long outputDocumentSize, long indexHitCount, Duration totalQueryExecutionTime, - QueryPreparationTimes queryPreparationTimes, Duration indexLookupTime, Duration documentLoadTime, - Duration vmExecutionTime, RuntimeExecutionTimes runtimeExecutionTimes, Duration documentWriteTime, - ClientSideMetrics clientSideMetrics) { - this.retrievedDocumentCount = retrievedDocumentCount; - this.retrievedDocumentSize = retrievedDocumentSize; - this.outputDocumentCount = outputDocumentCount; - this.outputDocumentSize = outputDocumentSize; - this.indexHitDocumentCount = indexHitCount; - this.totalQueryExecutionTime = totalQueryExecutionTime; - this.queryPreparationTimes = queryPreparationTimes; - this.indexLookupTime = indexLookupTime; - this.documentLoadTime = documentLoadTime; - this.vmExecutionTime = vmExecutionTime; - this.runtimeExecutionTimes = runtimeExecutionTimes; - this.documentWriteTime = documentWriteTime; - this.clientSideMetrics = clientSideMetrics; - this.activityIds = activities; - } - - /** - * @return the retrievedDocumentCount - */ - public long getRetrievedDocumentCount() { - return retrievedDocumentCount; - } - - /** - * @return the retrievedDocumentSize - */ - public long getRetrievedDocumentSize() { - return retrievedDocumentSize; - } - - /** - * @return the outputDocumentCount - */ - public long getOutputDocumentCount() { - return outputDocumentCount; - } - - /** - * @return the outputDocumentSize - */ - public long getOutputDocumentSize() { - return outputDocumentSize; - } - - /** - * @return the indexHitDocumentCount - */ - public long getIndexHitDocumentCount() { - return indexHitDocumentCount; - } - - /** - * Gets the index hit ratio by query in the Azure Cosmos database service. - * - * @return the IndexHitRatio - */ - public double getIndexHitRatio() { - return this.retrievedDocumentCount == 0 ? 1 : (double) this.indexHitDocumentCount / this.retrievedDocumentCount; - } - - /** - * @return the totalQueryExecutionTime - */ - public Duration getTotalQueryExecutionTime() { - return totalQueryExecutionTime; - } - - /** - * @return the queryPreparationTimes - */ - public QueryPreparationTimes getQueryPreparationTimes() { - return queryPreparationTimes; - } - - /** - * @return the indexLookupTime - */ - public Duration getIndexLookupTime() { - return indexLookupTime; - } - - /** - * @return the documentLoadTime - */ - public Duration getDocumentLoadTime() { - return documentLoadTime; - } - - /** - * @return the vmExecutionTime - */ - public Duration getVMExecutionTime() { - return vmExecutionTime; - } - - /** - * @return the runtimeExecutionTimes - */ - public RuntimeExecutionTimes getRuntimeExecutionTimes() { - return runtimeExecutionTimes; - } - - /** - * @return the documentWriteTime - */ - public Duration getDocumentWriteTime() { - return documentWriteTime; - } - - /** - * @return the clientSideMetrics - */ - ClientSideMetrics getClientSideMetrics() { - return clientSideMetrics; - } - - /** - * @return number of reties in the Azure Cosmos database service. - */ - public long getRetries() { - return this.clientSideMetrics.getRetries(); - } - - public QueryMetrics add(QueryMetrics... queryMetricsArgs) { - ArrayList queryMetricsList = new ArrayList(); - for (QueryMetrics queryMetrics : queryMetricsArgs) { - queryMetricsList.add(queryMetrics); - } - - queryMetricsList.add(this); - - return QueryMetrics.createFromCollection(queryMetricsList); - } - - private String toTextString() { - return toTextString(0); - } - - private String toTextString(int indentLevel) { - StringBuilder stringBuilder = new StringBuilder(); - QueryMetricsTextWriter queryMetricsTextWriter = new QueryMetricsTextWriter(stringBuilder); - queryMetricsTextWriter.writeQueryMetrics(this); - return stringBuilder.toString(); - } - - static QueryMetrics createFromCollection(Collection queryMetricsCollection) { - long retrievedDocumentCount = 0; - long retrievedDocumentSize = 0; - long outputDocumentCount = 0; - long outputDocumentSize = 0; - long indexHitDocumentCount = 0; - Duration totalQueryExecutionTime = Duration.ZERO; - Collection queryPreparationTimesCollection = new ArrayList(); - Duration indexLookupTime = Duration.ZERO; - Duration documentLoadTime = Duration.ZERO; - Duration vmExecutionTime = Duration.ZERO; - Collection runtimeExecutionTimesCollection = new ArrayList(); - Duration documentWriteTime = Duration.ZERO; - Collection clientSideMetricsCollection = new ArrayList(); - List activityIds = new ArrayList<>(); - - for (QueryMetrics queryMetrics : queryMetricsCollection) { - if (queryMetrics == null) { - throw new NullPointerException("queryMetricsList can not have null elements"); - } - activityIds.addAll(queryMetrics.activityIds); - retrievedDocumentCount += queryMetrics.retrievedDocumentCount; - retrievedDocumentSize += queryMetrics.retrievedDocumentSize; - outputDocumentCount += queryMetrics.outputDocumentCount; - outputDocumentSize += queryMetrics.outputDocumentSize; - indexHitDocumentCount += queryMetrics.indexHitDocumentCount; - totalQueryExecutionTime = totalQueryExecutionTime.plus(queryMetrics.totalQueryExecutionTime); - queryPreparationTimesCollection.add(queryMetrics.queryPreparationTimes); - indexLookupTime = indexLookupTime.plus(queryMetrics.indexLookupTime); - documentLoadTime = documentLoadTime.plus(queryMetrics.documentLoadTime); - vmExecutionTime = vmExecutionTime.plus(queryMetrics.vmExecutionTime); - runtimeExecutionTimesCollection.add(queryMetrics.runtimeExecutionTimes); - documentWriteTime = documentWriteTime.plus(queryMetrics.documentWriteTime); - clientSideMetricsCollection.add(queryMetrics.clientSideMetrics); - } - - return new QueryMetrics(activityIds, retrievedDocumentCount, retrievedDocumentSize, outputDocumentCount, - outputDocumentSize, - indexHitDocumentCount, totalQueryExecutionTime, - QueryPreparationTimes.createFromCollection(queryPreparationTimesCollection), indexLookupTime, documentLoadTime, - vmExecutionTime, RuntimeExecutionTimes.createFromCollection(runtimeExecutionTimesCollection), - documentWriteTime, ClientSideMetrics.createFromCollection(clientSideMetricsCollection)); - } - - private static double getOrDefault(HashMap metrics, String key) { - Double doubleReference = metrics.get(key); - return doubleReference == null ? 0 : doubleReference; - } - - static QueryMetrics createFromDelimitedString(String delimitedString) { - HashMap metrics = QueryMetricsUtils.parseDelimitedString(delimitedString); - return QueryMetrics.createFromDelimitedStringAndClientSideMetrics(delimitedString, - new ClientSideMetrics(0, 0, new ArrayList(), - new ArrayList>()), ""); - } - - static QueryMetrics createFromDelimitedStringAndClientSideMetrics(String delimitedString, ClientSideMetrics clientSideMetrics, - String activityId) { - HashMap metrics = QueryMetricsUtils.parseDelimitedString(delimitedString); - double indexHitRatio; - double retrievedDocumentCount; - indexHitRatio = metrics.get(QueryMetricsConstants.IndexHitRatio); - retrievedDocumentCount = metrics.get(QueryMetricsConstants.RetrievedDocumentCount); - long indexHitCount = (long) (indexHitRatio * retrievedDocumentCount); - double outputDocumentCount = metrics.get(QueryMetricsConstants.OutputDocumentCount); - double outputDocumentSize = metrics.get(QueryMetricsConstants.OutputDocumentSize); - double retrievedDocumentSize = metrics.get(QueryMetricsConstants.RetrievedDocumentSize); - Duration totalQueryExecutionTime = QueryMetricsUtils.getDurationFromMetrics(metrics, QueryMetricsConstants.TotalQueryExecutionTimeInMs); - - List activities = new ArrayList<>(); - activities.add(activityId); - - return new QueryMetrics( - activities, - (long) retrievedDocumentCount, - (long) retrievedDocumentSize, - (long) outputDocumentCount, - (long) outputDocumentSize, - indexHitCount, - totalQueryExecutionTime, - QueryPreparationTimes.createFromDelimitedString(delimitedString), - QueryMetricsUtils.getDurationFromMetrics(metrics, QueryMetricsConstants.IndexLookupTimeInMs), - QueryMetricsUtils.getDurationFromMetrics(metrics, QueryMetricsConstants.DocumentLoadTimeInMs), - QueryMetricsUtils.getDurationFromMetrics(metrics, QueryMetricsConstants.VMExecutionTimeInMs), - RuntimeExecutionTimes.createFromDelimitedString(delimitedString), - QueryMetricsUtils.getDurationFromMetrics(metrics, QueryMetricsConstants.DocumentWriteTimeInMs), - clientSideMetrics); - } - - @Override - public String toString() { - return toTextString(0); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetricsConstants.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetricsConstants.java deleted file mode 100644 index f14d338e1910..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetricsConstants.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -public final class QueryMetricsConstants { - // QueryMetrics - public static final String RetrievedDocumentCount = "retrievedDocumentCount"; - public static final String RetrievedDocumentSize = "retrievedDocumentSize"; - public static final String OutputDocumentCount = "outputDocumentCount"; - public static final String OutputDocumentSize = "outputDocumentSize"; - public static final String IndexHitRatio = "indexUtilizationRatio"; - public static final String IndexHitDocumentCount = "indexHitDocumentCount"; - public static final String TotalQueryExecutionTimeInMs = "totalExecutionTimeInMs"; - - // QueryPreparationTimes - public static final String QueryCompileTimeInMs = "queryCompileTimeInMs"; - public static final String LogicalPlanBuildTimeInMs = "queryLogicalPlanBuildTimeInMs"; - public static final String PhysicalPlanBuildTimeInMs = "queryPhysicalPlanBuildTimeInMs"; - public static final String QueryOptimizationTimeInMs = "queryOptimizationTimeInMs"; - - // QueryTimes - public static final String IndexLookupTimeInMs = "indexLookupTimeInMs"; - public static final String DocumentLoadTimeInMs = "documentLoadTimeInMs"; - public static final String VMExecutionTimeInMs = "VMExecutionTimeInMs"; - public static final String DocumentWriteTimeInMs = "writeOutputTimeInMs"; - - // RuntimeExecutionTimes - public static final String QueryEngineTimes = "queryEngineTimes"; - public static final String SystemFunctionExecuteTimeInMs = "systemFunctionExecuteTimeInMs"; - public static final String UserDefinedFunctionExecutionTimeInMs = "userFunctionExecuteTimeInMs"; - - // ClientSideMetrics - public static final String Retries = "retries"; - public static final String RequestCharge = "requestCharge"; - - // QueryMetrics Text - public static final String ActivityIds = "Activity Ids"; - public static final String RetrievedDocumentCountText = "Retrieved Document Count"; - public static final String RetrievedDocumentSizeText = "Retrieved Document Size"; - public static final String OutputDocumentCountText = "Output Document Count"; - public static final String OutputDocumentSizeText = "Output Document Size"; - public static final String IndexUtilizationText = "Index Utilization"; - public static final String TotalQueryExecutionTimeText = "Total Query Execution Time"; - - // QueryPreparationTimes Text - public static final String QueryPreparationTimesText = "Query Preparation Times"; - public static final String QueryCompileTimeText = "Query Compilation Time"; - public static final String LogicalPlanBuildTimeText = "Logical Plan Build Time"; - public static final String PhysicalPlanBuildTimeText = "Physical Plan Build Time"; - public static final String QueryOptimizationTimeText = "Query Optimization Time"; - - // QueryTimes Text - public static final String QueryEngineTimesText = "Query Engine Times"; - public static final String IndexLookupTimeText = "Index Lookup Time"; - public static final String DocumentLoadTimeText = "Document Load Time"; - public static final String WriteOutputTimeText = "Document Write Time"; - - // RuntimeExecutionTimes Text - public static final String RuntimeExecutionTimesText = "Runtime Execution Times"; - public static final String TotalExecutionTimeText = "Query Engine Execution Time"; - public static final String SystemFunctionExecuteTimeText = "System Function Execution Time"; - public static final String UserDefinedFunctionExecutionTimeText = "User-defined Function Execution Time"; - - // ClientSideQueryMetrics Text - public static final String ClientSideQueryMetricsText = "Client Side Metrics"; - public static final String RetriesText = "Retry Count"; - public static final String RequestChargeText = "Request Charge"; - public static final String FetchExecutionRangesText = "Partition Execution Timeline"; - public static final String SchedulingMetricsText = "Scheduling Metrics"; -} - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetricsUtils.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetricsUtils.java deleted file mode 100644 index 320e68e67346..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryMetricsUtils.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.lang3.StringUtils; - -import java.time.Duration; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; - -class QueryMetricsUtils { - static final String Indent = StringUtils.SPACE; - private static final int NANOS_TO_MILLIS = 1000000; - private static final String BytesUnitString = "bytes"; - - static HashMap parseDelimitedString(String delimitedString) { - if (delimitedString == null) { - throw new NullPointerException("delimitedString"); - } - - HashMap metrics = new HashMap<>(); - - final int key = 0; - final int value = 1; - String[] headerAttributes = StringUtils.split(delimitedString, ";"); - - for (String attribute : headerAttributes) { - String[] attributeKeyValue = StringUtils.split(attribute, "="); - - if (attributeKeyValue.length != 2) { - throw new NullPointerException("recieved a malformed delimited String"); - } - - String attributeKey = attributeKeyValue[key]; - double attributeValue = Double.parseDouble(attributeKeyValue[value]); - metrics.put(attributeKey, attributeValue); - } - - return metrics; - } - - static Duration durationFromMetrics(HashMap metrics, String key) { - // Just attempt to get the metrics - Double durationInMilliseconds = metrics.get(key); - if (durationInMilliseconds == null) { - return Duration.ZERO; - } - - long seconds = (long) (durationInMilliseconds / 1e3); - long nanoseconds = (long) ((durationInMilliseconds - (seconds * 1e3)) * 1e6); - - return Duration.ofSeconds(seconds, nanoseconds); - } - - static Duration getDurationFromMetrics(HashMap metrics, String key) { - double timeSpanInMilliseconds; - Duration timeSpanFromMetrics; - timeSpanInMilliseconds = metrics.get(key); - timeSpanFromMetrics = QueryMetricsUtils.doubleMillisecondsToDuration(timeSpanInMilliseconds); - return timeSpanFromMetrics; - } - - private static Duration doubleMillisecondsToDuration(double timeSpanInMilliseconds) { - long timeInNanoSeconds = (long) (timeSpanInMilliseconds * NANOS_TO_MILLIS); - return Duration.ofNanos(timeInNanoSeconds); - } - - private static void appendToStringBuilder(StringBuilder stringBuilder, String property, String value, - String units, int indentLevel) { - final String FormatString = "%-40s : %15s %-12s %s"; - - stringBuilder.append(String.format( - Locale.ROOT, - FormatString, - StringUtils.repeat(Indent, indentLevel) + property, - value, - units, - System.lineSeparator())); - } - - static void appendBytesToStringBuilder(StringBuilder stringBuilder, String property, long bytes, int indentLevel) { - final String BytesFormatString = "%d"; - - QueryMetricsUtils.appendToStringBuilder( - stringBuilder, - property, - String.format(BytesFormatString, bytes), - BytesUnitString, - indentLevel); - } - - static void appendMillisecondsToStringBuilder(StringBuilder stringBuilder, String property, double milliseconds, - int indentLevel) { - final String MillisecondsFormatString = "%f"; - final String MillisecondsUnitString = "milliseconds"; - - QueryMetricsUtils.appendToStringBuilder(stringBuilder, property, String.format(MillisecondsFormatString, - milliseconds), MillisecondsUnitString, indentLevel); - } - - static void appendNanosecondsToStringBuilder(StringBuilder stringBuilder, String property, double nanoSeconds, - int indentLevel) { - final String MillisecondsFormatString = "%.2f"; - final String MillisecondsUnitString = "milliseconds"; - QueryMetricsUtils.appendToStringBuilder(stringBuilder, property, String.format(MillisecondsFormatString, - nanosToMilliSeconds(nanoSeconds)), MillisecondsUnitString, indentLevel); - } - - static double nanosToMilliSeconds(double nanos) { - return nanos / NANOS_TO_MILLIS; - } - - static void appendHeaderToStringBuilder(StringBuilder stringBuilder, String headerTitle, int indentLevel) { - final String FormatString = "%s %s"; - stringBuilder.append(String.format( - Locale.ROOT, - FormatString, - String.join(StringUtils.repeat(Indent, indentLevel)) + headerTitle, - System.lineSeparator())); - } - - static void appendRUToStringBuilder(StringBuilder stringBuilder, String property, double requestCharge, - int indentLevel) { - final String RequestChargeFormatString = "%s"; - final String RequestChargeUnitString = "RUs"; - - QueryMetricsUtils.appendToStringBuilder( - stringBuilder, - property, - String.format(Locale.ROOT, RequestChargeFormatString, requestCharge), - RequestChargeUnitString, - indentLevel); - } - - static void appendActivityIdsToStringBuilder(StringBuilder stringBuilder, String activityIdsLabel, - List activityIds, int indentLevel) { - stringBuilder.append(activityIdsLabel); - stringBuilder.append(System.lineSeparator()); - for (String activityId : activityIds) { - stringBuilder.append(Indent); - stringBuilder.append(activityId); - stringBuilder.append(System.lineSeparator()); - } - } - - static void appendPercentageToStringBuilder(StringBuilder stringBuilder, String property, double percentage, - int indentLevel) { - final String PercentageFormatString = "%.2f"; - final String PercentageUnitString = "%"; - - QueryMetricsUtils.appendToStringBuilder(stringBuilder, property, String.format(PercentageFormatString, - percentage * 100), PercentageUnitString, indentLevel); - } - - static void appendCountToStringBuilder(StringBuilder stringBuilder, String property, long count, int indentLevel) { - final String CountFormatString = "%s"; - final String CountUnitString = ""; - - QueryMetricsUtils.appendToStringBuilder( - stringBuilder, - property, - String.format(CountFormatString, count), - CountUnitString, - indentLevel); - } - - static void appendNewlineToStringBuilder(StringBuilder stringBuilder) { - QueryMetricsUtils.appendHeaderToStringBuilder(stringBuilder, StringUtils.EMPTY, 0); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryPreparationTimes.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryPreparationTimes.java deleted file mode 100644 index 1ab1ae83bf75..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/QueryPreparationTimes.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import java.time.Duration; -import java.util.Collection; -import java.util.HashMap; - -public final class QueryPreparationTimes { - - static final QueryPreparationTimes ZERO = new QueryPreparationTimes(Duration.ZERO, Duration.ZERO, Duration.ZERO, Duration.ZERO); - - private final Duration queryCompilationTime; - private final Duration logicalPlanBuildTime; - private final Duration physicalPlanBuildTime; - private final Duration queryOptimizationTime; - - /** - * @param queryCompilationTime - * @param logicalPlanBuildTime - * @param physicalPlanBuildTime - * @param queryOptimizationTime - */ - QueryPreparationTimes(Duration queryCompilationTime, Duration logicalPlanBuildTime, Duration physicalPlanBuildTime, - Duration queryOptimizationTime) { - super(); - - if (queryCompilationTime == null) { - throw new NullPointerException("queryCompilationTime"); - } - - if (logicalPlanBuildTime == null) { - throw new NullPointerException("logicalPlanBuildTime"); - } - - if (physicalPlanBuildTime == null) { - throw new NullPointerException("physicalPlanBuildTime"); - } - - if (queryOptimizationTime == null) { - throw new NullPointerException("queryOptimizationTime"); - } - - this.queryCompilationTime = queryCompilationTime; - this.logicalPlanBuildTime = logicalPlanBuildTime; - this.physicalPlanBuildTime = physicalPlanBuildTime; - this.queryOptimizationTime = queryOptimizationTime; - } - - /** - * @return the queryCompilationTime - */ - public Duration getQueryCompilationTime() { - return queryCompilationTime; - } - - /** - * @return the logicalPlanBuildTime - */ - public Duration getLogicalPlanBuildTime() { - return logicalPlanBuildTime; - } - - /** - * @return the physicalPlanBuildTime - */ - public Duration getPhysicalPlanBuildTime() { - return physicalPlanBuildTime; - } - - /** - * @return the queryOptimizationTime - */ - public Duration getQueryOptimizationTime() { - return queryOptimizationTime; - } - - static QueryPreparationTimes createFromCollection( - Collection queryPreparationTimesCollection) { - if (queryPreparationTimesCollection == null) { - throw new NullPointerException("queryPreparationTimesCollection"); - } - - Duration queryCompilationTime = Duration.ZERO; - Duration logicalPlanBuildTime = Duration.ZERO; - Duration physicalPlanBuildTime = Duration.ZERO; - Duration queryOptimizationTime = Duration.ZERO; - - for (QueryPreparationTimes queryPreparationTimes : queryPreparationTimesCollection) { - if (queryPreparationTimes == null) { - throw new NullPointerException("queryPreparationTimesList can not have a null element"); - } - - queryCompilationTime = queryCompilationTime.plus(queryPreparationTimes.queryCompilationTime); - logicalPlanBuildTime = logicalPlanBuildTime.plus(queryPreparationTimes.logicalPlanBuildTime); - physicalPlanBuildTime = physicalPlanBuildTime.plus(queryPreparationTimes.physicalPlanBuildTime); - queryOptimizationTime = queryOptimizationTime.plus(queryPreparationTimes.queryOptimizationTime); - } - - return new QueryPreparationTimes( - queryCompilationTime, - logicalPlanBuildTime, - physicalPlanBuildTime, - queryOptimizationTime); - } - - static QueryPreparationTimes createFromDelimitedString(String delimitedString) { - HashMap metrics = QueryMetricsUtils.parseDelimitedString(delimitedString); - - return new QueryPreparationTimes( - QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.QueryCompileTimeInMs), - QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.LogicalPlanBuildTimeInMs), - QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.PhysicalPlanBuildTimeInMs), - QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.QueryOptimizationTimeInMs)); - } - - String toDelimitedString() { - String formatString = "%s=%.2f;%s=%.2f;%s=%.2f;%s=%.2f"; - return String.format( - formatString, - QueryMetricsConstants.QueryCompileTimeInMs, - this.queryCompilationTime.toMillis(), - QueryMetricsConstants.LogicalPlanBuildTimeInMs, - this.logicalPlanBuildTime.toMillis(), - QueryMetricsConstants.PhysicalPlanBuildTimeInMs, - this.physicalPlanBuildTime.toMillis(), - QueryMetricsConstants.QueryOptimizationTimeInMs, - this.queryOptimizationTime.toMillis()); - } - - String toTextString(int indentLevel) { - if (indentLevel == Integer.MAX_VALUE) { - throw new NumberFormatException("indentLevel input must be less than Integer.MaxValue"); - } - - StringBuilder stringBuilder = new StringBuilder(); - - QueryMetricsUtils.appendHeaderToStringBuilder(stringBuilder, QueryMetricsConstants.QueryPreparationTimesText, - indentLevel); - - QueryMetricsUtils.appendNanosecondsToStringBuilder(stringBuilder, QueryMetricsConstants.QueryCompileTimeText - , this.queryCompilationTime.toNanos(), indentLevel + 1); - - QueryMetricsUtils.appendNanosecondsToStringBuilder(stringBuilder, - QueryMetricsConstants.LogicalPlanBuildTimeText, this.logicalPlanBuildTime.toNanos(), - indentLevel + 1); - - QueryMetricsUtils.appendNanosecondsToStringBuilder(stringBuilder, - QueryMetricsConstants.PhysicalPlanBuildTimeText, this.physicalPlanBuildTime.toNanos(), - indentLevel + 1); - - QueryMetricsUtils.appendNanosecondsToStringBuilder(stringBuilder, - QueryMetricsConstants.QueryOptimizationTimeText, this.queryOptimizationTime.toNanos(), - indentLevel + 1); - return stringBuilder.toString(); - } -} - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RangeIndex.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RangeIndex.java deleted file mode 100644 index 27ef781fe73a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RangeIndex.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.text.WordUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a range index in the Azure Cosmos DB database service. - */ -public final class RangeIndex extends Index { - - /** - * Initializes a new instance of the RangeIndex class with specified DataType. - *

- * Here is an example to instantiate RangeIndex class passing in the DataType: - *

-     * {@code
-     *
-     * RangeIndex rangeIndex = new RangeIndex(DataType.Number);
-     *
-     * }
-     * 
- * - * @param dataType the data type. - */ - public RangeIndex(DataType dataType) { - super(IndexKind.Range); - this.setDataType(dataType); - } - - /** - * Initializes a new instance of the RangeIndex class with specified DataType and precision. - *
-     * {@code
-     *
-     * RangeIndex rangeIndex = new RangeIndex(DataType.Number, -1);
-     *
-     * }
-     * 
- * @param dataType the data type of the RangeIndex - * @param precision the precision of the RangeIndex - */ - public RangeIndex(DataType dataType, int precision) { - super(IndexKind.Range); - this.setDataType(dataType); - this.setPrecision(precision); - } - - /** - * Initializes a new instance of the RangeIndex class with json string. - * - * @param jsonString the json string that represents the index. - */ - public RangeIndex(String jsonString) { - super(jsonString, IndexKind.Range); - if (this.getDataType() == null) { - throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'."); - } - } - - /** - * Gets data type. - * - * @return the data type. - */ - public DataType getDataType() { - DataType result = null; - try { - result = DataType.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.DATA_TYPE))); - } catch (IllegalArgumentException e) { - this.getLogger().warn("Invalid index dataType value {}.", super.getString(Constants.Properties.DATA_TYPE)); - } - return result; - } - - /** - * Sets data type. - * - * @param dataType the data type. - */ - public void setDataType(DataType dataType) { - super.set(Constants.Properties.DATA_TYPE, dataType.name()); - } - - /** - * Gets precision. - * - * @return the precision. - */ - public int getPrecision() { - return super.getInt(Constants.Properties.PRECISION); - } - - /** - * Sets precision. - * - * @param precision the precision. - */ - public void setPrecision(int precision) { - super.set(Constants.Properties.PRECISION, precision); - } - - boolean hasPrecision() { - return super.has(Constants.Properties.PRECISION); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ReplicationPolicy.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ReplicationPolicy.java deleted file mode 100644 index 727fcd588b63..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ReplicationPolicy.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Encapsulates the replication policy in the Azure Cosmos DB database service. - */ -public class ReplicationPolicy extends JsonSerializable { - private static final int DEFAULT_MAX_REPLICA_SET_SIZE = 4; - private static final int DEFAULT_MIN_REPLICA_SET_SIZE = 3; - - public ReplicationPolicy() { - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the replication policy. - */ - public ReplicationPolicy(String jsonString) { - super(jsonString); - } - - public int getMaxReplicaSetSize() { - Integer maxReplicaSetSize = super.getInt(Constants.Properties.MAX_REPLICA_SET_SIZE); - if (maxReplicaSetSize == null) { - return DEFAULT_MAX_REPLICA_SET_SIZE; - } - - return maxReplicaSetSize; - } - - void setMaxReplicaSetSize(int value) { - Integer maxReplicaSetSize = super.getInt(Constants.Properties.MAX_REPLICA_SET_SIZE); - super.set(Constants.Properties.MAX_REPLICA_SET_SIZE, value); - } - - public int getMinReplicaSetSize() { - Integer minReplicaSetSize = super.getInt(Constants.Properties.MIN_REPLICA_SET_SIZE); - if (minReplicaSetSize == null) { - return DEFAULT_MIN_REPLICA_SET_SIZE; - } - - return minReplicaSetSize; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RequestOptions.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RequestOptions.java deleted file mode 100644 index 9a9e77a3503e..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RequestOptions.java +++ /dev/null @@ -1,329 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Encapsulates options that can be specified for a request issued to the Azure Cosmos DB database service. - */ -public class RequestOptions { - private Map customOptions; - private List preTriggerInclude; - private List postTriggerInclude; - private AccessCondition accessCondition; - private IndexingDirective indexingDirective; - private ConsistencyLevel consistencyLevel; - private String sessionToken; - private Integer resourceTokenExpirySeconds; - private String offerType; - private Integer offerThroughput; - private PartitionKey partitionkey; - private String partitionKeyRangeId; - private boolean scriptLoggingEnabled; - private boolean populateQuotaInfo; - private Map properties; - - /** - * Gets the triggers to be invoked before the operation. - * - * @return the triggers to be invoked before the operation. - */ - public List getPreTriggerInclude() { - return this.preTriggerInclude; - } - - /** - * Sets the triggers to be invoked before the operation. - * - * @param preTriggerInclude the triggers to be invoked before the operation. - */ - public void setPreTriggerInclude(List preTriggerInclude) { - this.preTriggerInclude = preTriggerInclude; - } - - /** - * Gets the triggers to be invoked after the operation. - * - * @return the triggers to be invoked after the operation. - */ - public List getPostTriggerInclude() { - return this.postTriggerInclude; - } - - /** - * Sets the triggers to be invoked after the operation. - * - * @param postTriggerInclude the triggers to be invoked after the operation. - */ - public void setPostTriggerInclude(List postTriggerInclude) { - this.postTriggerInclude = postTriggerInclude; - } - - /** - * Gets the conditions associated with the request. - * - * @return the access condition. - */ - public AccessCondition getAccessCondition() { - return this.accessCondition; - } - - /** - * Sets the conditions associated with the request. - * - * @param accessCondition the access condition. - */ - public void setAccessCondition(AccessCondition accessCondition) { - this.accessCondition = accessCondition; - } - - /** - * Gets the indexing directive (index, do not index etc). - * - * @return the indexing directive. - */ - public IndexingDirective getIndexingDirective() { - return this.indexingDirective; - } - - /** - * Sets the indexing directive (index, do not index etc). - * - * @param indexingDirective the indexing directive. - */ - public void setIndexingDirective(IndexingDirective indexingDirective) { - this.indexingDirective = indexingDirective; - } - - /** - * Gets the consistency level required for the request. - * - * @return the consistency level. - */ - public ConsistencyLevel getConsistencyLevel() { - return this.consistencyLevel; - } - - /** - * Sets the consistency level required for the request. - * - * @param consistencyLevel the consistency level. - */ - public void setConsistencyLevel(ConsistencyLevel consistencyLevel) { - this.consistencyLevel = consistencyLevel; - } - - /** - * Gets the token for use with session consistency. - * - * @return the session token. - */ - public String getSessionToken() { - return this.sessionToken; - } - - /** - * Sets the token for use with session consistency. - * - * @param sessionToken the session token. - */ - public void setSessionToken(String sessionToken) { - this.sessionToken = sessionToken; - } - - /** - * Gets the expiry time for resource token. Used when creating, updating, reading permission. - * - * @return the resource token expiry seconds. - */ - public Integer getResourceTokenExpirySeconds() { - return this.resourceTokenExpirySeconds; - } - - /** - * Sets the expiry time for resource token. Used when creating, updating, reading permission. - * - * @param resourceTokenExpirySeconds the resource token expiry seconds. - */ - public void setResourceTokenExpirySeconds(Integer resourceTokenExpirySeconds) { - this.resourceTokenExpirySeconds = resourceTokenExpirySeconds; - } - - /** - * Gets the offer type when creating a document collection. - * - * @return the offer type. - */ - public String getOfferType() { - return this.offerType; - } - - /** - * Sets the offer type when creating a document collection. - * - * @param offerType the offer type. - */ - public void setOfferType(String offerType) { - this.offerType = offerType; - } - - /** - * Gets the throughput in the form of Request Units per second when creating a document collection. - * - * @return the throughput value. - */ - public Integer getOfferThroughput() { - return this.offerThroughput; - } - - /** - * Sets the throughput in the form of Request Units per second when creating a document collection. - * - * @param offerThroughput the throughput value. - */ - public void setOfferThroughput(Integer offerThroughput) { - this.offerThroughput = offerThroughput; - } - - /** - * Gets the partition key used to identify the current request's target partition. - * - * @return the partition key value. - */ - public PartitionKey getPartitionKey() { - return this.partitionkey; - } - - /** - * Sets the partition key used to identify the current request's target partition. - * - * @param partitionkey the partition key value. - */ - public void setPartitionKey(PartitionKey partitionkey) { - this.partitionkey = partitionkey; - } - - /** - * Internal usage only: Gets the partition key range id used to identify the current request's target partition. - * - * @return the partition key range id value. - */ - String getPartitionKeyRangeId() { - return this.partitionKeyRangeId; - } - - /** - * Internal usage only: Sets the partition key range id used to identify the current request's target partition. - * - * @param partitionKeyRangeId the partition key range id value. - */ - protected void setPartitionKeyRengeId(String partitionKeyRangeId) { - this.partitionKeyRangeId = partitionKeyRangeId; - } - - /** - * Gets whether Javascript stored procedure logging is enabled for the current request in the Azure Cosmos DB database - * service or not. - * - * @return true if Javascript stored procedure logging is enabled - */ - public boolean isScriptLoggingEnabled() { - return scriptLoggingEnabled; - } - - /** - * Sets whether Javascript stored procedure logging is enabled for the current request in the Azure Cosmos DB database - * service or not. - * - * @param scriptLoggingEnabled true if stored procedure Javascript logging is enabled - */ - public void setScriptLoggingEnabled(boolean scriptLoggingEnabled) { - this.scriptLoggingEnabled = scriptLoggingEnabled; - } - - /** - * Gets the PopulateQuotaInfo setting for document collection read requests in the Azure Cosmos DB database service. - * PopulateQuotaInfo is used to enable/disable getting document collection quota related stats for document - * collection read requests. - * - * @return true if PopulateQuotaInfo is enabled - */ - public boolean isPopulateQuotaInfo() { - return populateQuotaInfo; - } - - /** - * Sets the PopulateQuotaInfo setting for document collection read requests in the Azure Cosmos DB database service. - * PopulateQuotaInfo is used to enable/disable getting document collection quota related stats for document - * collection read requests. - * - * @param populateQuotaInfo a boolean value indicating whether PopulateQuotaInfo is enabled or not - */ - public void setPopulateQuotaInfo(boolean populateQuotaInfo) { - this.populateQuotaInfo = populateQuotaInfo; - } - - /** - * Sets the custom request option value by key - * - * @param name a string representing the custom option's name - * @param value a String representing the custom option's value - */ - public void setHeader(String name, String value) { - if (this.customOptions == null) { - this.customOptions = new HashMap<>(); - } - this.customOptions.put(name, value); - } - - /** - * Gets the custom request options - * - * @return Map of custom request options - */ - public Map getHeaders() { - return this.customOptions; - } - /** - * Gets the properties - * - * @return Map of request options properties - */ - public Map getProperties() { - return properties; - } - - /** - * Sets the properties used to identify the request token. - * - * @param properties the properties. - */ - public void setProperties(Map properties) { - this.properties = properties; - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Resource.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Resource.java deleted file mode 100644 index eb84bf89a0b1..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Resource.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents the base resource in the Azure Cosmos DB database service. - */ -public class Resource extends JsonSerializable { - private String altLink; - - /** - * Copy constructor. - * @param resource resource to by copied. - */ - protected Resource(Resource resource) { - this.setId(resource.getId()); - this.setResourceId(resource.getResourceId()); - this.setSelfLink(resource.getSelfLink()); - this.setAltLink(resource.getAltLink()); - this.setTimestamp(resource.getTimestamp()); - this.setETag(resource.getETag()); - } - - /** - * Constructor. - */ - protected Resource() { - super(); - } - - /** - * Constructor. - * - * @param objectNode the {@link ObjectNode} that represent the {@link JsonSerializable} - */ - Resource(ObjectNode objectNode) { - super(objectNode); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the resource. - * @param objectMapper the custom object mapper - */ - protected Resource(String jsonString, ObjectMapper objectMapper) { - super(jsonString, objectMapper); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the resource. - */ - protected Resource(String jsonString) { - super(jsonString); - } - - /** - * Gets the name of the resource. - * - * @return the name of the resource. - */ - public String getId() { - return super.getString(Constants.Properties.ID); - } - - /** - * Sets the name of the resource. - * - * @param id the name of the resource. - */ - public void setId(String id) { - super.set(Constants.Properties.ID, id); - } - - /** - * Gets the ID associated with the resource. - * - * @return the ID associated with the resource. - */ - public String getResourceId() { - return super.getString(Constants.Properties.R_ID); - } - - /** - * Set the ID associated with the resource. - * - * @param resourceId the ID associated with the resource. - */ - public void setResourceId(String resourceId) { - super.set(Constants.Properties.R_ID, resourceId); - } - - /** - * Get the self-link associated with the resource. - * - * @return the self link. - */ - public String getSelfLink() { - return super.getString(Constants.Properties.SELF_LINK); - } - - /** - * Set the self-link associated with the resource. - * - * @param selfLink the self link. - */ - void setSelfLink(String selfLink) { - super.set(Constants.Properties.SELF_LINK, selfLink); - } - - /** - * Get the last modified timestamp associated with the resource. - * - * @return the timestamp. - */ - public Date getTimestamp() { - Double seconds = super.getDouble(Constants.Properties.LAST_MODIFIED); - if (seconds == null) return null; - return new Date(TimeUnit.SECONDS.toMillis(seconds.longValue())); - } - - /** - * Set the last modified timestamp associated with the resource. - * - * @param timestamp the timestamp. - */ - void setTimestamp(Date timestamp) { - double millisec = timestamp.getTime(); - super.set(Constants.Properties.LAST_MODIFIED, TimeUnit.MILLISECONDS.toSeconds((long) millisec)); - } - - /** - * Get the entity tag associated with the resource. - * - * @return the e tag. - */ - public String getETag() { - return super.getString(Constants.Properties.E_TAG); - } - - /** - * Set the self-link associated with the resource. - * - * @param eTag the e tag. - */ - void setETag(String eTag) { - super.set(Constants.Properties.E_TAG, eTag); - } - - /** - * Sets the alt-link associated with the resource from the Azure Cosmos DB service. - * @param altLink - */ - void setAltLink(String altLink) { - this.altLink = altLink; - } - - /** - * Gets the alt-link associated with the resource from the Azure Cosmos DB service. - */ - String getAltLink() { - return this.altLink; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ResourceResponse.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ResourceResponse.java deleted file mode 100644 index d92db7263700..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/ResourceResponse.java +++ /dev/null @@ -1,447 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; - -/** - * Represents the service response to a request made from DocumentClient in the Azure Cosmos DB database service. - * Contains both the resource and the response headers. - * - * @param the resource type of the resource response. - */ -public final class ResourceResponse { - private Class cls; - private T resource; - private RxDocumentServiceResponse response; - private Map usageHeaders; - private Map quotaHeaders; - - ResourceResponse(RxDocumentServiceResponse response, Class cls) { - this.response = response; - this.usageHeaders = new HashMap(); - this.quotaHeaders = new HashMap(); - this.cls = cls; - this.resource = this.response.getResource(this.cls); - } - - /** - * Max Quota. - * - * @return the database quota. - */ - public long getDatabaseQuota() { - return this.getMaxQuotaHeader(Constants.Quota.DATABASE); - } - - /** - * Current Usage. - * - * @return the current database usage. - */ - public long getDatabaseUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.DATABASE); - } - - /** - * Max Quota. - * - * @return the collection quota. - */ - public long getCollectionQuota() { - return this.getMaxQuotaHeader(Constants.Quota.COLLECTION); - } - - /** - * Current Usage. - * - * @return the current collection usage. - */ - public long getCollectionUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.COLLECTION); - } - - /** - * Max Quota. - * - * @return the user quota. - */ - public long getUserQuota() { - return this.getMaxQuotaHeader(Constants.Quota.USER); - } - - /** - * Current Usage. - * - * @return the current user usage. - */ - public long getUserUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.USER); - } - - /** - * Max Quota. - * - * @return the permission quota. - */ - public long getPermissionQuota() { - return this.getMaxQuotaHeader(Constants.Quota.PERMISSION); - } - - /** - * Current Usage. - * - * @return the current permission usage. - */ - public long getPermissionUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.PERMISSION); - } - - /** - * Max Quota. - * - * @return the collection size quota. - */ - public long getCollectionSizeQuota() { - return this.getMaxQuotaHeader(Constants.Quota.COLLECTION_SIZE); - } - - /** - * Current Usage. - * - * @return the collection size usage. - */ - public long getCollectionSizeUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.COLLECTION_SIZE); - } - - /** - * Max Quota. - * - * @return the document quota. - */ - public long getDocumentQuota() { - return this.getMaxQuotaHeader(Constants.Quota.DOCUMENTS_SIZE); - } - - /** - * Current Usage. - * - * @return the document usage. - */ - public long getDocumentUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.DOCUMENTS_SIZE); - } - - /** - * Max document count quota. - * - * @return the document count quota. - */ - public long getDocumentCountQuota() { - return this.getMaxQuotaHeader(Constants.Quota.DOCUMENTS_COUNT); - } - - /** - * Current document count usage. - * - * @return the document count usage. - */ - public long getDocumentCountUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.DOCUMENTS_COUNT); - } - - /** - * Max Quota. - * - * @return the stored procedures quota. - */ - public long getStoredProceduresQuota() { - return this.getMaxQuotaHeader(Constants.Quota.STORED_PROCEDURE); - } - - /** - * Current Usage. - * - * @return the current stored procedures usage. - */ - public long getStoredProceduresUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.STORED_PROCEDURE); - } - - /** - * Max Quota. - * - * @return the triggers quota. - */ - public long getTriggersQuota() { - return this.getMaxQuotaHeader(Constants.Quota.TRIGGER); - } - - /** - * Current Usage. - * - * @return the current triggers usage. - */ - public long getTriggersUsage() { - return this.getCurrentQuotaHeader(Constants.Quota.TRIGGER); - } - - /** - * Max Quota. - * - * @return the user defined functions quota. - */ - public long getUserDefinedFunctionsQuota() { - return this.getMaxQuotaHeader(Constants.Quota.USER_DEFINED_FUNCTION); - } - - /** - * Current Usage. - * - * @return the current user defined functions usage. - */ - public long getUserDefinedFunctionsUsage() { - return this.getCurrentQuotaHeader( - Constants.Quota.USER_DEFINED_FUNCTION); - } - - /** - * Gets the Activity ID for the request. - * - * @return the activity id. - */ - public String getActivityId() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.ACTIVITY_ID); - } - - /** - * Gets the token used for managing client's consistency requirements. - * - * @return the session token. - */ - public String getSessionToken() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - } - - /** - * Gets the HTTP status code associated with the response. - * - * @return the status code. - */ - public int getStatusCode() { - return this.response.getStatusCode(); - } - - /** - * Gets the maximum size limit for this entity (in megabytes (MB) for server resources and in count for master - * resources). - * - * @return the max resource quota. - */ - public String getMaxResourceQuota() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.MAX_RESOURCE_QUOTA); - } - - /** - * Gets the current size of this entity (in megabytes (MB) for server resources and in count for master resources) - * - * @return the current resource quota usage. - */ - public String getCurrentResourceQuotaUsage() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE); - } - - /** - * Gets the resource for the request. - * - * @return the resource. - */ - public T getResource() { - return this.resource; - } - - /** - * Gets the number of index paths (terms) generated by the operation. - * - * @return the request charge. - */ - public double getRequestCharge() { - String value = this.getResponseHeaders().get(HttpConstants.HttpHeaders.REQUEST_CHARGE); - if (StringUtils.isEmpty(value)) { - return 0; - } - return Double.valueOf(value); - } - - /** - * Gets the headers associated with the response. - * - * @return the response headers. - */ - public Map getResponseHeaders() { - return this.response.getResponseHeaders(); - } - - /** - * Gets the progress of an index transformation, if one is underway. - * - * @return the progress of an index transformation. - */ - public long getIndexTransformationProgress() { - String value = this.getResponseHeaders().get(HttpConstants.HttpHeaders.INDEX_TRANSFORMATION_PROGRESS); - if (StringUtils.isEmpty(value)) { - return -1; - } - return Long.parseLong(value); - } - - /** - * Gets the progress of lazy indexing. - * - * @return the progress of lazy indexing. - */ - public long getLazyIndexingProgress() { - String value = this.getResponseHeaders().get(HttpConstants.HttpHeaders.LAZY_INDEXING_PROGRESS); - if (StringUtils.isEmpty(value)) { - return -1; - } - return Long.parseLong(value); - } - - /** - * Gets the request statistics for the current request to Azure Cosmos DB service. - * - * @return request statistics for the current request to Azure Cosmos DB service. - */ - public ClientSideRequestStatistics getClientSideRequestStatistics() { - return this.response.getClientSideRequestStatistics(); - } - - /** - * Gets the end-to-end request latency for the current request to Azure Cosmos DB service. - * - * @return end-to-end request latency for the current request to Azure Cosmos DB service. - */ - public Duration getRequestLatency() { - ClientSideRequestStatistics clientSideRequestStatistics = this.response.getClientSideRequestStatistics(); - if (clientSideRequestStatistics == null) { - return Duration.ZERO; - } - - return clientSideRequestStatistics.getRequestLatency(); - } - - /** - * Gets the diagnostics information for the current request to Azure Cosmos DB service. - * - * @return diagnostics information for the current request to Azure Cosmos DB service. - */ - public String getRequestDiagnosticsString() { - ClientSideRequestStatistics clientSideRequestStatistics = this.response.getClientSideRequestStatistics(); - if (clientSideRequestStatistics == null) { - return StringUtils.EMPTY; - } - return clientSideRequestStatistics.toString(); - } - - long getCurrentQuotaHeader(String headerName) { - if (this.usageHeaders.size() == 0 && - !StringUtils.isEmpty(this.getMaxResourceQuota()) && - !StringUtils.isEmpty(this.getCurrentResourceQuotaUsage())) { - this.populateQuotaHeader(this.getMaxResourceQuota(), this.getCurrentResourceQuotaUsage()); - } - - if (this.usageHeaders.containsKey(headerName)) { - return this.usageHeaders.get(headerName); - } - - return 0; - } - - long getMaxQuotaHeader(String headerName) { - if (this.quotaHeaders.size() == 0 && - !StringUtils.isEmpty(this.getMaxResourceQuota()) && - !this.getCurrentResourceQuotaUsage().isEmpty()) { - this.populateQuotaHeader(this.getMaxResourceQuota(), this.getCurrentResourceQuotaUsage()); - } - - if (this.quotaHeaders.containsKey(headerName)) { - return this.quotaHeaders.get(headerName); - } - - return 0; - } - - private void populateQuotaHeader(String headerMaxQuota, String headerCurrentUsage) { - String[] headerMaxQuotaWords = headerMaxQuota.split(Constants.Quota.DELIMITER_CHARS, -1); - String[] headerCurrentUsageWords = headerCurrentUsage.split(Constants.Quota.DELIMITER_CHARS, -1); - - assert (headerMaxQuotaWords.length == headerCurrentUsageWords.length); - - for (int i = 0; i < headerMaxQuotaWords.length; ++i) { - if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.DATABASE)) { - this.quotaHeaders.put(Constants.Quota.DATABASE, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.DATABASE, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.COLLECTION)) { - this.quotaHeaders.put(Constants.Quota.COLLECTION, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.COLLECTION, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.USER)) { - this.quotaHeaders.put(Constants.Quota.USER, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.USER, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.PERMISSION)) { - this.quotaHeaders.put(Constants.Quota.PERMISSION, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.PERMISSION, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.COLLECTION_SIZE)) { - this.quotaHeaders.put(Constants.Quota.COLLECTION_SIZE, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.COLLECTION_SIZE, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.DOCUMENTS_SIZE)) { - this.quotaHeaders.put(Constants.Quota.DOCUMENTS_SIZE, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.DOCUMENTS_SIZE, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.STORED_PROCEDURE)) { - this.quotaHeaders.put(Constants.Quota.STORED_PROCEDURE, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.STORED_PROCEDURE, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.TRIGGER)) { - this.quotaHeaders.put(Constants.Quota.TRIGGER, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.TRIGGER, Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.USER_DEFINED_FUNCTION)) { - this.quotaHeaders.put(Constants.Quota.USER_DEFINED_FUNCTION, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.USER_DEFINED_FUNCTION, - Long.valueOf(headerCurrentUsageWords[i + 1])); - } else if (headerMaxQuotaWords[i].equalsIgnoreCase(Constants.Quota.DOCUMENTS_COUNT)) { - this.quotaHeaders.put(Constants.Quota.DOCUMENTS_COUNT, Long.valueOf(headerMaxQuotaWords[i + 1])); - this.usageHeaders.put(Constants.Quota.DOCUMENTS_COUNT, - Long.valueOf(headerCurrentUsageWords[i + 1])); - } - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RetryOptions.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RetryOptions.java deleted file mode 100644 index 2fb19427228c..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RetryOptions.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Encapsulates retry options in the Azure Cosmos DB database service. - */ -public class RetryOptions { - private int maxRetryAttemptsOnThrottledRequests; - private int maxRetryWaitTimeInSeconds; - - /** - * Creates a new instance of the RetryOptions class and initializes all - * properties to default values. - */ - public RetryOptions() { - this.maxRetryAttemptsOnThrottledRequests = 9; - this.maxRetryWaitTimeInSeconds = 30; - } - - /** - * Gets the maximum number of retries in the case where the request fails - * because the service has applied rate limiting on the client. - * - * @return the maximum number of retries. - */ - public int getMaxRetryAttemptsOnThrottledRequests() { - return this.maxRetryAttemptsOnThrottledRequests; - } - - /** - * Sets the maximum number of retries in the case where the request fails - * because the service has applied rate limiting on the client. - *

- * When a client is sending requests faster than the allowed rate, the - * service will return HttpStatusCode 429 (Too Many Request) to throttle the - * client. The current implementation in the SDK will then wait for the - * amount of time the service tells it to wait and retry after the time has - * elapsed. - *

- * The default value is 9. This means in the case where the request is - * throttled, the same request will be issued for a maximum of 10 times to - * the server before an error is returned to the application. - * - * @param maxRetryAttemptsOnThrottledRequests the max number of retry attempts on failed requests due to a - * throttle error. - */ - public void setMaxRetryAttemptsOnThrottledRequests(int maxRetryAttemptsOnThrottledRequests) { - if (maxRetryAttemptsOnThrottledRequests < 0) { - throw new IllegalArgumentException("maxRetryAttemptsOnThrottledRequests value must be a positive integer."); - } - - this.maxRetryAttemptsOnThrottledRequests = maxRetryAttemptsOnThrottledRequests; - } - - /** - * Gets the maximum retry time in seconds. - * - * @return the maximum retry time in seconds. - */ - public int getMaxRetryWaitTimeInSeconds() { - return this.maxRetryWaitTimeInSeconds; - } - - /** - * Sets the maximum retry time in seconds. - *

- * When a request fails due to a throttle error, the service sends back a - * response that contains a value indicating the client should not retry - * before the time period has elapsed (Retry-After). The MaxRetryWaitTime - * flag allows the application to set a maximum wait time for all retry - * attempts. If the cumulative wait time exceeds the MaxRetryWaitTime, the - * SDK will stop retrying and return the error to the application. - *

- * The default value is 30 seconds. - * - * @param maxRetryWaitTimeInSeconds the maximum number of seconds a request will be retried. - */ - public void setMaxRetryWaitTimeInSeconds(int maxRetryWaitTimeInSeconds) { - if (maxRetryWaitTimeInSeconds < 0 || maxRetryWaitTimeInSeconds > Integer.MAX_VALUE / 1000) { - throw new IllegalArgumentException( - "value must be a positive integer between the range of 0 to " + Integer.MAX_VALUE / 1000); - } - - this.maxRetryWaitTimeInSeconds = maxRetryWaitTimeInSeconds; - } - - @Override - public String toString() { - return "RetryOptions{" + - "maxRetryAttemptsOnThrottledRequests=" + maxRetryAttemptsOnThrottledRequests + - ", maxRetryWaitTimeInSeconds=" + maxRetryWaitTimeInSeconds + - '}'; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RuntimeExecutionTimes.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RuntimeExecutionTimes.java deleted file mode 100644 index 0beb503a80ab..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/RuntimeExecutionTimes.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import java.time.Duration; -import java.util.Collection; -import java.util.HashMap; - -/** - * Query runtime execution times in the Azure Cosmos DB service. - */ -public final class RuntimeExecutionTimes { - - static final RuntimeExecutionTimes ZERO = new RuntimeExecutionTimes(Duration.ZERO, Duration.ZERO, Duration.ZERO); - - private final Duration queryEngineExecutionTime; - private final Duration systemFunctionExecutionTime; - private final Duration userDefinedFunctionExecutionTime; - - /** - * @param queryEngineExecutionTime - * @param systemFunctionExecutionTime - * @param userDefinedFunctionExecutionTime - */ - RuntimeExecutionTimes(Duration queryEngineExecutionTime, Duration systemFunctionExecutionTime, - Duration userDefinedFunctionExecutionTime) { - super(); - - if (queryEngineExecutionTime == null) { - throw new NullPointerException("queryEngineExecutionTime"); - } - - if (systemFunctionExecutionTime == null) { - throw new NullPointerException("systemFunctionExecutionTime"); - } - - if (userDefinedFunctionExecutionTime == null) { - throw new NullPointerException("userDefinedFunctionExecutionTime"); - } - - this.queryEngineExecutionTime = queryEngineExecutionTime; - this.systemFunctionExecutionTime = systemFunctionExecutionTime; - this.userDefinedFunctionExecutionTime = userDefinedFunctionExecutionTime; - } - - /** - * @return the queryEngineExecutionTime - */ - public Duration getQueryEngineExecutionTime() { - return queryEngineExecutionTime; - } - - /** - * @return the systemFunctionExecutionTime - */ - public Duration getSystemFunctionExecutionTime() { - return systemFunctionExecutionTime; - } - - /** - * @return the userDefinedFunctionExecutionTime - */ - public Duration getUserDefinedFunctionExecutionTime() { - return userDefinedFunctionExecutionTime; - } - - static RuntimeExecutionTimes createFromCollection( - Collection runtimeExecutionTimesCollection) { - if (runtimeExecutionTimesCollection == null) { - throw new NullPointerException("runtimeExecutionTimesCollection"); - } - - Duration queryEngineExecutionTime = Duration.ZERO; - Duration systemFunctionExecutionTime = Duration.ZERO; - Duration userDefinedFunctionExecutionTime = Duration.ZERO; - - for (RuntimeExecutionTimes runtimeExecutionTime : runtimeExecutionTimesCollection) { - queryEngineExecutionTime = queryEngineExecutionTime.plus(runtimeExecutionTime.queryEngineExecutionTime); - systemFunctionExecutionTime = systemFunctionExecutionTime.plus(runtimeExecutionTime.systemFunctionExecutionTime); - userDefinedFunctionExecutionTime = userDefinedFunctionExecutionTime.plus(runtimeExecutionTime.userDefinedFunctionExecutionTime); - } - - return new RuntimeExecutionTimes( - queryEngineExecutionTime, - systemFunctionExecutionTime, - userDefinedFunctionExecutionTime); - } - - static RuntimeExecutionTimes createFromDelimitedString(String delimitedString) { - HashMap metrics = QueryMetricsUtils.parseDelimitedString(delimitedString); - - Duration vmExecutionTime = QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.VMExecutionTimeInMs); - Duration indexLookupTime = QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.IndexLookupTimeInMs); - Duration documentLoadTime = QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.DocumentLoadTimeInMs); - Duration documentWriteTime = QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.DocumentWriteTimeInMs); - - return new RuntimeExecutionTimes( - vmExecutionTime.minus(indexLookupTime).minus(documentLoadTime).minus(documentWriteTime), - QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.SystemFunctionExecuteTimeInMs), - QueryMetricsUtils.durationFromMetrics(metrics, QueryMetricsConstants.UserDefinedFunctionExecutionTimeInMs)); - } - - String toDelimitedString() { - String formatString = "%s=%2f;%s=%2f"; - - // queryEngineExecutionTime is not emitted, since it is calculated as - // vmExecutionTime - indexLookupTime - documentLoadTime - documentWriteTime - return String.format( - formatString, - QueryMetricsConstants.SystemFunctionExecuteTimeInMs, - this.systemFunctionExecutionTime.toMillis(), - QueryMetricsConstants.UserDefinedFunctionExecutionTimeInMs, - this.userDefinedFunctionExecutionTime.toMillis()); - } - - String toTextString(int indentLevel) { - if (indentLevel == Integer.MAX_VALUE) { - throw new NumberFormatException("indentLevel input must be less than Int32.MaxValue"); - } - StringBuilder stringBuilder = new StringBuilder(); - - QueryMetricsUtils.appendHeaderToStringBuilder(stringBuilder, QueryMetricsConstants.RuntimeExecutionTimesText, - indentLevel); - - QueryMetricsUtils.appendNanosecondsToStringBuilder(stringBuilder, - QueryMetricsConstants.TotalExecutionTimeText, this.queryEngineExecutionTime.toNanos(), - indentLevel + 1); - - QueryMetricsUtils.appendNanosecondsToStringBuilder(stringBuilder, - QueryMetricsConstants.SystemFunctionExecuteTimeText, - this.systemFunctionExecutionTime.toNanos(), indentLevel + 1); - - QueryMetricsUtils.appendNanosecondsToStringBuilder(stringBuilder, - QueryMetricsConstants.UserDefinedFunctionExecutionTimeText, - this.userDefinedFunctionExecutionTime.toNanos(), indentLevel + 1); - - return stringBuilder.toString(); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SerializationFormattingPolicy.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SerializationFormattingPolicy.java deleted file mode 100644 index bd753f5e394c..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SerializationFormattingPolicy.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * The formatting policy associated with JSON serialization in the Azure Cosmos DB database service. - */ -public enum SerializationFormattingPolicy { - - /** - * No additional formatting required. - */ - None, - - /** - * Indent the fields appropriately. - */ - Indented -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialIndex.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialIndex.java deleted file mode 100644 index a263640bcb3d..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialIndex.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.text.WordUtils; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a spatial index in the Azure Cosmos DB database service. - */ -public final class SpatialIndex extends Index { - - /** - * Initializes a new instance of the SpatialIndex class. - *

- * Here is an example to instantiate SpatialIndex class passing in the DataType - *

-     * {@code
-     *
-     * SpatialIndex spatialIndex = new SpatialIndex(DataType.Point);
-     *
-     * }
-     * 
- * - * @param dataType specifies the target data type for the index path specification. - */ - public SpatialIndex(DataType dataType) { - super(IndexKind.Spatial); - this.setDataType(dataType); - } - - /** - * Initializes a new instance of the SpatialIndex class. - * - * @param jsonString the json string that represents the index. - */ - public SpatialIndex(String jsonString) { - super(jsonString, IndexKind.Spatial); - if (this.getDataType() == null) { - throw new IllegalArgumentException("The jsonString doesn't contain a valid 'dataType'."); - } - } - - /** - * Gets data type. - * - * @return the data type. - */ - public DataType getDataType() { - DataType result = null; - try { - result = DataType.valueOf(WordUtils.capitalize(super.getString(Constants.Properties.DATA_TYPE))); - } catch (IllegalArgumentException e) { - this.getLogger().warn("Invalid index dataType value {}.", super.getString(Constants.Properties.DATA_TYPE)); - } - return result; - } - - /** - * Sets data type. - * - * @param dataType the data type. - */ - public void setDataType(DataType dataType) { - super.set(Constants.Properties.DATA_TYPE, dataType.name()); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialSpec.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialSpec.java deleted file mode 100644 index 828bd0895699..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialSpec.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.ArrayList; -import java.util.Collection; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -public class SpatialSpec extends JsonSerializable { - - private Collection spatialTypes; - - /** - * Constructor. - */ - public SpatialSpec() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the included path. - */ - public SpatialSpec(String jsonString) { - super(jsonString); - } - - - /** - * Gets path. - * - * @return the path. - */ - public String getPath() { - return super.getString(Constants.Properties.PATH); - } - - /** - * Sets path. - * - * @param path the path. - */ - public void setPath(String path) { - super.set(Constants.Properties.PATH, path); - } - - /** - * Gets the collection of spatial types. - * - * @return the collection of spatial types. - */ - public Collection getSpatialTypes() { - if (this.spatialTypes == null) { - this.spatialTypes = super.getCollection(Constants.Properties.TYPES, SpatialType.class); - - if (this.spatialTypes == null) { - this.spatialTypes = new ArrayList(); - } - } - - return this.spatialTypes; - } - - /** - * Sets the collection of spatial types. - * - * @param spatialTypes the collection of spatial types. - */ - public void setSpatialTypes(Collection spatialTypes) { - this.spatialTypes = spatialTypes; - Collection spatialTypeNames = new ArrayList(); - for (SpatialType spatialType : this.spatialTypes) { - spatialTypeNames.add(spatialType.name()); - } - super.set(Constants.Properties.TYPES, spatialTypeNames); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialType.java deleted file mode 100644 index 23ddd664f872..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SpatialType.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Defines the target data type of an index path specification in the Azure Cosmos DB service. - * - */ -public enum SpatialType { - /** - * Represent a point data type. - */ - Point, - - /** - * Represent a line string data type. - */ - LineString, - - /** - * Represent a polygon data type. - */ - Polygon, - - /** - * Represent a multi-polygon data type. - */ - MultiPolygon -} - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlParameter.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlParameter.java deleted file mode 100644 index 6d6018f04e33..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlParameter.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Represents a SQL parameter in the SqlQuerySpec used for queries in the Azure Cosmos DB database service. - */ -public final class SqlParameter extends JsonSerializable { - - - /** - * Initializes a new instance of the SqlParameter class. - */ - public SqlParameter() { - super(); - } - - /** - * Initializes a new instance of the SqlParameter class with the name and value of the parameter. - * - * @param name the name of the parameter. - * @param value the value of the parameter. - */ - public SqlParameter(String name, Object value) { - super(); - this.setName(name); - this.setValue(value); - } - - /** - * Gets the name of the parameter. - * - * @return the name of the parameter. - */ - public String getName() { - return super.getString("name"); - } - - /** - * Sets the name of the parameter. - * - * @param name the name of the parameter. - */ - public void setName(String name) { - super.set("name", name); - } - - /** - * Gets the value of the parameter. - * - * @param c the class of the parameter value. - * @param the type of the parameter - * @return the value of the parameter. - */ - public Object getValue(Class c) { - return super.getObject("value", c); - } - - /** - * Sets the value of the parameter. - * - * @param value the value of the parameter. - */ - public void setValue(Object value) { - super.set("value", value); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlParameterCollection.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlParameterCollection.java deleted file mode 100644 index 8d7a5bcbe8ac..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlParameterCollection.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * Represents a collection of SQL parameters to for a SQL query in the Azure Cosmos DB database service. - */ -public final class SqlParameterCollection implements Collection { - - private List parameters; - - /** - * Initializes a new instance of the SqlParameterCollection class. - */ - public SqlParameterCollection() { - this.parameters = new ArrayList(); - } - - /** - * Initializes a new instance of the SqlParameterCollection class from an array of parameters. - * - * @param parameters the array of parameters. - */ - public SqlParameterCollection(SqlParameter... parameters) { - if (parameters == null) { - throw new IllegalArgumentException("parameters"); - } - - this.parameters = Arrays.asList(parameters); - } - - /** - * Initializes a new instance of the SqlParameterCollection class from a collection of parameters. - * - * @param parameters the collection of parameters. - */ - public SqlParameterCollection(Collection parameters) { - if (parameters == null) { - throw new IllegalArgumentException("parameters"); - } - - this.parameters = new ArrayList(parameters); - } - - @Override - public boolean add(SqlParameter parameter) { - return this.parameters.add(parameter); - } - - @Override - public boolean addAll(Collection parameters) { - return this.parameters.addAll(parameters); - } - - @Override - public void clear() { - this.parameters.clear(); - } - - @Override - public boolean contains(Object parameter) { - return this.parameters.contains(parameter); - } - - @Override - public boolean containsAll(Collection parameters) { - return this.parameters.containsAll(parameters); - } - - @Override - public boolean isEmpty() { - return this.parameters.isEmpty(); - } - - @Override - public Iterator iterator() { - return this.parameters.iterator(); - } - - @Override - public boolean remove(Object parameter) { - return this.parameters.remove(parameter); - } - - @Override - public boolean removeAll(Collection parameters) { - return this.parameters.removeAll(parameters); - } - - @Override - public boolean retainAll(Collection parameters) { - return this.parameters.retainAll(parameters); - } - - @Override - public int size() { - return this.parameters.size(); - } - - @Override - public Object[] toArray() { - return this.parameters.toArray(); - } - - @Override - public T[] toArray(T[] parameters) { - return this.parameters.toArray(parameters); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlQuerySpec.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlQuerySpec.java deleted file mode 100644 index a73f3112c83a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/SqlQuerySpec.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * Represents a SQL query in the Azure Cosmos DB database service. - */ -public final class SqlQuerySpec extends JsonSerializable { - - private SqlParameterCollection parameters; - - /** - * Initializes a new instance of the SqlQuerySpec class. - */ - public SqlQuerySpec() { - super(); - } - - /** - * Initializes a new instance of the SqlQuerySpec class with the text of the - * query. - * - * @param queryText - * the query text. - */ - public SqlQuerySpec(String queryText) { - super(); - this.setQueryText(queryText); - } - - /** - * Initializes a new instance of the SqlQuerySpec class with the text of the - * query and parameters. - * - * @param queryText the query text. - * @param parameters the query parameters. - */ - public SqlQuerySpec(String queryText, SqlParameterCollection parameters) { - super(); - this.setQueryText(queryText); - this.parameters = parameters; - } - - /** - * Gets the text of the query. - * - * @return the query text. - */ - public String getQueryText() { - return super.getString("query"); - } - - /** - * Sets the text of the query. - * - * @param queryText - * the query text. - */ - public void setQueryText(String queryText) { - super.set("query", queryText); - } - - /** - * Gets the collection of query parameters. - * - * @return the query parameters. - */ - public SqlParameterCollection getParameters() { - if (this.parameters == null) { - Collection sqlParameters = super.getCollection("parameters", SqlParameter.class); - if (sqlParameters == null) { - sqlParameters = new ArrayList(); - } - - this.parameters = new SqlParameterCollection(sqlParameters); - } - - return this.parameters; - } - - /** - * Sets the collection of query parameters. - * - * @param parameters - * the query parameters. - */ - public void setParameters(SqlParameterCollection parameters) { - this.parameters = parameters; - } - - @Override - void populatePropertyBag() { - boolean defaultParameters = (this.parameters != null && this.parameters.size() != 0); - - if (defaultParameters) { - super.set("parameters", this.parameters); - } else { - super.remove("parameters"); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/StoredProcedure.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/StoredProcedure.java deleted file mode 100644 index 0972ca2f57a7..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/StoredProcedure.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a stored procedure in the Azure Cosmos DB database service. - *

- * Cosmos DB allows stored procedures to be executed in the storage tier, directly against a document collection. The - * script gets executed under ACID transactions on the primary storage partition of the specified collection. For - * additional details, refer to the server-side JavaScript API documentation. - */ -public class StoredProcedure extends Resource { - - /** - * Constructor. - */ - public StoredProcedure() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the stored procedure. - */ - public StoredProcedure(String jsonString) { - super(jsonString); - } - - /** - * Get the body of the stored procedure. - * - * @return the body of the stored procedure. - */ - public String getBody() { - return super.getString(Constants.Properties.BODY); - } - - /** - * Set the body of the stored procedure. - * - * @param body the body of the stored procedure. - */ - public void setBody(String body) { - super.set(Constants.Properties.BODY, body); - } -} - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/StoredProcedureResponse.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/StoredProcedureResponse.java deleted file mode 100644 index ea358de0d579..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/StoredProcedureResponse.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.Map; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; - -/** - * Represents the response returned from a stored procedure in the Azure Cosmos DB database service. - * Wraps the response body and headers. - */ -public final class StoredProcedureResponse { - private final static Logger logger = LoggerFactory.getLogger(StoredProcedureResponse.class); - private final RxDocumentServiceResponse response; - - /** - * Constructs StoredProcedureResponse. - * - * @param response the document service response. - */ - StoredProcedureResponse(RxDocumentServiceResponse response) { - this.response = response; - } - - /** - * Gets the Activity ID of the request. - * - * @return the activity id. - */ - public String getActivityId() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.ACTIVITY_ID); - } - - /** - * Gets the token for use with session consistency requests. - * - * @return the session token. - */ - public String getSessionToken() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - } - - /** - * Gets the request completion status code. - * - * @return the status code. - */ - public int getStatusCode() { - return this.response.getStatusCode(); - } - - /** - * Gets the maximum size limit for this entity (in megabytes (MB) for server resources and in count for master - * resources). - * - * @return the max resource quota. - */ - public String getMaxResourceQuota() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.MAX_RESOURCE_QUOTA); - } - - /** - * Gets the current size of this entity (in megabytes (MB) for server resources and in count for master resources) - * - * @return the current resource quota usage. - */ - public String getCurrentResourceQuotaUsage() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE); - } - - /** - * Gets the number of normalized requests charged. - * - * @return the request charge. - */ - public double getRequestCharge() { - String value = this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.REQUEST_CHARGE); - try { - return Double.valueOf(value); - } catch (NumberFormatException e) { - logger.warn("Invalid x-ms-request-charge value {}.", value); - return 0; - } - } - - /** - * Gets the headers associated with the response. - * - * @return the response headers. - */ - public Map getResponseHeaders() { - return this.response.getResponseHeaders(); - } - - /** - * Gets the response of a stored procedure, serialized into a document. - * - * @return the response as a document. - */ - public Document getResponseAsDocument() { - return this.response.getResource(Document.class); - } - - /** - * Gets the response of a stored procedure, serialized into an attachment. - * - * @return the response as an attachment. - */ - public Attachment getResponseAsAttachment() { - return this.response.getResource(Attachment.class); - } - - /** - * Gets the response of a stored procedure as a string. - * - * @return the response as a string. - */ - public String getResponseAsString() { - return this.response.getReponseBodyAsString(); - } - - /** - * Gets the output from stored procedure console.log() statements. - * - * @return the output string from the stored procedure console.log() statements. - */ - public String getScriptLog() { - return this.response.getResponseHeaders().get(HttpConstants.HttpHeaders.SCRIPT_LOG_RESULTS); - } - - /** - * Gets the client side request statics for execution of stored procedure. - * - * @return client side request statistics for execution of stored procedure. - */ - public ClientSideRequestStatistics getClientSideRequestStatistics() { - return this.response.getClientSideRequestStatistics(); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TokenResolver.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TokenResolver.java deleted file mode 100644 index 363626a557ff..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TokenResolver.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.Map; - -/** - * This interface is for client side implementation, which can be used for initializing - * AsyncDocumentClient without passing master key, resource token and permission feed.
- *
- * Each time the SDK create request for CosmosDB, authorization token is generated based on that - * request at client side which enables creation of one AsyncDocumentClient per application shared across various users - * with different resource permissions. - */ -@FunctionalInterface -public interface TokenResolver { - - /** - * This method will consume the request information and based on that it will generate the authorization token. - * @param properties the user properties. - * @param requestVerb Request verb i.e. GET, POST, PUT etc. - * @param resourceIdOrFullName ResourceID or resource full name. - * @param resourceType Resource type i.e. Database, DocumentCollection, Document etc. - * @return The authorization token. - */ - public String getAuthorizationToken(String requestVerb, String resourceIdOrFullName, CosmosResourceType resourceType, Map properties); - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Trigger.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Trigger.java deleted file mode 100644 index 2b71da26710f..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Trigger.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.text.WordUtils; -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a trigger in the Azure Cosmos DB database service. - *

- * Cosmos DB supports pre and post triggers defined in JavaScript to be executed on creates, updates and deletes. For - * additional details, refer to the server-side JavaScript API documentation. - */ -public class Trigger extends Resource { - - /** - * Constructor. - */ - public Trigger() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the trigger. - */ - public Trigger(String jsonString) { - super(jsonString); - } - - /** - * Get the body of the trigger. - * - * @return the body of the trigger. - */ - public String getBody() { - return super.getString(Constants.Properties.BODY); - } - - /** - * Set the body of the trigger. - * - * @param body the body of the trigger. - */ - public void setBody(String body) { - super.set(Constants.Properties.BODY, body); - } - - /** - * Get the type of the trigger. - * - * @return the trigger type. - */ - public TriggerType getTriggerType() { - TriggerType result = TriggerType.Pre; - try { - result = TriggerType.valueOf( - WordUtils.capitalize(super.getString(Constants.Properties.TRIGGER_TYPE))); - } catch (IllegalArgumentException e) { - // ignore the exception and return the default - this.getLogger().warn("Invalid triggerType value {}.", super.getString(Constants.Properties.TRIGGER_TYPE)); - } - return result; - } - - /** - * Set the type of the resource. - * - * @param triggerType the trigger type. - */ - public void setTriggerType(TriggerType triggerType) { - super.set(Constants.Properties.TRIGGER_TYPE, triggerType.name()); - } - - /** - * Get the operation type of the trigger. - * - * @return the trigger operation. - */ - public TriggerOperation getTriggerOperation() { - TriggerOperation result = TriggerOperation.Create; - try { - result = TriggerOperation.valueOf( - WordUtils.capitalize(super.getString(Constants.Properties.TRIGGER_OPERATION))); - } catch (IllegalArgumentException e) { - // ignore the exception and return the default - this.getLogger().warn("Invalid triggerOperation value {}.", super.getString(Constants.Properties.TRIGGER_OPERATION)); - } - return result; - } - - /** - * Set the operation type of the trigger. - * - * @param triggerOperation the trigger operation. - */ - public void setTriggerOperation(TriggerOperation triggerOperation) { - super.set(Constants.Properties.TRIGGER_OPERATION, triggerOperation.name()); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TriggerOperation.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TriggerOperation.java deleted file mode 100644 index 084250371a94..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TriggerOperation.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Specifies the operations on which a trigger should be executed in the Azure Cosmos DB database service. - */ -public enum TriggerOperation { - /** - * All operations. - */ - All(0x0), - - /** - * Create operations only. - */ - Create(0x1), - - /** - * Update operations only. - */ - Update(0x2), - - /** - * Delete operations only. - */ - Delete(0x3), - - /** - * Replace operations only. - */ - Replace(0x4); - - private int value; - - TriggerOperation(int value) { - this.value = value; - } - - /** - * Gets the numerical value of the trigger operation. - * - * @return the numerical value. - */ - public int getValue() { - return value; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TriggerType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TriggerType.java deleted file mode 100644 index 9f46d79cd916..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/TriggerType.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * The trigger type in the Azure Cosmos DB database service. - */ -public enum TriggerType { - /** - * Trigger should be executed before the associated operation(s). - */ - Pre(0x0), - - /** - * Trigger should be executed after the associated operation(s). - */ - Post(0x1); - - private int value; - - TriggerType(int value) { - this.value = value; - } - - /** - * Gets the numerical value of the trigger type. - * - * @return the numerical value. - */ - public int getValue() { - return value; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Undefined.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Undefined.java deleted file mode 100644 index ceb3fc06bb04..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/Undefined.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -/** - * Represents the 'Undefined' partition key in the Azure Cosmos DB database service. - */ -public class Undefined extends JsonSerializable { - - private final static Undefined value = new Undefined(); - - /** - * Constructor. Create a new instance of the Undefined object. - */ - private Undefined() { - } - - /** - * Returns the singleton value of Undefined. - * - * @return the Undefined value - */ - public static Undefined Value() { - return value; - } - - /** - * Returns the string representation of Undfined. - */ - public String toString() { - return "{}"; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UniqueKey.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UniqueKey.java deleted file mode 100644 index 7a60410c8fbe..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UniqueKey.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2016 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import java.util.ArrayList; -import java.util.Collection; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a unique key on that enforces uniqueness constraint on documents in the collection in the Azure Cosmos DB service. - * - * 1) For partitioned collections, the value of partition key is implicitly a part of each unique key. - * 2) Uniqueness constraint is also enforced for missing values. - * For instance, if unique key policy defines a unique key with single property path, there could be only one document that has missing value for this property. - * @see UniqueKeyPolicy - */ -public class UniqueKey extends JsonSerializable { - private Collection paths; - - public UniqueKey() { - super(); - } - - public UniqueKey(String jsonString) { - super(jsonString); - } - - /** - * Gets the paths, a set of which must be unique for each document in the Azure Cosmos DB service. - * - * The paths to enforce uniqueness on. Each path is a rooted path of the unique property in the document, - * such as "/name/first". - * - * @return the unique paths. - */ - public Collection getPaths() { - if (this.paths == null) { - this.paths = super.getCollection(Constants.Properties.PATHS, String.class); - - if (this.paths == null) { - this.paths = new ArrayList(); - } - } - - return this.paths; - } - - - /** - * Sets the paths, a set of which must be unique for each document in the Azure Cosmos DB service. - * - * The paths to enforce uniqueness on. Each path is a rooted path of the unique property in the document, - * such as "/name/first". - * - * @param paths the unique paths. - */ - public void setPaths(Collection paths) { - this.paths = paths; - } - - @Override - void populatePropertyBag() { - if (paths != null) { - super.set(Constants.Properties.PATHS, paths); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UniqueKeyPolicy.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UniqueKeyPolicy.java deleted file mode 100644 index 26e5983eaf77..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UniqueKeyPolicy.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import java.util.ArrayList; -import java.util.Collection; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents the unique key policy configuration for specifying uniqueness constraints on documents in the - * collection in the Azure Cosmos DB service. - */ -public class UniqueKeyPolicy extends JsonSerializable { - private Collection uniqueKeys; - - public UniqueKeyPolicy() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the Unique Key policy. - */ - public UniqueKeyPolicy(String jsonString) { - super(jsonString); - } - - /** - * Gets or sets collection of {@link UniqueKey} that guarantee uniqueness of documents in collection - * in the Azure Cosmos DB service. - * - * @return the unique keys. - */ - public Collection getUniqueKeys() { - if (this.uniqueKeys == null) { - this.uniqueKeys = super.getCollection(Constants.Properties.UNIQUE_KEYS, UniqueKey.class); - if (this.uniqueKeys == null) { - this.uniqueKeys = new ArrayList<>(); - } - } - return this.uniqueKeys; - } - - public void setUniqueKeys(Collection uniqueKeys) { - if (uniqueKeys == null) { - throw new IllegalArgumentException("uniqueKeys cannot be null."); - } - this.uniqueKeys = uniqueKeys; - } - - @Override - void populatePropertyBag() { - if (this.uniqueKeys != null) { - for(UniqueKey uniqueKey: uniqueKeys) { - uniqueKey.populatePropertyBag(); - } - super.set(Constants.Properties.UNIQUE_KEYS, uniqueKeys); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/User.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/User.java deleted file mode 100644 index f3a0137051e0..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/User.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a database user in the Azure Cosmos DB database service. - */ -public class User extends Resource { - - /** - * Initialize a user object. - */ - public User() { - super(); - } - - /** - * Initialize a user object from json string. - * - * @param jsonString the json string that represents the database user. - */ - public User(String jsonString) { - super(jsonString); - } - - /** - * Gets the self-link of the permissions associated with the user. - * - * @return the permissions link. - */ - public String getPermissionsLink() { - String selfLink = this.getSelfLink(); - if (selfLink.endsWith("/")) { - return selfLink + super.getString(Constants.Properties.PERMISSIONS_LINK); - } else { - return selfLink + "/" + super.getString(Constants.Properties.PERMISSIONS_LINK); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UserDefinedFunction.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UserDefinedFunction.java deleted file mode 100644 index 7cfb585ead3e..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/UserDefinedFunction.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Represents a user defined function in the Azure Cosmos DB database service. - *

- * Cosmos DB supports JavaScript UDFs which can be used inside queries, stored procedures and triggers. For additional - * details, refer to the server-side JavaScript API documentation. - */ -public class UserDefinedFunction extends Resource { - - /** - * Constructor. - */ - public UserDefinedFunction() { - super(); - } - - /** - * Constructor. - * - * @param jsonString the json string that represents the user defined function. - */ - public UserDefinedFunction(String jsonString) { - super(jsonString); - } - - /** - * Get the body of the user defined function. - * - * @return the body. - */ - public String getBody() { - return super.getString(Constants.Properties.BODY); - } - - /** - * Set the body of the user defined function. - * - * @param body the body. - */ - public void setBody(String body) { - super.set(Constants.Properties.BODY, body); - } -} - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Bytes.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Bytes.java deleted file mode 100644 index 9220f79f73a5..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Bytes.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - - -public class Bytes { - - public static void reverse(byte[] bytes, int offset, int endIndex) { - for(int i = offset, j = endIndex - 1; i < j; --j, i++) { - byte aux = bytes[i]; - bytes[i] = bytes[j]; - bytes[j] = aux; - } - } - - public static void reverse(byte[] bytes) { - Bytes.reverse(bytes, 0, bytes.length); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Constants.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Constants.java deleted file mode 100644 index 6ae4ca51597a..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Constants.java +++ /dev/null @@ -1,223 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Used internally. Constants in the Azure Cosmos DB database service Java SDK. - */ -public final class Constants { - - public static final class Quota { - // Quota Strings - public static final String DATABASE = "databases"; - public static final String COLLECTION = "collections"; - public static final String USER = "users"; - public static final String PERMISSION = "permissions"; - public static final String COLLECTION_SIZE = "collectionSize"; - public static final String DOCUMENTS_SIZE = "documentsSize"; - public static final String STORED_PROCEDURE = "storedProcedures"; - public static final String TRIGGER = "triggers"; - public static final String USER_DEFINED_FUNCTION = "functions"; - public static final String DELIMITER_CHARS = "=|;"; - public static final String DOCUMENTS_COUNT = "documentsCount"; - } - - public static final class Properties { - public static final String ID = "id"; - public static final String R_ID = "_rid"; - public static final String SELF_LINK = "_self"; - public static final String LAST_MODIFIED = "_ts"; - public static final String COUNT = "_count"; - public static final String E_TAG = "_etag"; - public static final String AGGREGATE = "_aggregate"; - - public static final String CONSISTENCY_POLICY = "consistencyPolicy"; - public static final String DEFAULT_CONSISTENCY_LEVEL = "defaultConsistencyLevel"; - public static final String MAX_STALENESS_PREFIX = "maxStalenessPrefix"; - public static final String MAX_STALENESS_INTERVAL_IN_SECONDS = "maxIntervalInSeconds"; - public static final String PARENTS = "parents"; - - public static final String DATABASES_LINK = "_dbs"; - public static final String COLLECTIONS_LINK = "_colls"; - public static final String USERS_LINK = "_users"; - public static final String PERMISSIONS_LINK = "_permissions"; - public static final String ATTACHMENTS_LINK = "_attachments"; - public static final String STORED_PROCEDURES_LINK = "_sprocs"; - public static final String TRIGGERS_LINK = "_triggers"; - public static final String USER_DEFINED_FUNCTIONS_LINK = "_udfs"; - public static final String CONFLICTS_LINK = "_conflicts"; - public static final String DOCUMENTS_LINK = "_docs"; - public static final String RESOURCE_LINK = "resource"; - public static final String MEDIA_LINK = "media"; - - public static final String PERMISSION_MODE = "permissionMode"; - public static final String RESOURCE_KEY = "key"; - public static final String TOKEN = "_token"; - public static final String SQL_API_TYPE = "0x10"; - - // Scripting - public static final String BODY = "body"; - public static final String TRIGGER_TYPE = "triggerType"; - public static final String TRIGGER_OPERATION = "triggerOperation"; - - public static final String MAX_SIZE = "maxSize"; - public static final String CURRENT_USAGE = "currentUsage"; - - public static final String CONTENT = "content"; - - public static final String CONTENT_TYPE = "contentType"; - - // ErrorResource. - public static final String CODE = "code"; - public static final String MESSAGE = "message"; - public static final String ERROR_DETAILS = "errorDetails"; - public static final String ADDITIONAL_ERROR_INFO = "additionalErrorInfo"; - - // PartitionInfo. - public static final String RESOURCE_TYPE = "resourceType"; - public static final String SERVICE_INDEX = "serviceIndex"; - public static final String PARTITION_INDEX = "partitionIndex"; - - public static final String ADDRESS_LINK = "addresses"; - public static final String USER_REPLICATION_POLICY = "userReplicationPolicy"; - public static final String USER_CONSISTENCY_POLICY = "userConsistencyPolicy"; - public static final String SYSTEM_REPLICATION_POLICY = "systemReplicationPolicy"; - public static final String READ_POLICY = "readPolicy"; - public static final String QUERY_ENGINE_CONFIGURATION = "queryEngineConfiguration"; - - //ReplicationPolicy - public static final String REPLICATION_POLICY = "replicationPolicy"; - public static final String ASYNC_REPLICATION = "asyncReplication"; - public static final String MAX_REPLICA_SET_SIZE = "maxReplicasetSize"; - public static final String MIN_REPLICA_SET_SIZE = "minReplicaSetSize"; - - //Indexing Policy. - public static final String INDEXING_POLICY = "indexingPolicy"; - public static final String AUTOMATIC = "automatic"; - public static final String STRING_PRECISION = "StringPrecision"; - public static final String NUMERIC_PRECISION = "NumericPrecision"; - public static final String MAX_PATH_DEPTH = "maxPathDepth"; - public static final String INDEXING_MODE = "indexingMode"; - public static final String INDEX_TYPE = "IndexType"; - public static final String INDEX_KIND = "kind"; - public static final String DATA_TYPE = "dataType"; - public static final String PRECISION = "precision"; - - public static final String PATHS = "paths"; - public static final String PATH = "path"; - public static final String INCLUDED_PATHS = "includedPaths"; - public static final String EXCLUDED_PATHS = "excludedPaths"; - public static final String INDEXES = "indexes"; - public static final String COMPOSITE_INDEXES = "compositeIndexes"; - public static final String ORDER = "order"; - public static final String SPATIAL_INDEXES = "spatialIndexes"; - public static final String TYPES = "types"; - - // Unique index. - public static final String UNIQUE_KEY_POLICY = "uniqueKeyPolicy"; - public static final String UNIQUE_KEYS = "uniqueKeys"; - - // Conflict. - public static final String CONFLICT = "conflict"; - public static final String OPERATION_TYPE = "operationType"; - public static final String SOURCE_RESOURCE_ID = "resourceId"; - - // Offer resource - public static final String OFFER_TYPE = "offerType"; - public static final String OFFER_VERSION = "offerVersion"; - public static final String OFFER_CONTENT = "content"; - public static final String OFFER_THROUGHPUT = "offerThroughput"; - public static final String OFFER_VERSION_V1 = "V1"; - public static final String OFFER_VERSION_V2 = "V2"; - public static final String OFFER_RESOURCE_ID = "offerResourceId"; - - // PartitionKey - public static final String PARTITION_KEY = "partitionKey"; - public static final String PARTITION_KEY_PATHS = "paths"; - public static final String PARTITION_KIND = "kind"; - public static final String PARTITION_KEY_DEFINITION_VERSION = "version"; - - public static final String RESOURCE_PARTITION_KEY = "resourcePartitionKey"; - public static final String PARTITION_KEY_RANGE_ID = "partitionKeyRangeId"; - public static final String MIN_INCLUSIVE_EFFECTIVE_PARTITION_KEY = "minInclusiveEffectivePartitionKey"; - public static final String MAX_EXCLUSIVE_EFFECTIVE_PARTITION_KEY = "maxExclusiveEffectivePartitionKey"; - - // AddressResource - public static final String IS_PRIMARY = "isPrimary"; - public static final String PROTOCOL = "protocol"; - public static final String LOGICAL_URI = "logicalUri"; - public static final String PHYISCAL_URI = "physcialUri"; - - // Time-to-Live - public static final String TTL = "ttl"; - public static final String DEFAULT_TTL = "defaultTtl"; - - // Global DB account properties - public static final String Name = "name"; - public static final String WRITABLE_LOCATIONS = "writableLocations"; - public static final String READABLE_LOCATIONS = "readableLocations"; - public static final String DATABASE_ACCOUNT_ENDPOINT = "databaseAccountEndpoint"; - - //Authorization - public static final String MASTER_TOKEN = "master"; - public static final String RESOURCE_TOKEN = "resource"; - public static final String TOKEN_VERSION = "1.0"; - public static final String AUTH_SCHEMA_TYPE = "type"; - public static final String AUTH_VERSION = "ver"; - public static final String AUTH_SIGNATURE = "sig"; - public static final String READ_PERMISSION_MODE = "read"; - public static final String ALL_PERMISSION_MODE = "all"; - public static final String PATH_SEPARATOR = "/"; - - public static final int DEFAULT_MAX_PAGE_SIZE = 100; - public static final String ENABLE_MULTIPLE_WRITE_LOCATIONS = "enableMultipleWriteLocations"; - - // Conflict resolution policy - public static final String CONFLICT_RESOLUTION_POLICY = "conflictResolutionPolicy"; - public static final String MODE = "mode"; - public static final String CONFLICT_RESOLUTION_PATH = "conflictResolutionPath"; - public static final String CONFLICT_RESOLUTION_PROCEDURE = "conflictResolutionProcedure"; - - //Handler names for RXNetty httpClient - public static final String SSL_HANDLER_NAME = "ssl-handler"; - public static final String SSL_COMPLETION_HANDLER_NAME = "ssl-completion-handler"; - public static final String HTTP_PROXY_HANDLER_NAME = "http-proxy-handler"; - public static final String LOGGING_HANDLER_NAME = "logging-handler"; - } - - public static final class UrlEncodingInfo { - public static final String PLUS_SYMBOL_ESCAPED = "\\+"; - public static final String PLUS_SYMBOL_URI_ENCODING = "%2b"; - public static final String SINGLE_SPACE_URI_ENCODING = "%20"; - public static final String UTF_8 = "UTF-8"; - } - - public static final class PartitionedQueryExecutionInfo { - public static final int VERSION_1 = 1; - } - - public static final class QueryExecutionContext { - public static final String INCREMENTAL_FEED_HEADER_VALUE = "Incremental feed"; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/HttpConstants.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/HttpConstants.java deleted file mode 100644 index 0ca46de53635..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/HttpConstants.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Used internally. HTTP constants in the Azure Cosmos DB database service Java SDK. - */ -public class HttpConstants { - public static class HttpMethods { - public static final String GET = "GET"; - public static final String POST = "POST"; - public static final String PUT = "PUT"; - public static final String DELETE = "DELETE"; - public static final String HEAD = "HEAD"; - public static final String OPTIONS = "OPTIONS"; - public static final String PATCH = "PATCH"; - } - - public static class QueryStrings { - public static final String URL = "$resolveFor"; - public static final String FILTER = "$filter"; - public static final String PARTITION_KEY_RANGE_IDS = "$partitionKeyRangeIds"; - } - - public static class HttpHeaders { - public static final String AUTHORIZATION = "authorization"; - public static final String E_TAG = "etag"; - public static final String METHOD_OVERRIDE = "X-HTTP-Method"; - public static final String SLUG = "Slug"; - public static final String CONTENT_TYPE = "Content-Type"; - public static final String LAST_MODIFIED = "Last-Modified"; - public static final String CONTENT_ENCODING = "Content-Encoding"; - public static final String CHARACTER_SET = "CharacterSet"; - public static final String USER_AGENT = "User-Agent"; - public static final String IF_MODIFIED_SINCE = "If-Modified-Since"; - public static final String IF_MATCH = "If-Match"; - public static final String IF_NONE_MATCH = "If-None-Match"; - public static final String CONTENT_LENGTH = "Content-Length"; - public static final String ACCEPT_ENCODING = "Accept-Encoding"; - public static final String KEEP_ALIVE = "Keep-Alive"; - public static final String CONNECTION = "Connection"; - public static final String CACHE_CONTROL = "Cache-Control"; - public static final String TRANSFER_ENCODING = "Transfer-Encoding"; - public static final String CONTENT_LANGUAGE = "Content-Language"; - public static final String CONTENT_LOCATION = "Content-Location"; - public static final String CONTENT_MD5 = "Content-Md5"; - public static final String CONTENT_RANGE = "Content-Range"; - public static final String ACCEPT = "Accept"; - public static final String ACCEPT_CHARSET = "Accept-Charset"; - public static final String ACCEPT_LANGUAGE = "Accept-Language"; - public static final String IF_RANGE = "If-Range"; - public static final String IF_UNMODIFIED_SINCE = "If-Unmodified-Since"; - public static final String MAX_FORWARDS = "Max-Forwards"; - public static final String PROXY_AUTHORIZATION = "Proxy-Authorization"; - public static final String ACCEPT_RANGES = "Accept-Ranges"; - public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate"; - public static final String RETRY_AFTER = "Retry-After"; - public static final String SET_COOKIE = "Set-Cookie"; - public static final String WWW_AUTHENTICATE = "Www-Authenticate"; - public static final String ORIGIN = "Origin"; - public static final String HOST = "Host"; - public static final String ACCESS_CONTROL_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; - public static final String ACCESS_CONTROL_ALLOW_HEADERS = "Access-Control-Allow-Headers"; - public static final String KEY_VALUE_ENCODING_FORMAT = "application/x-www-form-urlencoded"; - public static final String WRAP_ASSERTION_FORMAT = "wrap_assertion_format"; - public static final String WRAP_ASSERTION = "wrap_assertion"; - public static final String WRAP_SCOPE = "wrap_scope"; - public static final String SIMPLE_TOKEN = "SWT"; - public static final String HTTP_DATE = "date"; - public static final String PREFER = "Prefer"; - public static final String LOCATION = "Location"; - public static final String REFERER = "referer"; - - // Query - public static final String QUERY = "x-ms-documentdb-query"; - public static final String IS_QUERY = "x-ms-documentdb-isquery"; - public static final String ENABLE_CROSS_PARTITION_QUERY = "x-ms-documentdb-query-enablecrosspartition"; - public static final String PARALLELIZE_CROSS_PARTITION_QUERY = "x-ms-documentdb-query-parallelizecrosspartitionquery"; - - // Our custom DocDB headers - public static final String CONTINUATION = "x-ms-continuation"; - public static final String PAGE_SIZE = "x-ms-max-item-count"; - public static final String RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB = "x-ms-documentdb-responsecontinuationtokenlimitinkb"; - - // Request sender generated. Simply echoed by backend. - public static final String ACTIVITY_ID = "x-ms-activity-id"; - public static final String PRE_TRIGGER_INCLUDE = "x-ms-documentdb-pre-trigger-include"; - public static final String PRE_TRIGGER_EXCLUDE = "x-ms-documentdb-pre-trigger-exclude"; - public static final String POST_TRIGGER_INCLUDE = "x-ms-documentdb-post-trigger-include"; - public static final String POST_TRIGGER_EXCLUDE = "x-ms-documentdb-post-trigger-exclude"; - public static final String INDEXING_DIRECTIVE = "x-ms-indexing-directive"; - public static final String SESSION_TOKEN = "x-ms-session-token"; - public static final String CONSISTENCY_LEVEL = "x-ms-consistency-level"; - public static final String X_DATE = "x-ms-date"; - public static final String COLLECTION_PARTITION_INFO = "x-ms-collection-partition-info"; - public static final String COLLECTION_SERVICE_INFO = "x-ms-collection-service-info"; - public static final String RETRY_AFTER_IN_MILLISECONDS = "x-ms-retry-after-ms"; - public static final String IS_FEED_UNFILTERED = "x-ms-is-feed-unfiltered"; - public static final String RESOURCE_TOKEN_EXPIRY = "x-ms-documentdb-expiry-seconds"; - public static final String ENABLE_SCAN_IN_QUERY = "x-ms-documentdb-query-enable-scan"; - public static final String EMIT_VERBOSE_TRACES_IN_QUERY = "x-ms-documentdb-query-emit-traces"; - - // target lsn for head requests - public static final String TARGET_LSN = "x-ms-target-lsn"; - public static final String TARGET_GLOBAL_COMMITTED_LSN = "x-ms-target-global-committed-lsn"; - - //Request validation - public static final String REQUEST_VALIDATION_FAILURE = "x-ms-request-validation-failure"; - - public static final String WRITE_REQUEST_TRIGGER_ADDRESS_REFRESH = "x-ms-write-request-trigger-refresh"; - - // Quota Info - public static final String MAX_RESOURCE_QUOTA = "x-ms-resource-quota"; - public static final String CURRENT_RESOURCE_QUOTA_USAGE = "x-ms-resource-usage"; - public static final String MAX_MEDIA_STORAGE_USAGE_IN_MB = "x-ms-max-media-storage-usage-mb"; - - // Usage Info - public static final String REQUEST_CHARGE = "x-ms-request-charge"; - public static final String CURRENT_MEDIA_STORAGE_USAGE_IN_MB = "x-ms-media-storage-usage-mb"; - public static final String DATABASE_ACCOUNT_CONSUMED_DOCUMENT_STORAGE_IN_MB = "x-ms-databaseaccount-consumed-mb"; - public static final String DATABASE_ACCOUNT_RESERVED_DOCUMENT_STORAGE_IN_MB = "x-ms-databaseaccount-reserved-mb"; - public static final String DATABASE_ACCOUNT_PROVISIONED_DOCUMENT_STORAGE_IN_MB = "x-ms-databaseaccount-provisioned-mb"; - - // Address related headers. - public static final String FORCE_REFRESH = "x-ms-force-refresh"; - public static final String ITEM_COUNT = "x-ms-item-count"; - public static final String NEW_RESOURCE_ID = "x-ms-new-resource-id"; - public static final String USE_MASTER_COLLECTION_RESOLVER = "x-ms-use-master-collection-resolver"; - - // Admin Headers - public static final String FULL_UPGRADE = "x-ms-force-full-upgrade"; - public static final String ONLY_UPGRADE_SYSTEM_APPLICATIONS = "x-ms-only-upgrade-system-applications"; - public static final String ONLY_UPGRADE_NON_SYSTEM_APPLICATIONS = "x-ms-only-upgrade-non-system-applications"; - public static final String UPGRADE_FABRIC_RING_CODE_AND_CONFIG = "x-ms-upgrade-fabric-code-config"; - public static final String IGNORE_IN_PROGRESS_UPGRADE = "x-ms-ignore-inprogress-upgrade"; - public static final String UPGRADE_VERIFICATION_KIND = "x-ms-upgrade-verification-kind"; - public static final String IS_CANARY = "x-ms-iscanary"; - public static final String FORCE_DELETE = "x-ms-force-delete"; - - // Version headers and values - public static final String VERSION = "x-ms-version"; - public static final String SCHEMA_VERSION = "x-ms-schemaversion"; - public static final String SERVER_VERSION = "x-ms-serviceversion"; - public static final String GATEWAY_VERSION = "x-ms-gatewayversion"; - - // RDFE Resource Provider headers - public static final String OCP_RESOURCE_PROVIDER_REGISTERED_URI = "ocp-resourceprovider-registered-uri"; - - // For Document service management operations only. This is in - // essence a 'handle' to (long running) operations. - public static final String REQUEST_ID = "x-ms-request-id"; - - // Object returning this determines what constitutes state and what - // last state change means. For replica, it is the last role change. - public static final String LAST_STATE_CHANGE_UTC = "x-ms-last-state-change-utc"; - - // CSM specific headers - // Client-request-id: Optional caller-specified request ID, in the form - // of a GUID - public static final String CLIENT_REQUEST_ID = "x-ms-client-request-id"; - - // Offer header - public static final String OFFER_TYPE = "x-ms-offer-type"; - public static final String OFFER_THROUGHPUT = "x-ms-offer-throughput"; - public static final String OFFER_IS_RU_PER_MINUTE_THROUGHPUT_ENABLED = "x-ms-offer-is-ru-per-minute-throughput-enabled"; - - // Upsert header - public static final String IS_UPSERT = "x-ms-documentdb-is-upsert"; - - // Index progress headers - public static final String INDEX_TRANSFORMATION_PROGRESS = "x-ms-documentdb-collection-index-transformation-progress"; - public static final String LAZY_INDEXING_PROGRESS = "x-ms-documentdb-collection-lazy-indexing-progress"; - - //Owner name - public static final String OWNER_FULL_NAME = "x-ms-alt-content-path"; - - // Owner ID used for name based request in session token. - public static final String OWNER_ID = "x-ms-content-path"; - - // Partition headers - public static final String PARTITION_KEY = "x-ms-documentdb-partitionkey"; - public static final String PARTITION_KEY_RANGE_ID = "x-ms-documentdb-partitionkeyrangeid"; - - // Error response sub status code - public static final String SUB_STATUS = "x-ms-substatus"; - - public static final String LSN = "lsn"; - - // Custom DocDB JavaScript logging headers - public static final String SCRIPT_ENABLE_LOGGING = "x-ms-documentdb-script-enable-logging"; - public static final String SCRIPT_LOG_RESULTS = "x-ms-documentdb-script-log-results"; - - // Collection quota - public static final String POPULATE_QUOTA_INFO = "x-ms-documentdb-populatequotainfo"; - - // ChangeFeed - public static final String A_IM = "A-IM"; - public static final String ALLOW_TENTATIVE_WRITES = "x-ms-cosmos-allow-tentative-writes"; - - // These settings were added to support RNTBD and they've been added here to reduce merge conflicts - - public static final String CAN_CHARGE = "x-ms-cancharge"; - public static final String CAN_OFFER_REPLACE_COMPLETE = "x-ms-can-offer-replace-complete"; - public static final String CAN_THROTTLE = "x-ms-canthrottle"; - public static final String CLIENT_RETRY_ATTEMPT_COUNT = "x-ms-client-retry-attempt-count"; - public static final String COLLECTION_INDEX_TRANSFORMATION_PROGRESS = "x-ms-documentdb-collection-index-transformation-progress"; - public static final String COLLECTION_LAZY_INDEXING_PROGRESS = "x-ms-documentdb-collection-lazy-indexing-progress"; - public static final String COLLECTION_REMOTE_STORAGE_SECURITY_IDENTIFIER = "x-ms-collection-security-identifier"; - public static final String CONTENT_SERIALIZATION_FORMAT = "x-ms-documentdb-content-serialization-format"; - public static final String DISABLE_RNTBD_CHANNEL = "x-ms-disable-rntbd-channel"; - public static final String DISABLE_RU_PER_MINUTE_USAGE = "x-ms-documentdb-disable-ru-per-minute-usage"; - public static final String ENABLE_LOGGING = "x-ms-documentdb-script-enable-logging"; - public static final String ENABLE_LOW_PRECISION_ORDER_BY = "x-ms-documentdb-query-enable-low-precision-order-by"; - public static final String END_EPK = "x-ms-end-epk"; - public static final String END_ID = "x-ms-end-id"; - public static final String ENUMERATION_DIRECTION = "x-ms-enumeration-direction"; - public static final String FILTER_BY_SCHEMA_RESOURCE_ID = "x-ms-documentdb-filterby-schema-rid"; - public static final String FORCE_QUERY_SCAN = "x-ms-documentdb-force-query-scan"; - public static final String GATEWAY_SIGNATURE = "x-ms-gateway-signature"; - public static final String IS_AUTO_SCALE_REQUEST = "x-ms-is-auto-scale"; - public static final String IS_READ_ONLY_SCRIPT = "x-ms-is-readonly-script"; - public static final String LOG_RESULTS = "x-ms-documentdb-script-log-results"; - public static final String MIGRATE_COLLECTION_DIRECTIVE = "x-ms-migratecollection-directive"; - public static final String POPULATE_COLLECTION_THROUGHPUT_INFO = "x-ms-documentdb-populatecollectionthroughputinfo"; - public static final String POPULATE_PARTITION_STATISTICS = "x-ms-documentdb-populatepartitionstatistics"; - public static final String POPULATE_QUERY_METRICS = "x-ms-documentdb-populatequerymetrics"; - public static final String PROFILE_REQUEST = "x-ms-profile-request"; - public static final String READ_FEED_KEY_TYPE = "x-ms-read-key-type"; - public static final String REMAINING_TIME_IN_MS_ON_CLIENT_REQUEST = "x-ms-remaining-time-in-ms-on-client"; - public static final String RESTORE_METADATA_FILTER = "x-ms-restore-metadata-filter"; - public static final String SHARED_OFFER_THROUGHPUT = "x-ms-cosmos-shared-offer-throughput"; - public static final String START_EPK = "x-ms-start-epk"; - public static final String START_ID = "x-ms-start-id"; - public static final String SUPPORT_SPATIAL_LEGACY_COORDINATES = "x-ms-documentdb-supportspatiallegacycoordinates"; - public static final String TRANSPORT_REQUEST_ID = "x-ms-transport-request-id"; - public static final String USE_POLYGONS_SMALLER_THAN_AHEMISPHERE = "x-ms-documentdb-usepolygonssmallerthanahemisphere"; - public static final String API_TYPE = "x-ms-cosmos-apitype"; - public static final String QUERY_METRICS = "x-ms-documentdb-query-metrics"; - - } - - public static class A_IMHeaderValues { - public static final String INCREMENTAL_FEED = "Incremental Feed"; - } - - public static class Versions { - public static final String CURRENT_VERSION = "2018-09-17"; - - // TODO: FIXME we can use maven plugin for generating a version file - // @see https://stackoverflow.com/questions/2469922/generate-a-version-java-file-in-maven - public static final String SDK_VERSION = "2.4.5"; - public static final String SDK_NAME = "cosmosdb-java-sdk"; - } - - public static class StatusCodes { - public static final int NOT_MODIFIED = 304; - // Client error - public static final int MINIMUM_STATUSCODE_AS_ERROR_GATEWAY = 400; - public static final int BADREQUEST = 400; - public static final int UNAUTHORIZED = 401; - public static final int FORBIDDEN = 403; - public static final int NOTFOUND = 404; - public static final int METHOD_NOT_ALLOWED = 405; - public static final int REQUEST_TIMEOUT = 408; - public static final int CONFLICT = 409; - public static final int GONE = 410; - public static final int PRECONDITION_FAILED = 412; - public static final int REQUEST_ENTITY_TOO_LARGE = 413; - public static final int LOCKED = 423; - public static final int TOO_MANY_REQUESTS = 429; - public static final int RETRY_WITH = 449; - - public static final int SERVICE_UNAVAILABLE = 503; - public static final int INTERNAL_SERVER_ERROR = 500; - } - - public static class SubStatusCodes { - // Unknown SubStatus Code - public static final int UNKNOWN = 0; - - // 400: Bad Request substatus - public static final int PARTITION_KEY_MISMATCH = 1001; - public static final int CROSS_PARTITION_QUERY_NOT_SERVABLE = 1004; - - // 410: StatusCodeType_Gone: substatus - public static final int NAME_CACHE_IS_STALE = 1000; - public static final int PARTITION_KEY_RANGE_GONE = 1002; - public static final int COMPLETING_SPLIT = 1007; - public static final int COMPLETING_PARTITION_MIGRATION = 1008; - - // 403: Forbidden substatus - public static final int FORBIDDEN_WRITEFORBIDDEN = 3; - public static final int DATABASE_ACCOUNT_NOTFOUND = 1008; - - // 404: LSN in session token is higher - public static final int READ_SESSION_NOT_AVAILABLE = 1002; - } - - public static class HeaderValues { - public static final String NoCache = "no-cache"; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ISessionToken.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ISessionToken.java deleted file mode 100644 index 08ce7f9c1f7e..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ISessionToken.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; - -/** - * Models session token. - * - * We make assumption that instances of this interface are immutable (read only after they are constructed), so if you want to change - * this behaviour please review all of its uses and make sure that mutability doesn't break anything. - */ -public interface ISessionToken { - - String PARTITION_KEY_RANGE_SESSION_SEPARATOR = ":"; - - /** - * Returns true if this instance of session token is valid with respect to other session token. - * This is used to decide if the client can accept server's response (based on comparison between client's - * and server's session token) - * - * @param other Session token to validate - * @return true if this instance of session token is valid with respect to other session token; - * false otherwise - */ - boolean isValid(ISessionToken other) throws DocumentClientException; - - /** - * Returns a new instance of session token obtained by merging this session token with - * the given session token other. - * - * Merge is commutative operation, so a.Merge(b).Equals(b.Merge(a)) - * - * @param other Other session token to merge - * @return Instance of merged session token - */ - ISessionToken merge(ISessionToken other) throws DocumentClientException; - - long getLSN(); - - String convertToString(); -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Integers.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Integers.java deleted file mode 100644 index 3d9c3cb6fdcb..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Integers.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -public class Integers { - public static int tryParse(String value, int defaultValue) { - if (Strings.isNullOrEmpty(value)) { - return defaultValue; - } - - try { - return Integer.valueOf(value); - } catch (NumberFormatException e) { - return defaultValue; - } - } - - public static Integer tryParse(String value) { - if (Strings.isNullOrEmpty(value)) { - return null; - } - - try { - return Integer.valueOf(value); - } catch (NumberFormatException e) { - return null; - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/InternalServerErrorException.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/InternalServerErrorException.java deleted file mode 100644 index b6a12f08b3c6..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/InternalServerErrorException.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.net.URL; -import java.util.Map; - -/** - * This exception is thrown when DocumentServiceRequest contains x-ms-documentdb-partitionkeyrangeid - * header and such range id doesn't exist. - *

- * No retries should be made in this case, as either split or merge might have happened and query/readfeed - * must take appropriate actions. - */ -public class InternalServerErrorException extends DocumentClientException { - - public InternalServerErrorException() { - this(RMResources.InternalServerError); - } - - public InternalServerErrorException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public InternalServerErrorException(String message) { - this(message, (Exception) null, (Map) null, (String) null); - } - - - public InternalServerErrorException(String message, Exception innerException) { - this(message, innerException, (HttpResponseHeaders) null, (String) null); - } - - public InternalServerErrorException(Exception innerException) { - this(RMResources.InternalServerError, innerException, (HttpResponseHeaders) null, (String) null); - } - - public InternalServerErrorException(String message, HttpResponseHeaders headers, URI requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, requestUri != null ? requestUri.toString() : null); - } - - public InternalServerErrorException(String message, HttpResponseHeaders headers, String requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, requestUri); - } - - public InternalServerErrorException(String message, HttpResponseHeaders headers, URL requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, requestUri != null ? requestUri.toString() : null); - } - - public InternalServerErrorException(String message, Exception innerException, HttpResponseHeaders headers, URI requestUri) { - super(message, innerException, HttpUtils.asMap(headers), HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, requestUri != null ? requestUri.toString() : null); - } - - public InternalServerErrorException(String message, Exception innerException, HttpResponseHeaders headers, String requestUri) { - super(message, innerException, HttpUtils.asMap(headers), HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, requestUri); - } - - public InternalServerErrorException(String message, Exception innerException, Map headers, String requestUri) { - super(message, innerException, headers, HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, requestUri); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/JavaStreamUtils.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/JavaStreamUtils.java deleted file mode 100644 index bc0c51223603..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/JavaStreamUtils.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import org.apache.commons.lang3.StringUtils; - -import java.util.Collection; -import java.util.Iterator; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class JavaStreamUtils { - - private static String safeToString(T t) { - return t != null ? t.toString() : "null"; - } - - public static String toString(Collection collection, String delimiter) { - return collection.stream() - .map( t -> safeToString(t) ) - .collect(Collectors.joining(delimiter)); - } - - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/LifeCycleUtils.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/LifeCycleUtils.java deleted file mode 100644 index a5bc168b5db8..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/LifeCycleUtils.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class LifeCycleUtils { - private final static Logger logger = LoggerFactory.getLogger(LifeCycleUtils.class); - public static void closeQuietly(AutoCloseable closeable) { - try { - if (closeable != null) { - logger.debug("closing an instance of {}", closeable.getClass().getCanonicalName()); - closeable.close(); - } - } catch (Exception e) { - logger.warn("attempting to close an instance of {} failed", closeable.getClass().getCanonicalName(), e); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Lists.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Lists.java deleted file mode 100644 index d3007dab8312..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Lists.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.util.List; - -public class Lists { - - public static V firstOrDefault(List list, V defaultValue) { - return list.isEmpty() ? defaultValue : list.get(0); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Longs.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Longs.java deleted file mode 100644 index 5a8c9398385f..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Longs.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -public class Longs { - public static long tryParse(String value, long defaultValue) { - if (Strings.isNullOrEmpty(value)) { - return defaultValue; - } - - try { - return Long.valueOf(value); - } catch (NumberFormatException e) { - return defaultValue; - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/MutableVolatile.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/MutableVolatile.java deleted file mode 100644 index 4b4c9b2338e4..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/MutableVolatile.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -public class MutableVolatile { - - public MutableVolatile(T initValue){ - v = initValue; - } - - public MutableVolatile() {} - public volatile T v; -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/OperationType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/OperationType.java deleted file mode 100644 index 05b1a484509d..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/OperationType.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Operation types in the Azure Cosmos DB database service. - */ -public enum OperationType { - AbortPartitionMigration, - AbortSplit, - AddComputeGatewayRequestCharges, - BatchApply, - BatchReportThroughputUtilization, - CompletePartitionMigration, - CompleteSplit, - Crash, - Create, - Delete, - ExecuteJavaScript, - ForceConfigRefresh, - GetSplitPoint, - Head, - HeadFeed, - MigratePartition, - Pause, - PreCreateValidation, - OfferPreGrowValidation, - OfferUpdateOperation, - PreReplaceValidation, - Query, - Read, - ReadFeed, - Recreate, - Recycle, - Replace, - Resume, - SqlQuery, - Stop, - Throttle, - Update, - Upsert; - - public boolean isWriteOperation() { - return this == Create || - this == Delete || - this == Recreate || - this == ExecuteJavaScript || - this == Replace || - this == Upsert || - this == Update; - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathInfo.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathInfo.java deleted file mode 100644 index b1884975d5f5..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathInfo.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Represents a resource path's information in the Azure Cosmos DB database service. - */ -public final class PathInfo { - public boolean isFeed; - public String resourcePath; - public String resourceIdOrFullName; - public boolean isNameBased; - - public PathInfo(boolean isFeed, String resourcePath, String resourceIdOrFullName, boolean isNameBased) { - this.isFeed = isFeed; - this.resourcePath = resourcePath; - this.resourceIdOrFullName = resourceIdOrFullName; - this.isNameBased = isNameBased; - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathParser.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathParser.java deleted file mode 100644 index c1f54819e453..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathParser.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * Provide functionality to parse resource paths in the Azure Cosmos DB database service. - */ -public final class PathParser { - - private static final char segmentSeparator = '/'; - - public static List getPathParts(String path) { - ArrayList tokens = new ArrayList(); - int currentIndex = 0; - - while (currentIndex < path.length()) { - if (path.charAt(currentIndex) != segmentSeparator) { - throw new IllegalArgumentException(String.format("Invalid path, failed at index %d.", currentIndex)); - } - - if (++currentIndex == path.length()) - break; - - if (path.charAt(currentIndex) == '\"' || path.charAt(currentIndex) == '\'') { - char quote = path.charAt(currentIndex); - int newIndex = ++currentIndex; - while (true) { - newIndex = path.indexOf(quote, newIndex); - if (newIndex == -1) { - throw new IllegalArgumentException(String.format("Invalid path, failed at index %d.", currentIndex)); - } - - if (path.charAt(newIndex - 1) != '\\') { - break; - } - - ++newIndex; - } - - String token = path.substring(currentIndex, newIndex); - tokens.add(token); - currentIndex = newIndex + 1; - } else { - int newIndex = path.indexOf(segmentSeparator, currentIndex); - String token = null; - if (newIndex == -1) { - token = path.substring(currentIndex); - currentIndex = path.length(); - } else { - token = path.substring(currentIndex, newIndex); - currentIndex = newIndex; - } - - token = token.trim(); - tokens.add(token); - } - } - - return tokens; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Paths.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Paths.java deleted file mode 100644 index 25b0af49db4c..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Paths.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Used internally. Contains string constants to work with the paths in the Azure Cosmos DB database service. - */ -public class Paths { - static final String ROOT = "/"; - - public static final String DATABASES_PATH_SEGMENT = "dbs"; - public static final String DATABASES_ROOT = ROOT + DATABASES_PATH_SEGMENT; - - public static final String USERS_PATH_SEGMENT = "users"; - public static final String PERMISSIONS_PATH_SEGMENT = "permissions"; - public static final String COLLECTIONS_PATH_SEGMENT = "colls"; - public static final String STORED_PROCEDURES_PATH_SEGMENT = "sprocs"; - public static final String TRIGGERS_PATH_SEGMENT = "triggers"; - public static final String USER_DEFINED_FUNCTIONS_PATH_SEGMENT = "udfs"; - public static final String CONFLICTS_PATH_SEGMENT = "conflicts"; - public static final String DOCUMENTS_PATH_SEGMENT = "docs"; - public static final String ATTACHMENTS_PATH_SEGMENT = "attachments"; - - // /offers - public static final String OFFERS_PATH_SEGMENT = "offers"; - public static final String OFFERS_ROOT = ROOT + OFFERS_PATH_SEGMENT + "/"; - - public static final String ADDRESS_PATH_SEGMENT = "addresses"; - public static final String PARTITIONS_PATH_SEGMENT = "partitions"; - public static final String DATABASE_ACCOUNT_PATH_SEGMENT = "databaseaccount"; - public static final String TOPOLOGY_PATH_SEGMENT = "topology"; - public static final String MEDIA_PATH_SEGMENT = "media"; - public static final String MEDIA_ROOT = ROOT + MEDIA_PATH_SEGMENT; - public static final String SCHEMAS_PATH_SEGMENT = "schemas"; - public static final String PARTITION_KEY_RANGES_PATH_SEGMENT = "pkranges"; - - public static final String USER_DEFINED_TYPES_PATH_SEGMENT = "udts"; - - public static final String RID_RANGE_PATH_SEGMENT = "ridranges"; -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathsHelper.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathsHelper.java deleted file mode 100644 index f65d3f5c0e6f..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/PathsHelper.java +++ /dev/null @@ -1,884 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.util.ArrayList; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.Conflict; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -import org.apache.commons.text.StringEscapeUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; - -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -/** - * Used internally to provide utility methods to work with the resource's path in the Azure Cosmos DB database service. - */ -public class PathsHelper { - private final static Logger logger = LoggerFactory.getLogger(PathsHelper.class); - - public static String generatePath(ResourceType resourceType, RxDocumentServiceRequest request, boolean isFeed) { - if (request.getIsNameBased()) { - return PathsHelper.generatePathForNameBased(resourceType, request.getResourceAddress(), isFeed); - } else { - return PathsHelper.generatePath(resourceType, request.getResourceId(), isFeed); - } - } - - public static String generatePathForNameBased(Resource resourceType, String resourceOwnerFullName, String resourceName) { - if (resourceName == null) - return null; - - if (resourceType instanceof Database) { - return Paths.DATABASES_PATH_SEGMENT + "/" + resourceName; - } else if (resourceOwnerFullName == null) { - return null; - } else if (resourceType instanceof DocumentCollection) { - return resourceOwnerFullName + "/" + Paths.COLLECTIONS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof StoredProcedure) { - return resourceOwnerFullName + "/" + Paths.STORED_PROCEDURES_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof UserDefinedFunction) { - return resourceOwnerFullName + "/" + Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof Trigger) { - return resourceOwnerFullName + "/" + Paths.TRIGGERS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof Conflict) { - return resourceOwnerFullName + "/" + Paths.CONFLICTS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof Attachment) { - return resourceOwnerFullName + "/" + Paths.ATTACHMENTS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof User) { - return resourceOwnerFullName + "/" + Paths.USERS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof Permission) { - return resourceOwnerFullName + "/" + Paths.PERMISSIONS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof Document) { - return resourceOwnerFullName + "/" + Paths.DOCUMENTS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof Offer) { - return Paths.OFFERS_PATH_SEGMENT + "/" + resourceName; - } else if (resourceType instanceof Resource) { - // just generic Resource type. - return null; - } - - String errorMessage = String.format(RMResources.UnknownResourceType, resourceType.toString()); - assert false : errorMessage; - throw new IllegalArgumentException(errorMessage); - } - - private static String generatePathForNameBased(ResourceType resourceType, String resourceFullName, boolean isFeed) { - if (isFeed && Strings.isNullOrEmpty(resourceFullName) && resourceType != ResourceType.Database) { - String errorMessage = String.format(RMResources.UnexpectedResourceType, resourceType); - throw new IllegalArgumentException(errorMessage); - } - - String resourcePath = null; - if (!isFeed) { - resourcePath = resourceFullName; - } else if (resourceType == ResourceType.Database) { - return Paths.DATABASES_PATH_SEGMENT; - } else if (resourceType == ResourceType.DocumentCollection) { - resourcePath = resourceFullName + "/" + Paths.COLLECTIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.StoredProcedure) { - resourcePath = resourceFullName + "/" + Paths.STORED_PROCEDURES_PATH_SEGMENT; - } else if (resourceType == ResourceType.UserDefinedFunction) { - resourcePath = resourceFullName + "/" + Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Trigger) { - resourcePath = resourceFullName + "/" + Paths.TRIGGERS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Conflict) { - resourcePath = resourceFullName + "/" + Paths.CONFLICTS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Attachment) { - resourcePath = resourceFullName + "/" + Paths.ATTACHMENTS_PATH_SEGMENT; - } else if (resourceType == ResourceType.User) { - resourcePath = resourceFullName + "/" + Paths.USERS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Permission) { - resourcePath = resourceFullName + "/" + Paths.PERMISSIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Document) { - resourcePath = resourceFullName + "/" + Paths.DOCUMENTS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Offer) { - return resourceFullName + "/" + Paths.OFFERS_PATH_SEGMENT; - } else if (resourceType == ResourceType.PartitionKeyRange) { - return resourceFullName + "/" + Paths.PARTITION_KEY_RANGES_PATH_SEGMENT; - } else if (resourceType == ResourceType.Schema) { - resourcePath = resourceFullName + "/" + Paths.SCHEMAS_PATH_SEGMENT; - } else { - String errorMessage = String.format(RMResources.UnknownResourceType, resourceType.toString()); - assert false : errorMessage; - throw new IllegalArgumentException(errorMessage); - } - - return resourcePath; - } - - public static String generatePath(ResourceType resourceType, String ownerOrResourceId, boolean isFeed) { - if (isFeed && (ownerOrResourceId == null || ownerOrResourceId.isEmpty()) && - resourceType != ResourceType.Database && - resourceType != ResourceType.Offer && - resourceType != ResourceType.MasterPartition && - resourceType != ResourceType.ServerPartition && - resourceType != ResourceType.DatabaseAccount && - resourceType != ResourceType.Topology) { - throw new IllegalStateException("Invalid resource type"); - } - - if(ownerOrResourceId == null) { - ownerOrResourceId = StringUtils.EMPTY; - } - - if (isFeed && resourceType == ResourceType.Database) { - return Paths.DATABASES_PATH_SEGMENT; - } else if (resourceType == ResourceType.Database) { - return Paths.DATABASES_PATH_SEGMENT + "/" + ownerOrResourceId; - } else if (isFeed && resourceType == ResourceType.DocumentCollection) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.DocumentCollection) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentCollectionId().toString(); - } else if (isFeed && resourceType == ResourceType.Offer) { - return Paths.OFFERS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Offer) { - return Paths.OFFERS_PATH_SEGMENT + "/" + ownerOrResourceId; - } else if (isFeed && resourceType == ResourceType.StoredProcedure) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return - Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentCollectionId().toString() + "/" + - Paths.STORED_PROCEDURES_PATH_SEGMENT; - } else if (resourceType == ResourceType.StoredProcedure) { - ResourceId storedProcedureId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + storedProcedureId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + storedProcedureId.getDocumentCollectionId().toString() + "/" + - Paths.STORED_PROCEDURES_PATH_SEGMENT + "/" + storedProcedureId.getStoredProcedureId().toString(); - } else if (isFeed && resourceType == ResourceType.UserDefinedFunction) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return - Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentCollectionId().toString() + "/" + - Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.UserDefinedFunction) { - ResourceId functionId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + functionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + functionId.getDocumentCollectionId().toString() + "/" + - Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT + "/" + functionId.getUserDefinedFunctionId().toString(); - } else if (isFeed && resourceType == ResourceType.Trigger) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return - Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentCollectionId().toString() + "/" + - Paths.TRIGGERS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Trigger) { - ResourceId triggerId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + triggerId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + triggerId.getDocumentCollectionId().toString() + "/" + - Paths.TRIGGERS_PATH_SEGMENT + "/" + triggerId.getTriggerId().toString(); - } else if (isFeed && resourceType == ResourceType.Conflict) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return - Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentCollectionId().toString() + "/" + - Paths.CONFLICTS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Conflict) { - ResourceId conflictId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + conflictId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + conflictId.getDocumentCollectionId().toString() + "/" + - Paths.CONFLICTS_PATH_SEGMENT + "/" + conflictId.getConflictId().toString(); - } else if (isFeed && resourceType == ResourceType.PartitionKeyRange) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + - documentCollectionId.getDocumentCollectionId().toString() + "/" + - Paths.PARTITION_KEY_RANGES_PATH_SEGMENT; - } else if (resourceType == ResourceType.PartitionKeyRange) { - ResourceId partitionKeyRangeId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + partitionKeyRangeId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + partitionKeyRangeId.getDocumentCollectionId().toString() + "/" + - Paths.PARTITION_KEY_RANGES_PATH_SEGMENT + "/" + partitionKeyRangeId.getPartitionKeyRangeId().toString(); - } else if (isFeed && resourceType == ResourceType.Attachment) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return - Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentCollectionId().toString() + "/" + - Paths.DOCUMENTS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentId().toString() + "/" + - Paths.ATTACHMENTS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Attachment) { - ResourceId attachmentId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + attachmentId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + attachmentId.getDocumentCollectionId().toString() + "/" + - Paths.DOCUMENTS_PATH_SEGMENT + "/" + attachmentId.getDocumentId().toString() + "/" + - Paths.ATTACHMENTS_PATH_SEGMENT + "/" + attachmentId.getAttachmentId().toString(); - } else if (isFeed && resourceType == ResourceType.User) { - return - Paths.DATABASES_PATH_SEGMENT + "/" + ownerOrResourceId + "/" + - Paths.USERS_PATH_SEGMENT; - } else if (resourceType == ResourceType.User) { - ResourceId userId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + userId.getDatabaseId().toString() + "/" + - Paths.USERS_PATH_SEGMENT + "/" + userId.getUserId().toString(); - } else if (isFeed && resourceType == ResourceType.Permission) { - ResourceId userId = ResourceId.parse(ownerOrResourceId); - - return - Paths.DATABASES_PATH_SEGMENT + "/" + userId.getDatabaseId().toString() + "/" + - Paths.USERS_PATH_SEGMENT + "/" + userId.getUserId().toString() + "/" + - Paths.PERMISSIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Permission) { - ResourceId permissionId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + permissionId.getDatabaseId().toString() + "/" + - Paths.USERS_PATH_SEGMENT + "/" + permissionId.getUserId().toString() + "/" + - Paths.PERMISSIONS_PATH_SEGMENT + "/" + permissionId.getPermissionId().toString(); - } else if (isFeed && resourceType == ResourceType.Document) { - ResourceId documentCollectionId = ResourceId.parse(ownerOrResourceId); - - return - Paths.DATABASES_PATH_SEGMENT + "/" + documentCollectionId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentCollectionId.getDocumentCollectionId().toString() + "/" + - Paths.DOCUMENTS_PATH_SEGMENT; - } else if (resourceType == ResourceType.Document) { - ResourceId documentId = ResourceId.parse(ownerOrResourceId); - - return Paths.DATABASES_PATH_SEGMENT + "/" + documentId.getDatabaseId().toString() + "/" + - Paths.COLLECTIONS_PATH_SEGMENT + "/" + documentId.getDocumentCollectionId().toString() + "/" + - Paths.DOCUMENTS_PATH_SEGMENT + "/" + documentId.getDocumentId().toString(); - } else if (isFeed && resourceType == ResourceType.MasterPartition) { - return Paths.PARTITIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.MasterPartition) { - return Paths.PARTITIONS_PATH_SEGMENT + "/" + ownerOrResourceId; - } else if (isFeed && resourceType == ResourceType.ServerPartition) { - return Paths.PARTITIONS_PATH_SEGMENT; - } else if (resourceType == ResourceType.ServerPartition) { - return Paths.PARTITIONS_PATH_SEGMENT + "/" + ownerOrResourceId; - } else if (isFeed && resourceType == ResourceType.Topology) { - return Paths.TOPOLOGY_PATH_SEGMENT; - } else if (resourceType == ResourceType.Topology) { - return Paths.TOPOLOGY_PATH_SEGMENT + "/" + ownerOrResourceId; - } else if (isFeed && resourceType == ResourceType.DatabaseAccount) { - return Paths.DATABASE_ACCOUNT_PATH_SEGMENT; - } else if (resourceType == ResourceType.DatabaseAccount) { - return Paths.DATABASE_ACCOUNT_PATH_SEGMENT + "/" + ownerOrResourceId; - } - - String errorMessage = "invalid resource type"; - throw new IllegalStateException(errorMessage); - } - - public static PathInfo parsePathSegments(String resourceUrl) { - String[] segments = StringUtils.strip(resourceUrl, "/").split("/"); - if (segments == null || segments.length < 1) { - return null; - } - - int uriSegmentsCount = segments.length; - String segmentOne = StringUtils.strip(segments[uriSegmentsCount - 1], "/"); - String segmentTwo = (uriSegmentsCount >= 2) ? StringUtils.strip(segments[uriSegmentsCount - 2], "/") - : StringUtils.EMPTY; - - // handle name based operation - if (uriSegmentsCount >= 2) { - // parse the databaseId, if failed, it is name based routing - // mediaId is special, we will treat it always as id based. - if (Paths.MEDIA_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.OFFERS_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.PARTITIONS_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.DATABASE_ACCOUNT_PATH_SEGMENT.compareTo(segments[0]) != 0) { - Pair result = ResourceId.tryParse(segments[1]); - if (!result.getLeft() || !result.getRight().isDatabaseId()) { - return parseNameSegments(resourceUrl, segments); - } - } - - } - - // Feed paths have odd number of segments - if ((uriSegmentsCount % 2 != 0) && isResourceType(segmentOne)) { - return new PathInfo(true, segmentOne, - segmentOne.compareToIgnoreCase(Paths.DATABASES_PATH_SEGMENT) != 0 ? segmentTwo : StringUtils.EMPTY, - false); - } else if (isResourceType(segmentTwo)) { - return new PathInfo(false, segmentTwo, segmentOne, false); - } - - return null; - } - - /** - * Method which will return boolean based on whether it is able to parse the - * path and name segment from resource url , and fill info in PathInfo object - * @param resourceUrl Complete ResourceLink - * @param pathInfo Path info object which will hold information - * @param clientVersion The Client version - * @return - */ - public static boolean tryParsePathSegments(String resourceUrl, PathInfo pathInfo, String clientVersion) { - pathInfo.resourcePath = StringUtils.EMPTY; - pathInfo.resourceIdOrFullName = StringUtils.EMPTY; - pathInfo.isFeed = false; - pathInfo.isNameBased = false; - if (StringUtils.isEmpty(resourceUrl)) { - return false; - } - String trimmedStr = StringUtils.strip(resourceUrl, Constants.Properties.PATH_SEPARATOR); - String[] segments = StringUtils.split(trimmedStr, Constants.Properties.PATH_SEPARATOR); - if (segments == null || segments.length < 1) { - return false; - } - int uriSegmentsCount = segments.length; - String segmentOne = segments[uriSegmentsCount - 1]; - String segmentTwo = (uriSegmentsCount >= 2) ? segments[uriSegmentsCount - 2] : StringUtils.EMPTY; - - // handle name based operation - if (uriSegmentsCount >= 2) { - // parse the databaseId, if failed, it is name based routing - // mediaId is special, we will treat it always as id based. - if (Paths.MEDIA_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.OFFERS_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.PARTITIONS_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.DATABASE_ACCOUNT_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.TOPOLOGY_PATH_SEGMENT.compareTo(segments[0]) != 0 - && Paths.RID_RANGE_PATH_SEGMENT.compareTo(segments[0]) != 0) { - Pair result = ResourceId.tryParse(segments[1]); - if (!result.getLeft() || !result.getRight().isDatabaseId()) { - pathInfo.isNameBased = true; - return tryParseNameSegments(resourceUrl, segments, pathInfo); - } - } - } - // Feed paths have odd number of segments - if ((uriSegmentsCount % 2 != 0) && PathsHelper.isResourceType(segmentOne)) { - pathInfo.isFeed = true; - pathInfo.resourcePath = segmentOne; - // The URL for dbs may contain the management endpoint as the segmentTwo which - // should not be used as resourceId - if (!segmentOne.equalsIgnoreCase(Paths.DATABASES_PATH_SEGMENT)) { - pathInfo.resourceIdOrFullName = segmentTwo; - } - } else if (PathsHelper.isResourceType(segmentTwo)) { - pathInfo.isFeed = false; - pathInfo.resourcePath = segmentTwo; - pathInfo.resourceIdOrFullName = segmentOne; - // Media ID is not supposed to be used for any ID verification. However, if the - // old client makes a call for media ID - // we still need to support it. - // For new clients, parse to return the attachment id. For old clients do not - // modify. - if (!StringUtils.isEmpty(clientVersion) - && pathInfo.resourcePath.equalsIgnoreCase(Paths.MEDIA_PATH_SEGMENT)) { - String attachmentId = null; - byte storeIndex = 0; - // MEDIA Id parsing code will come here , supported MediaIdHelper file missing in java sdk(Sync and Async both) - //Below code from .net - // if (!MediaIdHelper.TryParseMediaId(resourceIdOrFullName, out attachmentId, out storeIndex)) - // { - // return false; - //} - //resourceIdOrFullName = attachmentId; - } - } else { - return false; - } - - return true; - - } - - /** - * Method which will return boolean based on whether it is able to parse the - * name segment from resource url , and fill info in PathInfo object - * @param resourceUrl Complete ResourceLink - * @param segments - * @param pathInfo Path info object which will hold information - * @return - */ - private static boolean tryParseNameSegments(String resourceUrl, String[] segments, PathInfo pathInfo) { - pathInfo.isFeed = false; - pathInfo.resourceIdOrFullName = ""; - pathInfo.resourcePath = ""; - if (segments == null || segments.length < 1) { - return false; - } - if (segments.length % 2 == 0) { - // even number, assume it is individual resource - if (isResourceType(segments[segments.length - 2])) { - pathInfo.resourcePath = segments[segments.length - 2]; - pathInfo.resourceIdOrFullName = StringEscapeUtils.unescapeJava(StringUtils.removeEnd( - StringUtils.removeStart(resourceUrl, Paths.ROOT), Paths.ROOT)); - return true; - } - } else { - // odd number, assume it is feed request - if (isResourceType(segments[segments.length - 1])) { - pathInfo.isFeed = true; - pathInfo.resourcePath = segments[segments.length - 1]; - String resourceIdOrFullName = resourceUrl.substring(0, StringUtils.removeEnd(resourceUrl,Paths.ROOT).lastIndexOf(Paths.ROOT)); - pathInfo.resourceIdOrFullName = StringEscapeUtils.unescapeJava(StringUtils.removeEnd( - StringUtils.removeStart(resourceIdOrFullName, Paths.ROOT), Paths.ROOT)); - return true; - } - } - return false; - } - - public static PathInfo parseNameSegments(String resourceUrl, String[] segments) { - if (segments == null || segments.length < 1) { - return null; - } - - if (segments.length % 2 == 0) { - // even number, assume it is individual resource - if (isResourceType(segments[segments.length - 2])) { - return new PathInfo(false, segments[segments.length - 2], - StringEscapeUtils.unescapeJava(StringUtils.strip(resourceUrl, Paths.ROOT)), true); - } - } else { - // odd number, assume it is feed request - if (isResourceType(segments[segments.length - 1])) { - return new PathInfo(true, segments[segments.length - 1], - StringEscapeUtils.unescapeJava(StringUtils.strip( - resourceUrl.substring(0, - StringUtils.removeEnd(resourceUrl, Paths.ROOT).lastIndexOf(Paths.ROOT)), - Paths.ROOT)), - true); - } - } - - return null; - } - - private static boolean isResourceType(String resourcePathSegment) { - if (StringUtils.isEmpty(resourcePathSegment)) { - return false; - } - - switch (resourcePathSegment.toLowerCase()) { - case Paths.ATTACHMENTS_PATH_SEGMENT: - case Paths.COLLECTIONS_PATH_SEGMENT: - case Paths.DATABASES_PATH_SEGMENT: - case Paths.PERMISSIONS_PATH_SEGMENT: - case Paths.USERS_PATH_SEGMENT: - case Paths.DOCUMENTS_PATH_SEGMENT: - case Paths.STORED_PROCEDURES_PATH_SEGMENT: - case Paths.TRIGGERS_PATH_SEGMENT: - case Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT: - case Paths.CONFLICTS_PATH_SEGMENT: - case Paths.MEDIA_PATH_SEGMENT: - case Paths.OFFERS_PATH_SEGMENT: - case Paths.PARTITIONS_PATH_SEGMENT: - case Paths.DATABASE_ACCOUNT_PATH_SEGMENT: - case Paths.TOPOLOGY_PATH_SEGMENT: - case Paths.PARTITION_KEY_RANGES_PATH_SEGMENT: - case Paths.SCHEMAS_PATH_SEGMENT: - return true; - default: - return false; - } - } - - public static String generatePathForNameBased(ResourceType resourceType, String resourceOwnerFullName, String resourceName) { - switch (resourceType) { - case Database: - return Paths.DATABASES_PATH_SEGMENT + "/" + resourceName; - case DocumentCollection: - return resourceOwnerFullName + "/" + Paths.COLLECTIONS_PATH_SEGMENT + "/" + resourceName; - case StoredProcedure: - return resourceOwnerFullName + "/" + Paths.STORED_PROCEDURES_PATH_SEGMENT + "/" + resourceName; - case UserDefinedFunction: - return resourceOwnerFullName + "/" + Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT + "/" + resourceName; - case Trigger: - return resourceOwnerFullName + "/" + Paths.TRIGGERS_PATH_SEGMENT + "/" + resourceName; - case Attachment: - return resourceOwnerFullName + "/" + Paths.ATTACHMENTS_PATH_SEGMENT + "/" + resourceName; - case Conflict: - return resourceOwnerFullName + "/" + Paths.CONFLICTS_PATH_SEGMENT + "/" + resourceName; - case Document: - return resourceOwnerFullName + "/" + Paths.DOCUMENTS_PATH_SEGMENT + "/" + resourceName; - case Offer: - return resourceOwnerFullName + "/" + Paths.OFFERS_PATH_SEGMENT + "/" + resourceName; - case Permission: - return resourceOwnerFullName + "/" + Paths.PERMISSIONS_PATH_SEGMENT + "/" + resourceName; - case User: - return resourceOwnerFullName + "/" + Paths.USERS_PATH_SEGMENT + "/" + resourceName; - case PartitionKeyRange: - return resourceOwnerFullName + "/" + Paths.PARTITION_KEY_RANGES_PATH_SEGMENT + "/" + resourceName; - default: - return null; - } - } - - public static String getCollectionPath(String resourceFullName) { - if (resourceFullName != null) { - String trimmedResourceFullName = Utils.trimBeginningAndEndingSlashes(resourceFullName); - int index = indexOfNth(trimmedResourceFullName, '/', 4); - if (index > 0) - return trimmedResourceFullName.substring(0, index); - } - - return resourceFullName; - } - - public static String getDatabasePath(String resourceFullName) { - if (resourceFullName != null) { - int index = indexOfNth(resourceFullName, '/', 2); - if (index > 0) - return resourceFullName.substring(0, index); - } - - return resourceFullName; - } - - public static String getParentByIndex(String resourceFullName, int segmentIndex) { - int index = indexOfNth(resourceFullName, '/', segmentIndex); - if (index > 0) - return resourceFullName.substring(0, index); - else { - index = indexOfNth(resourceFullName, '/', segmentIndex - 1); - if (index > 0) - return resourceFullName; - else - return null; - } - } - public static boolean isNameBased(String resourceIdOrFullName) { - // quick way to tell whether it is resourceId nor not, non conclusively. - if (resourceIdOrFullName != null && !resourceIdOrFullName.isEmpty() - && resourceIdOrFullName.length() > 4 && resourceIdOrFullName.charAt(3) == '/') { - return true; - } - return false; - } - - private static int indexOfNth(String str, char value, int nthOccurance) { - int remaining = nthOccurance; - char[] characters = str.toCharArray(); - for (int i = 0; i < characters.length; i++) { - if (characters[i] == value) { - remaining--; - if (remaining == 0) { - return i; - } - } - } - return -1; - } - - public static ResourceType getResourcePathSegment(String resourcePathSegment) throws BadRequestException { - if (StringUtils.isEmpty(resourcePathSegment)) { - String message = String.format(RMResources.StringArgumentNullOrEmpty, "resourcePathSegment"); - throw new BadRequestException(message); - } - - switch (resourcePathSegment) { - case Paths.ATTACHMENTS_PATH_SEGMENT: - return ResourceType.Attachment; - - case Paths.COLLECTIONS_PATH_SEGMENT: - return ResourceType.DocumentCollection; - - case Paths.DATABASES_PATH_SEGMENT: - return ResourceType.Database; - - case Paths.PERMISSIONS_PATH_SEGMENT: - return ResourceType.Permission; - - case Paths.USERS_PATH_SEGMENT: - return ResourceType.User; - - case Paths.DOCUMENTS_PATH_SEGMENT: - return ResourceType.Document; - - case Paths.STORED_PROCEDURES_PATH_SEGMENT: - return ResourceType.StoredProcedure; - - case Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT: - return ResourceType.UserDefinedFunction; - - case Paths.TRIGGERS_PATH_SEGMENT: - return ResourceType.Trigger; - - case Paths.CONFLICTS_PATH_SEGMENT: - return ResourceType.Conflict; - - case Paths.OFFERS_PATH_SEGMENT: - return ResourceType.Offer; - - case Paths.SCHEMAS_PATH_SEGMENT: - return ResourceType.Schema; - } - - String errorMessage = String.format(RMResources.UnknownResourceType, resourcePathSegment); - throw new BadRequestException(errorMessage); - } - - public static String getResourcePath(ResourceType resourceType) throws BadRequestException { - switch (resourceType) { - case Database: - return Paths.DATABASES_PATH_SEGMENT; - - case DocumentCollection: - return Paths.COLLECTIONS_PATH_SEGMENT; - - case Document: - return Paths.DOCUMENTS_PATH_SEGMENT; - - case StoredProcedure: - return Paths.STORED_PROCEDURES_PATH_SEGMENT; - - case UserDefinedFunction: - return Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT; - - case Trigger: - return Paths.TRIGGERS_PATH_SEGMENT; - - case Conflict: - return Paths.CONFLICTS_PATH_SEGMENT; - - case Attachment: - return Paths.ATTACHMENTS_PATH_SEGMENT; - - case User: - return Paths.USERS_PATH_SEGMENT; - - case Permission: - return Paths.PERMISSIONS_PATH_SEGMENT; - - case Offer: - return Paths.OFFERS_PATH_SEGMENT; - - case MasterPartition: - case ServerPartition: - return Paths.PARTITIONS_PATH_SEGMENT; - - case PartitionKeyRange: - return Paths.PARTITION_KEY_RANGES_PATH_SEGMENT; - - case Media: - return Paths.MEDIA_ROOT; - - case Schema: - return Paths.SCHEMAS_PATH_SEGMENT; - - - case DatabaseAccount: - case Topology: - - return Paths.ROOT; - - default: - String errorMessage = String.format(RMResources.UnknownResourceType, resourceType.toString()); - throw new BadRequestException(errorMessage); - } - } - - public static boolean validateResourceFullName(ResourceType resourceType, String resourceFullName) { - String[] segments = StringUtils.split(resourceFullName, '/'); - String[] resourcePathArray = getResourcePathArray(resourceType); - if (resourcePathArray == null) { - return false; - } - - if (segments.length != resourcePathArray.length * 2) { - return false; - } - for (int i = 0; i < resourcePathArray.length; i++) { - if(resourcePathArray[i].compareTo(segments[2 * i]) != 0) { - return false; - } - } - return true; - } - - private static String[] getResourcePathArray(ResourceType resourceType) { - List segments = new ArrayList(); - segments.add(Paths.DATABASES_PATH_SEGMENT); - - if (resourceType == ResourceType.Permission || - resourceType == ResourceType.User) { - segments.add(Paths.USERS_PATH_SEGMENT); - if (resourceType == ResourceType.Permission) { - segments.add(Paths.PERMISSIONS_PATH_SEGMENT); - } - } else if (resourceType == ResourceType.DocumentCollection || - resourceType == ResourceType.StoredProcedure || - resourceType == ResourceType.UserDefinedFunction || - resourceType == ResourceType.Trigger || - resourceType == ResourceType.Conflict || - resourceType == ResourceType.Attachment || - resourceType == ResourceType.Document || - resourceType == ResourceType.PartitionKeyRange || - resourceType == ResourceType.Schema) { - segments.add(Paths.COLLECTIONS_PATH_SEGMENT); - if (resourceType == ResourceType.StoredProcedure) { - segments.add(Paths.STORED_PROCEDURES_PATH_SEGMENT); - } else if(resourceType == ResourceType.UserDefinedFunction) { - segments.add(Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT); - } else if(resourceType == ResourceType.Trigger) { - segments.add(Paths.TRIGGERS_PATH_SEGMENT); - } else if (resourceType == ResourceType.Conflict) { - segments.add(Paths.CONFLICTS_PATH_SEGMENT); - } else if (resourceType == ResourceType.Schema) { - segments.add(Paths.SCHEMAS_PATH_SEGMENT); - } else if(resourceType == ResourceType.Document || - resourceType == ResourceType.Attachment) { - segments.add(Paths.DOCUMENTS_PATH_SEGMENT); - if (resourceType == ResourceType.Attachment) { - segments.add(Paths.ATTACHMENTS_PATH_SEGMENT); - } - } else if(resourceType == ResourceType.PartitionKeyRange) { - segments.add(Paths.PARTITION_KEY_RANGES_PATH_SEGMENT); - } - } else if (resourceType != ResourceType.Database) { - return null; - } - return segments.stream().toArray(String[]::new); - } - - public static boolean validateResourceId(ResourceType resourceType, String resourceId) { - if (resourceType == ResourceType.Conflict) { - return PathsHelper.validateConflictId(resourceId); - } else if (resourceType == ResourceType.Database) { - return PathsHelper.validateDatabaseId(resourceId); - } else if (resourceType == ResourceType.DocumentCollection) { - return PathsHelper.validateDocumentCollectionId(resourceId); - } else if (resourceType == ResourceType.Document) { - return PathsHelper.validateDocumentId(resourceId); - } else if (resourceType == ResourceType.Permission) { - return PathsHelper.validatePermissionId(resourceId); - } else if (resourceType == ResourceType.StoredProcedure) { - return PathsHelper.validateStoredProcedureId(resourceId); - } else if (resourceType == ResourceType.Trigger) { - return PathsHelper.validateTriggerId(resourceId); - } else if (resourceType == ResourceType.UserDefinedFunction) { - return PathsHelper.validateUserDefinedFunctionId(resourceId); - } else if (resourceType == ResourceType.User) { - return PathsHelper.validateUserId(resourceId); - } else if (resourceType == ResourceType.Attachment) { - return PathsHelper.validateAttachmentId(resourceId); - } else { - logger.error(String.format("ValidateResourceId not implemented for Type %s in ResourceRequestHandler", resourceType.toString())); - return false; - } - } - - public static boolean validateDatabaseId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getDatabase() != 0; - } - - public static boolean validateDocumentCollectionId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getDocumentCollection() != 0; - } - - public static boolean validateDocumentId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getDocument() != 0; - } - - public static boolean validateConflictId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getConflict() != 0; - } - - public static boolean validateAttachmentId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getAttachment() != 0; - } - - public static boolean validatePermissionId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getPermission() != 0; - } - - public static boolean validateStoredProcedureId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getStoredProcedure() != 0; - } - - public static boolean validateTriggerId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getTrigger() != 0; - } - - public static boolean validateUserDefinedFunctionId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getUserDefinedFunction() != 0; - } - - public static boolean validateUserId(String resourceIdString) { - Pair pair = ResourceId.tryParse(resourceIdString); - return pair.getLeft() && pair.getRight().getUser() != 0; - } - - - public static boolean isPublicResource(Resource resourceType) { - if (resourceType instanceof Database || - resourceType instanceof DocumentCollection || - resourceType instanceof StoredProcedure || - resourceType instanceof UserDefinedFunction || - resourceType instanceof Trigger || - resourceType instanceof Conflict || - resourceType instanceof Attachment || - resourceType instanceof User || - resourceType instanceof Permission || - resourceType instanceof Document || - resourceType instanceof Offer - ) { - return true; - } else { - return false; - } - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Quadruple.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Quadruple.java deleted file mode 100644 index 624c12b5148e..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Quadruple.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Represents class with four different generic objects. - */ -public class Quadruple { - - private final A val0; - private final B val1; - private final C val2; - private final D val3; - - public static Quadruple with(final A value0, final B value1, final C value2, - final D value3) { - return new Quadruple(value0, value1, value2, value3); - } - - public Quadruple(final A value0, final B value1, final C value2, final D value3) { - this.val0 = value0; - this.val1 = value1; - this.val2 = value2; - this.val3 = value3; - } - - public A getValue0() { - return this.val0; - } - - public B getValue1() { - return this.val1; - } - - public C getValue2() { - return this.val2; - } - - public D getValue3() { - return this.val3; - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/QueryCompatibilityMode.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/QueryCompatibilityMode.java deleted file mode 100644 index 77dba9f5c531..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/QueryCompatibilityMode.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * A client query compatibility mode when making query request in the Azure Cosmos DB database service. Can be used - * to force a specific query request format. - */ -public enum QueryCompatibilityMode { - Default, - Query, - SqlQuery -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/RequestChargeTracker.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/RequestChargeTracker.java deleted file mode 100644 index 0cb8d3468835..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/RequestChargeTracker.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.util.concurrent.atomic.AtomicLong; - -/** - * Tracks requests charge in the Azure Cosmos DB database service. - */ -public final class RequestChargeTracker { - private final static int NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR = 1000; - private final AtomicLong totalRUs = new AtomicLong(); - - public double getTotalRequestCharge() { - return ((double) this.totalRUs.get()) / NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR; - } - - public void addCharge(double ruUsage) { - this.totalRUs.addAndGet((long) (ruUsage * NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR)); - } - - public double getAndResetCharge() { - return (double) this.totalRUs.getAndSet(0) / NUMBER_OF_DECIMAL_POINT_TO_RESERVE_FACTOR; - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceId.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceId.java deleted file mode 100644 index 78bd93de8946..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceId.java +++ /dev/null @@ -1,540 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; - -/** - * Used internally to represents a Resource ID in the Azure Cosmos DB database service. - */ -public class ResourceId { - static final short Length = 20; - static final short OFFER_ID_LENGTH = 3; - static final short MAX_PATH_FRAGMENT = 8; - - private int database; - private int documentCollection; - private long storedProcedure; - private long trigger; - private long userDefinedFunction; - private long conflict; - private long document; - private long partitionKeyRange; - private int user; - private long permission; - private int attachment; - private long offer; - - private ResourceId() { - this.offer = 0; - this.database = 0; - this.documentCollection = 0; - this.storedProcedure = 0; - this.trigger = 0; - this.userDefinedFunction = 0; - this.document = 0; - this.partitionKeyRange = 0; - this.user = 0; - this.conflict = 0; - this.permission = 0; - this.attachment = 0; - } - - public static ResourceId parse(String id) throws IllegalArgumentException { - Pair pair = ResourceId.tryParse(id); - - if (!pair.getKey()) { - throw new IllegalArgumentException(String.format( - "Invalid resource id %s", id)); - } - return pair.getValue(); - } - - public static byte[] parse(ResourceType type, String id) { - if (ResourceId.hasNonHierarchicalResourceId(type)) { - return id.getBytes(StandardCharsets.UTF_8); - } - return ResourceId.parse(id).getValue(); - } - - private static boolean hasNonHierarchicalResourceId(ResourceType type) { - switch (type) { - case MasterPartition: - case ServerPartition: - case RidRange: - return true; - default: - return false; - } - } - - public static ResourceId newDatabaseId(int dbid) { - ResourceId resourceId = new ResourceId(); - resourceId.database = dbid; - return resourceId; - } - - public static ResourceId newDocumentCollectionId(String databaseId, int collectionId) { - ResourceId dbId = ResourceId.parse(databaseId); - - return newDocumentCollectionId(dbId.database, collectionId); - } - - static ResourceId newDocumentCollectionId(int dbId, int collectionId) { - ResourceId collectionResourceId = new ResourceId(); - collectionResourceId.database = dbId; - collectionResourceId.documentCollection = collectionId; - - return collectionResourceId; - } - - public static ResourceId newUserId(String databaseId, int userId) { - ResourceId dbId = ResourceId.parse(databaseId); - - ResourceId userResourceId = new ResourceId(); - userResourceId.database = dbId.database; - userResourceId.user = userId; - - return userResourceId; - } - - public static ResourceId newPermissionId(String userId, long permissionId) { - ResourceId usrId = ResourceId.parse(userId); - - ResourceId permissionResourceId = new ResourceId(); - permissionResourceId.database = usrId.database; - permissionResourceId.user = usrId.user; - permissionResourceId.permission = permissionId; - return permissionResourceId; - } - - public static ResourceId newAttachmentId(String documentId, int attachmentId) { - ResourceId docId = ResourceId.parse(documentId); - - ResourceId attachmentResourceId = new ResourceId(); - attachmentResourceId.database = docId.database; - attachmentResourceId.documentCollection = docId.documentCollection; - attachmentResourceId.document = docId.document; - attachmentResourceId.attachment = attachmentId; - - return attachmentResourceId; - } - - public static Pair tryParse(String id) { - ResourceId rid = null; - - try { - if (StringUtils.isEmpty(id)) - return Pair.of(false, null); - - if (id.length() % 4 != 0) { - // our ResourceId string is always padded - return Pair.of(false, null); - } - - byte[] buffer = null; - - Pair pair = ResourceId.verify(id); - - if (!pair.getKey()) - return Pair.of(false, null); - - buffer = pair.getValue(); - - if (buffer.length % 4 != 0 && buffer.length != ResourceId.OFFER_ID_LENGTH) { - return Pair.of(false, null); - } - - rid = new ResourceId(); - - if (buffer.length == ResourceId.OFFER_ID_LENGTH) { - rid.offer = 0; - for (int index = 0; index < ResourceId.OFFER_ID_LENGTH; index++) - { - rid.offer |= (long)(buffer[index] << (index * 8)); - } - return Pair.of(true, rid); - } - - if (buffer.length >= 4) - rid.database = ByteBuffer.wrap(buffer).getInt(); - - if (buffer.length >= 8) { - byte[] temp = new byte[4]; - ResourceId.blockCopy(buffer, 4, temp, 0, 4); - - boolean isCollection = (temp[0] & (128)) > 0; - - if (isCollection) { - rid.documentCollection = ByteBuffer.wrap(temp).getInt(); - - if (buffer.length >= 16) { - byte[] subCollRes = new byte[8]; - ResourceId.blockCopy(buffer, 8, subCollRes, 0, 8); - - long subCollectionResource = ByteBuffer.wrap(buffer, 8, 8).getLong(); - if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.Document) { - rid.document = subCollectionResource; - - if (buffer.length == 20) { - rid.attachment = ByteBuffer.wrap(buffer, 16, 4).getInt(); - } - } else if (Math.abs(subCollRes[7] >> 4) == (byte) CollectionChildResourceType.StoredProcedure) { - rid.storedProcedure = subCollectionResource; - } else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.Trigger) { - rid.trigger = subCollectionResource; - } else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.UserDefinedFunction) { - rid.userDefinedFunction = subCollectionResource; - } else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.Conflict) { - rid.conflict = subCollectionResource; - } else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.PartitionKeyRange) { - rid.partitionKeyRange = subCollectionResource; - } else { - return Pair.of(false, rid); - } - } else if (buffer.length != 8) { - return Pair.of(false, rid); - } - } else { - rid.user = ByteBuffer.wrap(temp).getInt(); - - if (buffer.length == 16) { - rid.permission = ByteBuffer.wrap(buffer, 8, 8).getLong(); - } else if (buffer.length != 8) { - return Pair.of(false, rid); - } - } - } - - return Pair.of(true, rid); - } catch (Exception e) { - return Pair.of(false, null); - } - } - - public static Pair verify(String id) { - if (StringUtils.isEmpty(id)) - throw new IllegalArgumentException("id"); - - byte[] buffer = null; - - try { - buffer = ResourceId.fromBase64String(id); - } catch (Exception e) { - } - - if (buffer == null || buffer.length > ResourceId.Length) { - buffer = null; - return Pair.of(false, buffer); - } - - return Pair.of(true, buffer); - } - - public static boolean verifyBool(String id) { - return verify(id).getKey(); - } - - static byte[] fromBase64String(String s) { - return Utils.Base64Decoder.decode(s.replace('-', '/')); - } - - static String toBase64String(byte[] buffer) { - return ResourceId.toBase64String(buffer, 0, buffer.length); - } - - static String toBase64String(byte[] buffer, int offset, int length) { - byte[] subBuffer = Arrays.copyOfRange(buffer, offset, length); - - return Utils.encodeBase64String(subBuffer).replace('/', '-'); - } - - // Copy the bytes provided with a for loop, faster when there are only a few - // bytes to copy - static void blockCopy(byte[] src, int srcOffset, byte[] dst, int dstOffset, int count) { - int stop = srcOffset + count; - for (int i = srcOffset; i < stop; i++) - dst[dstOffset++] = src[i]; - } - - private static byte[] convertToBytesUsingByteBuffer(int value) { - ByteOrder order = ByteOrder.BIG_ENDIAN; - ByteBuffer buffer = ByteBuffer.allocate(4); - buffer.order(order); - return buffer.putInt(value).array(); - } - - private static byte[] convertToBytesUsingByteBuffer(long value) { - ByteOrder order = ByteOrder.BIG_ENDIAN; - ByteBuffer buffer = ByteBuffer.allocate(8); - buffer.order(order); - return buffer.putLong(value).array(); - } - - public boolean isDatabaseId() { - return this.getDatabase() != 0 && (this.getDocumentCollection() == 0 && this.getUser() == 0); - } - - public int getDatabase() { - return this.database; - } - - public ResourceId getDatabaseId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - return rid; - } - - public int getDocumentCollection() { - return this.documentCollection; - } - - public ResourceId getDocumentCollectionId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - return rid; - } - - /** - * Unique (across all databases) Id for the DocumentCollection. - * First 4 bytes are DatabaseId and next 4 bytes are CollectionId. - * - * @return the unique collectionId - */ - public long getUniqueDocumentCollectionId() { - return (long) this.database << 32 | this.documentCollection; - } - - public long getStoredProcedure() { - return this.storedProcedure; - } - - public ResourceId getStoredProcedureId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - rid.storedProcedure = this.storedProcedure; - return rid; - } - - public long getTrigger() { - return this.trigger; - } - - public ResourceId getTriggerId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - rid.trigger = this.trigger; - return rid; - } - - public long getUserDefinedFunction() { - return this.userDefinedFunction; - } - - public ResourceId getUserDefinedFunctionId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - rid.userDefinedFunction = this.userDefinedFunction; - return rid; - } - - public long getConflict() { - return this.conflict; - } - - public ResourceId getConflictId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - rid.conflict = this.conflict; - return rid; - } - - public long getDocument() { - return this.document; - } - - public ResourceId getDocumentId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - rid.document = this.document; - return rid; - } - - public long getPartitionKeyRange() { - return this.partitionKeyRange; - } - - public ResourceId getPartitionKeyRangeId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - rid.partitionKeyRange = this.partitionKeyRange; - return rid; - } - - public int getUser() { - return this.user; - } - - public ResourceId getUserId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.user = this.user; - return rid; - } - - public long getPermission() { - return this.permission; - } - - public ResourceId getPermissionId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.user = this.user; - rid.permission = this.permission; - return rid; - } - - public int getAttachment() { - return this.attachment; - } - - public ResourceId getAttachmentId() { - ResourceId rid = new ResourceId(); - rid.database = this.database; - rid.documentCollection = this.documentCollection; - rid.document = this.document; - rid.attachment = this.attachment; - return rid; - } - - public long getOffer() { return this.offer; } - - public ResourceId getOfferId() { - ResourceId rid = new ResourceId(); - rid.offer = this.offer; - return rid; - } - - public byte[] getValue() { - int len = 0; - if (this.offer != 0) - len += ResourceId.OFFER_ID_LENGTH; - else if (this.database != 0) - len += 4; - if (this.documentCollection != 0 || this.user != 0) - len += 4; - if (this.document != 0 || this.permission != 0 - || this.storedProcedure != 0 || this.trigger != 0 - || this.userDefinedFunction != 0 || this.conflict != 0 - || this.partitionKeyRange != 0) - len += 8; - if (this.attachment != 0) - len += 4; - - byte[] val = new byte[len]; - - if (this.offer != 0) - ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.offer), - 0, val, 0, ResourceId.OFFER_ID_LENGTH); - else if (this.database != 0) - ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.database), - 0, val, 0, 4); - - if (this.documentCollection != 0) - ResourceId.blockCopy( - convertToBytesUsingByteBuffer(this.documentCollection), - 0, val, 4, 4); - else if (this.user != 0) - ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.user), - 0, val, 4, 4); - - if (this.storedProcedure != 0) - ResourceId.blockCopy( - convertToBytesUsingByteBuffer(this.storedProcedure), - 0, val, 8, 8); - else if (this.trigger != 0) - ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.trigger), - 0, val, 8, 8); - else if (this.userDefinedFunction != 0) - ResourceId.blockCopy( - convertToBytesUsingByteBuffer(this.userDefinedFunction), - 0, val, 8, 8); - else if (this.conflict != 0) - ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.conflict), - 0, val, 8, 8); - else if (this.document != 0) - ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.document), - 0, val, 8, 8); - else if (this.permission != 0) - ResourceId.blockCopy( - convertToBytesUsingByteBuffer(this.permission), - 0, val, 8, 8); - else if (this.partitionKeyRange != 0) - ResourceId.blockCopy( - convertToBytesUsingByteBuffer(this.partitionKeyRange), - 0, val, 8, 8); - - if (this.attachment != 0) - ResourceId.blockCopy( - convertToBytesUsingByteBuffer(this.attachment), - 0, val, 16, 4); - - return val; - } - - public String toString() { - return ResourceId.toBase64String(this.getValue()); - } - - public boolean equals(ResourceId other) { - if (other == null) { - return false; - } - - return Arrays.equals(this.getValue(), other.getValue()); - } - - // Using a byte however, we only need nibble here. - private static class CollectionChildResourceType { - public static final byte Document = 0x0; - public static final byte StoredProcedure = 0x08; - public static final byte Trigger = 0x07; - public static final byte UserDefinedFunction = 0x06; - public static final byte Conflict = 0x04; - public static final byte PartitionKeyRange = 0x05; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceTokenAuthorizationHelper.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceTokenAuthorizationHelper.java deleted file mode 100644 index 9e0577917258..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceTokenAuthorizationHelper.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal; - -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.tuple.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyAndResourceTokenPair; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; - -/** - * This class is used internally and act as a helper in authorization of - * resources from permission feed and its supporting method. - * - */ -public class ResourceTokenAuthorizationHelper { - - private static final Logger logger = LoggerFactory.getLogger(ResourceTokenAuthorizationHelper.class); - - /** - * This method help to differentiate between master key and resource token - * - * @param token - * ResourceToken provide - * @return Whether given token is resource token or not - */ - public static boolean isResourceToken(String token) { - int typeSeparatorPosition = token.indexOf('&'); - if (typeSeparatorPosition == -1) { - return false; - } - String authType = token.substring(0, typeSeparatorPosition); - int typeKeyValueSepartorPosition = authType.indexOf('='); - if (typeKeyValueSepartorPosition == -1 || !authType.substring(0, typeKeyValueSepartorPosition) - .equalsIgnoreCase(Constants.Properties.AUTH_SCHEMA_TYPE)) { - return false; - } - - String authTypeValue = authType.substring(typeKeyValueSepartorPosition + 1); - - return authTypeValue.equalsIgnoreCase(Constants.Properties.RESOURCE_TOKEN); - } - - /** - * Private method which will fetch resource token based on partition key and - * resource address . - * - * @param resourceTokensMap - * @param resourceAddress - * @param partitionKey - * @return - */ - private static String getResourceToken(Map> resourceTokensMap, - String resourceAddress, - PartitionKeyInternal partitionKey) { - List partitionKeyAndResourceTokenPairs = resourceTokensMap - .get(resourceAddress); - if (partitionKeyAndResourceTokenPairs != null) { - for (PartitionKeyAndResourceTokenPair pair : partitionKeyAndResourceTokenPairs) { - if (pair.getPartitionKey().contains(partitionKey) || partitionKey.equals(PartitionKeyInternal.Empty)) { - return pair.getResourceToken(); - } - } - } - - return null; - } - - /** - * This method will try to fetch the resource token to access the resource . - * - * @param resourceTokensMap - * It contains the resource link and its partition key and resource - * token list . - * @param headers - * Header information of the request . - * @param resourceAddress - * Resource full name or ID . - * @param requestVerb - * The verb . - */ - public static String getAuthorizationTokenUsingResourceTokens( - Map> resourceTokensMap, - String requestVerb, - String resourceAddress, - Map headers) { - PartitionKeyInternal partitionKey = PartitionKeyInternal.Empty; - String partitionKeyString = headers.get(HttpConstants.HttpHeaders.PARTITION_KEY); - if (partitionKeyString != null) { - partitionKey = PartitionKeyInternal.fromJsonString(partitionKeyString); - } - - if (PathsHelper.isNameBased(resourceAddress)) { - String resourceToken = null; - for (int index = 2; index < ResourceId.MAX_PATH_FRAGMENT; index = index + 2) { - String resourceParent = PathsHelper.getParentByIndex(resourceAddress, index); - if (resourceParent == null) - break; - resourceToken = getResourceToken(resourceTokensMap, resourceParent, partitionKey); - if (resourceToken != null) - break; - } - - // Get or Head for collection can be done with any child token - if (resourceToken == null && PathsHelper.getCollectionPath(resourceAddress).equalsIgnoreCase(resourceAddress) - && HttpConstants.HttpMethods.GET.equalsIgnoreCase(requestVerb) - || HttpConstants.HttpMethods.HEAD.equalsIgnoreCase(requestVerb)) { - String resourceAddressWithSlash = resourceAddress.endsWith(Constants.Properties.PATH_SEPARATOR) - ? resourceAddress - : resourceAddress + Constants.Properties.PATH_SEPARATOR; - for (String key : resourceTokensMap.keySet()) { - if (key.startsWith(resourceAddressWithSlash)) { - if (resourceTokensMap.get(key) != null && resourceTokensMap.get(key).size() > 0) - resourceToken = resourceTokensMap.get(key).get(0).getResourceToken(); - break; - } - } - } - - if (resourceToken == null) { - throw new IllegalArgumentException(RMResources.ResourceTokenNotFound); - } - - logger.debug("returned token for resourceAddress [{}] = [{}]", - resourceAddress, resourceToken); - return resourceToken; - } else { - String resourceToken = null; - ResourceId resourceId = ResourceId.parse(resourceAddress); - if (resourceId.getAttachment() != 0 || resourceId.getPermission() != 0 - || resourceId.getStoredProcedure() != 0 || resourceId.getTrigger() != 0 - || resourceId.getUserDefinedFunction() != 0) { - // Use the leaf ID - attachment/permission/sproc/trigger/udf - resourceToken = getResourceToken(resourceTokensMap, resourceAddress, partitionKey); - } - - if (resourceToken == null && (resourceId.getAttachment() != 0 || resourceId.getDocument() != 0)) { - // Use DocumentID for attachment/document - resourceToken = getResourceToken(resourceTokensMap, resourceId.getDocumentId().toString(), - partitionKey); - } - - if (resourceToken == null && (resourceId.getAttachment() != 0 || resourceId.getDocument() != 0 - || resourceId.getStoredProcedure() != 0 || resourceId.getTrigger() != 0 - || resourceId.getUserDefinedFunction() != 0 || resourceId.getDocumentCollection() != 0)) { - // Use CollectionID for attachment/document/sproc/trigger/udf/collection - resourceToken = getResourceToken(resourceTokensMap, resourceId.getDocumentCollectionId().toString(), - partitionKey); - } - - if (resourceToken == null && (resourceId.getPermission() != 0 || resourceId.getUser() != 0)) { - // Use UserID for permission/user - resourceToken = getResourceToken(resourceTokensMap, resourceId.getUserId().toString(), partitionKey); - } - - if (resourceToken == null) { - // Use DatabaseId if all else fail - resourceToken = getResourceToken(resourceTokensMap, resourceId.getDatabaseId().toString(), - partitionKey); - } - // Get or Head for collection can be done with any child token - if (resourceToken == null && resourceId.getDocumentCollection() != 0 - && (HttpConstants.HttpMethods.GET.equalsIgnoreCase(requestVerb) - || HttpConstants.HttpMethods.HEAD.equalsIgnoreCase(requestVerb))) { - for (String key : resourceTokensMap.keySet()) { - ResourceId tokenRid; - Pair pair = ResourceId.tryParse(key); - ResourceId test1= pair.getRight().getDocumentCollectionId(); - boolean test = test1.equals(resourceId); - if (!PathsHelper.isNameBased(key) && pair.getLeft() - && pair.getRight().getDocumentCollectionId().equals(resourceId)) { - if (resourceTokensMap.get(key) != null && resourceTokensMap.get(key).size() > 0) { - resourceToken = resourceTokensMap.get(key).get(0).getResourceToken(); - } - } - } - - } - - if (resourceToken == null) { - throw new IllegalArgumentException(RMResources.ResourceTokenNotFound); - } - - logger.debug("returned token for resourceAddress [{}] = [{}]", - resourceAddress, resourceToken); - return resourceToken; - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceType.java deleted file mode 100644 index cf6a2f609487..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/ResourceType.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Resource types in the Azure Cosmos DB database service. - */ -public enum ResourceType { - - // REQUIRED: This enum must be kept in sync with the ResourceType enum in backend native - - Unknown(-1), - Attachment(3), - BatchApply(112), - DocumentCollection(1), - ComputeGatewayCharges(131), - Conflict(107), - Database(0), - DatabaseAccount(118), - Document(2), - Index(104), - IndexBookmark(105), - IndexSize(106), - LargeInvalid(100), - LogStoreLogs(126), - MasterPartition(120), - Module(9), - ModuleCommand(103), - Offer(113), - PartitionKeyRange(125), - PartitionSetInformation(114), - Permission(5), - PreviousImage(128), - Progress(6), - Record(108), - Replica(7), - RestoreMetadata(127), - RidRange(130), - Schema(124), - SchemaContainer(123), - ServerPartition(121), - SmallMaxInvalid(10), - StoredProcedure(109), - Timestamp(117), - Tombstone(8), - Topology(122), - Trigger(110), - User(4), - UserDefinedFunction(111), - UserDefinedType(133), - VectorClock(129), - XPReplicatorAddress(115), - - // These names make it unclear what they map to in ResourceType. - Address(-5), - Key(-2), - Media(-3), - ServiceFabricService(-4); - - final private int value; - - ResourceType(int value) { - this.value = value; - } - - public int value() { - return this.value; - } - - public boolean isCollectionChild() { - return this == ResourceType.Document || - this == ResourceType.Attachment || - this == ResourceType.Conflict || - this == ResourceType.Schema || - this.isScript(); - } - - public boolean isMasterResource() { - return this == ResourceType.Offer || - this == ResourceType.Database || - this == ResourceType.User || - this == ResourceType.Permission || - this == ResourceType.Topology || - this == ResourceType.PartitionKeyRange || - this == ResourceType.DocumentCollection; - } - - ///

- /// Resources for which this method returns true, are spread between multiple partitions - /// - public boolean isPartitioned() { - return this == ResourceType.Document || - this == ResourceType.Attachment || - this == ResourceType.Conflict; - } - - public boolean isScript() { - return this == ResourceType.UserDefinedFunction || - this == ResourceType.Trigger || - this == ResourceType.StoredProcedure; - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/RuntimeConstants.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/RuntimeConstants.java deleted file mode 100644 index fe1907cca044..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/RuntimeConstants.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Used internally. Runtime constants in the Azure Cosmos DB database service Java SDK. - */ -public class RuntimeConstants { - public static class MediaTypes { - // http://www.iana.org/assignments/media-types/media-types.xhtml - public static final String ANY = "*/*"; - public static final String IMAGE_JPEG = "image/jpeg"; - public static final String IMAGE_PNG = "image/png"; - public static final String JAVA_SCRIPT = "application/x-javascript"; - public static final String JSON = "application/json"; - public static final String OCTET_STREAM = "application/octet-stream"; - public static final String QUERY_JSON = "application/query+json"; - public static final String SQL = "application/sql"; - public static final String TEXT_HTML = "text/html"; - public static final String TEXT_PLAIN = "text/plain"; - public static final String XML = "application/xml"; - } - - public static class ProtocolScheme { - public static final String HTTPS = "https"; - public static final String TCP = "rntbd"; - } - - static class Separators { - static final char[] Url = new char[] {'/'}; - static final char[] Quote = new char[] {'\''}; - static final char[] DomainId = new char[] {'-'}; - static final char[] Query = new char[] {'?', '&', '='}; - static final char[] Parenthesis = new char[] {'(', ')'}; - static final char[] UserAgentHeader = new char[] {'(', ')', ';', ','}; - - - //Note that the accept header separator here is ideally comma. Semicolon is used for separators within individual - //header for now cloud moe does not recognize such accept header hence we allow both semicolon or comma separated - //accept header - static final char[] Header = new char[] {';', ','}; - static final char[] CookieSeparator = new char[] {';'}; - static final char[] CookieValueSeparator = new char[] {'='}; - static final char[] PPMUserToken = new char[] {':'}; - static final char[] Identifier = new char[] {'-'}; - static final char[] Host = new char[] {'.'}; - static final char[] Version = new char[] {','}; - static final char[] Pair = new char[] {';'}; - static final char[] ETag = new char[] {'#'}; - static final char[] MemberQuery = new char[] {'+'}; - - static final String HeaderEncodingBegin = "=?"; - static final String HeaderEncodingEnd = "?="; - static final String HeaderEncodingSeparator = "?"; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Utils.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Utils.java deleted file mode 100644 index 821e25392566..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/Utils.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLEncoder; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Base64; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.uuid.EthernetAddress; -import com.fasterxml.uuid.Generators; -import com.fasterxml.uuid.impl.TimeBasedGenerator; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentCollection; - -/** - * Used internally to provides utility functions for the Azure Cosmos DB database service Java SDK. - */ -public final class Utils { - private static final ZoneId GMT_ZONE_ID = ZoneId.of("GMT"); - public static final Base64.Encoder Base64Encoder = Base64.getEncoder(); - public static final Base64.Decoder Base64Decoder = Base64.getDecoder(); - - private static final ObjectMapper simpleObjectMapper = new ObjectMapper(); - private static final TimeBasedGenerator TimeUUIDGegerator = - Generators.timeBasedGenerator(EthernetAddress.constructMulticastAddress()); - - // NOTE DateTimeFormatter.RFC_1123_DATE_TIME cannot be used. - // because cosmos db rfc1123 validation requires two digits for day. - // so Thu, 04 Jan 2018 00:30:37 GMT is accepted by the cosmos db service, - // but Thu, 4 Jan 2018 00:30:37 GMT is not. - // Therefore, we need a custom date time formatter. - private static final DateTimeFormatter RFC_1123_DATE_TIME = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); - - static { - Utils.simpleObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Utils.simpleObjectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - Utils.simpleObjectMapper.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA, true); - Utils.simpleObjectMapper.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true); - } - - public static byte[] getUTF8Bytes(String str) throws UnsupportedEncodingException { - return str.getBytes("UTF-8"); - } - - public static String encodeBase64String(byte[] binaryData) { - String encodedString = Base64Encoder.encodeToString(binaryData); - - if (encodedString.endsWith("\r\n")) { - encodedString = encodedString.substring(0, encodedString.length() - 2); - } - return encodedString; - } - - /** - * Checks whether the specified link is Name based or not - * - * @param link the link to analyze. - * @return true or false - */ - public static boolean isNameBased(String link) { - if (StringUtils.isEmpty(link)) { - return false; - } - - // trimming the leading "/" - if (link.startsWith("/") && link.length() > 1) { - link = link.substring(1); - } - - // Splitting the link(separated by "/") into parts - String[] parts = StringUtils.split(link, "/"); - - // First part should be "dbs" - if (parts.length == 0 || StringUtils.isEmpty(parts[0]) - || !parts[0].equalsIgnoreCase(Paths.DATABASES_PATH_SEGMENT)) { - return false; - } - - // The second part is the database id(ResourceID or Name) and cannot be - // empty - if (parts.length < 2 || StringUtils.isEmpty(parts[1])) { - return false; - } - - // Either ResourceID or database name - String databaseID = parts[1]; - - // Length of databaseID(in case of ResourceID) is always 8 - if (databaseID.length() != 8) { - return true; - } - - // Decoding the databaseID - byte[] buffer = ResourceId.fromBase64String(databaseID); - - // Length of decoded buffer(in case of ResourceID) is always 4 - if (buffer.length != 4) { - return true; - } - - return false; - } - - /** - * Checks whether the specified link is a Database Self Link or a Database - * ID based link - * - * @param link the link to analyze. - * @return true or false - */ - public static boolean isDatabaseLink(String link) { - if (StringUtils.isEmpty(link)) { - return false; - } - - // trimming the leading and trailing "/" from the input string - link = trimBeginningAndEndingSlashes(link); - - // Splitting the link(separated by "/") into parts - String[] parts = StringUtils.split(link, "/"); - - if (parts.length != 2) { - return false; - } - - // First part should be "dbs" - if (StringUtils.isEmpty(parts[0]) || !parts[0].equalsIgnoreCase(Paths.DATABASES_PATH_SEGMENT)) { - return false; - } - - // The second part is the database id(ResourceID or Name) and cannot be - // empty - if (StringUtils.isEmpty(parts[1])) { - return false; - } - - return true; - } - - /** - * Checks whether the specified path segment is a resource type - * - * @param resourcePathSegment the path segment to analyze. - * @return true or false - */ - public static boolean IsResourceType(String resourcePathSegment) { - if (StringUtils.isEmpty(resourcePathSegment)) { - return false; - } - - switch (resourcePathSegment.toLowerCase()) { - case Paths.ATTACHMENTS_PATH_SEGMENT: - case Paths.COLLECTIONS_PATH_SEGMENT: - case Paths.DATABASES_PATH_SEGMENT: - case Paths.PERMISSIONS_PATH_SEGMENT: - case Paths.USERS_PATH_SEGMENT: - case Paths.DOCUMENTS_PATH_SEGMENT: - case Paths.STORED_PROCEDURES_PATH_SEGMENT: - case Paths.TRIGGERS_PATH_SEGMENT: - case Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT: - case Paths.CONFLICTS_PATH_SEGMENT: - case Paths.PARTITION_KEY_RANGES_PATH_SEGMENT: - return true; - - default: - return false; - } - } - - /** - * Joins the specified paths by appropriately padding them with '/' - * - * @param path1 the first path segment to join. - * @param path2 the second path segment to join. - * @return the concatenated path with '/' - */ - public static String joinPath(String path1, String path2) { - path1 = trimBeginningAndEndingSlashes(path1); - String result = "/" + path1 + "/"; - - if (!StringUtils.isEmpty(path2)) { - path2 = trimBeginningAndEndingSlashes(path2); - result += path2 + "/"; - } - - return result; - } - - /** - * Trims the beginning and ending '/' from the given path - * - * @param path the path to trim for beginning and ending slashes - * @return the path without beginning and ending '/' - */ - public static String trimBeginningAndEndingSlashes(String path) { - if(path == null) { - return null; - } - - if (path.startsWith("/")) { - path = path.substring(1); - } - - if (path.endsWith("/")) { - path = path.substring(0, path.length() - 1); - } - - return path; - } - - public static Map paramEncode(Map queryParams) { - // TODO: this is not performant revisit - HashMap map = new HashMap<>(); - for(Map.Entry paramEntry: queryParams.entrySet()) { - try { - map.put(paramEntry.getKey(), URLEncoder.encode(paramEntry.getValue(), "UTF-8")); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException(e); - } - } - return map; - } - - public static String createQuery(Map queryParameters) { - if (queryParameters == null) - return ""; - StringBuilder queryString = new StringBuilder(); - for (Map.Entry nameValuePair : queryParameters.entrySet()) { - String key = nameValuePair.getKey(); - String value = nameValuePair.getValue(); - if (key != null && !key.isEmpty()) { - if (queryString.length() > 0) { - queryString.append(RuntimeConstants.Separators.Query[1]); - } - queryString.append(key); - if (value != null) { - queryString.append(RuntimeConstants.Separators.Query[2]); - queryString.append(value); - } - } - } - return queryString.toString(); - } - - public static URL setQuery(String urlString, String query) { - - if (urlString == null) - throw new IllegalStateException("urlString parameter can't be null."); - query = Utils.removeLeadingQuestionMark(query); - try { - if (query != null && !query.isEmpty()) { - return new URI(Utils.addTrailingSlash(urlString) + RuntimeConstants.Separators.Query[0] + query) - .toURL(); - } else { - return new URI(Utils.addTrailingSlash(urlString)).toURL(); - } - } catch (MalformedURLException e) { - throw new IllegalStateException("Uri is invalid: ", e); - } catch (URISyntaxException e) { - throw new IllegalStateException("Uri is invalid: ", e); - } - } - - /** - * Given the full path to a resource, extract the collection path. - * - * @param resourceFullName the full path to the resource. - * @return the path of the collection in which the resource is. - */ - public static String getCollectionName(String resourceFullName) { - if (resourceFullName != null) { - resourceFullName = Utils.trimBeginningAndEndingSlashes(resourceFullName); - - int slashCount = 0; - for (int i = 0; i < resourceFullName.length(); i++) { - if (resourceFullName.charAt(i) == '/') { - slashCount++; - if (slashCount == 4) { - return resourceFullName.substring(0, i); - } - } - } - } - return resourceFullName; - } - - public static Boolean isCollectionPartitioned(DocumentCollection collection) { - if (collection == null) { - throw new IllegalArgumentException("collection"); - } - - return collection.getPartitionKey() != null - && collection.getPartitionKey().getPaths() != null - && collection.getPartitionKey().getPaths().size() > 0; - } - - public static boolean isCollectionChild(ResourceType type) { - return type == ResourceType.Document || type == ResourceType.Attachment || type == ResourceType.Conflict - || type == ResourceType.StoredProcedure || type == ResourceType.Trigger || type == ResourceType.UserDefinedFunction; - } - - public static boolean isWriteOperation(OperationType operationType) { - return operationType == OperationType.Create || operationType == OperationType.Upsert || operationType == OperationType.Delete || operationType == OperationType.Replace - || operationType == OperationType.ExecuteJavaScript; - } - - public static boolean isFeedRequest(OperationType requestOperationType) { - return requestOperationType == OperationType.Create || - requestOperationType == OperationType.Upsert || - requestOperationType == OperationType.ReadFeed || - requestOperationType == OperationType.Query || - requestOperationType == OperationType.SqlQuery || - requestOperationType == OperationType.HeadFeed; - } - - private static String addTrailingSlash(String path) { - if (path == null || path.isEmpty()) - path = new String(RuntimeConstants.Separators.Url); - else if (path.charAt(path.length() - 1) != RuntimeConstants.Separators.Url[0]) - path = path + RuntimeConstants.Separators.Url[0]; - - return path; - } - - private static String removeLeadingQuestionMark(String path) { - if (path == null || path.isEmpty()) - return path; - - if (path.charAt(0) == RuntimeConstants.Separators.Query[0]) - return path.substring(1); - - return path; - } - - public static boolean isValidConsistency(ConsistencyLevel backendConsistency, - ConsistencyLevel desiredConsistency) { - switch (backendConsistency) { - case Strong: - return desiredConsistency == ConsistencyLevel.Strong || - desiredConsistency == ConsistencyLevel.BoundedStaleness || - desiredConsistency == ConsistencyLevel.Session || - desiredConsistency == ConsistencyLevel.Eventual || - desiredConsistency == ConsistencyLevel.ConsistentPrefix; - - case BoundedStaleness: - return desiredConsistency == ConsistencyLevel.BoundedStaleness || - desiredConsistency == ConsistencyLevel.Session || - desiredConsistency == ConsistencyLevel.Eventual || - desiredConsistency == ConsistencyLevel.ConsistentPrefix; - - case Session: - case Eventual: - case ConsistentPrefix: - return desiredConsistency == ConsistencyLevel.Session || - desiredConsistency == ConsistencyLevel.Eventual || - desiredConsistency == ConsistencyLevel.ConsistentPrefix; - - default: - throw new IllegalArgumentException("backendConsistency"); - } - } - - public static String getUserAgent(String sdkName, String sdkVersion) { - String osName = System.getProperty("os.name"); - if (osName == null) { - osName = "Unknown"; - } - osName = osName.replaceAll("\\s", ""); - String userAgent = String.format("%s/%s JRE/%s %s/%s", - osName, - System.getProperty("os.version"), - System.getProperty("java.version"), - sdkName, - sdkVersion); - return userAgent; - } - - public static ObjectMapper getSimpleObjectMapper() { - return Utils.simpleObjectMapper; - } - - /** - * Returns Current Time in RFC 1123 format, e.g, - * Fri, 01 Dec 2017 19:22:30 GMT. - * - * @return an instance of String - */ - public static String nowAsRFC1123() { - ZonedDateTime now = ZonedDateTime.now(GMT_ZONE_ID); - return Utils.RFC_1123_DATE_TIME.format(now); - } - - public static UUID randomUUID() { - return TimeUUIDGegerator.generate(); - } - - public static String zonedDateTimeAsUTCRFC1123(ZonedDateTime zonedDateTime){ - return Utils.RFC_1123_DATE_TIME.format(zonedDateTime.withZoneSameInstant(GMT_ZONE_ID)); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Address.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Address.java deleted file mode 100644 index ac09a6669e5d..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Address.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.Constants; - -/** - * Used internally to represent a physical address in the Azure Cosmos DB database service. - */ -public class Address extends Resource { - /** - * Initialize an offer object. - */ - public Address() { - super(); - } - - /** - * Initialize an address object from json string. - * - * @param jsonString the json string that represents the address. - */ - public Address(String jsonString) { - super(jsonString); - } - - public boolean IsPrimary() { - return super.getBoolean(Constants.Properties.IS_PRIMARY); - } - - void setIsPrimary(boolean isPrimary) { - super.set(Constants.Properties.IS_PRIMARY, isPrimary); - } - - public String getProtocolScheme() { - return super.getString(Constants.Properties.PROTOCOL); - } - - void setProtocol(String protocol) { - super.set(Constants.Properties.PROTOCOL, protocol); - } - - public String getLogicalUri() { - return super.getString(Constants.Properties.LOGICAL_URI); - } - - void setLogicalUri(String logicalUri) { - super.set(Constants.Properties.LOGICAL_URI, logicalUri); - } - - public String getPhyicalUri() { - return super.getString(Constants.Properties.PHYISCAL_URI); - } - - void setPhysicalUri(String phyicalUri) { - super.set(Constants.Properties.PHYISCAL_URI, phyicalUri); - } - - public String getPartitionIndex() { - return super.getString(Constants.Properties.PARTITION_INDEX); - } - - void setPartitionIndex(String partitionIndex) { - super.set(Constants.Properties.PARTITION_INDEX, partitionIndex); - } - - public String getParitionKeyRangeId() { - return super.getString(Constants.Properties.PARTITION_KEY_RANGE_ID); - } - - public void setPartitionKeyRangeId(String partitionKeyRangeId) { - super.set(Constants.Properties.PARTITION_KEY_RANGE_ID, partitionKeyRangeId); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressInformation.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressInformation.java deleted file mode 100644 index 10ecf29854c2..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressInformation.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import java.util.Objects; - -/** - * Used internally to encapsulate a physical address information in the Azure Cosmos DB database service. - */ -public class AddressInformation { - private Protocol protocol; - private boolean isPublic; - private boolean isPrimary; - private String physicalUri; - - public AddressInformation(boolean isPublic, boolean isPrimary, String physicalUri, Protocol protocol) { - Objects.requireNonNull(protocol); - this.protocol = protocol; - this.isPublic = isPublic; - this.isPrimary = isPrimary; - this.physicalUri = physicalUri; - } - - public AddressInformation(boolean isPublic, boolean isPrimary, String physicalUri, String protocolScheme) { - this(isPublic, isPrimary, physicalUri, scheme2protocol(protocolScheme)); - } - - public boolean isPublic() { - return isPublic; - } - - public boolean isPrimary() { - return isPrimary; - } - - public String getPhysicalUri() { - return physicalUri; - } - - public Protocol getProtocol() { - return this.protocol; - } - - public String getProtocolName() { - return this.protocol.name(); - } - - public String getProtocolScheme() { - return this.protocol.scheme(); - } - - @Override - public String toString() { - return "AddressInformation{" + - "protocol='" + protocol + '\'' + - ", isPublic=" + isPublic + - ", isPrimary=" + isPrimary + - ", physicalUri='" + physicalUri + '\'' + - '}'; - } - - private static Protocol scheme2protocol(String scheme) { - - Objects.requireNonNull(scheme, "scheme"); - - switch (scheme.toLowerCase()) { - case "https": - return Protocol.Https; - case "rntbd": - return Protocol.Tcp; - default: - throw new IllegalArgumentException(String.format("scheme: %s", scheme)); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneException.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneException.java deleted file mode 100644 index 04aaaf9cb138..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneException.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.HashMap; -import java.util.Map; - -public class GoneException extends DocumentClientException { - - public GoneException(String msg) { - this(msg, null); - } - public GoneException() { - this(RMResources.Gone, (String) null); - } - - public GoneException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.GONE, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public GoneException(String message, String requestUri) { - this(message, (Exception) null, new HashMap<>(), requestUri); - } - - public GoneException(String message, - Exception innerException, - URI requestUri, - String localIpAddress) { - this(message(localIpAddress, message), innerException, (HttpResponseHeaders) null, requestUri); - } - - public GoneException(Exception innerException) { - this(RMResources.Gone, innerException, new HashMap<>(), (String) null); - } - - public GoneException(String message, HttpResponseHeaders headers, URI requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.GONE, requestUri != null ? requestUri.toString() : null); - } - - public GoneException(String message, HttpResponseHeaders headers, String requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.GONE, requestUri); - } - - public GoneException(String message, - Exception innerException, - HttpResponseHeaders headers, - URI requestUri) { - super(message, innerException, HttpUtils.asMap(headers), HttpConstants.StatusCodes.GONE, requestUri != null ? requestUri.toString() : null); - } - - public GoneException(String message, - Exception innerException, - Map headers, - String requestUri) { - super(message, innerException, headers, HttpConstants.StatusCodes.GONE, requestUri); - } - - public GoneException(Error error, Map headers) { - super(HttpConstants.StatusCodes.GONE, error, headers); - } - - private static String message(String localIP, String baseMessage) { - if (!Strings.isNullOrEmpty(localIP)) { - return String.format( - RMResources.ExceptionMessageAddIpAddress, - baseMessage, - localIP); - } - - return baseMessage; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpUtils.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpUtils.java deleted file mode 100644 index 13bbb27aee3f..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.internal.Constants.UrlEncodingInfo; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import io.reactivex.netty.protocol.http.client.HttpRequestHeaders; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URLDecoder; -import java.net.URLEncoder; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -public class HttpUtils { - - private static Logger log = LoggerFactory.getLogger(HttpUtils.class); - - public static String urlEncode(String url) { - try { - return URLEncoder.encode(url, UrlEncodingInfo.UTF_8).replaceAll(UrlEncodingInfo.PLUS_SYMBOL_ESCAPED, UrlEncodingInfo.SINGLE_SPACE_URI_ENCODING); - } catch (UnsupportedEncodingException e) { - log.error("failed to encode {}", url, e); - throw new IllegalArgumentException("failed to encode url " + url, e); - } - } - - public static String urlDecode(String url) { - try { - return URLDecoder.decode(url.replaceAll(UrlEncodingInfo.PLUS_SYMBOL_ESCAPED, UrlEncodingInfo.PLUS_SYMBOL_URI_ENCODING), UrlEncodingInfo.UTF_8); - } catch (UnsupportedEncodingException e) { - log.error("failed to decode {}", url, e); - throw new IllegalArgumentException("failed to decode url " + url, e); - } - } - - public static URI toURI(String uri) { - try { - return new URI(uri); - } catch (Exception e) { - log.error("failed to parse {}", uri, e); - throw new IllegalArgumentException("failed to parse uri " + uri, e); - } - } - - public static Map asMap(HttpResponseHeaders headers) { - if (headers == null) { - return new HashMap<>(); - } - - HashMap map = new HashMap<>(headers.names().size()); - for (Entry entry : headers.entries()) { - if (entry.getKey().equals(HttpConstants.HttpHeaders.OWNER_FULL_NAME)) { - map.put(entry.getKey(), HttpUtils.urlDecode(entry.getValue())); - } else { - map.put(entry.getKey(), entry.getValue()); - } - } - return map; - } - - public static Map asMap(HttpRequestHeaders headers) { - HashMap map = new HashMap<>(); - if (headers == null) { - return map; - } - for (Entry entry : headers.entries()) { - map.put(entry.getKey(), entry.getValue()); - } - return map; - } - - public static String getDateHeader(Map headerValues) { - if (headerValues == null) { - return StringUtils.EMPTY; - } - - // Since Date header is overridden by some proxies/http client libraries, we support - // an additional date header 'x-ms-date' and prefer that to the regular 'date' header. - String date = headerValues.get(HttpConstants.HttpHeaders.X_DATE); - if (Strings.isNullOrEmpty(date)) { - date = headerValues.get(HttpConstants.HttpHeaders.HTTP_DATE); - } - - return date != null ? date : StringUtils.EMPTY; - } - - public static List> unescape(List> headers) { - List> result = new ArrayList>(); - for (Entry entry : headers) { - if (entry.getKey().equals(HttpConstants.HttpHeaders.OWNER_FULL_NAME)) { - String unescapedUrl = HttpUtils.urlDecode(entry.getValue()); - entry = new AbstractMap.SimpleEntry(entry.getKey(), unescapedUrl); - } - result.add(entry); - } - return result; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Protocol.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Protocol.java deleted file mode 100644 index 5f5c1d7ef6a2..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Protocol.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -public enum Protocol { - Https, Tcp; - - String scheme() { - switch (this) { - case Https: - return "https"; - case Tcp: - return "rntbd"; - default: - throw new IllegalStateException(); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestTimeoutException.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestTimeoutException.java deleted file mode 100644 index 836d4b3935dc..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestTimeoutException.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -public class RequestTimeoutException extends DocumentClientException { - - public RequestTimeoutException() { - this(RMResources.RequestTimeout, null); - } - - public RequestTimeoutException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.REQUEST_TIMEOUT, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public RequestTimeoutException(String message, URI requestUri) { - this(message, (Exception) null, (HttpResponseHeaders) null, requestUri); - } - - public RequestTimeoutException(String message, - Exception innerException, - URI requestUri, - String localIpAddress) { - this(message(localIpAddress, message), innerException, (HttpResponseHeaders) null, requestUri); - } - - public RequestTimeoutException(Exception innerException) { - this(RMResources.Gone, innerException, (HttpResponseHeaders) null, null); - } - - public RequestTimeoutException(String message, HttpResponseHeaders headers, URI requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.REQUEST_TIMEOUT, requestUri != null ? requestUri.toString() : null); - } - - public RequestTimeoutException(String message, HttpResponseHeaders headers, String requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.REQUEST_TIMEOUT, requestUri); - } - - public RequestTimeoutException(String message, - Exception innerException, - HttpResponseHeaders headers, - URI requestUri) { - super(message, innerException, HttpUtils.asMap(headers), HttpConstants.StatusCodes.REQUEST_TIMEOUT, requestUri != null ? requestUri.toString() : null); - } - - private static String message(String localIP, String baseMessage) { - if (!Strings.isNullOrEmpty(localIP)) { - return String.format( - RMResources.ExceptionMessageAddIpAddress, - baseMessage, - localIP); - } - - return baseMessage; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponse.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponse.java deleted file mode 100644 index 816918cc7512..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponse.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.InputStream; -import java.util.List; -import java.util.Map.Entry; - -/** - * Used internally to represents a response from the store. - */ -public class StoreResponse { - final static Logger LOGGER = LoggerFactory.getLogger(StoreResponse.class); - final private int status; - final private String[] responseHeaderNames; - final private String[] responseHeaderValues; - final private InputStream httpEntityStream; - final private String content; - - private ClientSideRequestStatistics clientSideRequestStatistics; - - public StoreResponse(int status, List> headerEntries, InputStream inputStream) { - this(status, headerEntries, null, inputStream); - } - - public StoreResponse(int status, List> headerEntries, String content) { - this(status, headerEntries, content, null); - } - - private StoreResponse( - int status, - List> headerEntries, - String content, - InputStream inputStream) { - responseHeaderNames = new String[headerEntries.size()]; - responseHeaderValues = new String[headerEntries.size()]; - - int i = 0; - - for(Entry headerEntry: headerEntries) { - responseHeaderNames[i] = headerEntry.getKey(); - responseHeaderValues[i] = headerEntry.getValue(); - i++; - } - - this.status = status; - - this.content = content; - this.httpEntityStream = inputStream; - } - - public int getStatus() { - return status; - } - - public String[] getResponseHeaderNames() { - return responseHeaderNames; - } - - public String[] getResponseHeaderValues() { - return responseHeaderValues; - } - - public String getResponseBody() { - return this.content; - } - - public InputStream getResponseStream() { - // Some operation type doesn't have a response stream so this can be null - return this.httpEntityStream; - } - - public long getLSN() { - String lsnString = this.getHeaderValue(WFConstants.BackendHeaders.LSN); - if (StringUtils.isNotEmpty(lsnString)) { - return Long.parseLong(lsnString); - } - - return -1; - } - - public String getPartitionKeyRangeId() { - return this.getHeaderValue(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID); - } - - public String getContinuation() { - return this.getHeaderValue(HttpConstants.HttpHeaders.CONTINUATION); - } - - public String getHeaderValue(String attribute) { - if (this.responseHeaderValues == null || this.responseHeaderNames.length != this.responseHeaderValues.length) { - return null; - } - - for (int i = 0; i < responseHeaderNames.length; i++) { - if (responseHeaderNames[i].equalsIgnoreCase(attribute)) { - return responseHeaderValues[i]; - } - } - - return null; - } - - public ClientSideRequestStatistics getClientSideRequestStatistics() { - return clientSideRequestStatistics; - } - - public void setClientSideRequestStatistics(ClientSideRequestStatistics clientSideRequestStatistics) { - this.clientSideRequestStatistics = clientSideRequestStatistics; - } - - int getSubStatusCode() { - int subStatusCode = HttpConstants.SubStatusCodes.UNKNOWN; - String subStatusCodeString = this.getHeaderValue(WFConstants.BackendHeaders.SUB_STATUS); - if (StringUtils.isNotEmpty(subStatusCodeString)) { - try { - subStatusCode = Integer.parseInt(subStatusCodeString); - } catch (NumberFormatException e) { - // If value cannot be parsed as Integer, return Unknown. - } - } - return subStatusCode; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResult.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResult.java deleted file mode 100644 index 9dbb0d416052..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResult.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.rx.internal.Exceptions; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; - -public class StoreResult { - private final static Logger logger = LoggerFactory.getLogger(StoreResult.class); - - private final StoreResponse storeResponse; - private final DocumentClientException exception; - - final public long lsn; - final public String partitionKeyRangeId; - final public long quorumAckedLSN; - final public long globalCommittedLSN; - final public long numberOfReadRegions; - final public long itemLSN; - final public ISessionToken sessionToken; - final public double requestCharge; - final public int currentReplicaSetSize; - final public int currentWriteQuorum; - final public boolean isValid; - final public boolean isGoneException; - final public boolean isNotFoundException; - final public boolean isInvalidPartitionException; - final public URI storePhysicalAddress; - - public StoreResult( - StoreResponse storeResponse, - DocumentClientException exception, - String partitionKeyRangeId, - long lsn, - long quorumAckedLsn, - double requestCharge, - int currentReplicaSetSize, - int currentWriteQuorum, - boolean isValid, - URI storePhysicalAddress, - long globalCommittedLSN, - int numberOfReadRegions, - long itemLSN, - ISessionToken sessionToken) { - this.storeResponse = storeResponse; - this.exception = exception; - this.partitionKeyRangeId = partitionKeyRangeId; - this.lsn = lsn; - this.quorumAckedLSN = quorumAckedLsn; - this.requestCharge = requestCharge; - this.currentReplicaSetSize = currentReplicaSetSize; - this.currentWriteQuorum = currentWriteQuorum; - this.isValid = isValid; - this.isGoneException = this.exception != null && this.exception.getStatusCode() == HttpConstants.StatusCodes.GONE; - this.isNotFoundException = this.exception != null && this.exception.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND; - this.isInvalidPartitionException = this.exception != null - && Exceptions.isNameCacheStale(this.exception); - this.storePhysicalAddress = storePhysicalAddress; - this.globalCommittedLSN = globalCommittedLSN; - this.numberOfReadRegions = numberOfReadRegions; - this.itemLSN = itemLSN; - this.sessionToken = sessionToken; - } - - public DocumentClientException getException() throws InternalServerErrorException { - if (this.exception == null) { - String message = "Exception should be available but found none"; - assert false : message; - logger.error(message); - throw new InternalServerErrorException(RMResources.InternalServerError); - } - - return exception; - } - - public StoreResponse toResponse() throws DocumentClientException { - return toResponse(null); - } - - public StoreResponse toResponse(RequestChargeTracker requestChargeTracker) throws DocumentClientException { - if (!this.isValid) { - if (this.exception == null) { - logger.error("Exception not set for invalid response"); - throw new InternalServerErrorException(RMResources.InternalServerError); - } - - throw this.exception; - } - - if (requestChargeTracker != null && this.isValid) { - StoreResult.setRequestCharge(this.storeResponse, this.exception, requestChargeTracker.getTotalRequestCharge()); - } - - if (this.exception != null) { - throw exception; - } - - return this.storeResponse; - } - - private static void setRequestCharge(StoreResponse response, DocumentClientException documentClientException, double totalRequestCharge) { - if (documentClientException != null) { - documentClientException.getResponseHeaders().put(HttpConstants.HttpHeaders.REQUEST_CHARGE, - Double.toString(totalRequestCharge)); - } - // Set total charge as final charge for the response. - else if (response.getResponseHeaderNames() != null) { - for (int i = 0; i < response.getResponseHeaderNames().length; ++i) { - if (Strings.areEqualIgnoreCase( - response.getResponseHeaderNames()[i], - HttpConstants.HttpHeaders.REQUEST_CHARGE)) { - response.getResponseHeaderValues()[i] = Double.toString(totalRequestCharge); - break; - } - } - } - } - - @Override - public String toString() { - int statusCode = 0; - int subStatusCode = HttpConstants.SubStatusCodes.UNKNOWN; - - if (this.storeResponse != null) { - statusCode = this.storeResponse.getStatus(); - subStatusCode = this.storeResponse.getSubStatusCode(); - } else if (this.exception != null) { - statusCode = this.exception.getStatusCode(); - subStatusCode = this.exception.getSubStatusCode(); - } - - return "storePhysicalAddress: " + this.storePhysicalAddress + - ", lsn: " + this.lsn + - ", globalCommittedLsn: " + this.globalCommittedLSN + - ", partitionKeyRangeId: " + this.partitionKeyRangeId + - ", isValid: " + this.isValid + - ", statusCode: " + statusCode + - ", subStatusCode: " + subStatusCode + - ", isGone: " + this.isGoneException + - ", isNotFound: " + this.isNotFoundException + - ", isInvalidPartition: " + this.isInvalidPartitionException + - ", requestCharge: " + this.requestCharge + - ", itemLSN: " + this.itemLSN + - ", sessionToken: " + (this.sessionToken != null ? this.sessionToken.convertToString() : null) + - ", exception: " + BridgeInternal.getInnerErrorMessage(this.exception); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TimeoutHelper.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TimeoutHelper.java deleted file mode 100644 index c870d8cf6ed9..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TimeoutHelper.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import java.time.Duration; -import java.time.Instant; - -public class TimeoutHelper { - private final Instant startTime; - private final Duration timeOut; - - public TimeoutHelper(Duration timeOut) { - this.startTime = Instant.now(); - this.timeOut = timeOut; - } - - public boolean isElapsed() { - Duration elapsed = Duration.ofMillis(Instant.now().toEpochMilli() - startTime.toEpochMilli()); - return elapsed.compareTo(this.timeOut) >= 0; - } - - public Duration getRemainingTime() { - Duration elapsed = Duration.ofMillis(Instant.now().toEpochMilli() - startTime.toEpochMilli()); - return this.timeOut.minus(elapsed); - } - - public void throwTimeoutIfElapsed() throws RequestTimeoutException { - if (this.isElapsed()) { - throw new RequestTimeoutException(); - } - } - - public void throwGoneIfElapsed() throws GoneException { - if (this.isElapsed()) { - throw new GoneException(); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WFConstants.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WFConstants.java deleted file mode 100644 index 9d177fbffae8..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WFConstants.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -public class WFConstants { - public static class BackendHeaders { - public static final String RESOURCE_ID = "x-docdb-resource-id"; - public static final String OWNER_ID = "x-docdb-owner-id"; - public static final String ENTITY_ID = "x-docdb-entity-id"; - public static final String DATABASE_ENTITY_MAX_COUNT = "x-ms-database-entity-max-count"; - public static final String DATABASE_ENTITY_CURRENT_COUNT = "x-ms-database-entity-current-count"; - public static final String COLLECTION_ENTITY_MAX_COUNT = "x-ms-collection-entity-max-count"; - public static final String COLLECTION_ENTITY_CURRENT_COUNT = "x-ms-collection-entity-current-count"; - public static final String USER_ENTITY_MAX_COUNT = "x-ms-user-entity-max-count"; - public static final String USER_ENTITY_CURRENT_COUNT = "x-ms-user-entity-current-count"; - public static final String PERMISSION_ENTITY_MAX_COUNT = "x-ms-permission-entity-max-count"; - public static final String PERMISSION_ENTITY_CURRENT_COUNT = "x-ms-permission-entity-current-count"; - public static final String ROOT_ENTITY_MAX_COUNT = "x-ms-root-entity-max-count"; - public static final String ROOT_ENTITY_CURRENT_COUNT = "x-ms-root-entity-current-count"; - public static final String RESOURCE_SCHEMA_NAME = "x-ms-resource-schema-name"; - public static final String LSN = "lsn"; - public static final String QUORUM_ACKED_LSN = "x-ms-quorum-acked-lsn"; - public static final String QUORUM_ACKED_LLSN = "x-ms-cosmos-quorum-acked-llsn"; - public static final String CURRENT_WRITE_QUORUM = "x-ms-current-write-quorum"; - public static final String CURRENT_REPLICA_SET_SIZE = "x-ms-current-replica-set-size"; - public static final String COLLECTION_PARTITION_INDEX = "collection-partition-index"; - public static final String COLLECTION_SERVICE_INDEX = "collection-service-index"; - public static final String STATUS = "Status"; - public static final String ACTIVITY_ID = "ActivityId"; - public static final String IS_FANOUT_REQUEST = "x-ms-is-fanout-request"; - public static final String PRIMARY_MASTER_KEY = "x-ms-primary-master-key"; - public static final String SECONDARY_MASTER_KEY = "x-ms-secondary-master-key"; - public static final String PRIMARY_READONLY_KEY = "x-ms-primary-readonly-key"; - public static final String SECONDARY_READONLY_KEY = "x-ms-secondary-readonly-key"; - public static final String BIND_REPLICA_DIRECTIVE = "x-ms-bind-replica"; - public static final String DATABASE_ACCOUNT_ID = "x-ms-database-account-id"; - public static final String REQUEST_VALIDATION_FAILURE = "x-ms-request-validation-failure"; - public static final String SUB_STATUS = "x-ms-substatus"; - public static final String PARTITION_KEY_RANGE_ID = "x-ms-documentdb-partitionkeyrangeid"; - public static final String BIND_MIN_EFFECTIVE_PARTITION_KEY = "x-ms-documentdb-bindmineffectivepartitionkey"; - public static final String BIND_MAX_EFFECTIVE_PARTITION_KEY = "x-ms-documentdb-bindmaxeffectivepartitionkey"; - public static final String BIND_PARTITION_KEY_RANGE_ID = "x-ms-documentdb-bindpartitionkeyrangeid"; - public static final String BIND_PARTITION_KEY_RANGE_RID_PREFIX = "x-ms-documentdb-bindpartitionkeyrangeridprefix"; - public static final String MINIMUM_ALLOWED_CLIENT_VERSION = "x-ms-documentdb-minimumallowedclientversion"; - public static final String PARTITION_COUNT = "x-ms-documentdb-partitioncount"; - public static final String COLLECTION_RID = "x-ms-documentdb-collection-rid"; - public static final String XP_ROLE = "x-ms-xp-role"; - public static final String HAS_TENTATIVE_WRITES = "x-ms-cosmosdb-has-tentative-writes"; - public static final String IS_RU_PER_MINUTE_USED = "x-ms-documentdb-is-ru-per-minute-used"; - public static final String QUERY_METRICS = "x-ms-documentdb-query-metrics"; - public static final String GLOBAL_COMMITTED_LSN = "x-ms-global-Committed-lsn"; - public static final String NUMBER_OF_READ_REGIONS = "x-ms-number-of-read-regions"; - public static final String OFFER_REPLACE_PENDING = "x-ms-offer-replace-pending"; - public static final String ITEM_LSN = "x-ms-item-lsn"; - public static final String REMOTE_STORAGE_TYPE = "x-ms-remote-storage-type"; - public static final String RESTORE_STATE = "x-ms-restore-state"; - public static final String COLLECTION_SECURITY_IDENTIFIER = "x-ms-collection-security-identifier"; - public static final String RESTORE_PARAMS = "x-ms-restore-params"; - public static final String SHARE_THROUGHPUT = "x-ms-share-throughput"; - public static final String PARTITION_RESOURCE_FILTER = "x-ms-partition-resource-filter"; - public static final String FEDERATION_ID_FOR_AUTH = "x-ms-federation-for-auth"; - public static final String FORCE_QUERY_SCAN = "x-ms-documentdb-force-query-scan"; - public static final String ENABLE_DYNAMIC_RID_RANGE_ALLOCATION = "x-ms-enable-dynamic-rid-range-allocation"; - public static final String EXCLUDE_SYSTEM_PROPERTIES = "x-ms-exclude-system-properties"; - public static final String LOCAL_LSN = "x-ms-cosmos-llsn"; - public static final String QUORUM_ACKED_LOCAL_LSN = "x-ms-cosmos-quorum-acked-llsn"; - public static final String ITEM_LOCAL_LSN = "x-ms-cosmos-item-llsn"; - public static final String BINARY_ID = "x-ms-binary-id"; - public static final String TIME_TO_LIVE_IN_SECONDS = "x-ms-time-to-live-in-seconds"; - public static final String EFFECTIVE_PARTITION_KEY = "x-ms-effective-partition-key"; - public static final String BINARY_PASSTHROUGH_REQUEST = "x-ms-binary-passthrough-request"; - public static final String FANOUT_OPERATION_STATE = "x-ms-fanout-operation-state"; - public static final String CONTENT_SERIALIZATION_FORMAT = "x-ms-documentdb-content-serialization-format"; - public static final String ALLOW_TENTATIVE_WRITES = "x-ms-cosmos-allow-tentative-writes"; - public static final String IS_USER_REQUEST = "x-ms-cosmos-internal-is-user-request"; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/ClientSideMetrics.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/ClientSideMetrics.java deleted file mode 100644 index 8a93a3a16e52..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/ClientSideMetrics.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -import org.apache.commons.lang3.tuple.ImmutablePair; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; - -/** - * Client side QueryMetrics - */ -public class ClientSideMetrics { - - public static final ClientSideMetrics ZERO = new ClientSideMetrics( - 0, /* retries*/ - 0, /* requestCharge */ - new ArrayList<>(), /* fetchExecutionRanges */ - new ArrayList<>()); /* partitionSchedulingTimeSpans */ - - private final long retries; - private final double requestCharge; - private final List fetchExecutionRanges; - private final List> partitionSchedulingTimeSpans; - - /** - * Constructor - * - * @param retries The number of retries required to execute the query. - * @param requestCharge The request charge incurred from executing the query. - * @param executionRanges The fetch execution ranges from executing the query. - * @param schedulingTimeSpans The partition scheduling timespans from the query. - */ - public ClientSideMetrics(int retries, double requestCharge, List executionRanges, - List> schedulingTimeSpans) { - if (executionRanges == null || executionRanges.contains(null)) { - throw new NullPointerException("executionRanges"); - } - if (schedulingTimeSpans == null || schedulingTimeSpans.contains(null)) { - throw new NullPointerException("schedulingTimeSpans"); - } - if (retries < 0) { - throw new IllegalArgumentException("retries must not be negative"); - } - if (requestCharge < 0) { - throw new IllegalArgumentException("requestCharge must not be negative"); - } - - this.retries = retries; - this.requestCharge = requestCharge; - this.fetchExecutionRanges = executionRanges; - this.partitionSchedulingTimeSpans = schedulingTimeSpans; - } - - /** - * Gets number of retries in the Azure Cosmos database service - * - * @return the retries - */ - public long getRetries() { - return retries; - } - - /** - * Gets the request charge for this continuation of the query. - * - * @return the requestCharge - */ - public double getRequestCharge() { - return requestCharge; - } - - /** - * create ClientSideMetrics from collection - * - * @param clientSideMetricsCollection - * @return - */ - public static ClientSideMetrics createFromCollection(Collection clientSideMetricsCollection) { - if (clientSideMetricsCollection == null) { - throw new NullPointerException("clientSideMetricsCollection"); - } - - int retries = 0; - double requestCharge = 0; - List fetchExecutionRanges = new ArrayList<>(); - List> partitionSchedulingTimeSpans = new ArrayList<>(); - - for (ClientSideMetrics clientSideQueryMetrics : clientSideMetricsCollection) { - retries += clientSideQueryMetrics.retries; - requestCharge += clientSideQueryMetrics.requestCharge; - fetchExecutionRanges.addAll(clientSideQueryMetrics.fetchExecutionRanges); - partitionSchedulingTimeSpans.addAll(clientSideQueryMetrics.partitionSchedulingTimeSpans); - } - - return new ClientSideMetrics(retries, requestCharge, fetchExecutionRanges, partitionSchedulingTimeSpans); - } - - static double getOrDefault(HashMap metrics, String key) { - Double doubleReference = metrics.get(key); - return doubleReference == null ? 0 : doubleReference; - } - - /** - * Gets the Fetch Execution Ranges for this continuation of the query. - * - * @return the Fetch Execution Ranges for this continuation of the query - */ - public List getFetchExecutionRanges() { - return fetchExecutionRanges; - } - - /** - * Gets the Partition Scheduling TimeSpans for this query. - * - * @return the List of Partition Scheduling TimeSpans for this query - */ - public List> getPartitionSchedulingTimeSpans() { - return partitionSchedulingTimeSpans; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/FetchExecutionRange.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/FetchExecutionRange.java deleted file mode 100644 index 30e1e341c26d..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/FetchExecutionRange.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -import java.time.Instant; - -/** - * Stores information about fetch execution - */ -public class FetchExecutionRange { - private final Instant startTime; - private final Instant endTime; - private final String partitionId; - private final long numberOfDocuments; - private final long retryCount; - private final String activityId; - - /** - * Constructor - * - * @param activityId The activityId of the fetch - * @param startTime The start time of the fetch - * @param endTime The end time of the fetch - * @param partitionId The partitionkeyrangeid from which you are fetching for - * @param numberOfDocuments The number of documents that were fetched in the particular execution range - * @param retryCount The number of times we retried for this fetch execution range - */ - FetchExecutionRange(String activityId, Instant startTime, Instant endTime, String partitionId, long numberOfDocuments, long retryCount) { - this.activityId = activityId; - this.startTime = startTime; - this.endTime = endTime; - this.partitionId = partitionId; - this.numberOfDocuments = numberOfDocuments; - this.retryCount = retryCount; - } - - /** - * Gets the start time of the fetch. - * - * @return the start time of the fetch. - */ - public Instant getStartTime() { - return startTime; - } - - /** - * Gets the end time of the fetch. - * - * @return the end time of the fetch. - */ - public Instant getEndTime() { - return endTime; - } - - /** - * Gets the partition id that was fetched from. - * - * @return the partition id that was fetched from. - */ - public String getPartitionId() { - return partitionId; - } - - /** - * Gets the number of documents that where fetched in the particular execution range. - * - * @return the number of documents that where fetched in the particular execution range. - */ - public long getNumberOfDocuments() { - return numberOfDocuments; - } - - /** - * Gets the number of times we retried for this fetch execution range. - * - * @return the number of times we retried for this fetch execution range. - */ - public long getRetryCount() { - return retryCount; - } - - /** - * Gets the activityId of the fetch. - * - * @return the activityId of the fetch. - */ - public String getActivityId() { - return activityId; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/FetchExecutionRangeAccumulator.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/FetchExecutionRangeAccumulator.java deleted file mode 100644 index cb67879c01aa..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/FetchExecutionRangeAccumulator.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -import org.apache.commons.lang3.time.StopWatch; - -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -/** - * Accumlator that acts as a builder of FetchExecutionRanges - */ -public class FetchExecutionRangeAccumulator { - private final String partitionKeyRangeId; - private final Instant constructionTime; - private final StopWatch stopwatch; - private List fetchExecutionRanges; - private Instant startTime; - private Instant endTime; - private boolean isFetching; - - public FetchExecutionRangeAccumulator(String partitionKeyRangeId) { - this.partitionKeyRangeId = partitionKeyRangeId; - this.constructionTime = Instant.now(); - // This stopwatch is always running and is only used to calculate deltas that are synchronized with the construction time. - this.stopwatch = new StopWatch(); - stopwatch.start(); - this.fetchExecutionRanges = new ArrayList(); - } - - /** - * Gets the FetchExecutionRanges and resets the accumulator. - * - * @return the SchedulingMetricsResult. - */ - public List getExecutionRanges() { - List returnValue = this.fetchExecutionRanges; - this.fetchExecutionRanges = new ArrayList<>(); - return returnValue; - } - - /** - * Updates the most recent start time internally. - */ - public void beginFetchRange() { - if (!this.isFetching) { - // Calculating the start time as the construction time and the stopwatch as a delta. - this.startTime = this.constructionTime.plus(Duration.ofMillis(this.stopwatch.getTime(TimeUnit.MILLISECONDS))); - this.isFetching = true; - } - } - - /** - * Updates the most recent end time internally and constructs a new FetchExecutionRange - * - * @param numberOfDocuments The number of documents that were fetched for this range. - * @param retryCount The number of times we retried for this fetch execution range. - */ - public void endFetchRange(String activityId, long numberOfDocuments, long retryCount) { - if (this.isFetching) { - // Calculating the end time as the construction time and the stopwatch as a delta. - this.endTime = this.constructionTime.plus(Duration.ofMillis(this.stopwatch.getTime(TimeUnit.MILLISECONDS))); - FetchExecutionRange fetchExecutionRange = new FetchExecutionRange( - activityId, - this.startTime, - this.endTime, - this.partitionKeyRangeId, - numberOfDocuments, - retryCount); - this.fetchExecutionRanges.add(fetchExecutionRange); - this.isFetching = false; - } - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/QueryMetricsTextWriter.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/QueryMetricsTextWriter.java deleted file mode 100644 index 72c6383b0054..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/QueryMetricsTextWriter.java +++ /dev/null @@ -1,600 +0,0 @@ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -import org.apache.commons.lang3.StringUtils; - -import java.time.Duration; -import java.time.Instant; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.UUID; - -public class QueryMetricsTextWriter extends QueryMetricsWriter { - - private final StringBuilder stringBuilder; - - // QueryMetrics - private static final String ActivityIds = "Activity Ids"; - private static final String RetrievedDocumentCount = "Retrieved Document Count"; - private static final String RetrievedDocumentSize = "Retrieved Document Size"; - private static final String OutputDocumentCount = "Output Document Count"; - private static final String OutputDocumentSize = "Output Document Size"; - private static final String IndexUtilizationText = "Index Utilization"; - private static final String TotalQueryExecutionTime = "Total Query Execution Time"; - - // QueryPreparationTimes - private static final String QueryPreparationTimes = "Query Preparation Times"; - private static final String QueryCompileTime = "Query Compilation Time"; - private static final String LogicalPlanBuildTime = "Logical Plan Build Time"; - private static final String PhysicalPlanBuildTime = "Physical Plan Build Time"; - private static final String QueryOptimizationTime = "Query Optimization Time"; - - // QueryTimes - private static final String QueryEngineTimes = "Query Engine Times"; - private static final String IndexLookupTime = "Index Lookup Time"; - private static final String DocumentLoadTime = "Document Load Time"; - private static final String DocumentWriteTime = "Document Write Time"; - - // RuntimeExecutionTimes - private static final String RuntimeExecutionTimes = "Runtime Execution Times"; - private static final String TotalExecutionTime = "Query Engine Execution Time"; - private static final String SystemFunctionExecuteTime = "System Function Execution Time"; - private static final String UserDefinedFunctionExecutionTime = "User-defined Function Execution Time"; - - // ClientSideQueryMetrics - private static final String ClientSideQueryMetrics = "Client Side Metrics"; - private static final String Retries = "Retry Count"; - private static final String RequestCharge = "Request Charge"; - private static final String FetchExecutionRanges = "Partition Execution Timeline"; - private static final String SchedulingMetrics = "Scheduling Metrics"; - - // Constants for Partition Execution Timeline Table - private static final String StartTimeHeader = "Start Time (UTC)"; - private static final String EndTimeHeader = "End Time (UTC)"; - private static final String DurationHeader = "Duration (ms)"; - private static final String PartitionKeyRangeIdHeader = "Partition Id"; - private static final String NumberOfDocumentsHeader = "Number of Documents"; - private static final String RetryCountHeader = "Retry Count"; - private static final String ActivityIdHeader = "Activity Id"; - - // Constants for Scheduling Metrics Table - private static final String PartitionIdHeader = "Partition Id"; - private static final String ResponseTimeHeader = "Response Time (ms)"; - private static final String RunTimeHeader = "Run Time (ms)"; - private static final String WaitTimeHeader = "Wait Time (ms)"; - private static final String TurnaroundTimeHeader = "Turnaround Time (ms)"; - private static final String NumberOfPreemptionHeader = "Number of Preemptions"; - - // Static for Partition Execution Timeline Table - // private static int MaxDateTimeStringLength = LocalDateTime.MAX.toString().length(); - private static final int MaxDateTimeStringLength = 16; - private static final int StartTimeHeaderLength = Math.max(MaxDateTimeStringLength, StartTimeHeader.length()); - private static final int EndTimeHeaderLength = Math.max(MaxDateTimeStringLength, EndTimeHeader.length()); - private static final int DurationHeaderLength = DurationHeader.length(); - private static final int PartitionKeyRangeIdHeaderLength = PartitionKeyRangeIdHeader.length(); - private static final int NumberOfDocumentsHeaderLength = NumberOfDocumentsHeader.length(); - private static final int RetryCountHeaderLength = RetryCountHeader.length(); - private static final int ActivityIdHeaderLength = UUID.randomUUID().toString().length(); - - private static TextTable.Column[] PartitionExecutionTimelineColumns = new TextTable.Column[] - { - new TextTable.Column(PartitionKeyRangeIdHeader, PartitionKeyRangeIdHeaderLength), - new TextTable.Column(ActivityIdHeader, ActivityIdHeaderLength), - new TextTable.Column(StartTimeHeader, StartTimeHeaderLength), - new TextTable.Column(EndTimeHeader, EndTimeHeaderLength), - new TextTable.Column(DurationHeader, DurationHeaderLength), - new TextTable.Column(NumberOfDocumentsHeader, NumberOfDocumentsHeaderLength), - new TextTable.Column(RetryCountHeader, RetryCountHeaderLength), - }; - - private static TextTable PartitionExecutionTimelineTable = new TextTable(Arrays.asList(PartitionExecutionTimelineColumns)); - - // Static for Scheduling Metrics Table - //private static readonly int MaxTimeSpanStringLength = Math.Max(TimeSpan.MaxValue.TotalMilliseconds.ToString - // ("G17").Length, TurnaroundTimeHeader.Length); - private static final int PartitionIdHeaderLength = PartitionIdHeader.length(); - private static final int ResponseTimeHeaderLength = ResponseTimeHeader.length(); - private static final int RunTimeHeaderLength = RunTimeHeader.length(); - private static final int WaitTimeHeaderLength = WaitTimeHeader.length(); - private static final int TurnaroundTimeHeaderLength = TurnaroundTimeHeader.length(); - private static final int NumberOfPreemptionHeaderLength = NumberOfPreemptionHeader.length(); - - private static TextTable.Column[] SchedulingMetricsColumns = new TextTable.Column[] - { - new TextTable.Column(PartitionIdHeader, PartitionIdHeaderLength), - new TextTable.Column(ResponseTimeHeader, ResponseTimeHeaderLength), - new TextTable.Column(RunTimeHeader, RunTimeHeaderLength), - new TextTable.Column(WaitTimeHeader, WaitTimeHeaderLength), - new TextTable.Column(TurnaroundTimeHeader, TurnaroundTimeHeaderLength), - new TextTable.Column(NumberOfPreemptionHeader, NumberOfPreemptionHeaderLength), - }; - - private static TextTable SchedulingMetricsTable = new TextTable(Arrays.asList(SchedulingMetricsColumns)); - - // FetchExecutionRange state - private String lastFetchPartitionId; - private String lastActivityId; - private Instant lastStartTime; - private Instant lastEndTime; - private long lastFetchDocumentCount; - private long lastFetchRetryCount; - - // PartitionSchedulingTimeSpan state - private String lastSchedulingPartitionId; - private long lastResponseTime; - private long lastRunTime; - private long lastWaitTime; - private long lastTurnaroundTime; - private long lastNumberOfPreemptions; - - static DateTimeFormatter formatter = - DateTimeFormatter.ofPattern("HH:mm:ss:SSSS").withZone(ZoneOffset.UTC); - - public QueryMetricsTextWriter(StringBuilder stringBuilder) { - assert stringBuilder != null; - this.stringBuilder = stringBuilder; - } - - @Override - protected void writeBeforeQueryMetrics() { - // Do Nothing - } - - @Override - protected void writeRetrievedDocumentCount(long retrievedDocumentCount) { - QueryMetricsTextWriter.appendCountToStringBuilder(stringBuilder, - QueryMetricsTextWriter.RetrievedDocumentCount, retrievedDocumentCount, 0); - } - - @Override - protected void writeRetrievedDocumentSize(long retrievedDocumentSize) { - QueryMetricsTextWriter.appendBytesToStringBuilder(stringBuilder, QueryMetricsTextWriter.RetrievedDocumentSize - , retrievedDocumentSize, 0); - } - - @Override - protected void writeOutputDocumentCount(long outputDocumentCount) { - QueryMetricsTextWriter.appendCountToStringBuilder(stringBuilder, QueryMetricsTextWriter.OutputDocumentCount, - outputDocumentCount, 0); - } - - @Override - protected void writeOutputDocumentSize(long outputDocumentSize) { - QueryMetricsTextWriter.appendBytesToStringBuilder(stringBuilder, QueryMetricsTextWriter.OutputDocumentSize, - outputDocumentSize, 0); - } - - @Override - protected void writeIndexHitRatio(double indexHitRatio) { - QueryMetricsTextWriter.appendPercentageToStringBuilder(stringBuilder, QueryMetricsTextWriter.IndexUtilizationText - , indexHitRatio, 0); - } - - @Override - protected void writeTotalQueryExecutionTime(Duration totalQueryExecutionTime) { - QueryMetricsTextWriter.appendNanosecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.TotalQueryExecutionTime, durationToMilliseconds(totalQueryExecutionTime), 0); - } - - @Override - protected void writeBeforeQueryPreparationTimes() { - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, - QueryMetricsTextWriter.QueryPreparationTimes, 1); - } - - @Override - protected void writeQueryCompilationTime(Duration queryCompilationTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.QueryCompileTime, durationToMilliseconds(queryCompilationTime), 2); - } - - @Override - protected void writeLogicalPlanBuildTime(Duration logicalPlanBuildTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.LogicalPlanBuildTime, durationToMilliseconds(logicalPlanBuildTime), 2); - } - - @Override - protected void writePhysicalPlanBuildTime(Duration physicalPlanBuildTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.PhysicalPlanBuildTime, durationToMilliseconds(physicalPlanBuildTime), 2); - } - - @Override - protected void writeQueryOptimizationTime(Duration queryOptimizationTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.QueryOptimizationTime, durationToMilliseconds(queryOptimizationTime), 2); - } - - @Override - protected void writeAfterQueryPreparationTimes() { - // Do Nothing - } - - @Override - protected void writeIndexLookupTime(Duration indexLookupTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.IndexLookupTime, durationToMilliseconds(indexLookupTime), 1); - } - - @Override - protected void writeDocumentLoadTime(Duration documentLoadTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.DocumentLoadTime, durationToMilliseconds(documentLoadTime), 1); - } - - @Override - protected void writeVMExecutionTime(Duration vMExecutionTime) { - // Do Nothing - } - - @Override - protected void writeBeforeRuntimeExecutionTimes() { - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, - QueryMetricsTextWriter.RuntimeExecutionTimes, 1); - } - - @Override - protected void writeQueryEngineExecutionTime(Duration queryEngineExecutionTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.QueryEngineTimes, durationToMilliseconds(queryEngineExecutionTime), 2); - } - - @Override - protected void writeSystemFunctionExecutionTime(Duration systemFunctionExecutionTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.SystemFunctionExecuteTime, durationToMilliseconds(systemFunctionExecutionTime) - , 2); - } - - @Override - protected void writeUserDefinedFunctionExecutionTime(Duration userDefinedFunctionExecutionTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.UserDefinedFunctionExecutionTime, - durationToMilliseconds(userDefinedFunctionExecutionTime), 2); - } - - @Override - protected void writeAfterRuntimeExecutionTimes() { - // Do Nothing - } - - @Override - protected void writeDocumentWriteTime(Duration documentWriteTime) { - QueryMetricsTextWriter.appendMillisecondsToStringBuilder(stringBuilder, - QueryMetricsTextWriter.DocumentWriteTime, durationToMilliseconds(documentWriteTime), 1); - } - - @Override - protected void writeBeforeClientSideMetrics() { - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, - QueryMetricsTextWriter.ClientSideQueryMetrics, 0); - } - - @Override - protected void writeRetries(long retries) { - QueryMetricsTextWriter.appendCountToStringBuilder(stringBuilder, QueryMetricsTextWriter.Retries, retries, 1); - } - - @Override - protected void writeRequestCharge(double requestCharge) { - QueryMetricsTextWriter.appendRUToStringBuilder(stringBuilder, QueryMetricsTextWriter.RequestCharge, - requestCharge, 1); - } - - @Override - protected void writeBeforePartitionExecutionTimeline() { - QueryMetricsTextWriter.appendNewlineToStringBuilder(stringBuilder); - - // Building the table for fetch execution ranges - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, QueryMetricsTextWriter.FetchExecutionRanges - , 1); - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.getTopLine(), 1); - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.getHeader(), 1); - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.getMiddleLine(), 1); - } - - @Override - protected void writeBeforeFetchExecutionRange() { - // Do Nothing - } - - @Override - protected void writeFetchPartitionKeyRangeId(String partitionId) { - this.lastFetchPartitionId = partitionId; - } - - @Override - protected void writeActivityId(String activityId) { - this.lastActivityId = activityId; - } - - @Override - protected void writeStartTime(Instant startTime) { - this.lastStartTime = startTime; - } - - @Override - protected void writeEndTime(Instant endTime) { - this.lastEndTime = endTime; - } - - @Override - protected void writeFetchDocumentCount(long numberOfDocuments) { - this.lastFetchDocumentCount = numberOfDocuments; - } - - @Override - protected void writeFetchRetryCount(long retryCount) { - this.lastFetchRetryCount = retryCount; - } - - @Override - protected void writeAfterFetchExecutionRange() { - QueryMetricsTextWriter.appendHeaderToStringBuilder( - stringBuilder, - PartitionExecutionTimelineTable.getRow(Arrays.asList( - this.lastFetchPartitionId, - this.lastActivityId, - formatter.format(this.lastStartTime), - formatter.format(this.lastEndTime), - nanosToMilliSeconds(this.lastEndTime.minusNanos(lastStartTime.getNano()).getNano()), - this.lastFetchDocumentCount, - this.lastFetchRetryCount)), - 1); - } - - @Override - protected void writeAfterPartitionExecutionTimeline() { - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, PartitionExecutionTimelineTable.getBottomLine(), - 1); - } - - @Override - protected void writeBeforeSchedulingMetrics() { - QueryMetricsTextWriter.appendNewlineToStringBuilder(stringBuilder); - - // Building the table for scheduling metrics - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, QueryMetricsTextWriter.SchedulingMetrics, 1); - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.getTopLine(), 1); - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.getHeader(), 1); - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.getMiddleLine(), 1); - } - - @Override - protected void writeBeforePartitionSchedulingDuration() { - // Do Nothing - } - - @Override - protected void writePartitionSchedulingDurationId(String partitionId) { - this.lastSchedulingPartitionId = partitionId; - } - - @Override - protected void writeResponseTime(long responseTime) { - this.lastResponseTime = responseTime; - } - - @Override - protected void writeRunTime(long runTime) { - this.lastRunTime = runTime; - } - - @Override - protected void writeWaitTime(long waitTime) { - this.lastWaitTime = waitTime; - } - - @Override - protected void writeTurnaroundTime(long turnaroundTime) { - this.lastTurnaroundTime = turnaroundTime; - } - - @Override - protected void writeNumberOfPreemptions(long numPreemptions) { - this.lastNumberOfPreemptions = numPreemptions; - } - - @Override - protected void writeAfterPartitionSchedulingDuration() { - QueryMetricsTextWriter.appendHeaderToStringBuilder( - stringBuilder, - SchedulingMetricsTable.getRow(Arrays.asList( - this.lastSchedulingPartitionId, - this.lastResponseTime, - this.lastRunTime, - this.lastWaitTime, - this.lastTurnaroundTime, - this.lastNumberOfPreemptions)), - 1); - } - - @Override - protected void writeAfterSchedulingMetrics() { - QueryMetricsTextWriter.appendHeaderToStringBuilder(stringBuilder, SchedulingMetricsTable.getBottomLine(), 1); - } - - @Override - protected void writeAfterClientSideMetrics() { - // Do Nothing - } - - @Override - protected void writeAfterQueryMetrics() { - // Do Nothing - } - - // Util functions - private static final int NANOS_TO_MILLIS = 1000000; - - static HashMap parseDelimitedString(String delimitedString) { - if (delimitedString == null) { - throw new NullPointerException("delimitedString"); - } - - HashMap metrics = new HashMap<>(); - - final int key = 0; - final int value = 1; - String[] headerAttributes = StringUtils.split(delimitedString, ";"); - - for (String attribute : headerAttributes) { - String[] attributeKeyValue = StringUtils.split(attribute, "="); - - if (attributeKeyValue.length != 2) { - throw new NullPointerException("recieved a malformed delimited String"); - } - - String attributeKey = attributeKeyValue[key]; - double attributeValue = Double.parseDouble(attributeKeyValue[value]); - metrics.put(attributeKey, attributeValue); - } - - return metrics; - } - - static Duration durationFromMetrics(HashMap metrics, String key) { - // Just attempt to get the metrics - Double durationInMilliseconds = metrics.get(key); - if (durationInMilliseconds == null) { - return Duration.ZERO; - } - - long seconds = (long) (durationInMilliseconds / 1e3); - long nanoseconds = (long) ((durationInMilliseconds - (seconds * 1e3)) * 1e6); - - return Duration.ofSeconds(seconds, nanoseconds); - } - - static double durationToMilliseconds(Duration duration) { - double seconds = duration.getSeconds(); - double nano = duration.getNano(); - - return (seconds * 1e3) + (nano / 1e6); - } - - static Duration getDurationFromMetrics(HashMap metrics, String key) { - double timeSpanInMilliseconds; - Duration timeSpanFromMetrics; - timeSpanInMilliseconds = metrics.get(key); - timeSpanFromMetrics = doubleMillisecondsToDuration(timeSpanInMilliseconds); - return timeSpanFromMetrics; - } - - private static Duration doubleMillisecondsToDuration(double timeSpanInMilliseconds) { - long timeInNanoSeconds = (long) (timeSpanInMilliseconds * NANOS_TO_MILLIS); - return Duration.ofNanos(timeInNanoSeconds); - } - - private static void appendToStringBuilder(StringBuilder stringBuilder, String property, String value, - String units, int indentLevel) { - final String Indent = " "; - final String FormatString = "%-40s : %15s %-12s %s"; - - stringBuilder.append(String.format( - Locale.ROOT, - FormatString, - StringUtils.repeat(Indent, indentLevel) + property, - value, - units, - System.lineSeparator())); - } - - static void appendBytesToStringBuilder(StringBuilder stringBuilder, String property, long bytes, int indentLevel) { - final String BytesFormatString = "%d"; - final String BytesUnitString = "bytes"; - - appendToStringBuilder( - stringBuilder, - property, - String.format(BytesFormatString, bytes), - BytesUnitString, - indentLevel); - } - - static void appendMillisecondsToStringBuilder(StringBuilder stringBuilder, String property, double milliseconds, - int indentLevel) { - final String MillisecondsFormatString = "%f"; - final String MillisecondsUnitString = "milliseconds"; - - appendToStringBuilder(stringBuilder, property, String.format(MillisecondsFormatString, - milliseconds), MillisecondsUnitString, indentLevel); - } - - static void appendNanosecondsToStringBuilder(StringBuilder stringBuilder, String property, double nanoSeconds, - int indentLevel) { - final String MillisecondsFormatString = "%.2f"; - final String MillisecondsUnitString = "milliseconds"; - appendToStringBuilder(stringBuilder, property, String.format(MillisecondsFormatString, - nanosToMilliSeconds(nanoSeconds)), MillisecondsUnitString, indentLevel); - } - - static double nanosToMilliSeconds(double nanos) { - return nanos / NANOS_TO_MILLIS; - } - - static void appendHeaderToStringBuilder(StringBuilder stringBuilder, String headerTitle, int indentLevel) { - final String Indent = " "; - final String FormatString = "%s %s"; - stringBuilder.append(String.format( - Locale.ROOT, - FormatString, - String.join(StringUtils.repeat(Indent, indentLevel)) + headerTitle, - System.lineSeparator())); - } - - static void appendRUToStringBuilder(StringBuilder stringBuilder, String property, double requestCharge, - int indentLevel) { - final String RequestChargeFormatString = "%s"; - final String RequestChargeUnitString = "RUs"; - - appendToStringBuilder( - stringBuilder, - property, - String.format(Locale.ROOT, RequestChargeFormatString, requestCharge), - RequestChargeUnitString, - indentLevel); - } - - static void appendActivityIdsToStringBuilder(StringBuilder stringBuilder, String activityIdsLabel, - List activityIds, int indentLevel) { - final String Indent = " "; - stringBuilder.append(activityIdsLabel); - stringBuilder.append(System.lineSeparator()); - for (String activityId : activityIds) { - stringBuilder.append(Indent); - stringBuilder.append(activityId); - stringBuilder.append(System.lineSeparator()); - } - } - - static void appendPercentageToStringBuilder(StringBuilder stringBuilder, String property, double percentage, - int indentLevel) { - final String PercentageFormatString = "%.2f"; - final String PercentageUnitString = "%"; - - appendToStringBuilder(stringBuilder, property, String.format(PercentageFormatString, - percentage * 100), PercentageUnitString, indentLevel); - } - - static void appendCountToStringBuilder(StringBuilder stringBuilder, String property, long count, int indentLevel) { - final String CountFormatString = "%s"; - final String CountUnitString = ""; - - appendToStringBuilder( - stringBuilder, - property, - String.format(CountFormatString, count), - CountUnitString, - indentLevel); - } - - static void appendNewlineToStringBuilder(StringBuilder stringBuilder) { - appendHeaderToStringBuilder(stringBuilder, StringUtils.EMPTY, 0); - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/QueryMetricsWriter.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/QueryMetricsWriter.java deleted file mode 100644 index 575760ec7b50..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/QueryMetricsWriter.java +++ /dev/null @@ -1,225 +0,0 @@ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.QueryMetrics; -import com.microsoft.azure.cosmosdb.QueryPreparationTimes; -import com.microsoft.azure.cosmosdb.RuntimeExecutionTimes; -import org.apache.commons.lang3.tuple.ImmutablePair; - -import java.time.Duration; -import java.time.Instant; -import java.util.List; - -abstract class QueryMetricsWriter { - - public void writeQueryMetrics(QueryMetrics queryMetrics) { - this.writeBeforeQueryMetrics(); - - // Top Level Properties - this.writeRetrievedDocumentCount(queryMetrics.getRetrievedDocumentCount()); - this.writeRetrievedDocumentSize(queryMetrics.getRetrievedDocumentSize()); - this.writeOutputDocumentCount(queryMetrics.getOutputDocumentCount()); - this.writeOutputDocumentSize(queryMetrics.getOutputDocumentSize()); - this.writeIndexHitRatio(queryMetrics.getIndexHitRatio()); - this.writeTotalQueryExecutionTime(queryMetrics.getTotalQueryExecutionTime()); - - // QueryPreparationTimes - this.writeQueryPreparationTimes(queryMetrics.getQueryPreparationTimes()); - - this.writeIndexLookupTime(queryMetrics.getIndexLookupTime()); - this.writeDocumentLoadTime(queryMetrics.getDocumentLoadTime()); - this.writeVMExecutionTime(queryMetrics.getVMExecutionTime()); - - // RuntimesExecutionTimes - this.writeRuntimesExecutionTimes(queryMetrics.getRuntimeExecutionTimes()); - - this.writeDocumentWriteTime(queryMetrics.getDocumentWriteTime()); - - // ClientSideMetrics - this.writeClientSideMetrics(BridgeInternal.getClientSideMetrics(queryMetrics)); - - this.writeAfterQueryMetrics(); - } - - protected abstract void writeBeforeQueryMetrics(); - - protected abstract void writeRetrievedDocumentCount(long retrievedDocumentCount); - - protected abstract void writeRetrievedDocumentSize(long retrievedDocumentSize); - - protected abstract void writeOutputDocumentCount(long outputDocumentCount); - - protected abstract void writeOutputDocumentSize(long outputDocumentSize); - - protected abstract void writeIndexHitRatio(double indexHitRatio); - - protected abstract void writeTotalQueryExecutionTime(Duration totalQueryExecutionTime); - - //QueryPreparationTimes - private void writeQueryPreparationTimes(QueryPreparationTimes queryPreparationTimes) { - this.writeBeforeQueryPreparationTimes(); - - this.writeQueryCompilationTime(queryPreparationTimes.getQueryCompilationTime()); - this.writeLogicalPlanBuildTime(queryPreparationTimes.getLogicalPlanBuildTime()); - this.writePhysicalPlanBuildTime(queryPreparationTimes.getPhysicalPlanBuildTime()); - this.writeQueryOptimizationTime(queryPreparationTimes.getQueryOptimizationTime()); - - this.writeAfterQueryPreparationTimes(); - } - - protected abstract void writeBeforeQueryPreparationTimes(); - - protected abstract void writeQueryCompilationTime(Duration queryCompilationTime); - - protected abstract void writeLogicalPlanBuildTime(Duration logicalPlanBuildTime); - - protected abstract void writePhysicalPlanBuildTime(Duration physicalPlanBuildTime); - - protected abstract void writeQueryOptimizationTime(Duration queryOptimizationTime); - - protected abstract void writeAfterQueryPreparationTimes(); - - protected abstract void writeIndexLookupTime(Duration indexLookupTime); - - protected abstract void writeDocumentLoadTime(Duration documentLoadTime); - - protected abstract void writeVMExecutionTime(Duration vMExecutionTime); - - // RuntimeExecutionTimes - private void writeRuntimesExecutionTimes(RuntimeExecutionTimes runtimeExecutionTimes) { - this.writeBeforeRuntimeExecutionTimes(); - - this.writeQueryEngineExecutionTime(runtimeExecutionTimes.getQueryEngineExecutionTime()); - this.writeSystemFunctionExecutionTime(runtimeExecutionTimes.getSystemFunctionExecutionTime()); - this.writeUserDefinedFunctionExecutionTime(runtimeExecutionTimes.getUserDefinedFunctionExecutionTime()); - - this.writeAfterRuntimeExecutionTimes(); - } - - - protected abstract void writeBeforeRuntimeExecutionTimes(); - - protected abstract void writeQueryEngineExecutionTime(Duration queryEngineExecutionTime); - - protected abstract void writeSystemFunctionExecutionTime(Duration systemFunctionExecutionTime); - - protected abstract void writeUserDefinedFunctionExecutionTime(Duration userDefinedFunctionExecutionTime); - - protected abstract void writeAfterRuntimeExecutionTimes(); - - protected abstract void writeDocumentWriteTime(Duration documentWriteTime); - - // ClientSideMetrics - private void writeClientSideMetrics(ClientSideMetrics clientSideMetrics) { - this.writeBeforeClientSideMetrics(); - - this.writeRetries(clientSideMetrics.getRetries()); - this.writeRequestCharge(clientSideMetrics.getRequestCharge()); - this.writePartitionExecutionTimeline(clientSideMetrics); - this.writeSchedulingMetrics(clientSideMetrics); - - this.writeAfterClientSideMetrics(); - } - - protected abstract void writeBeforeClientSideMetrics(); - - protected abstract void writeRetries(long retries); - - protected abstract void writeRequestCharge(double requestCharge); - - private void writePartitionExecutionTimeline(ClientSideMetrics clientSideMetrics) { - this.writeBeforePartitionExecutionTimeline(); - List fetchExecutionRanges = clientSideMetrics.getFetchExecutionRanges(); - fetchExecutionRanges.sort((f1, f2) -> f2.getStartTime().compareTo(f1.getStartTime())); - for (FetchExecutionRange fetchExecutionRange : clientSideMetrics.getFetchExecutionRanges()) { - this.writeFetchExecutionRange(fetchExecutionRange); - } - this.writeAfterPartitionExecutionTimeline(); - } - - protected abstract void writeBeforePartitionExecutionTimeline(); - - private void writeFetchExecutionRange(FetchExecutionRange fetchExecutionRange) { - this.writeBeforeFetchExecutionRange(); - - this.writeFetchPartitionKeyRangeId(fetchExecutionRange.getPartitionId()); - this.writeActivityId(fetchExecutionRange.getActivityId()); - this.writeStartTime(fetchExecutionRange.getStartTime()); - this.writeEndTime(fetchExecutionRange.getEndTime()); - this.writeFetchDocumentCount(fetchExecutionRange.getNumberOfDocuments()); - this.writeFetchRetryCount(fetchExecutionRange.getRetryCount()); - - this.writeAfterFetchExecutionRange(); - } - - protected abstract void writeBeforeFetchExecutionRange(); - - protected abstract void writeFetchPartitionKeyRangeId(String partitionId); - - protected abstract void writeActivityId(String activityId); - - protected abstract void writeStartTime(Instant startTime); - - protected abstract void writeEndTime(Instant endTime); - - protected abstract void writeFetchDocumentCount(long numberOfDocuments); - - protected abstract void writeFetchRetryCount(long retryCount); - - protected abstract void writeAfterFetchExecutionRange(); - - protected abstract void writeAfterPartitionExecutionTimeline(); - - private void writeSchedulingMetrics(ClientSideMetrics clientSideMetrics) { - this.writeBeforeSchedulingMetrics(); - List> partitionSchedulingTimeSpans = clientSideMetrics.getPartitionSchedulingTimeSpans(); - partitionSchedulingTimeSpans.sort((o1, o2) -> (int) (o2.right.getResponseTime() - o1.right.getResponseTime())); - for (ImmutablePair partitionSchedulingDuration : - partitionSchedulingTimeSpans) { - String partitionId = partitionSchedulingDuration.getLeft(); - SchedulingTimeSpan schedulingDuration = partitionSchedulingDuration.getRight(); - - this.writePartitionSchedulingDuration(partitionId, schedulingDuration); - } - - this.writeAfterSchedulingMetrics(); - } - - protected abstract void writeBeforeSchedulingMetrics(); - - private void writePartitionSchedulingDuration(String partitionId, SchedulingTimeSpan schedulingDuration) { - this.writeBeforePartitionSchedulingDuration(); - - this.writePartitionSchedulingDurationId(partitionId); - this.writeResponseTime(schedulingDuration.getResponseTime()); - this.writeRunTime(schedulingDuration.getRunTime()); - this.writeWaitTime(schedulingDuration.getWaitTime()); - this.writeTurnaroundTime(schedulingDuration.getTurnaroundTime()); - this.writeNumberOfPreemptions(schedulingDuration.getNumPreemptions()); - - this.writeAfterPartitionSchedulingDuration(); - } - - protected abstract void writeBeforePartitionSchedulingDuration(); - - protected abstract void writePartitionSchedulingDurationId(String partitionId); - - protected abstract void writeResponseTime(long responseTime); - - protected abstract void writeRunTime(long runTime); - - protected abstract void writeWaitTime(long waitTime); - - protected abstract void writeTurnaroundTime(long turnaroundTime); - - protected abstract void writeNumberOfPreemptions(long numPreemptions); - - protected abstract void writeAfterPartitionSchedulingDuration(); - - protected abstract void writeAfterSchedulingMetrics(); - - protected abstract void writeAfterClientSideMetrics(); - - protected abstract void writeAfterQueryMetrics(); - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/SchedulingStopwatch.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/SchedulingStopwatch.java deleted file mode 100644 index eac7270f90be..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/SchedulingStopwatch.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -import org.apache.commons.lang3.time.StopWatch; - -public class SchedulingStopwatch { - private StopWatch turnaroundTimeStopwatch; - private StopWatch responseTimeStopwatch; - private StopWatch runTimeStopwatch; - private long numPreemptions; - private boolean responded; - - public SchedulingStopwatch() { - this.turnaroundTimeStopwatch = new StopWatch(); - this.responseTimeStopwatch = new StopWatch(); - this.runTimeStopwatch = new StopWatch(); - } - - public SchedulingTimeSpan getElapsedTime() { - return new SchedulingTimeSpan(this.turnaroundTimeStopwatch.getTime(), this.responseTimeStopwatch.getTime(), - this.runTimeStopwatch.getTime(), - this.turnaroundTimeStopwatch.getTime() - this.runTimeStopwatch.getTime(), this.numPreemptions); - } - - /** - * Tells the SchedulingStopwatch know that the process is in a state where it is ready to be worked on, - * which in turn starts the stopwatch for for response time and turnaround time. - */ - public void ready() { - startStopWatch(this.turnaroundTimeStopwatch); - startStopWatch(this.responseTimeStopwatch); - } - - public void start() { - if (!this.runTimeStopwatch.isStarted()) { - if (!this.responded) { - // This is the first time the process got a response, so the response time stopwatch needs to stop. - this.responseTimeStopwatch.stop(); - this.responded = true; - } - this.runTimeStopwatch.reset(); - startStopWatch(this.runTimeStopwatch); - } - } - - public void stop() { - if (this.runTimeStopwatch.isStarted()) { - stopStopWatch(this.runTimeStopwatch); - this.numPreemptions++; - } - } - - public void terminate() { - stopStopWatch(this.turnaroundTimeStopwatch); - stopStopWatch(this.responseTimeStopwatch); - } - - private void startStopWatch(StopWatch stopwatch) { - synchronized (stopwatch) { - stopwatch.start(); - } - } - - private void stopStopWatch(StopWatch stopwatch) { - synchronized (stopwatch) { - stopwatch.stop(); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/SchedulingTimeSpan.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/SchedulingTimeSpan.java deleted file mode 100644 index 02bd4cbd80dc..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/SchedulingTimeSpan.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -public class SchedulingTimeSpan { - - /** - * The total time taken from when the process arrives to when it ended. - */ - private final long turnaroundTime; - - /** - * The total latency (time) taken from when the process arrived to when the CPU actually started working on it. - */ - private final long responseTime; - - /** - * The total time the process spent in the running state. - */ - private final long runTime; - - /** - * The total time that the process spent is on the ready or waiting state. - */ - private final long waitTime; - - /** - * Number of times the process was preempted. - */ - private final long numPreemptions; - - public SchedulingTimeSpan(long turnaroundTime, long responseTime, long runTime, long waitTime, long numPreemptions) { - this.turnaroundTime = turnaroundTime; - this.responseTime = responseTime; - this.runTime = runTime; - this.waitTime = waitTime; - this.numPreemptions = numPreemptions; - } - - public long getTurnaroundTime() { - return turnaroundTime; - } - - public long getResponseTime() { - return responseTime; - } - - public long getRunTime() { - return runTime; - } - - public long getWaitTime() { - return waitTime; - } - - public long getNumPreemptions() { - return numPreemptions; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/TextTable.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/TextTable.java deleted file mode 100644 index ca7c711ee4f1..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/query/metrics/TextTable.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.query.metrics; - -import org.apache.commons.lang3.StringUtils; - -import java.util.ArrayList; -import java.util.List; - -class TextTable { - private static final char CellLeftTop = '┌'; - private static final char CellRightTop = '┐'; - private static final char CellLeftBottom = '└'; - private static final char CellRightBottom = '┘'; - private static final char CellHorizontalJointTop = '┬'; - private static final char CellHorizontalJointBottom = '┴'; - private static final char CellVerticalJointLeft = '├'; - private static final char CellTJoint = '┼'; - private static final char CellVerticalJointRight = '┤'; - private static final char CellHorizontalLine = '-'; - private static final char CellVerticalLine = '│'; - - private List columns; - - private String header; - private String topLine; - private String middleLine; - private String bottomLine; - - private String rowFormatString; - - /** - * Initializes a new instance of the TextTable class. - * - * @param columns The columns of the table - */ - public TextTable(List columns) { - this.columns = new ArrayList<>(columns); - - // Building the table header - String headerFormatString = TextTable.buildLineFormatString(columns); - this.header = String.format(headerFormatString, columns.stream().map(textTableColumn -> textTableColumn.columnName).toArray()); - - // building the different lines - this.topLine = TextTable.buildLine(CellLeftTop, CellRightTop, CellHorizontalJointTop, columns); - this.middleLine = TextTable.buildLine(CellVerticalJointLeft, CellVerticalJointRight, CellTJoint, columns); - this.bottomLine = TextTable.buildLine(CellLeftBottom, CellRightBottom, CellHorizontalJointBottom, columns); - - // building the row format string - this.rowFormatString = TextTable.buildLineFormatString(columns); - } - - public String getRow(List cells) { - if (cells.size() != this.columns.size()) { - throw new IllegalArgumentException("Cells in a row needs to have exactly 1 element per column"); - } - return String.format(this.rowFormatString, cells.toArray()); - } - - private static String buildLine(char firstChar, char lastChar, char seperator, List columns) { - StringBuilder lineStringBuilder = new StringBuilder(); - lineStringBuilder.append(firstChar); - for (Column column : columns.subList(0, columns.size() - 1)) { - lineStringBuilder.append(StringUtils.repeat(CellHorizontalLine, column.columnWidth)); - lineStringBuilder.append(seperator); - } - - lineStringBuilder.append(StringUtils.repeat(CellHorizontalLine, columns.get(columns.size() - 1).columnWidth)); - lineStringBuilder.append(lastChar); - - return lineStringBuilder.toString(); - } - - private static String buildLineFormatString(List columns) { - StringBuilder lineFormatStringBuilder = new StringBuilder(); - lineFormatStringBuilder.append(CellVerticalLine); - for (Column column : columns) { - lineFormatStringBuilder.append("%" + column.columnWidth + "s"); - lineFormatStringBuilder.append(CellVerticalLine); - } - - return lineFormatStringBuilder.toString(); - } - - - static class Column { - String columnName; - int columnWidth; - - public Column(String columnName, int columnWidth) { - this.columnName = columnName; - this.columnWidth = columnWidth; - } - } - - public String getHeader() { - return header; - } - - public String getTopLine() { - return topLine; - } - - public String getMiddleLine() { - return middleLine; - } - - public String getBottomLine() { - return bottomLine; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/BoolPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/BoolPartitionKeyComponent.java deleted file mode 100644 index eda8dd7a9422..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/BoolPartitionKeyComponent.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class BoolPartitionKeyComponent implements IPartitionKeyComponent { - - private final boolean value; - - public BoolPartitionKeyComponent(boolean value) { - this.value = value; - } - - @Override - public int CompareTo(IPartitionKeyComponent other) { - BoolPartitionKeyComponent otherBool = Utils.as(other, BoolPartitionKeyComponent.class); - if (otherBool == null) { - throw new IllegalArgumentException("other"); - } - - return (int) Math.signum((this.value ? 1 : 0) - (otherBool.value ? 1 : 0)); - } - - @Override - public int GetTypeOrdinal() { - return this.value ? PartitionKeyComponentType.TRUE.type : PartitionKeyComponentType.FALSE.type; - } - - @Override - public void JsonEncode(JsonGenerator writer) { - try { - writer.writeBoolean(this.value); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - try { - outputStream.write((byte) (this.value ? PartitionKeyComponentType.TRUE.type - : PartitionKeyComponentType.FALSE.type)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - try { - outputStream.write((byte) (this.value ? PartitionKeyComponentType.TRUE.type - : PartitionKeyComponentType.FALSE.type)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) (this.value ? PartitionKeyComponentType.TRUE.type - : PartitionKeyComponentType.FALSE.type)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/IPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/IPartitionKeyComponent.java deleted file mode 100644 index ff21ae1d307c..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/IPartitionKeyComponent.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; - -interface IPartitionKeyComponent { - int CompareTo(IPartitionKeyComponent other); - - int GetTypeOrdinal(); - - void JsonEncode(JsonGenerator writer); - - void WriteForHashing(OutputStream outputStream); - - void WriteForHashingV2(OutputStream binaryWriter); - - void WriteForBinaryEncoding(OutputStream binaryWriter); - - IPartitionKeyComponent Truncate(); -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/InfinityPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/InfinityPartitionKeyComponent.java deleted file mode 100644 index fb5ed45050d2..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/InfinityPartitionKeyComponent.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class InfinityPartitionKeyComponent implements IPartitionKeyComponent { - @Override - public int CompareTo(IPartitionKeyComponent other) { - InfinityPartitionKeyComponent otherInfinity = Utils.as(other, InfinityPartitionKeyComponent.class); - if (otherInfinity == null) { - throw new IllegalArgumentException("other"); - } - - return 0; - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.INFINITY.type; - } - - @Override - public void JsonEncode(JsonGenerator writer) { - throw new UnsupportedOperationException(); - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - throw new IllegalStateException(); - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - throw new IllegalStateException(); - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.INFINITY.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MaxNumberPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MaxNumberPartitionKeyComponent.java deleted file mode 100644 index c88fa8889be4..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MaxNumberPartitionKeyComponent.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class MaxNumberPartitionKeyComponent implements IPartitionKeyComponent { - public static final MaxNumberPartitionKeyComponent VALUE = new MaxNumberPartitionKeyComponent(); - - @Override - public int CompareTo(IPartitionKeyComponent other) { - MaxNumberPartitionKeyComponent otherMaxNumber = Utils.as(other, MaxNumberPartitionKeyComponent.class); - if (otherMaxNumber == null) { - throw new IllegalArgumentException("other"); - } - - return 0; - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.MAXNUMBER.ordinal(); - } - - @Override - public void JsonEncode(JsonGenerator writer) { - PartitionKeyInternal.PartitionKeyInternalJsonSerializer.jsonEncode(this, writer); - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.MAXNUMBER.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MaxStringPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MaxStringPartitionKeyComponent.java deleted file mode 100644 index 0b45955919da..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MaxStringPartitionKeyComponent.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class MaxStringPartitionKeyComponent implements IPartitionKeyComponent { - public static final MaxStringPartitionKeyComponent VALUE = new MaxStringPartitionKeyComponent(); - - @Override - public int CompareTo(IPartitionKeyComponent other) { - MaxStringPartitionKeyComponent otherMaxString = Utils.as(other, MaxStringPartitionKeyComponent.class); - if (otherMaxString == null) { - throw new IllegalArgumentException("other"); - } - - return 0; - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.MAXSTRING.ordinal(); - } - - @Override - public void JsonEncode(JsonGenerator writer) { - PartitionKeyInternal.PartitionKeyInternalJsonSerializer.jsonEncode(this, writer); - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.MAXSTRING.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } - -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MinNumberPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MinNumberPartitionKeyComponent.java deleted file mode 100644 index 7d10d3126256..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MinNumberPartitionKeyComponent.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class MinNumberPartitionKeyComponent implements IPartitionKeyComponent { - public static final MinNumberPartitionKeyComponent VALUE = new MinNumberPartitionKeyComponent(); - - @Override - public int CompareTo(IPartitionKeyComponent other) { - MinNumberPartitionKeyComponent otherMinNumber = Utils.as(other, MinNumberPartitionKeyComponent.class); - if (otherMinNumber == null) { - throw new IllegalArgumentException("other"); - } - - return 0; - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.MINNUMBER.ordinal(); - } - - @Override - public void JsonEncode(JsonGenerator writer) { - PartitionKeyInternal.PartitionKeyInternalJsonSerializer.jsonEncode(this, writer); - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.MINNUMBER.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MinStringPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MinStringPartitionKeyComponent.java deleted file mode 100644 index 8b765dab91d3..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MinStringPartitionKeyComponent.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class MinStringPartitionKeyComponent implements IPartitionKeyComponent { - public static final MinStringPartitionKeyComponent VALUE = new MinStringPartitionKeyComponent(); - - @Override - public int CompareTo(IPartitionKeyComponent other) { - MinStringPartitionKeyComponent otherMinString = Utils.as(other, MinStringPartitionKeyComponent.class); - if (otherMinString == null) { - throw new IllegalArgumentException("other"); - } - - return 0; - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.MINSTRING.ordinal(); - } - - @Override - public void JsonEncode(JsonGenerator writer) { - PartitionKeyInternal.PartitionKeyInternalJsonSerializer.jsonEncode(this, writer); - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - throw new UnsupportedOperationException(); - } - - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.MINSTRING.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/NullPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/NullPartitionKeyComponent.java deleted file mode 100644 index a82585474370..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/NullPartitionKeyComponent.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class NullPartitionKeyComponent implements IPartitionKeyComponent { - - public static final NullPartitionKeyComponent VALUE = new NullPartitionKeyComponent(); - - @Override - public int CompareTo(IPartitionKeyComponent other) { - NullPartitionKeyComponent otherMinString = Utils.as(other, NullPartitionKeyComponent.class); - if (otherMinString == null) { - throw new IllegalArgumentException("other"); - } - - return 0; - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.NULL.type; - } - - @Override - public void JsonEncode(JsonGenerator writer) { - try { - writer.writeObject(null); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.NULL.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.NULL.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.NULL.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/NumberPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/NumberPartitionKeyComponent.java deleted file mode 100644 index 18eed71c03d9..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/NumberPartitionKeyComponent.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; -import java.math.BigInteger; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -/** - * Used internally to represent a number component in the partition key of the Azure Cosmos DB database service. - */ -public class NumberPartitionKeyComponent implements IPartitionKeyComponent { - - public static final NumberPartitionKeyComponent Zero = new NumberPartitionKeyComponent(0); - private final double value; - - public NumberPartitionKeyComponent(double value) { - this.value = value; - } - - private static byte[] doubleToByteArray(double d) { - byte[] output = new byte[8]; - long lng = Double.doubleToLongBits(d); - for (int i = 0; i < 8; i++) { - output[i] = (byte) ((lng >> (i * 8)) & 0xff); - } - return output; - } - - private static long EncodeDoubleAsUInt64(double value) { - long rawLongBits = Double.doubleToRawLongBits(value); - long mask = 0x8000000000000000L; - return Long.compareUnsigned(rawLongBits, mask) < 0 - ? rawLongBits ^ mask - : (~rawLongBits) + 1; - } - - @Override - public int CompareTo(IPartitionKeyComponent other) { - NumberPartitionKeyComponent otherBool = Utils.as(other, NumberPartitionKeyComponent.class); - if (otherBool == null) { - throw new IllegalArgumentException("other"); - } - - return Double.compare(this.value, ((NumberPartitionKeyComponent) other).value); - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.NUMBER.type; - } - - @Override - public void JsonEncode(JsonGenerator writer) { - try { - writer.writeNumber(String.valueOf(value)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.NUMBER.type); - outputStream.write(doubleToByteArray(this.value)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.NUMBER.type); - outputStream.write(doubleToByteArray(this.value)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.NUMBER.type); - - long payload = NumberPartitionKeyComponent.EncodeDoubleAsUInt64(this.value); - - // Encode first chunk with 8-bits of payload - outputStream.write((byte) (payload >> (64 - 8))); - payload <<= 8; - - // Encode remaining chunks with 7 bits of payload followed by single "1" bit each. - byte byteToWrite = 0; - boolean firstIteration = true; - do { - if (!firstIteration) { - outputStream.write(byteToWrite); - } else { - firstIteration = false; - } - - byteToWrite = (byte) ((payload >> (64 - 8)) | 0x01); - payload <<= 7; - } while (payload != 0); - - // Except for last chunk that ends with "0" bit. - outputStream.write((byte) (byteToWrite & 0xFE)); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyAndResourceTokenPair.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyAndResourceTokenPair.java deleted file mode 100644 index f1c3c5241c79..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyAndResourceTokenPair.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.routing; - -/** - * This is the pair for Partition key and its corresponding Resource Token , - * this is the value in resource token map which is getting filled during the - * construction of AsyncDocumentClient - */ -public class PartitionKeyAndResourceTokenPair { - - private PartitionKeyInternal partitionKey; - private String resourceToken; - - public PartitionKeyAndResourceTokenPair(PartitionKeyInternal partitionKey, String resourceToken) { - this.partitionKey = partitionKey; - this.resourceToken = resourceToken; - } - - /** - * Get the Partition Key - * - * @return Partition Key - */ - public PartitionKeyInternal getPartitionKey() { - return partitionKey; - } - - /** - * Sets the PartitionKey - * - * @param partitionKey - * The Partition key - */ - public void setPartitionKey(PartitionKeyInternal partitionKey) { - this.partitionKey = partitionKey; - } - - /** - * Gets the Resource Token - * - * @return Resource Token - */ - public String getResourceToken() { - return resourceToken; - } - - /** - * Sets the Resource Token - * - * @param resourceToken - * The Resource Token - */ - public void setResourceToken(String resourceToken) { - this.resourceToken = resourceToken; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyComponentType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyComponentType.java deleted file mode 100644 index ee1180f0a2aa..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyComponentType.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -enum PartitionKeyComponentType { - UNDEFINED(0x0), - NULL(0x1), - FALSE(0x2), - TRUE(0x3), - MINNUMBER(0x4), - NUMBER(0x5), - MAXNUMBER(0x6), - MINSTRING(0x7), - STRING(0x8), - MAXSTRING(0x9), - INFINITY(0xFF); - - public final int type; - PartitionKeyComponentType(int type) { - this.type = type; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternal.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternal.java deleted file mode 100644 index 1051193584ae..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternal.java +++ /dev/null @@ -1,333 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.ObjectCodec; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.fasterxml.jackson.databind.node.NullNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.as; - -/** - * Used internally to encapsulate internal information of a partition key in the Azure Cosmos DB database service. - */ -@JsonSerialize(using = PartitionKeyInternal.PartitionKeyInternalJsonSerializer.class) -@JsonDeserialize(using = PartitionKeyInternal.PartitionKeyInternalJsonDeserializer.class) -public class PartitionKeyInternal implements Comparable { - - private static final String TYPE = "type"; - private static final String MIN_NUMBER = "MinNumber"; - private static final String MAX_NUMBER = "MaxNumber"; - private static final String MIN_STRING = "MinString"; - private static final String MAX_STRING = "MaxString"; - private static final String INFINITY = "Infinity"; - - public static final PartitionKeyInternal EmptyPartitionKey = - new PartitionKeyInternal(new ArrayList<>()); - - @SuppressWarnings("serial") - public static final PartitionKeyInternal InfinityPartitionKey = - new PartitionKeyInternal(new ArrayList() {{ - add(new InfinityPartitionKeyComponent()); - }}); - - public static final PartitionKeyInternal InclusiveMinimum = PartitionKeyInternal.EmptyPartitionKey; - public static final PartitionKeyInternal ExclusiveMaximum = PartitionKeyInternal.InfinityPartitionKey; - public static final PartitionKeyInternal Empty = PartitionKeyInternal.EmptyPartitionKey; - - final List components; - - public PartitionKeyInternal(List values) { - if (values == null) { - throw new IllegalArgumentException("values"); - } - - this.components = values; - } - - public static PartitionKeyInternal fromJsonString(String partitionKey) { - if (Strings.isNullOrEmpty(partitionKey)) { - throw new IllegalArgumentException(String.format(RMResources.UnableToDeserializePartitionKeyValue, partitionKey)); - } - - try { - return Utils.getSimpleObjectMapper().readValue(partitionKey, PartitionKeyInternal.class); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - } - - public static PartitionKeyInternal fromObjectArray(Object[] values, boolean strict) { - if (values == null) { - throw new IllegalArgumentException("values"); - } - - return PartitionKeyInternal.fromObjectArray(Arrays.asList(values), strict); - } - - public static PartitionKeyInternal fromObjectArray(List values, boolean strict) { - if (values == null) { - throw new IllegalArgumentException("values"); - } - - List components = new ArrayList<>(); - for (Object value : values) { - if (value == NullNode.instance || value == null) { - components.add(NullPartitionKeyComponent.VALUE); - } else if (value instanceof Undefined) { - components.add(UndefinedPartitionKeyComponent.VALUE); - } else if (value instanceof Boolean) { - components.add(new BoolPartitionKeyComponent((boolean) value)); - } else if (value instanceof String) { - components.add(new StringPartitionKeyComponent((String) value)); - } else if (isNumeric(value)) { - components.add(new NumberPartitionKeyComponent(((Number) value).doubleValue())); - } else if (value instanceof ObjectNode && ((ObjectNode) value).get(TYPE) != null) { - switch (((ObjectNode) value).get(TYPE).asText()) { - case MIN_NUMBER: - components.add(MinNumberPartitionKeyComponent.VALUE); - break; - case MAX_NUMBER: - components.add(MaxNumberPartitionKeyComponent.VALUE); - break; - case MIN_STRING: - components.add(MinStringPartitionKeyComponent.VALUE); - break; - case MAX_STRING: - components.add(MaxStringPartitionKeyComponent.VALUE); - break; - } - } else { - if (strict) { - throw new IllegalArgumentException("Unable to construct PartitionKeyInternal from objects array"); - } else { - components.add(UndefinedPartitionKeyComponent.VALUE); - } - } - } - - return new PartitionKeyInternal(components); - } - - private static boolean isNumeric(Object value) { - return value instanceof Number; - } - - private static PartitionKeyInternal getExclusiveMaximum() { - return PartitionKeyInternal.InfinityPartitionKey; - } - - public static PartitionKeyInternal getEmpty() { - return PartitionKeyInternal.EmptyPartitionKey; - } - - @Override - public boolean equals(Object obj) { - PartitionKeyInternal pki = as(obj, PartitionKeyInternal.class); - if (pki == null) { - return false; - } - - if (pki == this) { - return true; - } - - return this.compareTo(pki) == 0; - } - - public int compareTo(PartitionKeyInternal other) { - if (other == null) { - throw new IllegalArgumentException("other"); - } - - for (int i = 0; i < Math.min(this.components.size(), other.components.size()); i++) { - int leftOrdinal = this.components.get(i).GetTypeOrdinal(); - int rightOrdinal = other.components.get(i).GetTypeOrdinal(); - if (leftOrdinal != rightOrdinal) { - return (int) Math.signum(leftOrdinal - rightOrdinal); - } - - int result = this.components.get(i).CompareTo(other.components.get(i)); - if (result != 0) { - return (int) Math.signum(result); - } - } - - return (int) Math.signum(this.components.size() - other.components.size()); - } - - public String toJson() { - try { - return Utils.getSimpleObjectMapper().writeValueAsString(this); - } catch (IOException e) { - throw new IllegalArgumentException("Unable serialize the partition key internal into the JSON string", e); - } - } - - public boolean contains(PartitionKeyInternal nestedPartitionKey) { - if (this.components.size() > nestedPartitionKey.components.size()) { - return false; - } - - for (int i = 0; i < this.components.size(); i++) { - if (this.components.get(i).CompareTo(nestedPartitionKey.components.get(i)) != 0) { - return false; - } - } - - return true; - } - - public List getComponents() { - return components; - } - - @SuppressWarnings("serial") - static final class PartitionKeyInternalJsonSerializer extends StdSerializer { - - protected PartitionKeyInternalJsonSerializer() { this(null); } - - protected PartitionKeyInternalJsonSerializer(Class t) { - super(t); - } - - @Override - public void serialize(PartitionKeyInternal partitionKey, JsonGenerator writer, SerializerProvider serializerProvider) { - try { - if (partitionKey.equals(PartitionKeyInternal.getExclusiveMaximum())) { - writer.writeString(INFINITY); - return; - } - - writer.writeStartArray(); - for (IPartitionKeyComponent componentValue : partitionKey.getComponents()) { - componentValue.JsonEncode(writer); - } - writer.writeEndArray(); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - static void jsonEncode(MinNumberPartitionKeyComponent component, JsonGenerator writer) { - jsonEncodeLimit(writer, MIN_NUMBER); - } - - static void jsonEncode(MaxNumberPartitionKeyComponent component, JsonGenerator writer) { - jsonEncodeLimit(writer, MAX_NUMBER); - } - - static void jsonEncode(MinStringPartitionKeyComponent component, JsonGenerator writer) { - jsonEncodeLimit(writer, MIN_STRING); - } - - static void jsonEncode(MaxStringPartitionKeyComponent component, JsonGenerator writer) { - jsonEncodeLimit(writer, MAX_STRING); - } - - private static void jsonEncodeLimit(JsonGenerator writer, String value) { - try { - writer.writeStartObject(); - writer.writeFieldName(TYPE); - writer.writeString(value); - writer.writeEndObject(); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - } - - @SuppressWarnings("serial") - static final class PartitionKeyInternalJsonDeserializer extends StdDeserializer { - - protected PartitionKeyInternalJsonDeserializer() { this(null); } - - protected PartitionKeyInternalJsonDeserializer(Class vc) { - super(vc); - } - - @Override - public PartitionKeyInternal deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) { - - ObjectCodec objectCodec = jsonParser.getCodec(); - JsonNode root; - try { - root = objectCodec.readTree(jsonParser); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - - if (root.isTextual() && root.asText().equals(INFINITY)) { - return PartitionKeyInternal.getExclusiveMaximum(); - } - - List objects = new ArrayList<>(); - if (root.isArray()) { - Iterator iterator = root.iterator(); - while (iterator.hasNext()) { - JsonNode node = iterator.next(); - if (node.isNull()) { - objects.add(null); - } else if (node.isNumber()) { - objects.add(node.asDouble()); - } else if (node.isBoolean()) { - objects.add(node.asBoolean()); - } else if (node.isTextual()) { - objects.add(node.asText()); - } else if (node.isArray() && node.size() == 0 - || node.isObject() - && (node.fields() == null || !node.fields().hasNext())) { - objects.add(Undefined.Value()); - } else { - objects.add(node); - } - } - return PartitionKeyInternal.fromObjectArray(objects, true); - } - - throw new IllegalStateException(String.format( - "Unable to deserialize PartitionKeyInternal '%s'", - root.toString())); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyRangeIdentity.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyRangeIdentity.java deleted file mode 100644 index 41360c5e20b9..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyRangeIdentity.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import org.apache.commons.lang3.StringUtils; - -/** - * Used internally to represents the identity of a partition key range in the Azure Cosmos DB database service. - */ -public final class PartitionKeyRangeIdentity { - private String collectionRid; - private String partitionKeyRangeId; - - public PartitionKeyRangeIdentity(String collectionRid, String partitionKeyRangeId) { - if (collectionRid == null) { - throw new IllegalArgumentException("collectionRid"); - } - - if (partitionKeyRangeId == null) { - throw new IllegalArgumentException("partitionKeyRangeId"); - } - - this.collectionRid = collectionRid; - this.partitionKeyRangeId = partitionKeyRangeId; - } - - /** - * This should only be used for user provided partitionKeyRangeId, because in this case - * he knows what he is doing. If collection was deleted/created with same name - it is his responsibility. - *

- * If our code infers partitionKeyRangeId automatically and uses collection information from collection cache, - * we need to ensure that request will reach correct collection. In this case constructor which takes collectionRid MUST - * be used. - * - * @param partitionKeyRangeId a string represents the partition key range Id - */ - public PartitionKeyRangeIdentity(String partitionKeyRangeId) { - if (partitionKeyRangeId == null) { - throw new IllegalArgumentException("partitionKeyRangeId"); - } - - this.partitionKeyRangeId = partitionKeyRangeId; - } - - public static PartitionKeyRangeIdentity fromHeader(String header) { - String[] parts = StringUtils.split(header,","); - if (parts.length == 2) { - return new PartitionKeyRangeIdentity(parts[0], parts[1]); - } else if (parts.length == 1) { - return new PartitionKeyRangeIdentity(parts[0]); - } else { - throw new IllegalStateException("x-ms-documentdb-partitionkeyrangeid header contains invalid value '" + header + "'"); - } - } - - public String toHeader() { - if (this.collectionRid != null) { - return String.format("%s,%s", this.collectionRid, this.partitionKeyRangeId); - } - - return String.format("%s", this.partitionKeyRangeId); - } - - @Override - public boolean equals(Object other) { - if (null == other) { - return false; - } - if (this == other) { - return true; - } - return other instanceof PartitionKeyRangeIdentity - && ((PartitionKeyRangeIdentity) other).collectionRid.equals(this.collectionRid) - && ((PartitionKeyRangeIdentity) other).partitionKeyRangeId.equals(this.partitionKeyRangeId); - } - - @Override - public int hashCode() { - return ((this.collectionRid != null ? this.collectionRid.hashCode() : 0) * 397) - ^ (this.partitionKeyRangeId != null ? this.partitionKeyRangeId.hashCode() : 0); - } - - public String getCollectionRid() { - return collectionRid; - } - - public String getPartitionKeyRangeId() { - return partitionKeyRangeId; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/Range.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/Range.java deleted file mode 100644 index e4a4d7ff8b39..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/Range.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.util.Comparator; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.JsonSerializable; - -@JsonIgnoreProperties({ "empty", "singleValue", "hashMap" }) -public final class Range> extends JsonSerializable { - private static final String MIN_PROPERTY = "min"; - private static final String MAX_PROPERTY = "max"; - private static final String IS_MIN_INCLUSIVE_PROPERTY = "isMinInclusive"; - private static final String IS_MAX_INCLUSIVE_PROPERTY = "isMaxInclusive"; - - private T minValue; - private T maxValue; - - public Range() { - super(); - } - - public Range(String jsonString) { - super(jsonString); - } - - public Range(T min, T max, boolean isMinInclusive, boolean isMaxInclusive) { - this.setMin(min); - this.setMax(max); - this.setMinInclusive(isMinInclusive); - this.setMaxInclusive(isMaxInclusive); - } - - public static > Range getPointRange(T value) { - return new Range(value, value, true, true); - } - - public static > Range getEmptyRange(T value) { - return new Range(value, value, true, false); - } - - public static > boolean checkOverlapping(Range range1, Range range2) { - if (range1 == null || range2 == null || range1.isEmpty() || range2.isEmpty()) { - return false; - } - - int cmp1 = range1.getMin().compareTo(range2.getMax()); - int cmp2 = range2.getMin().compareTo(range1.getMax()); - - if (cmp1 <= 0 && cmp2 <= 0) { - return !((cmp1 == 0 && !(range1.isMinInclusive() && range2.isMaxInclusive())) - || (cmp2 == 0 && !(range2.isMinInclusive() && range1.isMaxInclusive()))); - } - - return false; - } - - @SuppressWarnings("unchecked") - public T getMin() { - if (this.minValue == null) { - this.minValue = (T) super.get(Range.MIN_PROPERTY); - } - - return this.minValue; - } - - public void setMin(T min) { - this.minValue = min; - super.set(Range.MIN_PROPERTY, min); - } - - @SuppressWarnings("unchecked") - public T getMax() { - if (this.maxValue == null) { - this.maxValue = (T) super.get(Range.MAX_PROPERTY); - } - - return this.maxValue; - } - - public void setMax(T max) { - this.maxValue = max; - super.set(Range.MAX_PROPERTY, max); - } - - @JsonProperty("isMinInclusive") - public boolean isMinInclusive() { - return super.getBoolean(Range.IS_MIN_INCLUSIVE_PROPERTY); - } - - public void setMinInclusive(boolean isMinInclusive) { - super.set(Range.IS_MIN_INCLUSIVE_PROPERTY, isMinInclusive); - } - - @JsonProperty("isMaxInclusive") - public boolean isMaxInclusive() { - return super.getBoolean(Range.IS_MAX_INCLUSIVE_PROPERTY); - } - - public void setMaxInclusive(boolean isMaxInclusive) { - super.set(Range.IS_MAX_INCLUSIVE_PROPERTY, isMaxInclusive); - } - - public boolean isSingleValue() { - return this.isMinInclusive() && this.isMaxInclusive() && this.getMin().compareTo(this.getMax()) == 0; - } - - public boolean isEmpty() { - return this.getMin().compareTo(this.getMax()) == 0 && !(this.isMinInclusive() && this.isMaxInclusive()); - } - - public boolean contains(T value) { - int minToValueRelation = this.getMin().compareTo(value); - int maxToValueRelation = this.getMax().compareTo(value); - - return ((this.isMinInclusive() && minToValueRelation <= 0) - || (!this.isMinInclusive() && minToValueRelation < 0)) - && ((this.isMaxInclusive() && maxToValueRelation >= 0) - || (!this.isMaxInclusive() && maxToValueRelation > 0)); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Range)) - return false; - if (obj == this) - return true; - @SuppressWarnings("unchecked") - Range otherRange = (Range) obj; - - return this.getMin().compareTo(otherRange.getMin()) == 0 && this.getMax().compareTo(otherRange.getMax()) == 0 - && this.isMinInclusive() == otherRange.isMinInclusive() - && this.isMaxInclusive() == otherRange.isMaxInclusive(); - } - - @Override - public int hashCode() { - int hash = 0; - hash = (hash * 397) ^ this.getMin().hashCode(); - hash = (hash * 397) ^ this.getMax().hashCode(); - hash = (hash * 397) ^ Boolean.compare(this.isMinInclusive(), false); - hash = (hash * 397) ^ Boolean.compare(this.isMaxInclusive(), false); - return hash; - } - - public static class MinComparator> implements Comparator> { - @Override - public int compare(Range range1, Range range2) { - int result = range1.getMin().compareTo(range2.getMin()); - if (result != 0 || range1.isMinInclusive() == range2.isMinInclusive()) { - return result; - } - - return range1.isMinInclusive() ? -1 : 1; - } - } - - public static class MaxComparator> implements Comparator> { - @Override - public int compare(Range range1, Range range2) { - int result = range1.getMax().compareTo(range2.getMax()); - if (result != 0 || range1.isMaxInclusive() == range2.isMaxInclusive()) { - return result; - } - - return range1.isMaxInclusive() ? 1 : -1; - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/StringPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/StringPartitionKeyComponent.java deleted file mode 100644 index 5f373417d1cb..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/StringPartitionKeyComponent.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class StringPartitionKeyComponent implements IPartitionKeyComponent { - - public static final int MAX_STRING_CHARS = 100; - public static final int MAX_STRING_BYTES_TO_APPEND = 100; - private final String value; - private final byte[] utf8Value; - - public StringPartitionKeyComponent(String value) { - if (value == null) { - throw new IllegalArgumentException("value"); - } - - this.value = value; - try { - this.utf8Value = com.microsoft.azure.cosmosdb.internal.Utils.getUTF8Bytes(value); - } catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException(e); - } - } - - @Override - public int CompareTo(IPartitionKeyComponent other) { - StringPartitionKeyComponent otherString = Utils.as(other, StringPartitionKeyComponent.class) ; - if (otherString == null) { - throw new IllegalArgumentException("other"); - } - - return this.value.compareTo(otherString.value); - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.STRING.type; - } - - @Override - public int hashCode() { - // hashCode for hashmap dictionary, etc - return value.hashCode(); - } - - public IPartitionKeyComponent Truncate() { - if (this.value.length() > MAX_STRING_CHARS) { - return new StringPartitionKeyComponent(this.value.substring(0, MAX_STRING_CHARS)); - } - - return this; - } - - @Override - public void JsonEncode(JsonGenerator writer) { - try { - writer.writeString(this.value); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.STRING.type); - outputStream.write(utf8Value); - outputStream.write((byte) 0); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.STRING.type); - outputStream.write(utf8Value); - outputStream.write((byte) 0xFF); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.STRING.type); - boolean shortString = this.utf8Value.length <= MAX_STRING_BYTES_TO_APPEND; - - for (int index = 0; index < (shortString ? this.utf8Value.length : MAX_STRING_BYTES_TO_APPEND + 1); index++) { - byte charByte = this.utf8Value[index]; - if (charByte < 0xFF) charByte++; - outputStream.write(charByte); - } - - if (shortString) { - outputStream.write((byte) 0x00); - } - } catch (IOException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/UndefinedPartitionKeyComponent.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/UndefinedPartitionKeyComponent.java deleted file mode 100644 index 8bbad5c40153..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/UndefinedPartitionKeyComponent.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.io.IOException; -import java.io.OutputStream; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -class UndefinedPartitionKeyComponent implements IPartitionKeyComponent { - - public static final UndefinedPartitionKeyComponent VALUE = new UndefinedPartitionKeyComponent(); - - @Override - public int CompareTo(IPartitionKeyComponent other) { - UndefinedPartitionKeyComponent otherUndefined = Utils.as(other, UndefinedPartitionKeyComponent.class); - if (otherUndefined == null) { - throw new IllegalArgumentException("other"); - } - - return 0; - } - - @Override - public int GetTypeOrdinal() { - return PartitionKeyComponentType.UNDEFINED.type; - } - - @Override - public void JsonEncode(JsonGenerator writer) { - try { - writer.writeStartObject(); - writer.writeEndObject(); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashing(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.UNDEFINED.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForHashingV2(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.UNDEFINED.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public void WriteForBinaryEncoding(OutputStream outputStream) { - try { - outputStream.write((byte) PartitionKeyComponentType.UNDEFINED.type); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - - @Override - public IPartitionKeyComponent Truncate() { - return this; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/package-info.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/package-info.java deleted file mode 100644 index 351bf1499dc6..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/package-info.java +++ /dev/null @@ -1,28 +0,0 @@ - -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -/** - * This package provides Java SDK Common Resources for Azure Cosmos DB. - */ -package com.microsoft.azure.cosmosdb; \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/AuthorizationTokenType.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/AuthorizationTokenType.java deleted file mode 100644 index dc0e37c3dcc5..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/AuthorizationTokenType.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -public enum AuthorizationTokenType { - Invalid, - PrimaryMasterKey, - PrimaryReadonlyMasterKey, - SecondaryMasterKey, - SecondaryReadonlyMasterKey, - SystemReadOnly, - SystemReadWrite, - SystemAll, - ResourceToken -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/BadRequestException.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/BadRequestException.java deleted file mode 100644 index f9dc2cf70860..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/BadRequestException.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.HashMap; -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class BadRequestException extends DocumentClientException { - private static final long serialVersionUID = 1L; - - public BadRequestException(String message, Exception innerException) { - super(message, innerException, new HashMap<>(), HttpConstants.StatusCodes.BADREQUEST, null); - } - - public BadRequestException() { - this(RMResources.BadRequest); - } - - public BadRequestException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.BADREQUEST, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public BadRequestException(String message) { - this(message, (Exception) null, (HttpResponseHeaders) null, null); - } - - public BadRequestException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public BadRequestException(String message, HttpResponseHeaders headers, URI requestUri) { - this(message, headers, requestUri != null ? requestUri.toString() : null); - } - - public BadRequestException(Exception innerException) { - this(RMResources.BadRequest, innerException, null, null); - } - - public BadRequestException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.BadRequest, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.BADREQUEST, - requestUri != null ? requestUri.toString() : null); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Configs.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Configs.java deleted file mode 100644 index 7bd80d3fbdac..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Configs.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslContextBuilder; -import io.netty.handler.ssl.SslProvider; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.text.WordUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.net.ssl.SSLException; - -public class Configs { - private static final Logger logger = LoggerFactory.getLogger(Configs.class); - private final SslContext sslContext; - - private static final String PROTOCOL = "COSMOS.PROTOCOL"; - private static final Protocol DEFAULT_PROTOCOL = Protocol.Https; - - private static final String UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS = "COSMOS.UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS"; - - private static final String MAX_HTTP_BODY_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_BODY_LENGTH_IN_BYTES"; - private static final String MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES = "COSMOS.MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES"; - private static final String MAX_HTTP_CHUNK_SIZE_IN_BYTES = "COSMOS.MAX_HTTP_CHUNK_SIZE_IN_BYTES"; - private static final String MAX_HTTP_HEADER_SIZE_IN_BYTES = "COSMOS.MAX_HTTP_HEADER_SIZE_IN_BYTES"; - private static final String MAX_DIRECT_HTTPS_POOL_SIZE = "COSMOS.MAX_DIRECT_HTTP_CONNECTION_LIMIT"; - - private static final int DEFAULT_UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS = 5 * 60; - - private static final int DEFAULT_MAX_HTTP_BODY_LENGTH_IN_BYTES = 6 * 1024 * 1024; //6MB - private static final int DEFAULT_MAX_HTTP_INITIAL_LINE_LENGTH = 4096; //4KB - private static final int DEFAULT_MAX_HTTP_CHUNK_SIZE_IN_BYTES = 8192; //8KB - private static final int DEFAULT_MAX_HTTP_REQUEST_HEADER_SIZE = 32 * 1024; //32 KB - - private static final int MAX_NUMBER_OF_READ_BARRIER_READ_RETRIES = 6; - private static final int MAX_NUMBER_OF_PRIMARY_READ_RETRIES = 6; - private static final int MAX_NUMBER_OF_READ_QUORUM_RETRIES = 6; - private static final int DELAY_BETWEEN_READ_BARRIER_CALLS_IN_MS = 5; - - private static final int MAX_BARRIER_RETRIES_FOR_MULTI_REGION = 30; - private static final int BARRIER_RETRY_INTERVAL_IN_MS_FOR_MULTI_REGION = 30; - - private static final int MAX_SHORT_BARRIER_RETRIES_FOR_MULTI_REGION = 4; - private static final int SHORT_BARRIER_RETRY_INTERVAL_IN_MS_FOR_MULTI_REGION = 10; - private static final int CPU_CNT = Runtime.getRuntime().availableProcessors(); - private static final int DEFAULT_DIRECT_HTTPS_POOL_SIZE = CPU_CNT * 500; - - public Configs() { - this.sslContext = sslContextInit(); - } - - private SslContext sslContextInit() { - try { - SslProvider sslProvider = SslContext.defaultClientProvider(); - return SslContextBuilder.forClient().sslProvider(sslProvider).build(); - } catch (SSLException sslException) { - logger.error("Fatal error cannot instantiate ssl context due to {}", sslException.getMessage(), sslException); - throw new IllegalStateException(sslException); - } - } - - public SslContext getSslContext() { - return this.sslContext; - } - - public Protocol getProtocol() { - String protocol = getJVMConfigAsString(PROTOCOL, DEFAULT_PROTOCOL.name()); - try { - return Protocol.valueOf(WordUtils.capitalize(protocol.toLowerCase())); - } catch (Exception e) { - logger.error("Parsing protocol {} failed. Using the default {}.", protocol, DEFAULT_PROTOCOL, e); - return DEFAULT_PROTOCOL; - } - } - - public int getMaxNumberOfReadBarrierReadRetries() { - return MAX_NUMBER_OF_READ_BARRIER_READ_RETRIES; - } - - public int getMaxNumberOfPrimaryReadRetries() { - return MAX_NUMBER_OF_PRIMARY_READ_RETRIES; - } - - public int getMaxNumberOfReadQuorumRetries() { - return MAX_NUMBER_OF_READ_QUORUM_RETRIES; - } - - public int getDelayBetweenReadBarrierCallsInMs() { - return DELAY_BETWEEN_READ_BARRIER_CALLS_IN_MS; - } - - public int getMaxBarrierRetriesForMultiRegion() { - return MAX_BARRIER_RETRIES_FOR_MULTI_REGION; - } - - public int getBarrierRetryIntervalInMsForMultiRegion() { - return BARRIER_RETRY_INTERVAL_IN_MS_FOR_MULTI_REGION; - } - - public int getMaxShortBarrierRetriesForMultiRegion() { - return MAX_SHORT_BARRIER_RETRIES_FOR_MULTI_REGION; - } - - public int getShortBarrierRetryIntervalInMsForMultiRegion() { - return SHORT_BARRIER_RETRY_INTERVAL_IN_MS_FOR_MULTI_REGION; - } - - public int getDirectHttpsMaxConnectionLimit() { - return getJVMConfigAsInt(MAX_DIRECT_HTTPS_POOL_SIZE, DEFAULT_DIRECT_HTTPS_POOL_SIZE); - } - - public int getMaxHttpHeaderSize() { - return getJVMConfigAsInt(MAX_HTTP_HEADER_SIZE_IN_BYTES, DEFAULT_MAX_HTTP_REQUEST_HEADER_SIZE); - } - - public int getMaxHttpInitialLineLength() { - return getJVMConfigAsInt(MAX_HTTP_INITIAL_LINE_LENGTH_IN_BYTES, DEFAULT_MAX_HTTP_INITIAL_LINE_LENGTH); - } - - public int getMaxHttpChunkSize() { - return getJVMConfigAsInt(MAX_HTTP_CHUNK_SIZE_IN_BYTES, DEFAULT_MAX_HTTP_CHUNK_SIZE_IN_BYTES); - } - - public int getMaxHttpBodyLength() { - return getJVMConfigAsInt(MAX_HTTP_BODY_LENGTH_IN_BYTES, DEFAULT_MAX_HTTP_BODY_LENGTH_IN_BYTES); - } - - public int getUnavailableLocationsExpirationTimeInSeconds() { - return getJVMConfigAsInt(UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS, DEFAULT_UNAVAILABLE_LOCATIONS_EXPIRATION_TIME_IN_SECONDS); - } - - private static String getJVMConfigAsString(String propName, String defaultValue) { - String propValue = System.getProperty(propName); - return StringUtils.defaultString(propValue, defaultValue); - } - - private static int getJVMConfigAsInt(String propName, int defaultValue) { - String propValue = System.getProperty(propName); - return getIntValue(propValue, defaultValue); - } - - private static int getIntValue(String val, int defaultValue) { - if (StringUtils.isEmpty(val)) { - return defaultValue; - } else { - return Integer.valueOf(val); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/DocumentServiceRequestContext.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/DocumentServiceRequestContext.java deleted file mode 100644 index 11adef562364..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/DocumentServiceRequestContext.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.net.URL; -import java.util.List; - -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResult; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.TimeoutHelper; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; - -public class DocumentServiceRequestContext implements Cloneable{ - public volatile boolean forceAddressRefresh; - public volatile boolean forceRefreshAddressCache; - public volatile RequestChargeTracker requestChargeTracker; - public volatile TimeoutHelper timeoutHelper; - public volatile String resolvedCollectionRid; - public volatile ISessionToken sessionToken; - public volatile long quorumSelectedLSN; - public volatile long globalCommittedSelectedLSN; - public volatile StoreResponse globalStrongWriteResponse; - public volatile ConsistencyLevel originalRequestConsistencyLevel; - public volatile PartitionKeyRange resolvedPartitionKeyRange; - public volatile Integer regionIndex; - public volatile Boolean usePreferredLocations; - public volatile Integer locationIndexToRoute; - public volatile URL locationEndpointToRoute; - public volatile boolean performedBackgroundAddressRefresh; - public volatile boolean performLocalRefreshOnGoneException; - public volatile List storeResponses; - public volatile StoreResult quorumSelectedStoreResponse; - public volatile PartitionKeyInternal effectivePartitionKey; - public volatile ClientSideRequestStatistics clientSideRequestStatistics; - - /** - * Sets routing directive for GlobalEndpointManager to resolve the request - * to endpoint based on location index. - * - * @param locationIndex Index of the location to which the request should be routed. - * @param usePreferredLocations Use preferred locations to route request. - */ - public void RouteToLocation(int locationIndex, boolean usePreferredLocations) { - this.locationIndexToRoute = locationIndex; - this.usePreferredLocations = usePreferredLocations; - this.locationEndpointToRoute = null; - } - - /** - * Sets location-based routing directive for GlobalEndpointManager to resolve - * the request to given locationEndpoint. - * - * @param locationEndpoint Location endpoint to which the request should be routed. - */ - public void RouteToLocation(URL locationEndpoint) { - this.locationEndpointToRoute = locationEndpoint; - this.locationIndexToRoute = null; - this.usePreferredLocations = null; - } - - /** - * Clears location-based routing directive - */ - public void ClearRouteToLocation() { - this.locationIndexToRoute = null; - this.locationEndpointToRoute = null; - this.usePreferredLocations = null; - } - - @Override - public DocumentServiceRequestContext clone() { - DocumentServiceRequestContext context = new DocumentServiceRequestContext(); - context.forceAddressRefresh = this.forceAddressRefresh; - context.forceRefreshAddressCache = this.forceRefreshAddressCache; - context.requestChargeTracker = this.requestChargeTracker; - context.timeoutHelper = this.timeoutHelper; - context.resolvedCollectionRid = this.resolvedCollectionRid; - context.sessionToken = this.sessionToken; - context.quorumSelectedLSN = this.quorumSelectedLSN; - context.globalCommittedSelectedLSN = this.globalCommittedSelectedLSN; - context.globalStrongWriteResponse = this.globalStrongWriteResponse; - context.originalRequestConsistencyLevel = this.originalRequestConsistencyLevel; - context.resolvedPartitionKeyRange = this.resolvedPartitionKeyRange; - context.regionIndex = this.regionIndex; - context.usePreferredLocations = this.usePreferredLocations; - context.locationIndexToRoute = this.locationIndexToRoute; - context.locationEndpointToRoute = this.locationEndpointToRoute; - context.performLocalRefreshOnGoneException = this.performLocalRefreshOnGoneException; - context.effectivePartitionKey = this.effectivePartitionKey; - context.performedBackgroundAddressRefresh = this.performedBackgroundAddressRefresh; - context.clientSideRequestStatistics = this.clientSideRequestStatistics; - - return context; - } -} - diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Exceptions.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Exceptions.java deleted file mode 100644 index 08bea22645da..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Exceptions.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class Exceptions { - - public static boolean isStatusCode(DocumentClientException e, int status) { - return status == e.getStatusCode(); - } - - public static boolean isSubStatusCode(DocumentClientException e, int subStatus) { - return subStatus == e.getSubStatusCode(); - } - - public static boolean isPartitionSplit(DocumentClientException e) { - return isStatusCode(e, HttpConstants.StatusCodes.GONE) - && isSubStatusCode(e, HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE); - } - - public static boolean isNameCacheStale(DocumentClientException e) { - return isStatusCode(e, HttpConstants.StatusCodes.GONE) - && isSubStatusCode(e, HttpConstants.SubStatusCodes.NAME_CACHE_IS_STALE); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/HttpClientFactory.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/HttpClientFactory.java deleted file mode 100644 index 99967bb8b404..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/HttpClientFactory.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import io.netty.channel.ChannelPipeline; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.logging.LoggingHandler; -import io.netty.handler.proxy.HttpProxyHandler; -import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslContextBuilder; -import io.netty.handler.ssl.SslHandler; -import io.netty.handler.ssl.SslProvider; -import io.reactivex.netty.pipeline.PipelineConfigurator; -import io.reactivex.netty.pipeline.PipelineConfiguratorComposite; -import io.reactivex.netty.pipeline.ssl.SSLEngineFactory; -import io.reactivex.netty.pipeline.ssl.SslCompletionHandler; -import io.reactivex.netty.protocol.http.HttpObjectAggregationConfigurator; -import io.reactivex.netty.protocol.http.client.CompositeHttpClientBuilder; -import io.reactivex.netty.protocol.http.client.HttpClient.HttpClientConfig; -import io.reactivex.netty.protocol.http.client.HttpClientPipelineConfigurator; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; - -import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLException; - -import com.microsoft.azure.cosmosdb.internal.Constants; -import org.slf4j.LoggerFactory; - -import java.net.InetSocketAddress; -import java.util.concurrent.TimeUnit; - -/** - * Helper class internally used for instantiating rx http client. - */ -public class HttpClientFactory { - private final static String NETWORK_LOG_CATEGORY = "com.microsoft.azure.cosmosdb.netty-network"; - - private final Configs configs; - private Integer maxPoolSize; - private Integer maxIdleConnectionTimeoutInMillis; - private Integer requestTimeoutInMillis; - private InetSocketAddress proxy; - - public HttpClientFactory(Configs configs) { - this.configs = configs; - } - - public HttpClientFactory withPoolSize(int maxPoolSize) { - this.maxPoolSize = maxPoolSize; - return this; - } - - public HttpClientFactory withHttpProxy(InetSocketAddress proxy) { - this.proxy = proxy; - return this; - } - - public HttpClientFactory withMaxIdleConnectionTimeoutInMillis(int maxIdleConnectionTimeoutInMillis) { - this.maxIdleConnectionTimeoutInMillis = maxIdleConnectionTimeoutInMillis; - return this; - } - - public HttpClientFactory withRequestTimeoutInMillis(int requestTimeoutInMillis) { - this.requestTimeoutInMillis = requestTimeoutInMillis; - return this; - } - - class DefaultSSLEngineFactory implements SSLEngineFactory { - private final SslContext sslContext; - - private DefaultSSLEngineFactory() { - this.sslContext = configs.getSslContext(); - } - - @Override - public SSLEngine createSSLEngine(ByteBufAllocator allocator) { - return sslContext.newEngine(allocator); - } - } - class SslPipelineConfiguratorUsedWithProxy implements PipelineConfigurator { - - private final SSLEngineFactory sslEngineFactory; - - private SslPipelineConfiguratorUsedWithProxy(SSLEngineFactory sslEngineFactory) { - this.sslEngineFactory = sslEngineFactory; - } - - @Override - public void configureNewPipeline(ChannelPipeline pipeline) { - final SslHandler sslHandler = new SslHandler(sslEngineFactory.createSSLEngine(pipeline.channel().alloc())); - if(proxy != null) { - pipeline.addAfter(Constants.Properties.HTTP_PROXY_HANDLER_NAME,Constants.Properties.SSL_HANDLER_NAME, sslHandler); - } else { - pipeline.addFirst(Constants.Properties.SSL_HANDLER_NAME, sslHandler); - } - pipeline.addAfter(Constants.Properties.SSL_HANDLER_NAME, Constants.Properties.SSL_COMPLETION_HANDLER_NAME, - new SslCompletionHandler(sslHandler.handshakeFuture())); - } - } - - public CompositeHttpClientBuilder toHttpClientBuilder() { - - if (configs == null) { - throw new IllegalArgumentException("configs is null"); - } - - DefaultSSLEngineFactory defaultSSLEngineFactory = new DefaultSSLEngineFactory(); - CompositeHttpClientBuilder builder = new CompositeHttpClientBuilder(); - if (maxPoolSize != null) { - builder = builder.withMaxConnections(maxPoolSize); - } - - if (maxIdleConnectionTimeoutInMillis != null) { - builder = builder.withIdleConnectionsTimeoutMillis(maxIdleConnectionTimeoutInMillis); - } - - builder = builder.pipelineConfigurator(pipeline -> { - LoggingHandler loggingHandler = getLoggingHandler(); - - if (loggingHandler != null) { - pipeline.addFirst(Constants.Properties.LOGGING_HANDLER_NAME, loggingHandler); - } - - if(proxy != null) { - pipeline.addFirst(Constants.Properties.HTTP_PROXY_HANDLER_NAME, new HttpProxyHandler(proxy)); - } - }) - .appendPipelineConfigurator(new SslPipelineConfiguratorUsedWithProxy<>(defaultSSLEngineFactory)) - .appendPipelineConfigurator(createClientPipelineConfigurator(configs)); - - if (requestTimeoutInMillis != null) { - HttpClientConfig.Builder clientConfigBuilder = new HttpClientConfig.Builder(); - clientConfigBuilder.readTimeout(requestTimeoutInMillis, TimeUnit.MILLISECONDS); - return builder.config(clientConfigBuilder.build()); - } - - return builder; - } - - private static PipelineConfigurator createClientPipelineConfigurator(Configs config) { - PipelineConfigurator clientPipelineConfigurator = new PipelineConfiguratorComposite( - new HttpClientPipelineConfigurator( - config.getMaxHttpInitialLineLength(), - config.getMaxHttpHeaderSize(), - config.getMaxHttpChunkSize(), - true), - new HttpObjectAggregationConfigurator(config.getMaxHttpBodyLength())); - return clientPipelineConfigurator; - } - - private static LoggingHandler getLoggingHandler() { - if (LoggerFactory.getLogger(NETWORK_LOG_CATEGORY).isTraceEnabled()) { - return new LoggingHandler(NETWORK_LOG_CATEGORY, LogLevel.TRACE); - } - - return null; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InternalConstants.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InternalConstants.java deleted file mode 100644 index 991b807d28b6..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InternalConstants.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -class InternalConstants { - - static class ResourceKeys { - static final String ATTACHMENTS = "Attachments"; - static final String CONFLICTS = "Conflicts"; - static final String DATABASES = "Databases"; - static final String DOCUMENTS = "Documents"; - static final String DOCUMENT_COLLECTIONS = "DocumentCollections"; - static final String OFFERS = "Offers"; - static final String PERMISSIONS = "Permissions"; - static final String PARTITION_KEY_RANGES = "PartitionKeyRanges"; - static final String TRIGGERS = "Triggers"; - static final String STOREDPROCEDURES = "StoredProcedures"; - static final String USERS = "Users"; - static final String USER_DEFINED_FUNCTIONS = "UserDefinedFunctions"; - static final String ADDRESSES = "Addresss"; - } - - static class StreamApi { - static final int STREAM_LENGTH_EOF = -1; - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RMResources.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RMResources.java deleted file mode 100644 index 38a08c2476d5..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RMResources.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -public class RMResources { - - public static final String UnknownResourceType = "Resource type %s is unknown"; - public static final String InvalidDocumentCollection = "The specified document collection is invalid."; - public static final String StringArgumentNullOrEmpty = "String agument %s is null or empty"; - public static final String PartitionKeyAndParitionKeyRangeIdBothSpecified = "Both Partition Key and Partition Key range are Specified in %s"; - public static final String PartitionKeyRangeIdOrPartitionKeyMustBeSpecified = "One of the partition key range id or partition key must be specified"; - public static final String TooFewPartitionKeyComponents = "PartitionKey has fewer components than defined the collection resource."; - public static final String TooManyPartitionKeyComponents = "PartitionKey has more components than defined the collection resource."; - public static final String UnableToDeserializePartitionKeyValue = "Cannot deserialize PartitionKey value '%s"; - public static final String Gone = "The requested resource is no longer available at the server."; - public static final String ExceptionMessageAddIpAddress = "%s, Local IP: %s"; - public static final String ExceptionMessage = "Message: %s"; - public static final String ServiceUnavailable = "Service is currently unavailable, please retry after a while. If this problem persists please contact support."; - public static final String InternalServerError = "Unknown server error occurred when processing this request."; - public static final String InvalidBackendResponse = "The backend response was not in the correct format."; - public static final String PartitionKeyRangeNotFound = "PartitionKeyRange with id %s in collection %s doesn't exist"; - public static final String InvalidTarget = "Target for the request is invalid"; - public static final String InvalidPartitionKey = "Partition key %s is invalid."; - public static final String PartitionKeyMismatch = "Partition key provided either doesn't correspond to definition in the collection or doesn't match partition key field values specified in the document."; - public static final String MissingPartitionKeyValue = "PartitionKey value must be supplied for this operation."; - public static final String InvalidConflictResolutionMode = "Invalid mode '%s' for setting '%s'. MODE expected is '%s'."; - public static final String InvalidRegionsInSessionToken = "Compared session tokens '%s' and '%s' has unexpected regions."; - public static final String InvalidSessionToken = "The session token provided '%s' is invalid."; - public static final String ResourceTokenNotFound = "Resource token not found."; - public static final String Unauthorized = "Unable to authenticate the request. The request requires valid user authentication."; - public static final String Forbidden = "Unable to proceed with the request. Please check the authorization claims to ensure the required permissions to process the request."; - public static final String NotFound = "Entity with the specified id does not exist in the system."; - public static final String BadRequest = "One of the input values is invalid."; - public static final String MethodNotAllowed = "The requested verb is not supported."; - public static final String EntityAlreadyExists = "Entity with the specified id already exists in the system."; - public static final String PreconditionFailed = "Operation cannot be performed because one of the specified precondition is not met."; - public static final String RequestEntityTooLarge = "The size of the response exceeded the maximum allowed size, limit the response size by specifying smaller value for '%s' header."; - public static final String Locked = ""; - public static final String RetryWith = "Retry the request."; - public static final String TooManyRequests = "The request rate is too large. Please retry after sometime."; - public static final String UnexpectedResourceType = "ResourceType %s is unexpected."; - public static final String InvalidHeaderValue = "Value '%s' specified for the header '%s' is invalid."; - public static final String RequestTimeout = "Request timed out."; - public static final String GlobalStrongWriteBarrierNotMet = "Global Strong write barrier has not been met for the request."; - public static final String InvalidRequestHeaderValue = "Invalid value for request header %s: %s"; - public static final String InvalidResourceAddress = "Invalid address for resource %s: %s"; - public static final String ReadQuorumNotMet = "Read Quorum size of %d is not met for the request."; - public static final String ReadSessionNotAvailable = "The read session is not available for the input session token."; - public static final String InvalidUrl = "InvalidUrl"; - public static final String InvalidResourceUrlQuery = "The value %s specified for query %s is invalid."; - public static final String PartitionKeyRangeIdAbsentInContext = "PartitionKeyRangeId is absent in the context."; -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentServiceRequest.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentServiceRequest.java deleted file mode 100644 index d1346deb44c0..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentServiceRequest.java +++ /dev/null @@ -1,1060 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.io.InputStream; -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedOptionsBase; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.PathInfo; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.QueryCompatibilityMode; -import com.microsoft.azure.cosmosdb.internal.ResourceId; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; - -import rx.Observable; -import rx.observables.StringObservable; - -/** - * This is core Transport/Connection agnostic request to the Azure Cosmos DB database service. - */ -public class RxDocumentServiceRequest { - private static final char PREFER_HEADER_SEPERATOR = ';'; - private static final String PREFER_HEADER_VALUE_FORMAT = "%s=%s"; - - public volatile boolean forcePartitionKeyRangeRefresh; - public volatile boolean forceCollectionRoutingMapRefresh; - private String resourceId; - private final ResourceType resourceType; - private final Map headers; - private volatile String continuation; - private boolean isMedia = false; - private final boolean isNameBased; - private final OperationType operationType; - private final String resourceAddress; - public volatile boolean forceNameCacheRefresh; - private volatile URI endpointOverride = null; - private final String activityId; - private volatile String resourceFullName; - - private volatile String originalSessionToken; - private volatile PartitionKeyRangeIdentity partitionKeyRangeIdentity; - private volatile Integer defaultReplicaIndex; - - public DocumentServiceRequestContext requestContext; - - private Observable contentObservable; - private byte[] byteContent; - - // NOTE: TODO: these fields are copied from .Net SDK - // some of these fields are missing from the main java sdk service request - // so it means most likely the corresponding features are also missing from the main sdk - // we need to wire this up. - public boolean UseGatewayMode; - - private volatile boolean isDisposed = false; - public volatile String entityId; - public volatile String queryString; - public volatile boolean isFeed; - public volatile AuthorizationTokenType authorizationTokenType; - public volatile Map properties; - - public boolean isReadOnlyRequest() { - return this.operationType == OperationType.Read - || this.operationType == OperationType.ReadFeed - || this.operationType == OperationType.Head - || this.operationType == OperationType.HeadFeed - || this.operationType == OperationType.Query - || this.operationType == OperationType.SqlQuery; - } - - public boolean isReadOnlyScript() { - String isReadOnlyScript = this.headers.get(HttpConstants.HttpHeaders.IS_READ_ONLY_SCRIPT); - if(StringUtils.isEmpty(isReadOnlyScript)) { - return false; - } else { - return this.operationType.equals(OperationType.ExecuteJavaScript) && isReadOnlyScript.equalsIgnoreCase(Boolean.TRUE.toString()); - } - } - - /** - * @param operationType the operation type. - * @param resourceIdOrFullName the request id or full name. - * @param resourceType the resource type. - * @param byteContent the byte content. - * @param headers the headers. - * @param isNameBased whether request is name based. - * @param authorizationTokenType the request authorizationTokenType. - */ - private RxDocumentServiceRequest(OperationType operationType, - String resourceIdOrFullName, - ResourceType resourceType, - byte[] byteContent, - Map headers, - boolean isNameBased, - AuthorizationTokenType authorizationTokenType) { - this.operationType = operationType; - this.forceNameCacheRefresh = false; - this.resourceType = resourceType; - this.byteContent = byteContent; - this.headers = headers != null ? headers : new HashMap<>(); - this.activityId = Utils.randomUUID().toString(); - this.isFeed = false; - this.isNameBased = isNameBased; - if (!isNameBased) { - this.resourceId = resourceIdOrFullName; - } - this.resourceAddress = resourceIdOrFullName; - this.authorizationTokenType = authorizationTokenType; - this.requestContext = new DocumentServiceRequestContext(); - if (StringUtils.isNotEmpty(this.headers.get(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID))) - this.partitionKeyRangeIdentity = PartitionKeyRangeIdentity.fromHeader(this.headers.get(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID)); - } - - /** - * Creates a AbstractDocumentServiceRequest - * - * @param operationType the operation type. - * @param resourceIdOrFullName the request id or full name. - * @param resourceType the resource type. - * @param path the path. - * @param headers the headers - */ - private RxDocumentServiceRequest(OperationType operationType, - String resourceIdOrFullName, - ResourceType resourceType, - String path, - Map headers) { - this.requestContext = new DocumentServiceRequestContext(); - this.operationType = operationType; - this.resourceType = resourceType; - this.requestContext.sessionToken = null; - this.headers = headers != null ? headers : new HashMap<>(); - this.activityId = Utils.randomUUID().toString(); - this.isFeed = false; - PathInfo pathInfo = new PathInfo(false, null, null, false); - if (StringUtils.isNotEmpty(path)) { - if (PathsHelper.tryParsePathSegments(path, pathInfo, null)) { - this.isNameBased = pathInfo.isNameBased; - this.isFeed = pathInfo.isFeed; - resourceIdOrFullName = pathInfo.resourceIdOrFullName; - if (!this.isNameBased) { - if (resourceType == ResourceType.Media) { - this.resourceId = getAttachmentIdFromMediaId(resourceIdOrFullName); - } else { - this.resourceId = resourceIdOrFullName; - } - - this.resourceAddress = resourceIdOrFullName; - - // throw exception when the address parsing fail - // do not parse address for offer resource - if (StringUtils.isNotEmpty(this.resourceId) && !ResourceId.tryParse(this.resourceId).getLeft() - && !resourceType.equals(ResourceType.Offer) && !resourceType.equals(ResourceType.Media) - && !resourceType.equals(ResourceType.MasterPartition) - && !resourceType.equals(ResourceType.ServerPartition) - && !resourceType.equals(ResourceType.DatabaseAccount) - && !resourceType.equals(ResourceType.RidRange)) { - throw new IllegalArgumentException( - String.format(RMResources.InvalidResourceUrlQuery, path, HttpConstants.QueryStrings.URL)); - } - } else { - this.resourceAddress = resourceIdOrFullName; - this.resourceId = null; - } - } else { - throw new IllegalArgumentException(RMResources.NotFound); - } - } else { - this.isNameBased = false; - this.resourceAddress = resourceIdOrFullName; - } - - if (StringUtils.isNotEmpty(this.headers.get(HttpConstants.HttpHeaders.PARTITION_KEY_RANGE_ID))) { - this.partitionKeyRangeIdentity = PartitionKeyRangeIdentity - .fromHeader(this.headers.get(HttpConstants.HttpHeaders.PARTITION_KEY_RANGE_ID)); - } - } - - /** - * Creates a DocumentServiceRequest - * - * @param resourceId the resource Id. - * @param resourceType the resource type. - * @param content the byte content observable\ - * @param contentObservable the byte content observable - * @param headers the request headers. - */ - private RxDocumentServiceRequest(OperationType operationType, - String resourceId, - ResourceType resourceType, - Observable contentObservable, - byte[] content, - String path, - Map headers, - AuthorizationTokenType authorizationTokenType) { - this( operationType, - resourceId, - resourceType, - path, - headers); - this.authorizationTokenType = authorizationTokenType; - this.byteContent = content; - this.contentObservable = contentObservable; - } - - /** - * Creates a DocumentServiceRequest with an HttpEntity. - * - * @param resourceType the resource type. - * @param path the relative URI path. - * @param contentObservable the byte content observable - * @param headers the request headers. - */ - private RxDocumentServiceRequest(OperationType operationType, - ResourceType resourceType, - String path, - Observable contentObservable, - Map headers, - AuthorizationTokenType authorizationTokenType) { - this(operationType, extractIdFromUri(path), resourceType, contentObservable, null, path, headers, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest with an HttpEntity. - * - * @param resourceType the resource type. - * @param path the relative URI path. - * @param byteContent the byte content. - * @param headers the request headers. - */ - private RxDocumentServiceRequest(OperationType operationType, - ResourceType resourceType, - String path, - byte[] byteContent, - Map headers, - AuthorizationTokenType authorizationTokenType) { - this(operationType, extractIdFromUri(path), resourceType, null, byteContent, path, headers, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest with an HttpEntity. - * - * @param resourceType the resource type. - * @param path the relative URI path. - * @param headers the request headers. - */ - private RxDocumentServiceRequest(OperationType operationType, - ResourceType resourceType, - String path, - Map headers, - AuthorizationTokenType authorizationTokenType) { - this(operationType, extractIdFromUri(path), resourceType, null , null, path, headers, authorizationTokenType); - } - - public void setContentBytes(byte[] bytes) { - this.byteContent = bytes; - } - - /** - * Creates a DocumentServiceRequest with a stream. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param content the content observable - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - Observable content, - Map headers) { - return new RxDocumentServiceRequest(operation, resourceType, relativePath, content, headers, AuthorizationTokenType.PrimaryMasterKey); - } - - /** - * Creates a DocumentServiceRequest with a stream. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param content the content observable - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - Observable content, - Map headers, - AuthorizationTokenType authorizationTokenType) { - return new RxDocumentServiceRequest(operation, resourceType, relativePath, content, headers, authorizationTokenType); - } - - /** Creates a DocumentServiceRequest with a stream. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param inputStream the input stream. - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - InputStream inputStream, - Map headers) { - // StringObservable is mis-named. It doesn't make any assumptions on character set - // and handles bytes only - return new RxDocumentServiceRequest(operation, resourceType, relativePath, StringObservable.from(inputStream), headers, AuthorizationTokenType.PrimaryMasterKey); - } - - /** Creates a DocumentServiceRequest with a stream. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param inputStream the input stream. - * @param headers the request headers. - * @param authorizationTokenType the request authorizationTokenType. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - InputStream inputStream, - Map headers, - AuthorizationTokenType authorizationTokenType) { - // StringObservable is mis-named. It doesn't make any assumptions on character set - // and handles bytes only - return new RxDocumentServiceRequest(operation, resourceType, relativePath, StringObservable.from(inputStream), headers, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest with a resource. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param resource the resource of the request. - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - Resource resource, - Map headers) { - return RxDocumentServiceRequest.create(operation, resourceType, relativePath, resource, headers, (RequestOptions)null); - } - - /** - * Creates a DocumentServiceRequest with a resource. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param resource the resource of the request. - * @param headers the request headers. - * @param options the request/feed/changeFeed options. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - Resource resource, - Map headers, - Object options) { - - RxDocumentServiceRequest request = new RxDocumentServiceRequest(operation, resourceType, relativePath, - // TODO: this re-encodes, can we improve performance here? - resource.toJson().getBytes(StandardCharsets.UTF_8), headers, AuthorizationTokenType.PrimaryMasterKey); - request.properties = getProperties(options); - return request; - } - - /** - * Creates a DocumentServiceRequest with a query. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param query the query. - * @param headers the request headers. - * @param options the request/feed/changeFeed options. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - String query, - Map headers, - Object options) { - RxDocumentServiceRequest request = new RxDocumentServiceRequest(operation, resourceType, relativePath, - query.getBytes(StandardCharsets.UTF_8), headers, AuthorizationTokenType.PrimaryMasterKey); - request.properties = getProperties(options); - return request; - } - - /** - * Creates a DocumentServiceRequest with a query. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param query the query. - * @param headers the request headers. - * @param authorizationTokenType the request authorizationTokenType. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - String query, - Map headers, - AuthorizationTokenType authorizationTokenType) { - return new RxDocumentServiceRequest(operation, resourceType, relativePath, - query.getBytes(StandardCharsets.UTF_8), headers, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest with a query. - * - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param querySpec the query. - * @param queryCompatibilityMode the QueryCompatibilityMode mode. - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(ResourceType resourceType, - String relativePath, - SqlQuerySpec querySpec, - QueryCompatibilityMode queryCompatibilityMode, - Map headers) { - OperationType operation; - String queryText; - switch (queryCompatibilityMode) { - case SqlQuery: - if (querySpec.getParameters() != null && querySpec.getParameters().size() > 0) { - throw new IllegalArgumentException( - String.format("Unsupported argument in query compatibility mode '{%s}'", - queryCompatibilityMode.name())); - } - - operation = OperationType.SqlQuery; - queryText = querySpec.getQueryText(); - break; - - case Default: - case Query: - default: - operation = OperationType.Query; - queryText = querySpec.toJson(); - break; - } - - Observable body = StringObservable.encode(Observable.just(queryText), StandardCharsets.UTF_8); - return new RxDocumentServiceRequest(operation, resourceType, relativePath, body, headers, AuthorizationTokenType.PrimaryMasterKey); - } - - /** - * Creates a DocumentServiceRequest without body. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - Map headers) { - return RxDocumentServiceRequest.create(operation, resourceType, relativePath, headers, (RequestOptions)null); - } - - /** - * Creates a DocumentServiceRequest without body. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param headers the request headers. - * @param options the request/feed/changeFeed options. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - Map headers, - Object options) { - RxDocumentServiceRequest request = new RxDocumentServiceRequest(operation, resourceType, relativePath, headers, AuthorizationTokenType.PrimaryMasterKey); - request.properties = getProperties(options); - return request; - } - - /** - * Creates a DocumentServiceRequest without body. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param headers the request headers. - * @param authorizationTokenType the request authorizationTokenType. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType, - String relativePath, - Map headers, - AuthorizationTokenType authorizationTokenType) { - return new RxDocumentServiceRequest(operation, resourceType, relativePath, headers, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest without body. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - Resource resource, - ResourceType resourceType, - String relativePath, - Map headers) { - byte[] resourceContent = resource.toJson().getBytes(StandardCharsets.UTF_8); - return new RxDocumentServiceRequest(operation, resourceType, relativePath, resourceContent, headers, AuthorizationTokenType.PrimaryMasterKey); - } - - /** - * Creates a DocumentServiceRequest without body. - * - * @param operation the operation type. - * @param resourceType the resource type. - * @param relativePath the relative URI path. - * @param headers the request headers. - * @param authorizationTokenType the request authorizationTokenType. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - Resource resource, - ResourceType resourceType, - String relativePath, - Map headers, - AuthorizationTokenType authorizationTokenType) { - byte[] resourceContent = resource.toJson().getBytes(StandardCharsets.UTF_8); - return new RxDocumentServiceRequest(operation, resourceType, relativePath, resourceContent, headers, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest with a resourceId. - * - * @param operation the operation type. - * @param resourceId the resource id. - * @param resourceType the resource type. - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - String resourceId, - ResourceType resourceType, - Map headers) { - return new RxDocumentServiceRequest(operation, resourceId,resourceType, null, headers, false, AuthorizationTokenType.PrimaryMasterKey) ; - } - - /** - * Creates a DocumentServiceRequest with a resourceId. - * - * @param operation the operation type. - * @param resourceId the resource id. - * @param resourceType the resource type. - * @param headers the request headers. - * @param authorizationTokenType the request authorizationTokenType. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - String resourceId, - ResourceType resourceType, - Map headers, - AuthorizationTokenType authorizationTokenType) { - return new RxDocumentServiceRequest(operation, resourceId, resourceType, null, headers, false, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest with a resourceId. - * - * @param operation the operation type. - * @param resourceId the resource id. - * @param resourceType the resource type. - * @param headers the request headers. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - String resourceId, - ResourceType resourceType, - Resource resource, - Map headers) { - byte[] resourceContent = resource.toJson().getBytes(StandardCharsets.UTF_8); - return new RxDocumentServiceRequest(operation, resourceId, resourceType, resourceContent, headers, false, AuthorizationTokenType.PrimaryMasterKey); - } - - /** - * Creates a DocumentServiceRequest with a resourceId. - * - * @param operation the operation type. - * @param resourceId the resource id. - * @param resourceType the resource type. - * @param headers the request headers. - * @param authorizationTokenType the request authorizationTokenType. - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - String resourceId, - ResourceType resourceType, - Resource resource, - Map headers, - AuthorizationTokenType authorizationTokenType) { - byte[] resourceContent = resource.toJson().getBytes(StandardCharsets.UTF_8); - return new RxDocumentServiceRequest(operation, resourceId, resourceType, resourceContent, headers, false, authorizationTokenType); - } - - /** - * Creates a DocumentServiceRequest with operationType and resourceType - * @param operation the operation type - * @param resourceType the resource type - * @return the created document service request. - */ - public static RxDocumentServiceRequest create(OperationType operation, - ResourceType resourceType) { - return new RxDocumentServiceRequest(operation, null, resourceType, null, null); - } - - public static RxDocumentServiceRequest createFromName( - OperationType operationType, - String resourceFullName, - ResourceType resourceType) { - return new RxDocumentServiceRequest(operationType, - resourceFullName, - resourceType, - null, - new HashMap<>(), - true, - AuthorizationTokenType.PrimaryMasterKey - ); - } - - public static RxDocumentServiceRequest createFromName( - OperationType operationType, - String resourceFullName, - ResourceType resourceType, - AuthorizationTokenType authorizationTokenType) { - return new RxDocumentServiceRequest(operationType, - resourceFullName, - resourceType, - null, - new HashMap<>(), - true, - authorizationTokenType - ); - } - - public static RxDocumentServiceRequest createFromName( - OperationType operationType, - Resource resource, - String resourceFullName, - ResourceType resourceType) { - byte[] resourceContent = resource.toJson().getBytes(StandardCharsets.UTF_8); - return new RxDocumentServiceRequest(operationType, - resourceFullName, - resourceType, - resourceContent, - new HashMap<>(), - true, - AuthorizationTokenType.PrimaryMasterKey - ); - } - - public static RxDocumentServiceRequest createFromName( - OperationType operationType, - Resource resource, - String resourceFullName, - ResourceType resourceType, - AuthorizationTokenType authorizationTokenType) { - byte[] resourceContent = resource.toJson().getBytes(StandardCharsets.UTF_8); - return new RxDocumentServiceRequest(operationType, - resourceFullName, - resourceType, - resourceContent, - new HashMap<>(), - true, - authorizationTokenType - ); - } - - private static String extractIdFromUri(String path) { - if (path.length() == 0) { - return path; - } - - if (path.charAt(path.length() - 1) != '/') { - path = path + '/'; - } - - if (path.charAt(0) != '/') { - path = '/' + path; - } - // This is a hack. We need a padding '=' so that path.split("/") - // returns even number of string pieces. - // TODO(pushi): Improve the code and remove the hack. - path = path + '='; - - // The path will be in the form of - // /[resourceType]/[resourceId]/ or - // /[resourceType]/[resourceId]/[resourceType]/ - // The result of split will be in the form of - // [[[resourceType], [resourceId] ... ,[resourceType], ""] - // In the first case, to extract the resourceId it will the element - // before last ( at length -2 ) and the type will before it - // ( at length -3 ) - // In the second case, to extract the resource type it will the element - // before last ( at length -2 ) - String[] pathParts = StringUtils.split(path, "/"); - if (pathParts.length % 2 == 0) { - // request in form /[resourceType]/[resourceId]/. - return pathParts[pathParts.length - 2]; - } else { - // request in form /[resourceType]/[resourceId]/[resourceType]/. - return pathParts[pathParts.length - 3]; - } - } - - static String getAttachmentIdFromMediaId(String mediaId) { - // '/' was replaced with '-'. - byte[] buffer = Utils.Base64Decoder.decode(mediaId.replace('-', '/').getBytes()); - - final int resoureIdLength = 20; - String attachmentId; - - if (buffer.length > resoureIdLength) { - // We are cuting off the storage index. - byte[] newBuffer = new byte[resoureIdLength]; - System.arraycopy(buffer, 0, newBuffer, 0, resoureIdLength); - attachmentId = Utils.encodeBase64String(newBuffer).replace('/', '-'); - } else { - attachmentId = mediaId; - } - - return attachmentId; - } - - /** - * Gets the resource id. - * - * @return the resource id. - */ - public String getResourceId() { - return this.resourceId; - } - - /** - * Sets the resource id. - * - */ - public void setResourceId(String resourceId) { - this.resourceId = resourceId; - } - - /** - * Gets the resource type. - * - * @return the resource type. - */ - public ResourceType getResourceType() { - return this.resourceType; - } - - /** - * Gets the request headers. - * - * @return the request headers. - */ - public Map getHeaders() { - return this.headers; - } - - /** - * Gets the continuation. - * - * @return the continuation. - */ - public String getContinuation() { - return this.continuation; - } - - public void setContinuation(String continuation) { - this.continuation = continuation; - } - - public boolean getIsMedia() { - return this.isMedia; - } - - public void setIsMedia(boolean isMedia) { - this.isMedia = isMedia; - } - - public boolean getIsNameBased() { - return this.isNameBased; - } - - public OperationType getOperationType() { - return this.operationType; - } - - public String getResourceAddress() { - return resourceAddress; - } - - public boolean isForceNameCacheRefresh() { - return forceNameCacheRefresh; - } - - public void setForceNameCacheRefresh(boolean forceNameCacheRefresh) { - this.forceNameCacheRefresh = forceNameCacheRefresh; - } - - public URI getEndpointOverride() { - return this.endpointOverride; - } - - public void setEndpointOverride(URI endpointOverride) { - this.endpointOverride = endpointOverride; - } - - public String getActivityId() { - return this.activityId; - } - - public PartitionKeyRangeIdentity getPartitionKeyRangeIdentity() { - return partitionKeyRangeIdentity; - } - - public void routeTo(PartitionKeyRangeIdentity partitionKeyRangeIdentity) { - this.setPartitionKeyRangeIdentity(partitionKeyRangeIdentity); - } - - public void setPartitionKeyRangeIdentity(PartitionKeyRangeIdentity partitionKeyRangeIdentity) { - this.partitionKeyRangeIdentity = partitionKeyRangeIdentity; - if (partitionKeyRangeIdentity != null) { - this.headers.put(HttpConstants.HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeIdentity.toHeader()); - } else { - this.headers.remove(HttpConstants.HttpHeaders.PARTITION_KEY_RANGE_ID); - } - } - - public String getOriginalSessionToken() { - return originalSessionToken; - } - - public void setOriginalSessionToken(String originalSessionToken) { - this.originalSessionToken = originalSessionToken; - } - - public void setDefaultReplicaIndex(Integer defaultReplicaIndex) { - this.defaultReplicaIndex = defaultReplicaIndex; - } - - public Integer getDefaultReplicaIndex() { - return defaultReplicaIndex; - } - - public boolean isChangeFeedRequest() { - return this.headers.containsKey(HttpConstants.HttpHeaders.A_IM); - } - - public boolean isWritingToMaster() { - return operationType.isWriteOperation() && resourceType.isMasterResource(); - } - - public boolean isReadingFromMaster() { - if (resourceType == ResourceType.Offer || - resourceType == ResourceType.Database || - resourceType == ResourceType.User || - resourceType == ResourceType.Permission || - resourceType == ResourceType.Topology || - resourceType == ResourceType.DatabaseAccount || - resourceType == ResourceType.PartitionKeyRange || - (resourceType == ResourceType.DocumentCollection - && (operationType == OperationType.ReadFeed - || operationType == OperationType.Query - || operationType == OperationType.SqlQuery))) { - return true; - } - return false; - } - - public boolean isValidAddress(ResourceType resourceType) { - ResourceType resourceTypeToValidate = ResourceType.Unknown; - - if(resourceType != ResourceType.Unknown) { - resourceTypeToValidate = resourceType; - } else { - if(!this.isFeed) { - resourceTypeToValidate =this.resourceType; - } else { - if(this.resourceType == ResourceType.Database) { - return true; - } else if(this.resourceType == ResourceType.DocumentCollection || - this.resourceType == ResourceType.User) { - resourceTypeToValidate = ResourceType.Database; - } else if(this.resourceType == ResourceType.Permission) { - resourceTypeToValidate = ResourceType.User; - } else if(this.resourceType == ResourceType.Document || - this.resourceType == ResourceType.StoredProcedure || - this.resourceType == ResourceType.UserDefinedFunction || - this.resourceType == ResourceType.Trigger || - this.resourceType == ResourceType.Conflict || - this.resourceType == ResourceType.PartitionKeyRange) { - resourceTypeToValidate = ResourceType.DocumentCollection; - } else if(this.resourceType == ResourceType.Attachment) { - resourceTypeToValidate = ResourceType.Document; - } else { - return false; - } - } - } - - if (this.isNameBased) { - return PathsHelper.validateResourceFullName(resourceType != ResourceType.Unknown ? resourceType : resourceTypeToValidate, this.resourceAddress); - } else { - return PathsHelper.validateResourceId(resourceTypeToValidate, this.resourceId); - } - } - - public void addPreferHeader(String preferHeaderName, String preferHeaderValue) { - String headerToAdd = String.format(PREFER_HEADER_VALUE_FORMAT, preferHeaderName, preferHeaderValue); - String preferHeader = this.headers.get(HttpConstants.HttpHeaders.PREFER); - if(StringUtils.isNotEmpty(preferHeader)) { - preferHeader += PREFER_HEADER_SEPERATOR + headerToAdd; - } else { - preferHeader = headerToAdd; - } - this.headers.put(HttpConstants.HttpHeaders.PREFER, preferHeader); - } - - public static RxDocumentServiceRequest CreateFromResource(RxDocumentServiceRequest request, Resource modifiedResource) { - RxDocumentServiceRequest modifiedRequest; - if (!request.getIsNameBased()) { - modifiedRequest = RxDocumentServiceRequest.create(request.getOperationType(), - request.getResourceId(), - request.getResourceType(), - modifiedResource, - request.headers); - } else { - modifiedRequest = RxDocumentServiceRequest.createFromName(request.getOperationType(), - modifiedResource, - request.getResourceAddress(), - request.getResourceType()); - } - return modifiedRequest; - } - - public void clearRoutingHints() { - this.partitionKeyRangeIdentity = null; - this.requestContext.resolvedPartitionKeyRange = null; - } - - public Observable getContentObservable() { - return contentObservable; - } - - public byte[] getContent() { - return byteContent; - } - - public RxDocumentServiceRequest clone() { - RxDocumentServiceRequest rxDocumentServiceRequest = RxDocumentServiceRequest.create(this.getOperationType(), this.resourceId,this.getResourceType(),this.getHeaders()); - rxDocumentServiceRequest.setContentBytes(this.getContent()); - rxDocumentServiceRequest.setContinuation(this.getContinuation()); - rxDocumentServiceRequest.setDefaultReplicaIndex(this.getDefaultReplicaIndex()); - rxDocumentServiceRequest.setEndpointOverride(this.getEndpointOverride()); - rxDocumentServiceRequest.setForceNameCacheRefresh(this.isForceNameCacheRefresh()); - rxDocumentServiceRequest.setIsMedia(this.getIsMedia()); - rxDocumentServiceRequest.setOriginalSessionToken(this.getOriginalSessionToken()); - rxDocumentServiceRequest.setPartitionKeyRangeIdentity(this.getPartitionKeyRangeIdentity()); - rxDocumentServiceRequest.contentObservable = this.getContentObservable(); - rxDocumentServiceRequest.forceCollectionRoutingMapRefresh = this.forceCollectionRoutingMapRefresh; - rxDocumentServiceRequest.forcePartitionKeyRangeRefresh = this.forcePartitionKeyRangeRefresh; - rxDocumentServiceRequest.UseGatewayMode = this.UseGatewayMode; - rxDocumentServiceRequest.queryString = this.queryString; - rxDocumentServiceRequest.requestContext = this.requestContext; - return rxDocumentServiceRequest; - } - - public void Dispose() { - if (this.isDisposed) { - return; - } - - if (this.byteContent != null) { - this.byteContent = null; - } - - this.isDisposed = true; - } - - private static Map getProperties(Object options) { - if (options == null) { - return null; - } else if (options instanceof RequestOptions) { - return ((RequestOptions) options).getProperties(); - } else if (options instanceof FeedOptionsBase) { - return ((FeedOptionsBase) options).getProperties(); - } else { - return null; - } - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentServiceResponse.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentServiceResponse.java deleted file mode 100644 index 0cc618257ab5..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentServiceResponse.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.Conflict; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Address; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import org.apache.commons.lang3.StringUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * This is core Transport/Connection agnostic response for the Azure Cosmos DB database service. - */ -public class RxDocumentServiceResponse { - private final int statusCode; - private final Map headersMap; - private final StoreResponse storeResponse; - - public RxDocumentServiceResponse(StoreResponse response) { - String[] headerNames = response.getResponseHeaderNames(); - String[] headerValues = response.getResponseHeaderValues(); - - this.headersMap = new HashMap<>(headerNames.length); - - // Gets status code. - this.statusCode = response.getStatus(); - - // Extracts headers. - for (int i = 0; i < headerNames.length; i++) { - this.headersMap.put(headerNames[i], headerValues[i]); - } - - this.storeResponse = response; - } - - public static String getResourceKey(Class c) { - if (c.equals(Attachment.class)) { - return InternalConstants.ResourceKeys.ATTACHMENTS; - } else if (c.equals(Conflict.class)) { - return InternalConstants.ResourceKeys.CONFLICTS; - } else if (c.equals(Database.class)) { - return InternalConstants.ResourceKeys.DATABASES; - } else if (Document.class.isAssignableFrom(c)) { - return InternalConstants.ResourceKeys.DOCUMENTS; - } else if (c.equals(DocumentCollection.class)) { - return InternalConstants.ResourceKeys.DOCUMENT_COLLECTIONS; - } else if (c.equals(Offer.class)) { - return InternalConstants.ResourceKeys.OFFERS; - } else if (c.equals(Permission.class)) { - return InternalConstants.ResourceKeys.PERMISSIONS; - } else if (c.equals(Trigger.class)) { - return InternalConstants.ResourceKeys.TRIGGERS; - } else if (c.equals(StoredProcedure.class)) { - return InternalConstants.ResourceKeys.STOREDPROCEDURES; - } else if (c.equals(User.class)) { - return InternalConstants.ResourceKeys.USERS; - } else if (c.equals(UserDefinedFunction.class)) { - return InternalConstants.ResourceKeys.USER_DEFINED_FUNCTIONS; - } else if (c.equals(Address.class)) { - return InternalConstants.ResourceKeys.ADDRESSES; - } else if (c.equals(PartitionKeyRange.class)) { - return InternalConstants.ResourceKeys.PARTITION_KEY_RANGES; - } - - throw new IllegalArgumentException("c"); - } - - public int getStatusCode() { - return this.statusCode; - } - - public Map getResponseHeaders() { - return this.headersMap; - } - - public String getReponseBodyAsString() { - return this.storeResponse.getResponseBody(); - } - - public T getResource(Class c) { - String responseBody = this.getReponseBodyAsString(); - if (StringUtils.isEmpty(responseBody)) - return null; - - T resource = null; - try { - resource = c.getConstructor(String.class).newInstance(responseBody); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to instantiate class object.", e); - } - if(PathsHelper.isPublicResource(resource)) { - BridgeInternal.setAltLink(resource, PathsHelper.generatePathForNameBased(resource, this.getOwnerFullName(),resource.getId())); - } - - return resource; - } - - public List getQueryResponse(Class c) { - String responseBody = this.getReponseBodyAsString(); - if (responseBody == null) { - return new ArrayList(); - } - - JsonNode jobject = fromJson(responseBody); - String resourceKey = RxDocumentServiceResponse.getResourceKey(c); - ArrayNode jTokenArray = (ArrayNode) jobject.get(resourceKey); - - // Aggregate queries may return a nested array - ArrayNode innerArray; - while (jTokenArray != null && jTokenArray.size() == 1 && (innerArray = toArrayNode(jTokenArray.get(0))) != null) { - jTokenArray = innerArray; - } - - List queryResults = new ArrayList(); - - if (jTokenArray != null) { - for (int i = 0; i < jTokenArray.size(); ++i) { - JsonNode jToken = jTokenArray.get(i); - // Aggregate on single partition collection may return the aggregated value only - // In that case it needs to encapsulated in a special document - String resourceJson = jToken.isNumber() || jToken.isBoolean() - ? String.format("{\"%s\": %s}", Constants.Properties.AGGREGATE, jToken.asText()) - : toJson(jToken); - T resource = null; - try { - resource = c.getConstructor(String.class).newInstance(resourceJson); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to instantiate class object.", e); - } - - queryResults.add(resource); - } - } - - return queryResults; - } - - private ArrayNode toArrayNode(JsonNode n) { - if (n.isArray()) { - return (ArrayNode) n; - } else { - return null; - } - } - - private static JsonNode fromJson(String json){ - try { - return Utils.getSimpleObjectMapper().readTree(json); - } catch (IOException e) { - throw new IllegalStateException(String.format("Unable to parse JSON %s", json), e); - } - } - - private static String toJson(Object object){ - try { - return Utils.getSimpleObjectMapper().writeValueAsString(object); - } catch (JsonProcessingException e) { - throw new IllegalStateException("Can't serialize the object into the json string", e); - } - } - - private String getOwnerFullName() { - if (this.headersMap != null) { - return this.headersMap.get(HttpConstants.HttpHeaders.OWNER_FULL_NAME); - } - return null; - } - - public InputStream getContentStream() { - return this.storeResponse.getResponseStream(); - } - - public ClientSideRequestStatistics getClientSideRequestStatistics() { - if (this.storeResponse == null) { - return null; - } - return this.storeResponse.getClientSideRequestStatistics(); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Strings.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Strings.java deleted file mode 100644 index 468872ac4319..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Strings.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import org.apache.commons.lang3.StringUtils; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class Strings { - public static final String Emtpy = ""; - - public static boolean isNullOrWhiteSpace(String str) { - return StringUtils.isEmpty(str) || StringUtils.isWhitespace(str); - } - public static boolean isNullOrEmpty(String str) { - return StringUtils.isEmpty(str); - } - - public static String toString(boolean value) { - return Boolean.toString(value); - } - - public static String toString(int value) { - return Integer.toString(value); - } - - public static boolean areEqual(String str1, String str2) { - return StringUtils.equals(str1, str2); - } - - public static boolean areEqualIgnoreCase(String str1, String str2) { - return StringUtils.equalsIgnoreCase(str1, str2); - } - - public static boolean containsIgnoreCase(String str1, String str2) { - return StringUtils.containsIgnoreCase(str1, str2); - } - - public static int compare(String str1, String str2) { - return StringUtils.compare(str1, str2); - } - - public static String toCamelCase(String str) { - if (isNullOrEmpty(str)) { - return str; - } - - return str.substring(0, 1).toUpperCase() + str.substring(1, str.length()).toLowerCase(); - } -} diff --git a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Utils.java b/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Utils.java deleted file mode 100644 index 118aa91d3f0b..000000000000 --- a/cosmosdb/data-plane/commons/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/Utils.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class Utils { - - public static int getValueOrDefault(Integer val, int defaultValue) { - return val != null ? val.intValue() : defaultValue; - } - - public static void checkStateOrThrow(boolean value, String argumentName, String message) throws IllegalArgumentException { - - IllegalArgumentException t = checkStateOrReturnException(value, argumentName, message); - if (t != null) { - throw t; - } - } - - public static void checkNotNullOrThrow(Object val, String argumentName, String message) throws NullPointerException { - - NullPointerException t = checkNotNullOrReturnException(val, argumentName, message); - if (t != null) { - throw t; - } - } - - public static void checkStateOrThrow(boolean value, String argumentName, String messageTemplate, Object... messageTemplateParams) throws IllegalArgumentException { - IllegalArgumentException t = checkStateOrReturnException(value, argumentName, argumentName, messageTemplateParams); - if (t != null) { - throw t; - } - } - - public static IllegalArgumentException checkStateOrReturnException(boolean value, String argumentName, String message) { - - if (value) { - return null; - } - - return new IllegalArgumentException(String.format("argumentName: %s, message: %s", argumentName, message)); - } - - public static IllegalArgumentException checkStateOrReturnException(boolean value, String argumentName, String messageTemplate, Object... messageTemplateParams) { - if (value) { - return null; - } - - return new IllegalArgumentException(String.format("argumentName: %s, message: %s", argumentName, String.format(messageTemplate, messageTemplateParams))); - } - - private static NullPointerException checkNotNullOrReturnException(Object val, String argumentName, String messageTemplate, Object... messageTemplateParams) { - if (val != null) { - return null; - } - - return new NullPointerException(String.format("argumentName: %s, message: %s", argumentName, String.format(messageTemplate, messageTemplateParams))); - } - - public static BadRequestException checkRequestOrReturnException(boolean value, String argumentName, String message) { - - if (value) { - return null; - } - - return new BadRequestException(String.format("argumentName: %s, message: %s", argumentName, message)); - } - - public static BadRequestException checkRequestOrReturnException(boolean value, String argumentName, String messageTemplate, Object... messageTemplateParams) { - if (value) { - return null; - } - - return new BadRequestException(String.format("argumentName: %s, message: %s", argumentName, String.format(messageTemplate, messageTemplateParams))); - } - - @SuppressWarnings("unchecked") - public static O as(I i, Class klass) { - if (i == null) { - return null; - } - - if (klass.isInstance(i)) { - return (O) i; - } else { - return null; - } - } - - @SuppressWarnings("unchecked") - public static List immutableListOf() { - return Collections.EMPTY_LIST; - } - - public static List immutableListOf(V v1) { - List list = new ArrayList<>(); - list.add(v1); - return Collections.unmodifiableList(list); - } - - public static MapimmutableMapOf() { - return Collections.emptyMap(); - } - - public static MapimmutableMapOf(K k1, V v1) { - Map map = new HashMap(); - map.put(k1, v1); - map = Collections.unmodifiableMap(map); - return map; - } - - public static V firstOrDefault(List list) { - return list.size() > 0? list.get(0) : null ; - } - - public static class ValueHolder { - - public ValueHolder() { - } - - public ValueHolder(V v) { - this.v = v; - } - public V v; - - public static ValueHolder initialize(T v) { - return new ValueHolder(v); - } - } - - public static boolean tryGetValue(Map dictionary, K key, ValueHolder holder) { - // doesn't work for dictionary with null value - holder.v = dictionary.get(key); - return holder.v != null; - } - - public static boolean tryRemove(Map dictionary, K key, ValueHolder holder) { - // doesn't work for dictionary with null value - holder.v = dictionary.remove(key); - return holder.v != null; - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ConflictTests.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ConflictTests.java deleted file mode 100644 index 9139d319d52e..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ConflictTests.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import org.apache.commons.io.IOUtils; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConflictTests { - private String conflictAsString; - - @BeforeClass(groups = { "unit" }) - public void setup() throws Exception { - conflictAsString = IOUtils.toString( - getClass().getClassLoader().getResourceAsStream("sampleConflict.json"), "UTF-8"); - } - - @Test(groups = { "unit" }) - public void getSourceResourceId() { - Conflict conf = new Conflict(conflictAsString); - assertThat(conf.getSourceResourceId()).isEqualTo("k6d9ALgBmD+ChB4AAAAAAA=="); - } - - @Test(groups = { "unit" }) - public void getOperationKind() { - Conflict conf = new Conflict(conflictAsString); - assertThat(conf.getOperationKind()).isEqualTo("create"); - conf.getSourceResourceId(); - } - - @Test(groups = { "unit" }) - public void getResourceType() { - Conflict conf = new Conflict(conflictAsString); - assertThat(conf.getResouceType()).isEqualTo("document"); - conf.getSourceResourceId(); - } - - @Test(groups = { "unit" }) - public void getResource() { - Conflict conf = new Conflict(conflictAsString); - Document doc = conf.getResource(Document.class); - assertThat(doc.getId()).isEqualTo("0007312a-a1c5-4b54-9e39-35de2367fa33"); - assertThat(doc.getInt("regionId")).isEqualTo(2); - assertThat(doc.getResourceId()).isEqualTo("k6d9ALgBmD+ChB4AAAAAAA=="); - assertThat(doc.getETag()).isEqualTo("\"00000200-0000-0000-0000-5b6e214b0000\""); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ConnectionPolicyTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ConnectionPolicyTest.java deleted file mode 100644 index 5b4d34817b6a..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ConnectionPolicyTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConnectionPolicyTest { - - @DataProvider(name = "connectionModeArgProvider") - public Object[][] connectionModeArgProvider() { - return new Object[][]{ - { ConnectionMode.Gateway }, - { ConnectionMode.Direct }, - }; - } - - @Test(groups = { "unit" }, dataProvider = "connectionModeArgProvider") - public void connectionMode(ConnectionMode connectionMode) { - ConnectionPolicy policy = new ConnectionPolicy(); - policy.setConnectionMode(connectionMode); - - assertThat(policy.getConnectionMode()).isEqualTo(connectionMode); - } - - @DataProvider(name = "connectionProtocolModeArgProvider") - public Object[][] connectionProtocolModeArgProvider() { - return new Object[][]{ - { Protocol.Https }, - { Protocol.Tcp }, - }; - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentClientExceptionTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentClientExceptionTest.java deleted file mode 100644 index ddf535c3c577..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentClientExceptionTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.google.common.collect.ImmutableMap; -import org.testng.annotations.Test; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DocumentClientExceptionTest { - - @Test(groups = { "unit" }) - public void headerNotNull1() { - DocumentClientException dce = new DocumentClientException(0); - assertThat(dce.getResponseHeaders()).isNotNull(); - assertThat(dce.getResponseHeaders()).isEmpty(); - } - - @Test(groups = { "unit" }) - public void headerNotNull2() { - DocumentClientException dce = new DocumentClientException(0, "dummy"); - assertThat(dce.getResponseHeaders()).isNotNull(); - assertThat(dce.getResponseHeaders()).isEmpty(); - } - - @Test(groups = { "unit" }) - public void headerNotNull3() { - DocumentClientException dce = new DocumentClientException(0, new RuntimeException()); - assertThat(dce.getResponseHeaders()).isNotNull(); - assertThat(dce.getResponseHeaders()).isEmpty(); - } - - @Test(groups = { "unit" }) - public void headerNotNull4() { - DocumentClientException dce = new DocumentClientException(0, (Error) null, (Map) null); - assertThat(dce.getResponseHeaders()).isNotNull(); - assertThat(dce.getResponseHeaders()).isEmpty(); - } - - @Test(groups = { "unit" }) - public void headerNotNull5() { - DocumentClientException dce = new DocumentClientException((String) null, 0, (Error) null, (Map) null); - assertThat(dce.getResponseHeaders()).isNotNull(); - assertThat(dce.getResponseHeaders()).isEmpty(); - } - - @Test(groups = { "unit" }) - public void headerNotNull6() { - DocumentClientException dce = new DocumentClientException((String) null, (Exception) null, (Map) null, 0, (String) null); - assertThat(dce.getResponseHeaders()).isNotNull(); - assertThat(dce.getResponseHeaders()).isEmpty(); - } - - @Test(groups = { "unit" }) - public void headerNotNull7() { - ImmutableMap respHeaders = ImmutableMap.of("key", "value"); - DocumentClientException dce = new DocumentClientException((String) null, (Exception) null, respHeaders, 0, (String) null); - assertThat(dce.getResponseHeaders()).isNotNull(); - assertThat(dce.getResponseHeaders()).contains(respHeaders.entrySet().iterator().next()); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentCollectionTests.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentCollectionTests.java deleted file mode 100644 index 2e11ed6134e1..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentCollectionTests.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.google.common.collect.ImmutableList; -import org.testng.annotations.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DocumentCollectionTests { - - @Test(groups = { "unit" }) - public void getPartitionKey() { - DocumentCollection collection = new DocumentCollection(); - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - partitionKeyDefinition.setPaths(ImmutableList.of("/mypk")); - collection.setPartitionKey(partitionKeyDefinition); - assertThat(collection.getPartitionKey()).isEqualTo(partitionKeyDefinition); - } - - @Test(groups = { "unit" }) - public void getPartitionKey_serializeAndDeserialize() { - DocumentCollection collection = new DocumentCollection(); - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - partitionKeyDefinition.setPaths(ImmutableList.of("/mypk")); - partitionKeyDefinition.setVersion(PartitionKeyDefinitionVersion.V2); - collection.setPartitionKey(partitionKeyDefinition); - - DocumentCollection parsedColl = new DocumentCollection(collection.toJson()); - assertThat(parsedColl.getPartitionKey().getKind().toString()).isEqualTo(partitionKeyDefinition.getKind().toString()); - assertThat(parsedColl.getPartitionKey().getPaths()).isEqualTo(partitionKeyDefinition.getPaths()); - assertThat(parsedColl.getPartitionKey().getVersion()).isEqualTo(partitionKeyDefinition.getVersion()); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentTests.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentTests.java deleted file mode 100644 index d3777240f00f..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/DocumentTests.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Date; - -import org.testng.annotations.Test; - -public class DocumentTests { - - @Test(groups = { "unit" }) - public void timestamp() { - Document d = new Document(); - Date time = new Date(86400 * 1000); - d.setTimestamp(time); - assertThat(d.getTimestamp()).isEqualTo(time); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/IncludedPathTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/IncludedPathTest.java deleted file mode 100644 index 663c2834c206..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/IncludedPathTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Collection; - -import org.testng.annotations.Test; - -public class IncludedPathTest { - - @Test(groups = {"unit"}) - public void deserialize() { - String json = "{" + - " 'path': '\\/*'," + - " 'indexes': [" + - " {" + - " 'kind': 'Range'," + - " 'dataType': 'String'," + - " 'precision': -1" + - " }," + - " {" + - " 'kind': 'Range'," + - " 'dataType': 'Number'," + - " 'precision': -1" + - " }" + - " ]" + - "}"; - IncludedPath path = new IncludedPath(json); - Collection indexes = path.getIndexes(); - assertThat(indexes).hasSize(2); - assertThat(indexes).usingFieldByFieldElementComparator().contains(Index.Range(DataType.String, -1)); - assertThat(indexes).usingFieldByFieldElementComparator().contains(Index.Range(DataType.Number, -1)); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/JsonSerializableTests.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/JsonSerializableTests.java deleted file mode 100644 index ca5c4b4af07e..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/JsonSerializableTests.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.microsoft.azure.cosmosdb; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.fail; - -import java.io.Serializable; - -import org.testng.annotations.Test; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParseException; - -public class JsonSerializableTests { - - public static class Pojo implements Serializable { - int a; - int b; - - public Pojo(int a, int b) { - this.a = a; - this.b = b; - } - - @JsonCreator - public Pojo(@JsonProperty("a") String a, @JsonProperty("b") String b) { - this.a = Integer.parseInt(a); - this.b = Integer.parseInt(b); - } - - public int getA() { - return a; - } - - public int getB() { - return b; - } - - public void setA(int a) { - this.a = a; - } - - public void setB(int b) { - this.b = b; - } - - } - - public enum enums { - first, second, third - } - - @Test(groups = { "unit" }) - public void getObjectAndCastToClass() { - Document document = new Document(); - // numeric values - document.set("intValue", Integer.MAX_VALUE); - document.set("doubleValue", Double.MAX_VALUE); - document.set("longValue", Long.MAX_VALUE); - - assertThat(document.getObject("intValue", Integer.class).intValue()).isEqualTo(Integer.MAX_VALUE); - assertThat(document.getObject("doubleValue", Double.class).doubleValue()).isEqualTo(Double.MAX_VALUE); - assertThat(document.getObject("longValue", Long.class).longValue()).isEqualTo(Long.MAX_VALUE); - - // string - document.set("stringValue", "stringField"); - assertThat(document.getObject("stringValue", String.class)).isEqualTo("stringField"); - - // boolean - document.set("boolValue", true); - assertThat(document.getObject("boolValue", Boolean.class)).isEqualTo(true); - - // enum - document.set("enumValue", "third"); - assertThat(document.getObject("enumValue", enums.class)).isEqualTo(enums.third); - - // Pojo - Pojo pojo = new Pojo(1, 2); - document.set("pojoValue", pojo); - Pojo readPojo = document.getObject("pojoValue", Pojo.class); - assertThat(readPojo.getA()).isEqualTo(pojo.getA()); - assertThat(readPojo.getB()).isEqualTo(pojo.getB()); - - // JsonSerializable - Document innerDocument = new Document(); - innerDocument.setId("innerDocument"); - document.set("innerDocument", innerDocument); - Document readInnerDocument = document.getObject("innerDocument", Document.class); - assertThat(readInnerDocument.getId()).isEqualTo(innerDocument.getId()); - } - - @Test(groups = { "unit" }) - public void objectMapperInvalidJsonNoQuotesForFieldAndValue() { - // Invalid Json - field and value must be quoted - try { - new Document("{ field: value }"); - fail("failure expected"); - } catch (Exception e) { - assertThat(e.getCause() instanceof JsonParseException).isTrue(); - } - } - - @Test(groups = { "unit" }) - public void objectMapperInvalidJsonNoQuotesForField() { - // Invalid Json - field must be quoted - try { - new Document("{ field: 'value' }"); - fail("failure expected"); - } catch (Exception e) { - assertThat(e.getCause() instanceof JsonParseException).isTrue(); - } - } - - @Test(groups = { "unit" }) - public void objectMapperInvalidJsonNoDuplicatesAllowed() { - // Invalid Json - duplicates must not exist in Json string - try { - new Document("{ 'field': 'value1', 'field': 'value2' }"); - fail("failure expected"); - } catch (Exception e) { - assertThat(e.getCause() instanceof JsonParseException).isTrue(); - } - } - - @Test(groups = { "unit" }) - public void objectMapperValidJsonWithSingleQuotesAndTrailingComma() { - Document document = null; - - // Valid Json - Single quotes and trailing commas allowed in Json string - document = new Document("{ 'field1': 'value1', 'field2': 'value2', }"); - assertThat(document.toJson().equals("{\"field1\":\"value1\",\"field2\":\"value2\"}")).isEqualTo(true); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/PermissionTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/PermissionTest.java deleted file mode 100644 index 3a4f0edd2c6e..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/PermissionTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.testng.annotations.Test; - -public class PermissionTest { - - @Test(groups = {"unit"}) - public void deserialize() { - String json = "{" + - " 'id': 'a98eb026-b66b-4cec-8fb9-9b0e10ddab76'," + - " 'permissionMode': 'read'," + - " 'resource': 'dbs/AQAAAA==/colls/AQAAAJ0fgTc='," + - " 'resourcePartitionKey': ['/id']" + - "}"; - Permission p = new Permission(json); - assertThat(p.getResourcePartitionKey()).isEqualToComparingFieldByField(new PartitionKey("/id")); - assertThat(p.getPermissionMode()).isEqualTo(PermissionMode.Read); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ResourceIdTests.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ResourceIdTests.java deleted file mode 100644 index 62c514ac318c..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/ResourceIdTests.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; - -import org.apache.commons.lang3.tuple.Pair; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.internal.ResourceId; - -public class ResourceIdTests { - - @Test(groups = { "unit" }) - public void resourceIdTryParsing() { - HashMap cases = new HashMap<>(); - cases.put("testDb", false); - cases.put("db", false); - cases.put("cosmosdb", false); - cases.put("asosfactor", false); - - cases.put("f", false); - cases.put("fo", false); - cases.put("foo", false); - cases.put("foob", true); - cases.put("fooba", false); - cases.put("foobar", false); - cases.put("Zm8=", false); - cases.put("Zm9v", true); - cases.put("Zm9vYg==", true); - cases.put("Zm9vYmE=", false); - cases.put("Zm9vYmFy", false); - - // collection rid - cases.put("1-MxAPlgMgA=", true); - cases.put("nJRwAA==", true); - cases.put("MaZyAA==", true); - cases.put("-qpmAA==", true); - cases.put("wsIRAA==", true); - cases.put("GJwnAA==", true); - - // document rid - cases.put("ClZUAPp9+A0=", true); - - // offer rid - cases.put("-d8Hx", false); - - for (Map.Entry testCase : cases.entrySet()) { - Pair resourcePair = ResourceId.tryParse(testCase.getKey()); - assertThat( resourcePair.getKey()).as(String.format("ResourceId.tryParse failed for '%s'", testCase.getKey())).isEqualTo(testCase.getValue()); - } - } - - private static int randomNextIntForTest(Random rnd, Boolean positive) { - return rnd.nextInt(Integer.MAX_VALUE / 2) + (positive ? Integer.MAX_VALUE / 2 : - Integer.MAX_VALUE / 2); - } - - @Test(groups = { "unit" }) - public void resourceIdParsingRoundTrip() { - Random rnd = new Random(System.currentTimeMillis()); - - ResourceId dbRid = ResourceId.newDatabaseId(randomNextIntForTest(rnd, true)); - ResourceId parsedDbRid = ResourceId.parse(dbRid.toString()); - assertThat(parsedDbRid.getDatabase()).isEqualTo(dbRid.getDatabase()); - - ResourceId collRid = ResourceId.newDocumentCollectionId(dbRid.toString(), randomNextIntForTest(rnd, false)); - ResourceId parsedCollRid = ResourceId.parse(collRid.toString()); - assertThat(parsedCollRid.getDatabase()).isEqualTo(collRid.getDatabase()); - assertThat(parsedCollRid.getDocumentCollection()).isEqualTo(collRid.getDocumentCollection()); - - ResourceId userRid = ResourceId.newUserId(dbRid.toString(), randomNextIntForTest(rnd, true)); - ResourceId parsedUserRid = ResourceId.parse(userRid.toString()); - assertThat(parsedUserRid.getDatabase()).isEqualTo(userRid.getDatabase()); - assertThat(parsedUserRid.getUser()).isEqualTo(userRid.getUser()); - - ResourceId permissionRid = ResourceId.newPermissionId(userRid.toString(), randomNextIntForTest(rnd, false)); - ResourceId parsedPermissionRid = ResourceId.parse(permissionRid.toString()); - assertThat(parsedPermissionRid.getDatabase()).isEqualTo(permissionRid.getDatabase()); - assertThat(parsedPermissionRid.getUser()).isEqualTo(permissionRid.getUser()); - assertThat(parsedPermissionRid.getPermission()).isEqualTo(permissionRid.getPermission()); - - ResourceId attachmentRid = ResourceId.newAttachmentId("wsIRALoBhyQ9AAAAAAAACA==", randomNextIntForTest(rnd, true)); - ResourceId parsedAttachmentRid = ResourceId.parse(attachmentRid.toString()); - assertThat(parsedAttachmentRid.getDatabase()).isEqualTo(attachmentRid.getDatabase()); - assertThat(parsedAttachmentRid.getDocumentCollection()).isEqualTo(attachmentRid.getDocumentCollection()); - assertThat(parsedAttachmentRid.getDocument()).isEqualTo(attachmentRid.getDocument()); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/PathsHelperTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/PathsHelperTest.java deleted file mode 100644 index ee22d54ef190..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/PathsHelperTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.apache.commons.lang3.StringUtils; -import org.testng.annotations.Test; -import static org.assertj.core.api.Assertions.assertThat; - -public class PathsHelperTest { - - private static final String DATABASE_ID = "IXYFAA=="; - private static final String DATABASE_COLLECTION_ID = "IXYFAOHEBPM="; - private static final String DOCUMENT_ID = "IXYFAOHEBPMBAAAAAAAAAA=="; - private static final String ATTACHMENT_ID = "IXYFAOHEBPMBAAAAAAAAABJYSJk="; - private static final String PERMISSION_ID = "IXYFAE9ZOwBGkyqWIsNKAA=="; - private static final String STORED_PRCEDURE_ID = "IXYFAOHEBPMCAAAAAAAAgA=="; - private static final String TRIGGER_ID = "IXYFAOHEBPMCAAAAAAAAcA=="; - private static final String USER_DEFINED_FUNCTION_ID = "IXYFAOHEBPMBAAAAAAAAYA=="; - private static final String USER_ID = "IXYFAE9ZOwA="; - private static final String CONFLICT_ID = "k6d9ALgBmD8BAAAAAAAAQA=="; - - private static final String DATABASE_FULL_NAME = "dbs/IXYFAA==/"; - private static final String DOCUMENT_COLLECTION_FULL_NAME = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/"; - private static final String DOCUMENT_FULL_NAME = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/docs/IXYFAOHEBPMBAAAAAAAAAA==/"; - private static final String STORED_PRCEDURE_FULL_NAME = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/sprocs/IXYFAOHEBPMCAAAAAAAAgA==/"; - private static final String USER_DEFINED_FUNCTION_FULL_NAME = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/udfs/IXYFAOHEBPMBAAAAAAAAYA==/"; - private static final String USER_FULL_NAME = "dbs/IXYFAA==/users/IXYFAE9ZOwA=/"; - private static final String PERMISSION_FULL_NAME = "dbs/IXYFAA==/users/IXYFAE9ZOwA=/permissions/IXYFAE9ZOwBGkyqWIsNKAA==/"; - private static final String ATTACHMENT_FULL_NAME = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/docs/IXYFAOHEBPMBAAAAAAAAAA==/attachments/IXYFAOHEBPMBAAAAAAAAABJYSJk=/"; - private static final String TRIGGER_FULL_NAME = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/triggers/IXYFAOHEBPMCAAAAAAAAcA==/"; - private static final String CONFLICT_FULL_NAME = "dbs/k6d9AA==/colls/k6d9ALgBmD8=/conflicts/k6d9ALgBmD8BAAAAAAAAQA==/"; - - private static final String INCORRECT = "incorrect"; - - @Test(groups = { "unit" }) - public void validateResourceID() { - assertThat(PathsHelper.validateResourceId(ResourceType.Database, DATABASE_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.DocumentCollection, DATABASE_COLLECTION_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.Document, DOCUMENT_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.Attachment, ATTACHMENT_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.Permission, PERMISSION_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.StoredProcedure, STORED_PRCEDURE_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.Trigger, TRIGGER_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.UserDefinedFunction, USER_DEFINED_FUNCTION_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.User, USER_ID)).isTrue(); - assertThat(PathsHelper.validateResourceId(ResourceType.Conflict, CONFLICT_ID)).isTrue(); - - assertThat(PathsHelper.validateResourceId(ResourceType.Database, DATABASE_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.DocumentCollection, DATABASE_COLLECTION_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.Document, DOCUMENT_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.Attachment, ATTACHMENT_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.Permission, PERMISSION_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.StoredProcedure, STORED_PRCEDURE_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.Trigger, TRIGGER_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.UserDefinedFunction, USER_DEFINED_FUNCTION_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.User, USER_ID + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceId(ResourceType.Conflict, CONFLICT_ID + INCORRECT)).isFalse(); - } - - @Test(groups = { "unit" }) - public void validateResourceFullName() { - assertThat(PathsHelper.validateResourceFullName(ResourceType.Database, DATABASE_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.DocumentCollection, DOCUMENT_COLLECTION_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Document, DOCUMENT_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Attachment, ATTACHMENT_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Permission, PERMISSION_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.User, USER_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Conflict, CONFLICT_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.UserDefinedFunction, USER_DEFINED_FUNCTION_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.StoredProcedure, STORED_PRCEDURE_FULL_NAME)).isTrue(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Trigger, TRIGGER_FULL_NAME)).isTrue(); - - assertThat(PathsHelper.validateResourceFullName(ResourceType.Database, DATABASE_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.DocumentCollection, DOCUMENT_COLLECTION_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Document, DOCUMENT_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Attachment, ATTACHMENT_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Permission, PERMISSION_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.User, USER_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Conflict, CONFLICT_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.UserDefinedFunction, USER_DEFINED_FUNCTION_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.StoredProcedure, STORED_PRCEDURE_FULL_NAME + INCORRECT)).isFalse(); - assertThat(PathsHelper.validateResourceFullName(ResourceType.Trigger, TRIGGER_FULL_NAME + INCORRECT)).isFalse(); - - } - - @Test(groups = {"unit"}) - public void generatePathAtDBLevel() { - RxDocumentServiceRequest rxDocumentServiceRequest = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.DatabaseAccount); - String path = PathsHelper.generatePath(ResourceType.DatabaseAccount, rxDocumentServiceRequest, rxDocumentServiceRequest.isFeed); - assertThat(path).isEqualTo(Paths.DATABASE_ACCOUNT_PATH_SEGMENT + "/"); - - rxDocumentServiceRequest = RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Database); - path = PathsHelper.generatePath(ResourceType.Database, rxDocumentServiceRequest, rxDocumentServiceRequest.isFeed); - assertThat(path).isEqualTo(Paths.DATABASES_PATH_SEGMENT + "/"); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/RxDocumentServiceRequestTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/RxDocumentServiceRequestTest.java deleted file mode 100644 index 2d157911e347..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/RxDocumentServiceRequestTest.java +++ /dev/null @@ -1,456 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.nio.charset.StandardCharsets; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.Resource; -import org.apache.commons.collections4.map.HashedMap; -import org.apache.commons.lang3.StringUtils; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.rx.internal.AuthorizationTokenType; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import rx.Observable; - -public class RxDocumentServiceRequestTest { - - private final static String DOCUMENT_DEFINITION = "{ " + "\"id\": \"%s\", " + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" + "}"; - private static final String PARTITION_KEY_VALUE = "1"; - - private final String DOCUMENT_URL_WITH_ID = "/dbs/IXYFAA==/colls/IXYFAOHEBPM=/docs/IXYFAOHEBPMBAAAAAAAAAA==/"; - private final String DOCUMENT_URL_WITH_NAME = "/dbs/testDB/colls/testColl/docs/testDoc/"; - private final String DOCUMENT_URL_WITH_ID_WITHOUT_SLASH = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/docs/IXYFAOHEBPMBAAAAAAAAAA==/"; - private final String DOCUMENT_URL_WITH_NAME_WITHOUT_SLASH = "dbs/testDB/colls/testColl/docs/testDoc/"; - - private static final String DATABASE_URL = "/dbs/IXYFAA==/"; - private static final String DOCUMENT_COLLECTION_URL = "/dbs/IXYFAA==/colls/IXYFAOHEBPM=/"; - private static final String STORED_PRCEDURE_URL = "/dbs/IXYFAA==/colls/IXYFAOHEBPM=/sprocs/IXYFAOHEBPMCAAAAAAAAgA==/"; - private static final String USER_DEFINED_FUNCTION_URL = "/dbs/IXYFAA==/colls/IXYFAOHEBPM=/udfs/IXYFAOHEBPMBAAAAAAAAYA==/"; - private static final String USER_URL = "/dbs/IXYFAA==/users/IXYFAE9ZOwA=/"; - private static final String PERMISSION_URL = "/dbs/IXYFAA==/users/IXYFAE9ZOwA=/permissions/IXYFAE9ZOwBGkyqWIsNKAA==/"; - private static final String ATTACHMENT_URL = "/dbs/IXYFAA==/colls/IXYFAOHEBPM=/docs/IXYFAOHEBPMBAAAAAAAAAA==/attachments/IXYFAOHEBPMBAAAAAAAAABJYSJk=/"; - private static final String TRIGGER_URL = "/dbs/IXYFAA==/colls/IXYFAOHEBPM=/triggers/IXYFAOHEBPMCAAAAAAAAcA==/"; - private static final String CONFLICT_URL = "/dbs/k6d9AA==/colls/k6d9ALgBmD8=/conflicts/k6d9ALgBmD8BAAAAAAAAQA==/"; - - @DataProvider(name = "documentUrl") - public Object[][] documentUrlWithId() { - return new Object[][] { { DOCUMENT_URL_WITH_ID, DOCUMENT_URL_WITH_NAME, OperationType.Read }, - { DOCUMENT_URL_WITH_ID, DOCUMENT_URL_WITH_NAME, OperationType.Delete }, - { DOCUMENT_URL_WITH_ID, DOCUMENT_URL_WITH_NAME, OperationType.Replace }, - { DOCUMENT_URL_WITH_ID_WITHOUT_SLASH, DOCUMENT_URL_WITH_NAME_WITHOUT_SLASH, OperationType.Read }, - { DOCUMENT_URL_WITH_ID_WITHOUT_SLASH, DOCUMENT_URL_WITH_NAME_WITHOUT_SLASH, OperationType.Delete }, - { DOCUMENT_URL_WITH_ID_WITHOUT_SLASH, DOCUMENT_URL_WITH_NAME_WITHOUT_SLASH, OperationType.Replace }, }; - } - - @DataProvider(name = "resourceUrlWithOperationType") - public Object[][] resourceOperation() { - return new Object[][] { { DATABASE_URL, ResourceType.Database, OperationType.Read }, - { DOCUMENT_COLLECTION_URL, ResourceType.DocumentCollection, OperationType.Read }, - { STORED_PRCEDURE_URL, ResourceType.StoredProcedure, OperationType.Read }, - { USER_DEFINED_FUNCTION_URL, ResourceType.UserDefinedFunction, OperationType.Read }, - { USER_URL, ResourceType.User, OperationType.Read }, - { PERMISSION_URL, ResourceType.Permission, OperationType.Read }, - { ATTACHMENT_URL, ResourceType.Attachment, OperationType.Read }, - { TRIGGER_URL, ResourceType.Trigger, OperationType.Read }, - { CONFLICT_URL, ResourceType.Conflict, OperationType.Read }, - - { DATABASE_URL, ResourceType.Database, OperationType.Create }, - { DOCUMENT_COLLECTION_URL, ResourceType.DocumentCollection, OperationType.Create }, - { STORED_PRCEDURE_URL, ResourceType.StoredProcedure, OperationType.Create }, - { USER_DEFINED_FUNCTION_URL, ResourceType.UserDefinedFunction, OperationType.Create }, - { USER_URL, ResourceType.User, OperationType.Create }, - { PERMISSION_URL, ResourceType.Permission, OperationType.Create }, - { ATTACHMENT_URL, ResourceType.Attachment, OperationType.Create }, - { TRIGGER_URL, ResourceType.Trigger, OperationType.Create }, - { CONFLICT_URL, ResourceType.Conflict, OperationType.Create }, - - { DATABASE_URL, ResourceType.Database, OperationType.Delete }, - { DOCUMENT_COLLECTION_URL, ResourceType.DocumentCollection, OperationType.Delete }, - { STORED_PRCEDURE_URL, ResourceType.StoredProcedure, OperationType.Delete }, - { USER_DEFINED_FUNCTION_URL, ResourceType.UserDefinedFunction, OperationType.Delete }, - { USER_URL, ResourceType.User, OperationType.Delete }, - { PERMISSION_URL, ResourceType.Permission, OperationType.Delete }, - { ATTACHMENT_URL, ResourceType.Attachment, OperationType.Delete }, - { TRIGGER_URL, ResourceType.Trigger, OperationType.Delete }, - { CONFLICT_URL, ResourceType.Conflict, OperationType.Delete }, - - { DATABASE_URL, ResourceType.Database, OperationType.Replace }, - { DOCUMENT_COLLECTION_URL, ResourceType.DocumentCollection, OperationType.Replace }, - { STORED_PRCEDURE_URL, ResourceType.StoredProcedure, OperationType.Replace }, - { USER_DEFINED_FUNCTION_URL, ResourceType.UserDefinedFunction, OperationType.Replace }, - { USER_URL, ResourceType.User, OperationType.Replace }, - { PERMISSION_URL, ResourceType.Permission, OperationType.Replace }, - { ATTACHMENT_URL, ResourceType.Attachment, OperationType.Replace }, - { TRIGGER_URL, ResourceType.Trigger, OperationType.Replace }, - { CONFLICT_URL, ResourceType.Conflict, OperationType.Replace }, - - { DATABASE_URL, ResourceType.Database, OperationType.Query }, - { DOCUMENT_COLLECTION_URL, ResourceType.DocumentCollection, OperationType.Query }, - { STORED_PRCEDURE_URL, ResourceType.StoredProcedure, OperationType.Query }, - { USER_DEFINED_FUNCTION_URL, ResourceType.UserDefinedFunction, OperationType.Query }, - { USER_URL, ResourceType.User, OperationType.Query }, - { PERMISSION_URL, ResourceType.Permission, OperationType.Query }, - { ATTACHMENT_URL, ResourceType.Attachment, OperationType.Query }, - { TRIGGER_URL, ResourceType.Trigger, OperationType.Query }, - { CONFLICT_URL, ResourceType.Conflict, OperationType.Query }, - - { DATABASE_URL, ResourceType.Database, OperationType.Update }, - { DOCUMENT_COLLECTION_URL, ResourceType.DocumentCollection, OperationType.Update }, - { STORED_PRCEDURE_URL, ResourceType.StoredProcedure, OperationType.Update }, - { USER_DEFINED_FUNCTION_URL, ResourceType.UserDefinedFunction, OperationType.Update }, - { USER_URL, ResourceType.User, OperationType.Update }, - { PERMISSION_URL, ResourceType.Permission, OperationType.Update }, - { ATTACHMENT_URL, ResourceType.Attachment, OperationType.Update }, - { TRIGGER_URL, ResourceType.Trigger, OperationType.Update }, - { CONFLICT_URL, ResourceType.Conflict, OperationType.Update } }; - } - - @DataProvider(name = "resourceIdOrFullNameRequestAndOperationTypeData") - public Object[][] resourceIdOrFullNameRequestAndOperationTypeData() { - return new Object[][]{ - {"IXYFAA==", "dbs/testDB", ResourceType.Database, OperationType.Read}, - {"IXYFAA==", "dbs/testDB", ResourceType.Database, OperationType.Create}, - - {"IXYFAOHEBPM=", "dbs/testDB/colls/testColl", ResourceType.DocumentCollection, OperationType.Read}, - {"IXYFAOHEBPM=", "dbs/testDB/colls/testColl", ResourceType.DocumentCollection, OperationType.Create}, - {"IXYFAOHEBPM=", "dbs/testDB/colls/testColl", ResourceType.DocumentCollection, OperationType.Delete}, - {"IXYFAOHEBPM=", "dbs/testDB/colls/testColl", ResourceType.DocumentCollection, OperationType.Query}, - - {"IXYFAOHEBPMBAAAAAAAAAA==", "dbs/testDB/colls/testColl/docs/testDoc", ResourceType.Document, OperationType.Read}, - {"IXYFAOHEBPMBAAAAAAAAAA==", "dbs/testDB/colls/testColl/docs/testDoc", ResourceType.Document, OperationType.Create}, - {"IXYFAOHEBPMBAAAAAAAAAA==", "dbs/testDB/colls/testColl/docs/testDoc", ResourceType.Document, OperationType.Delete}, - {"IXYFAOHEBPMBAAAAAAAAAA==", "dbs/testDB/colls/testColl/docs/testDoc", ResourceType.Document, OperationType.Query}, - }; - } - - /** - * This test case will cover various create methods through resource url with Id in detail for document resource. - * @param documentUrlWithId Document url with id - * @param documentUrlWithName Document url with name - * @param operationType Operation type - */ - @Test(groups = { "unit" }, dataProvider = "documentUrl") - public void createWithResourceIdURL(String documentUrlWithId, String documentUrlWithName, - OperationType operationType) { - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithId, - new HashedMap(), AuthorizationTokenType.PrimaryMasterKey); - - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - - request = RxDocumentServiceRequest.create(operationType, "IXYFAOHEBPMBAAAAAAAAAA==", ResourceType.Document, - new HashedMap(), AuthorizationTokenType.PrimaryReadonlyMasterKey); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryReadonlyMasterKey); - assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - - Document document = getDocumentDefinition(); - request = RxDocumentServiceRequest.create(operationType, document, ResourceType.Document, documentUrlWithId, - new HashedMap(), AuthorizationTokenType.Invalid); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.Invalid); - assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - assertThat(request.getContent()).isEqualTo(document.toJson().getBytes(StandardCharsets.UTF_8)); - - Observable inputStream = Observable.just(document.toJson().getBytes(StandardCharsets.UTF_8)); - request = RxDocumentServiceRequest.create(operationType, ResourceType.Document, documentUrlWithId, inputStream, - new HashedMap(), AuthorizationTokenType.SecondaryMasterKey); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.SecondaryMasterKey); - assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - assertThat(request.getContentObservable()).isEqualTo(inputStream); - - // Creating one request without giving AuthorizationTokenType , it should take - // PrimaryMasterKey by default - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithId, - new HashedMap()); - - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - assertThat(request.getResourceAddress()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - assertThat(request.getResourceId()).isEqualTo("IXYFAOHEBPMBAAAAAAAAAA=="); - - } - - /** - * This test case will cover various create method through resource url with name in detail for document resource. - * @param documentUrlWithId Document url with id - * @param documentUrlWithName Document url with name - * @param operationType Operation type - */ - @Test(groups = { "unit" }, dataProvider = "documentUrl") - public void createWithResourceNameURL(String documentUrlWithId, String documentUrlWithName, - OperationType operationType) { - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithName, - new HashedMap(), AuthorizationTokenType.PrimaryMasterKey); - - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - assertThat(request.getResourceAddress()) - .isEqualTo(StringUtils.removeEnd(StringUtils.removeStart(documentUrlWithName, Paths.ROOT), Paths.ROOT)); - assertThat(request.getResourceId()).isNull(); - - Document document = getDocumentDefinition(); - Observable inputStream = Observable.just(document.toJson().getBytes(StandardCharsets.UTF_8)); - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithName, - inputStream, - new HashedMap(), - AuthorizationTokenType.SecondaryMasterKey); - - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.SecondaryMasterKey); - assertThat(request.getResourceAddress()) - .isEqualTo(StringUtils.removeEnd(StringUtils.removeStart(documentUrlWithName, Paths.ROOT), Paths.ROOT)); - assertThat(request.getResourceId()).isNull(); - assertThat(request.getContentObservable()).isEqualTo(inputStream); - - // Creating one request without giving AuthorizationTokenType , it should take - // PrimaryMasterKey by default - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithName, - new HashedMap()); - - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - assertThat(request.getResourceAddress()) - .isEqualTo(StringUtils.removeEnd(StringUtils.removeStart(documentUrlWithName, Paths.ROOT), Paths.ROOT)); - assertThat(request.getResourceId()).isNull(); - } - - - /** - * This will cover sanity for most of the combination of different source with various - * operation. - * @param resourceUrl Resource Url - * @param resourceType Resource Type - * @param operationType Operation type - */ - @Test(groups = { "unit" }, dataProvider = "resourceUrlWithOperationType") - public void createDifferentResourceRequestWithDiffOperation(String resourceUrl, ResourceType resourceType, - OperationType operationType) { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, resourceType, resourceUrl, - new HashedMap(), AuthorizationTokenType.PrimaryMasterKey); - assertThat(resourceUrl.contains(request.getResourceAddress())).isTrue(); - assertThat(resourceUrl.contains(request.getResourceId())).isTrue(); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.getHeaders()).isNotNull(); - } - - /** - * This will test all the create method without request path. - * - * @param resourceId Resource id - * @param resourceType Resource Type - * @param operationType Operation type - */ - @Test(groups = {"unit"}, dataProvider = "resourceIdOrFullNameRequestAndOperationTypeData") - public void createRequestWithoutPath(String resourceId, String resourceFullName, ResourceType resourceType, - OperationType operationType) { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, resourceId, resourceType, null); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceId); - assertThat(request.getResourceId()).isEqualTo(resourceId); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - - - request = RxDocumentServiceRequest.create(operationType, resourceId, resourceType, null, AuthorizationTokenType.ResourceToken); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceId); - assertThat(request.getResourceId()).isEqualTo(resourceId); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.ResourceToken); - - Document document = getDocumentDefinition(); - request = RxDocumentServiceRequest.create(operationType, resourceId, resourceType, document, null); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceId); - assertThat(request.getResourceId()).isEqualTo(resourceId); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - assertThat(request.getContent()).isEqualTo(document.toJson().getBytes(StandardCharsets.UTF_8)); - - request = RxDocumentServiceRequest.create(operationType, resourceId, resourceType, document, null, AuthorizationTokenType.ResourceToken); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceId); - assertThat(request.getResourceId()).isEqualTo(resourceId); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.ResourceToken); - assertThat(request.getContent()).isEqualTo(document.toJson().getBytes(StandardCharsets.UTF_8)); - - request = RxDocumentServiceRequest.createFromName(operationType, resourceFullName, resourceType); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceFullName); - assertThat(request.getResourceId()).isNull(); - assertThat(request.getIsNameBased()).isTrue(); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - - request = RxDocumentServiceRequest.createFromName(operationType, resourceFullName, resourceType, AuthorizationTokenType.ResourceToken); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceFullName); - assertThat(request.getResourceId()).isNull(); - assertThat(request.getIsNameBased()).isTrue(); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.ResourceToken); - - request = RxDocumentServiceRequest.createFromName(operationType, document, resourceFullName, resourceType); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceFullName); - assertThat(request.getResourceId()).isNull(); - assertThat(request.getIsNameBased()).isTrue(); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.PrimaryMasterKey); - assertThat(request.getContent()).isEqualTo(document.toJson().getBytes(StandardCharsets.UTF_8)); - - request = RxDocumentServiceRequest.createFromName(operationType, document, resourceFullName, resourceType, AuthorizationTokenType.ResourceToken); - assertThat(request.getHeaders()).isNotNull(); - assertThat(request.getResourceAddress()).isEqualTo(resourceFullName); - assertThat(request.getResourceId()).isNull(); - assertThat(request.getIsNameBased()).isTrue(); - assertThat(request.getResourceType()).isEqualTo(resourceType); - assertThat(request.getOperationType()).isEqualTo(operationType); - assertThat(request.authorizationTokenType).isEqualTo(AuthorizationTokenType.ResourceToken); - assertThat(request.getContent()).isEqualTo(document.toJson().getBytes(StandardCharsets.UTF_8)); - } - - @Test(groups = { "unit" }, dataProvider = "documentUrl") - public void isValidAddress(String documentUrlWithId, String documentUrlWithName, OperationType operationType) { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithId, - new HashedMap()); - - assertThat(request.isValidAddress(ResourceType.Database)).isTrue(); - assertThat(request.isValidAddress(ResourceType.DocumentCollection)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Document)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue(); - assertThat(request.isValidAddress(ResourceType.User)).isFalse(); - assertThat(request.isValidAddress(ResourceType.Trigger)).isFalse(); - assertThat(request.isValidAddress(ResourceType.Offer)).isFalse(); - assertThat(request.isValidAddress(ResourceType.Permission)).isFalse(); - assertThat(request.isValidAddress(ResourceType.Attachment)).isFalse(); - assertThat(request.isValidAddress(ResourceType.StoredProcedure)).isFalse(); - assertThat(request.isValidAddress(ResourceType.Conflict)).isFalse(); - assertThat(request.isValidAddress(ResourceType.PartitionKeyRange)).isFalse(); - - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithName, - new HashedMap()); - - assertThat(request.isValidAddress(ResourceType.Document)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue(); - String collectionFullName = "/dbs/testDB/colls/testColl/"; - request = RxDocumentServiceRequest.create(operationType, ResourceType.DocumentCollection, collectionFullName, - new HashedMap()); - - assertThat(request.isValidAddress(ResourceType.DocumentCollection)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue(); - - String databaseFullName = "/dbs/testDB"; - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Database, - databaseFullName, - new HashedMap()); - - assertThat(request.isValidAddress(ResourceType.Database)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue(); - - String permissionFullName = "/dbs/testDB/users/testUser/permissions/testPermission"; - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Permission, - permissionFullName, - new HashedMap()); - - assertThat(request.isValidAddress(ResourceType.Permission)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue(); - - String triggerFullName = "/dbs/testDB/colls/testUser/triggers/testTrigger"; - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Trigger, - triggerFullName, - new HashedMap()); - - assertThat(request.isValidAddress(ResourceType.Trigger)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue(); - - String attachmentFullName = "/dbs/testDB/colls/testUser/docs/testDoc/attachments/testAttachment"; - request = RxDocumentServiceRequest.create(operationType, - ResourceType.Attachment, - attachmentFullName, - new HashedMap()); - - assertThat(request.isValidAddress(ResourceType.Attachment)).isTrue(); - assertThat(request.isValidAddress(ResourceType.Unknown)).isTrue(); - } - - @Test(groups = { "unit" }, dataProvider = "documentUrl") - public void addPreferHeader(String documentUrlWithId, String documentUrlWithName, OperationType operationType) { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, - ResourceType.Document, - documentUrlWithId, - new HashedMap()); - - request.addPreferHeader("preferHeaderName1", "preferHeaderValue1"); - assertThat(request.getHeaders().size()).isEqualTo(1); - assertThat(request.getHeaders().get(HttpConstants.HttpHeaders.PREFER)) - .isEqualTo("preferHeaderName1=preferHeaderValue1"); - - request.addPreferHeader("preferHeaderName2", "preferHeaderValue2"); - assertThat(request.getHeaders().size()).isEqualTo(1); - assertThat(request.getHeaders().get(HttpConstants.HttpHeaders.PREFER)) - .isEqualTo("preferHeaderName1=preferHeaderValue1;" + "preferHeaderName2=preferHeaderValue2"); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format(DOCUMENT_DEFINITION, uuid, PARTITION_KEY_VALUE)); - return doc; - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/TimeTokenTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/TimeTokenTest.java deleted file mode 100644 index 710d740ae9a0..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/TimeTokenTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.time.format.DateTimeFormatter; -import java.util.Locale; - -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -public class TimeTokenTest { - - private Locale defaultLocale; - - @BeforeTest(groups = { "unit" }) - public void beforeMethod() { - defaultLocale = Locale.getDefault(); - } - - @Test(groups = { "unit" }) - public void nonLocaleUS() { - Locale.setDefault(Locale.ITALIAN); - DateTimeFormatter RFC_1123_DATE_TIME = - DateTimeFormatter.ofPattern("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); - String time = Utils.nowAsRFC1123(); - Locale.setDefault(Locale.US); - RFC_1123_DATE_TIME.parse(time); - } - - @AfterTest(groups = { "unit" }) - public void afterMethod() { - // set back default locale before test - if (defaultLocale != null) { - Locale.setDefault(defaultLocale); - } else { - Locale.setDefault(Locale.US); - } - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpUtilsTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpUtilsTest.java deleted file mode 100644 index de52b4fa83f7..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpUtilsTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2019 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -public class HttpUtilsTest { - - private static final String OWNER_FULL_NAME_VALUE = "dbs/RxJava.SDKTest.SharedDatabase_20190304T121302_iZc/colls/+%20-_,:.%7C~b2d67001-9000-454e-a140-abceb1756c48%20+-_,:.%7C~"; - - @Test(groups = { "unit" }) - public void verifyConversionOfHttpResponseHeadersToMap() throws UnsupportedEncodingException { - HttpHeaders headersMap = new DefaultHttpHeaders(); - headersMap.add(HttpConstants.HttpHeaders.OWNER_FULL_NAME, OWNER_FULL_NAME_VALUE); - - HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_0, - HttpResponseStatus.ACCEPTED, - headersMap); - HttpResponseHeaders httpResponseHeaders = new HttpClientResponse(httpResponse, null).getHeaders(); - Set> resultHeadersSet = HttpUtils.asMap(httpResponseHeaders).entrySet(); - - assertThat(resultHeadersSet.size()).isEqualTo(1); - Entry entry = resultHeadersSet.iterator().next(); - assertThat(entry.getKey()).isEqualTo(HttpConstants.HttpHeaders.OWNER_FULL_NAME); - assertThat(entry.getValue()).isEqualTo(HttpUtils.urlDecode(OWNER_FULL_NAME_VALUE)); - - List> resultHeadersList = HttpUtils.unescape(httpResponseHeaders.entries()); - assertThat(resultHeadersList.size()).isEqualTo(1); - entry = resultHeadersSet.iterator().next(); - assertThat(entry.getKey()).isEqualTo(HttpConstants.HttpHeaders.OWNER_FULL_NAME); - assertThat(entry.getValue()).isEqualTo(HttpUtils.urlDecode(OWNER_FULL_NAME_VALUE)); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseTest.java deleted file mode 100644 index d91eb8faf0fd..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.HashMap; - -import org.apache.commons.io.IOUtils; -import org.testng.annotations.Test; - -public class StoreResponseTest { - @Test(groups = { "unit" }) - public void stringContent() { - String content = "I am body"; - HashMap headerMap = new HashMap<>(); - headerMap.put("key1", "value1"); - headerMap.put("key2", "value2"); - - StoreResponse sp = new StoreResponse(200, new ArrayList<>(headerMap.entrySet()), content); - - assertThat(sp.getStatus()).isEqualTo(200); - assertThat(sp.getResponseStream()).isNull(); - assertThat(sp.getResponseBody()).isEqualTo(content); - assertThat(sp.getHeaderValue("key1")).isEqualTo("value1"); - } - - @Test(groups = { "unit" }) - public void streamContent() throws Exception { - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - baos.write(new byte[] { 3, 0, 1, 9, -1, 125 }); - HashMap headerMap = new HashMap<>(); - headerMap.put("key1", "value1"); - headerMap.put("key2", "value2"); - - StoreResponse sp = new StoreResponse(200, new ArrayList<>(headerMap.entrySet()), new ByteArrayInputStream(baos.toByteArray())); - - assertThat(sp.getStatus()).isEqualTo(200); - assertThat(sp.getResponseBody()).isNull(); - assertThat(sp.getResponseStream()).isNotNull(); - assertThat(IOUtils.contentEquals(new ByteArrayInputStream(baos.toByteArray()), sp.getResponseStream())); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/StringPartitionKeyComponentTest.java b/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/StringPartitionKeyComponentTest.java deleted file mode 100644 index 02b0bd685d80..000000000000 --- a/cosmosdb/data-plane/commons/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/StringPartitionKeyComponentTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.microsoft.azure.cosmosdb.internal.routing; - -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import static org.assertj.core.api.Assertions.assertThat; - -public class StringPartitionKeyComponentTest { - @DataProvider(name = "paramProvider") - public Object[][] paramProvider() { - return new Object[][] { - {"Friday", "Friday", 0}, - {"Friday", "Venerdì", -1}, - {"Fri", "Ven", -1}, - }; - } - - @Test(groups = { "unit" }, dataProvider = "paramProvider") - public void compare(String str1, String str2, int expectedCompare) { - StringPartitionKeyComponent spkc1 = new StringPartitionKeyComponent(str1); - StringPartitionKeyComponent spkc2 = new StringPartitionKeyComponent(str2); - - assertThat(Integer.signum(spkc1.CompareTo(spkc2))).isEqualTo(Integer.signum(expectedCompare)); - } -} diff --git a/cosmosdb/data-plane/commons/src/test/resources/log4j.properties b/cosmosdb/data-plane/commons/src/test/resources/log4j.properties deleted file mode 100644 index 00b89ecf16b7..000000000000 --- a/cosmosdb/data-plane/commons/src/test/resources/log4j.properties +++ /dev/null @@ -1,16 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -# Set HTTP components' logger to INFO - -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -log4j.category.com.microsoft.azure.cosmosdb=INFO -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p %c - %m%n diff --git a/cosmosdb/data-plane/commons/src/test/resources/sampleConflict.json b/cosmosdb/data-plane/commons/src/test/resources/sampleConflict.json deleted file mode 100644 index 12f2a507b7a3..000000000000 --- a/cosmosdb/data-plane/commons/src/test/resources/sampleConflict.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "id": "k6d9ALgBmD8BAAAAAAAAQA==", - "_rid": "k6d9ALgBmD8BAAAAAAAAQA==", - "_self": "dbs/k6d9AA==/colls/k6d9ALgBmD8=/conflicts/k6d9ALgBmD8BAAAAAAAAQA==/", - "_etag": "\"00004a0f-0000-0000-0000-5b6e214b0000\"", - "resourceType": "document", - "operationType": "create", - "resourceId": "k6d9ALgBmD+ChB4AAAAAAA==", - "content": "{\"id\":\"0007312a-a1c5-4b54-9e39-35de2367fa33\",\"regionId\":2,\"regionEndpoint\":\"https://test-southeastasia.documents.azure.com:443/\",\"_rid\":\"k6d9ALgBmD+ChB4AAAAAAA==\",\"_self\":\"dbs\\/k6d9AA==\\/colls\\/k6d9ALgBmD8=\\/docs\\/k6d9ALgBmD+ChB4AAAAAAA==\\/\",\"_etag\":\"\\\"00000200-0000-0000-0000-5b6e214b0000\\\"\",\"_attachments\":\"attachments\\/\",\"_ts\":1533944139}", - "_ts": 1533944139 -} diff --git a/cosmosdb/data-plane/direct-impl/pom.xml b/cosmosdb/data-plane/direct-impl/pom.xml deleted file mode 100644 index 58a49378abaf..000000000000 --- a/cosmosdb/data-plane/direct-impl/pom.xml +++ /dev/null @@ -1,327 +0,0 @@ - - - 4.0.0 - com.microsoft.azure - azure-cosmosdb-direct - Azure Cosmos DB Async SDK Direct Internal Implementation - 2.4.5 - Azure Cosmos DB Async SDK Direct Internal Implementation - https://docs.microsoft.com/en-us/azure/cosmos-db - jar - - UTF-8 - unit - 2.4.5 - 27.0.1-jre - 4.0.5 - - - - - unit - - default - unit - - - true - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - - - - - - fast - - simple - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - long - - long - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - direct - - direct - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - multi-master - - multi-master - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - emulator - - emulator - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - non-emulator - - non-emulator - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.0 - - unit - - **/*.java - - - - surefire.testng.verbose - 2 - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.22.0 - - - **/*.java - - ${test.groups} - - - surefire.testng.verbose - 2 - - - - - - - integration-test - verify - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 - - - - - - maven-javadoc-plugin - 3.0.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - empty-javadoc-jar - package - - jar - - - empty-javadoc - ${basedir}/javadoc - - - - empty-sources-jar - package - - jar - - - empty-sources - ${basedir}/sources - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.22.0 - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - org.apache.maven.plugins - maven-jxr-plugin - 2.1 - - - - - - com.microsoft.azure - azure-cosmosdb-gateway - ${cosmosdb-sdk.version} - - - com.microsoft.azure - azure-cosmosdb-commons-test-utils - ${cosmosdb-sdk.version} - test - - - com.google.guava - guava - ${guava.version} - - - io.dropwizard.metrics - metrics-core - ${metrics.version} - - - - - MIT License - http://www.opensource.org/licenses/mit-license.php - - - - scm:git:https://github.com/Azure/azure-cosmosdb-java.git - scm:git:https://github.com/Azure/azure-cosmosdb-java.git - https://github.com/Azure/azure-cosmosdb-java.git - - - - Azure Cosmos DB Developer Platform Devs - docdbdevplatdevs@microsoft.com - Microsoft - http://www.microsoft.com/ - - - diff --git a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/RntbdTransportClient.md b/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/RntbdTransportClient.md deleted file mode 100755 index aed9cacda209..000000000000 --- a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/RntbdTransportClient.md +++ /dev/null @@ -1,495 +0,0 @@ -This specification describes a Netty-based Java implementation for direct-mode access to Azure Cosmos using its proprietary RNTBD protocol. This enables a Java client to create direct channels to Azure Cosmos back-end endpoints. - -RNTBD is intended to be the high-performance TCP transport alternative to HTTP for Cosmos. At its core, the transport stack must implement the `Microsoft.Azure.Documents.TransportClient` contract. It must be able to: - -* Accept requests intended for a Cosmos DB replica. - -* Serialize and send the requests to the intended endpoint , - -* De-serialize the response and return a StoreResponse in a timely fashion or fail with an appropriate error. - -The `RntbdTransportClient` implements this contract. It extends `TransportClient` and implements its one-and-only-one overridable method: -``` - @Override - public Single invokeStoreAsync( - URI physicalAddress, - ResourceOperation operation, - RxDocumentServiceRequest request) -``` - -The `physicalAddress` address in the call to `invokeStoreAsync` is a request URI of the form: - - **rntbd://**_\_**:**_\_**/**_\_ - -Netty channel pipelines are created dynamically based on the host and port portion of the URI. The replica path is opaque to the `RntbdTransportClient`. - -Having one connection per remote endpoint might suffice in many cases, but there are reasons to believe the client will benefit from additional connections to the same endpoint in at least two cases: - -* Head-of-line blocking - - Requests or responses can become bottle-necked behind large payloads, as they all must pass sequentially through the same stream. - -* Object contention - - Machines with many cores might attempt to send requests to the same endpoint simultaneously, causing all requests to be sent serially, and then all responses to be dispatched serially. - -For these reasons, the `RntbdTransportClient` supports multiple connections to an endpoint. At least one channel is created for each unique combination of host name and port number. Additional channels are created when the number of pending requests on existing channels gets too high. The set of channels created for a host name and port number are represented as an `RntbdTransportClient.Endpoint`. - -The criteria and thresholds for deciding when to create new channels, when to close existing channels, how to balance traffic among multiple connections, and whether to limit the total number of requests pending to an `RntbdTransportClient.Endpoint` are to be determined. The following section briefly describes the RNTBD protocol and the `RntbdTransportClient` channel pipeline. - -## RNTBD Protocol and the RntbdTransportClient Channel Pipeline - -Following creation of a channel upon receipt of the first `RxDocumentServiceRequest` to an endpoint, the RNTBD protocol requires a two-step context negotiation to complete before message exchange begins. - -1. SSL Handshake - - At the end of this step all future messages will be encrypted. All SSL-related work--negotiation, encryption, and decryption--is performed by Netty's built-in `SSLHandler`. An RNTBD client must only negotiate TLS 1.2 or higher. This is subject to change as security requirements become more stringent over time. - -2. RNTBD context negotiation - - In this step the transport client makes a single request--an `RntbdContextRequest`--and awaits a single response--an `RntbdContext` message. - -Request messages that arrive during context negotiation are queued. After context negotiation is complete all pending requests are sent. Request messages are framed and sent one at a time in arrival order on the channel's outgoing message stream. Response messages may be received in any order. Because of this pending promises of replies are matched with incoming response messages based on Activity ID. The lifetime of an RNTBD channel is illustrated in Figure 1. - -``` -┌────────────────────────────────────────────────────────────────────────────────────┐ -│ RNTBD Channel Timeline │ -└────────────────────────────────────────────────────────────────────────────────────┘ - -┌──────────┐ ┌──────────┐ -│ │ │ │ -│ Client │ │ Service │ -│ │ │ │ -└──────────┘ └──────────┘ -┌──────────┐ ┌──────────┐ ──────────────────────┐ -│ │ │ │ │ -│ ├─────────────────┐ │ │ │ -│ │ │ │ │ │ -│ │ ┌─────────────┐ └──────────────────▶│ │ │ -│ │ │SSL Handshake│ │ │ │ -│ │ └─────────────┘ │ │ Negotiate context │ -│ │ ┌──────────────────┤ │ │ -│ │◀─────────────────┘ │ │ │ -│ │ │ │ │ -│ ├─RntbdContextRequest────────────────▶│ │ │ -│ │ │ │ │ -│ │◀──────────────────────RntbdContext──│ │ │ -│ │ │ │ ──────────────────────┘ -│ │ │ │ ──────────────────────┐ -│ │ │ │ │ -│ │ │ │ │ -│ ├─RntbdRequest[1]────────────────────▶│ │ │ -│ │ │ │ │ -│ │ │ │ │ -│ ├─RntbdRequest[2]────────────────────▶│ │ │ -│ │ │ │ │ -│ │ │ │ │ -│ │◀───────────────────RntbdResponse[2]─│ │ │ -│ │ │ │ │ -│ │ │ │ │ -│ ├──RntbdRequest[3]───────────────────▶│ │ │ -│ │ │ │ Exchange messages │ -│ │ │ │ │ -│ │◀───────────────────RntbdResponse[1]─│ │ │ -│ │ │ │ │ -│ │ │ │ │ -│ │◀───────────────────RntbdResponse[3]─│ │ │ -│ │ │ │ │ -│ │ │ │ │ -│ │ . │ │ │ -│ │ . │ │ │ -│ │ . │ │ │ -│ │ │ │ │ -│ │ │ │ │ -└──────────┘ └──────────┘ ──────────────────────┘ -``` -*Figure 1. RNTBD Channel Timeline* - -Figure 2 illustrates the `RntbdTransportClient` implementation of the RNTBD protocol. It diagrams the happy-path. Channel management, error handling, and the details of the channel pipeline will be discussed later in this document. -
- -![Figure 2. RNTBD Channel Implementation Overview ](attachments/RntbdTransportClient.sequence-diagram-1fd9c04f-87e6-472e-afe8-8b1ed30685c2.png) -*Figure 2. RNTBD Channel Implementation Overview* - -The next section describes the `RntbdTransportClient` channel implementation. - -## RNTBD Channel Implementation - -Once a connection is established on a channel, the `RntbdTransportClient` begins exchanging messages. Messages written to an RNTBD channel move through a pipeline. This pipeline is the heart of the RNTBD channel implementation. - -There are four outgoing (request) message types and three incoming (response) message types: - -| Request type | Response type | Description -| ------------------------- | ----------------| ------------------------------------------------------------------------ -| `RntbdContextRequest` | `RntbdContext` | Sent on receipt of the first request on a channel. The response indicates that the connected Cosmos Service is either ready or rejects the request to exchange messages. -| `RntbdReadRequest` | `RntbdResponse` | A request to read data with an error or non-error response. -| `RntbdHealthCheckRequest` | `RntbdHealth` | Sent before each write operation on a channel. A response indicates that the connected Cosmos Service is in good health. -| `RntbdWriteRequest` | `RntbdResponse` | A request to write data with an error or non-error response. - -Request and response message types share a common base: `RntbdRequest` and `RntbdResponse`, respectively. - -The RNTBD pipeline is composed of a small number of Netty pipeline handlers: - -| Pipeline class | Role -| ----------------------------- | -------------------------------------------------------------------------------------- -| `SslHandler` | Negotiates a secure connection. Subsequently encrypts data written to the channel's output stream and decrypts data read from the channel's input stream. The `SslHandler` reads/writes bytes. It knows nothing about RNTBD messages. -| `RntbdClientMessageFormatter` | Encodes `RntbdRequest` messages (to bytes) and decodes `RntbdResponse` messages (from bytes). -| `RntbdContextNegotiator` | Injects an `RntbdContextRequest` message upon receipt of the first `RntbdRequest` message on a channel. `RntbdRequest` messages are queued and left pending until receipt of an `RntbdContext` message. If the response acknowledges that the connected Cosmos service is ready to exchange messages, all pending messages are sent down the pipeline. On rejection, failure, cancellation, or timeout, the channel is closed and all pending responses are completed exceptionally. -| `RntbdHealthChecker` | Injects an `RntbdHealthCheckRequest` message upon receipt of an `RntbdWriteRequest` message. The `RntbdWriteRequest` is left pending until an associated `RntbdHealth` response is received. The `RntbdWriteRequest` message is then sent down the pipeline. On failure, cancellation, or timeout, the `RntbdWriteRequest` is completed exceptionally with an indication that the `RntbdWriteRequest` is retry-able. -| `RntbdClientMessageManager` | Creates and completes `CompletableFuture` instances. Handles cancellations, exceptions, and timeouts. Maintains the `RntbdContext`. - -## Health Checks, Write Operations, and Channel Failures - -Cosmos writes are not idempotent at the server. For this reason, the `RntbdTransportClient` must avoid sending writes through failed channels to whatever extent possible. This is the reason for sending write requests in two stages: - -* Check that the channel is healthy and then--only if the server reports that the connection is healthy-- - -* Proceed with the write operation - -The sequence of health check followed by write operation introduces a [time-of-check to time-of-use (TOCTOU)](https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use) race condition. Even if the health check succeeds, the write operation could fail any time before the client receives a response--before sending the payload, while sending, or while waiting for a response. - -There is no way to close the race. The race window should be as small as possible. For this reason success responses to health checks aren't cached. That said, it’s not possible to reduce the probability of write failures to zero. When a failure is detected (on read, write, or health check operation), the channel will be closed and the `CompletableFuture` associated with each pending request will be completed exceptionally. The error associated with a failed `CompletableFuture` will indicate whether a failed request is retry-able. - -## Cancellations, Exceptions, and Timeouts - -Cancellations may be initiated by `RntbdTransportClient` consumers using the `Single` returned by `RntbdTransportClient.invokeStoreAsync`. - -Four types of exceptions are thrown by elements of the RNTBD pipeline: - -* IllegalArgumentException is thrown when the argument to a function doesn't conform to the contract for a method and is indicative of a bug in the RNTBD channel pipeline code. - -* IllegalStateException is thrown when the state of a pipeline, request, or response object doesn't conform to expectations. It is indicative of a bug in the RNTBD channel pipeline code or an object passed to it. - -* CorruptedFrameException is thrown when an IO error is detected. This means there was a problem reading/writing bytes to the wire. It is indicative of a channel health issue. - -* SocketException (or one of its derivatives) are raised when a connection cannot be established or an established connection drops or hangs. - -## Exception propagation - -Exception propagate through the `RntbdTransportClient` like this: - -* Connection exceptions associated with opening a channel propagate to the future listener added by RntbdTransportClient.Endpoint.write. - -* Outbound channel exceptions propagate to the future listener added by RntbdTransportClient.Endpoint.doWrite - -* Inbound channel exceptions are caught by RntbdRequestManager.exceptionCaught and propagate to the RxJava Single emitter returned by RntbdTransportClient.invokeStoreAsync. - -#### Exception mapping - -TODO: DANOBLE - -## Performance Requirements - -The performance requirements of the transport client stack are somewhat fuzzy. As it’s one of the core components of the system, the per-request overhead must be minimal. The overhead is best emphasized by tiny reads (<1 KiB) at eventual consistency, in the same region (1 ms RTT). - -Each connection should be able to handle around 2,500-5,000 requests per second. Given enough cores and memory, the transport stack must be able to handle around 30,000-60,000 requests per second, per endpoint. - -The current version of the protocol performs worse than necessary because all headers are in a flat structure. As such, the (inherently single-threaded) logic that decodes a request header to determine which pending I/O to complete must parse more data than necessary, lowering the peak attainable throughput per connection. Fixing that requires a protocol breaking change (incrementing the protocol version number and rolling out in a deliberate fashion). - -## Confidentiality & Integrity - -The client must only negotiate TLS 1.2 or newer. This is subject to change, as security requirements become more stringent over time. - -## Pass-through Tokens - -RNTBD requests carry a correlation ID which is called `activityID` throughout the `RntbdTransportClient` implementation. An `activityID` is propagated to remote endpoints on every request. -The same holds for the user agent string which is included in the `RntbdContext` associated with a channel. - -## RNTBD Message Formats - -Each RNTBD message type consists of two parts: - -* a head frame followed by -* an optional body frame. - -Each frame begins with a 32-bit integer `length` field followed by a payload. - -``` -┌─────────────┬──────────────────┐ -│ length (32) │ payload (0...) ... -└─────────────┴──────────────────┘ -``` - -The definition of the `length` field is different for the head and body frames. - -| Frame | Definition of `length` field -| ----- | -------------------------------------------------------------------------------------------------------------- -| head | Length of the frame (four plus the length of the payload) expressed as an unsigned 32-bit integer in little-endian order. Values greater than `Integer.MAX_VALUE` must not be sent. -| body | Length of the payload expressed as a 32-bit integer in little-endian order. Values greater than `Integer.MAX_VALUE` must not be sent. - -The `RntbdTransportClient` sends request messages and receives response messages. Following RNTBD context negotiation there is no guarantee that responses will be received in the order that requests are sent. Hence, it is the job of the `RntbdTransportClient` to match requests to responses based on *Activity ID*. - -## RNTBD Request Messages - -RNTBD request messages have this format: - -``` -RntbdRequestHead frame -┌────────────────────────────────────┬──────────────────┬──────────────────┬──────────────────────────────────────────── -│length (32) │resourceType (16) │operationType (16)│activityID (128) -└────────────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┬──────────────────┐ - │headers (0...) ... -────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────────────┘ - -RntbdRequestBody frame -┌────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────┐ -│length (32) │ payload (0...) ... -└────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────┘ -``` - -The fields of the `RntbdRequestHead` are defined as: - -| Field | Definition -| ------------- | ----------------------------------------------------------------------------------------------------- -| length | Length of the frame expressed as an unsigned 32-bit integer in little-endian order. Values greater than `Integer.MAX_VALUE` must not be sent. -| resourceType | A 16-bit `RntbdResourceType.id()` value in little-endian order. -| operationType | A 16-bit `RntbdOperationType.id()` value in little-endian order. -| activityId | A 128-bit Activity ID that uniquely identifies the request message. It is a `UUID` serialized as an `int` followed by three `short` and six `byte` values in little-endian order. This serialization yields the same sequence of bytes as produced by `System.Guid.ToByteArray`. -| headers | A variable-length sequence of RNTBD headers expressed as `RntbdToken` values. - -A description of each message type follows. - -### RntbdContextRequest - -An `RntbdContextRequest` consists of a single frame: an `RntbdRequestHead` with three headers. - -``` -┌──────────────────────────────┬──────────────┬──────────────┬─────────────────────────────────────────────────────────┬ -│length (32) │0x0000 (16) │0x0000 (16) │activityID (128) ... -└──────────────────────────────┴──────────────┴──────────────┴─────────────────────────────────────────────────────────┴ -┬─────────────────────────────────────────────┬ ┬───────────────────────────────────────────────────────┐ -│protocolVersion: RntbdTokenType.ULong (56) ... │clientVersion: RntbdTokenType.SmallString (32..2072) ... -┴─────────────────────────────────────────────┴ ┴───────────────────────────────────────────────────────┘ -┬───────────────────────────────────────────────────────────┐ -│userAgent: RntbdTokenType.SmallString (32..2072) ... -┴───────────────────────────────────────────────────────────┘ -``` - -The fields of the `RntbdContextRequest` are defined as follows: - -| Field | Definition -| --------------- | ---------------------------------------------------------------------------------------------------- -| length | Length of the frame expressed as an unsigned 32-bit integer in little-endian order. -| resourceType | A 16-bit value of zero. This is the value of `RntbdResourceType.Connection.id()`. -| operationType | A 16-bit value of zero. This is the value of `RntbdOperationType.Connection.id()`. -| protocolVersion | The protocol version to be negotiated. It is represented as a 56-bit long `RntbdToken` of type `RntbdTokenType.ULong`. Its token identifier is `RntbdContextRequestHeader.ProtocolVersion.id()`. -| clientVersion | The client version string. It is represented as a variable-length `RntbdToken` of type `RntbdTokenType.ShortString`. Its token identifier is `RntbdContextRequestHeader.ClientVersion.id()`. -| userAgent | A string identifying the user agent. It is represented as a variable-length `RntbdToken` of type `RntbdTokenType.ShortString`. Its token identifier is `RntbdContextRequestHeader.UserAgent.id()`. - - -### RntbdHealthCheckRequest - -TODO: DANOBLE - -### RntbdReadRequest - -TODO: DANOBLE - -### RntbdWriteRequest - -TODO: DANOBLE - -## RNTBD Response Messages - -RNTBD response messages have this format: - -``` -RntbdResponseHead frame -┌────────────────────────────────────┬──────────────────┬─────────────────────────────────────────────────────────────── -│length (32) │status (16) │activityID (128) -└────────────────────────────────────┴──────────────────┴────────────────────────┬─────────────────────────────────────┐ - │headers (0...) ... -─────────────────────────────────────────────────────────────────────────────────┴─────────────────────────────────────┘ - -RntbdResponseBody frame -┌────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────┐ -│length (32) │ payload (0...) ... -└────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────┘ -``` - -The fields of the `RntbdResponseHead` are defined as: - -| Field | Definition -| ------------- | ------------------------------------------------------------------------------------------------------ -| length | Length of the frame expressed as an unsigned 32-bit integer in little-endian order. Values greater than `Integer.MAX_VALUE` must not be sent. -| status | A 32-bit `HttpResponseStatus` code in little-endian order. -| activityId | A 128-bit Activity ID that uniquely identifies the request message. It is a `UUID` serialized as an `int` followed by three `short` and six `byte` values in little-endian order. This serialization yields the same sequence of bytes as produced by `System.Guid.ToByteArray`. -| headers | A variable-length sequence of RNTBD headers expressed as `RntbdToken` values. - - -## RNTBD Headers - -RNTBD headers are expressed as a sequence of `RntbdToken` instances with this wire format: - -``` -┌────────────────┬────────┬────────────────────────────┐ -│id (16) │type (8)│value (0...) ... -└────────────────┴────────┴────────────────────────────┘ -``` - -The fields of an `RntbdToken` instance are defined as: - -| Field | Definition -| ------ | ------------------------------------------------------------------------------------------------------ -| id | A 16-bit `RntbdRequestHeader` or `RntbdResponseHeader` identifier in little-endian order. -| type | An 8-bit `RntbdTokenType` ID. -| value | Value of the header identified by `id`. The format and length of the value depend on the `type`. - -Here are the formats of `RntbdToken` instance values by `RntbdTokenType`. - -### RntbdTokenType.Byte (0x00) - -An `RntbdToken` of type `RntbdTokenType.UShort` represents an unsigned 8-bit integer-valued header. It has a fixed -length of 4 bytes (32 bits). - -``` -┌────────────────┬────────┬────────┐ -│id (16) │0x00 (8)│val (8) │ -└────────────────┴────────┴────────┘ -``` - -### RntbdTokenType.UShort (0x01) - -An `RntbdToken` of type `RntbdTokenType.UShort` represents an unsigned 16-bit integer-valued header. It has a fixed -length of 5 bytes (40 bits). - -``` -┌────────────────┬────────┬────────────────┐ -│id (16) │0x01 (8)│ value (16) │ -└────────────────┴────────┴────────────────┘ -``` - -### RntbdTokenType.ULong (0x02) - -An `RntbdToken` of type `RntbdTokenType.ULong` represents an unsigned 32-bit integer-valued header. It has a fixed -length of 7 bytes (56 bits). - -``` -┌────────────────┬────────┬────────────────────────────────┐ -│id (16) │0x02 (8)│value (32) │ -└────────────────┴────────┴────────────────────────────────┘ -``` - -### RntbdTokenType.Long (0x03) - -An `RntbdToken` of type `RntbdTokenType.Long` represents an signed 32-bit integer-valued header. It has a fixed length of 7 bytes (56 bits). - -``` -┌────────────────┬────────┬────────────────────────────────┐ -│id (16) │0x03 (8)│value (32) │ -└────────────────┴────────┴────────────────────────────────┘ -``` - -### RntbdTokenType.ULongLong (0x04) - -An `RntbdToken` of type `RntbdTokenType.ULongLong` represents an unsigned 64-bit integer-valued header. It has a fixed length of 11 bytes (88 bits). - -``` -┌────────────────┬────────┬────────────────────────────────────────────────────────────────┐ -│id (16) │0x04 (8)│value (64) │ -└────────────────┴────────┴────────────────────────────────────────────────────────────────┘ -``` - -### RntbdTokenType.LongLong (0x05) - -An `RntbdToken` of type `RntbdTokenType.LongLong` represents a signed 64-bit integer-valued header. It has a fixed -length of 11 bytes (88 bits). - -``` -┌────────────────┬────────┬────────────────────────────────────────────────────────────────┐ -│id (16) │ 0x05 │ (64) │ -└────────────────┴────────┴────────────────────────────────────────────────────────────────┘ -``` - -### RntbdTokenType.Guid (0x06) - -An `RntbdToken` of type `RntbdTokenType.Guid` represents a 128-bit UUID serializes using an algorithm that produces -the same byte sequence as [`System.Guid.ToByteArray`](https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray?view=netframework-4.7.2). It has a fixed length of 19 bytes (152 bits). - -``` -┌────────────────┬────────┬───────────────────────────────────────────────────────────────────────────────────────────── -│id (16) │0x06 (8)│ value (128) -└────────────────┴────────┴───────────────────────────────────────────────────────────────────────────────────────────── -───────────────────────────────────┐ - │ -───────────────────────────────────┘ -``` - -### RntbdTokenType.SmallString (0x07) - -An `RntbdToken` of type `RntbdTokenType.SmallString` represents a UTF-8 encoded string-valued header. It has a variable length between 4 bytes (32 bits) and 259 bytes (2,072 bits). Its encoded string value can be as large as 255 bytes. - -``` -┌────────────────┬────────┬────────┬────────────────────────────┐ -│id (16) │0x07 (8)│len (8) │ val (0..0xFF) ... -└────────────────┴────────┴────────┴────────────────────────────┘ -``` - -### RntbdTokenType.String (0x08) - -An `RntbdToken` of type `RntbdTokenType.String` represents a UTF-8 encoded string-valued header. It has a variable length between 5 bytes (40 bits) and 2,147,483,654 bytes (524,320 bits). Its encoded string value can be as large as -65,535 bytes (64 KiB - 1 byte). - -``` -┌────────────────┬────────┬────────────────┬────────────────────────────┐ -│id (16) │0x08 (8)│len (16) │ val (0..0xFFFF) ... -└────────────────┴────────┴────────────────┴────────────────────────────┘ -``` - -### RntbdTokenType.ULongString (0x09) - -An `RntbdToken` of type `RntbdTokenType.ULongString` represents a UTF-8 encoded string-valued header. It has a variable length between 7 bytes (56 bits) and 2,147,483,654 bytes (a little more than 16 gibits). Its encoded string value can be as large as 2,147,483,647 (2**31 - 1) bytes. - -``` -┌────────────────┬────────┬────────────────────────────────┬────────────────────────────┐ -│id (16) │0x09 (8)│len (32) │ val (0..0x7FFFFFFF) ... -└────────────────┴────────┴────────────────────────────────┴────────────────────────────┘ -``` - -### RntbdTokenType.SmallBytes (0x0A) - -``` -┌────────────────┬────────┬────────┬────────────────────────────┐ -│id (16) │ 0x0A │len (8) │ val (0..0xFF) ... -└────────────────┴────────┴────────┴────────────────────────────┘ -``` - -### RntbdTokenType.Bytes (0x0B) - -``` -┌────────────────┬────────┬────────────────┬────────────────────────────┐ -│id (16) │ 0x0B │len (16) │ val (0..0xFFFF) ... -└────────────────┴────────┴────────────────┴────────────────────────────┘ -``` - -### RntbdTokenType.ULongBytes (0x0C) - -``` -┌────────────────┬────────┬────────────────────────────────┬────────────────────────────┐ -│id (16) │ 0x0C │len (32) │ val (0..0x7FFFFFFF) ... -└────────────────┴────────┴────────────────────────────────┴────────────────────────────┘ -``` - -### RntbdTokenType.Float (0x0D) - -``` -┌────────────────┬────────┬────────────────────────────────┐ -│id (16) │ 0x0D │ val (32) │ -└────────────────┴────────┴────────────────────────────────┘ -``` - -### RntbdTokenType.Double (0x0E) - -``` -┌────────────────┬────────┬────────────────────────────────────────────────────────────────┐ -│id (16) │ 0x0E │ val (64) │ -└────────────────┴────────┴────────────────────────────────────────────────────────────────┘ -``` - -### RntbdTokenType.Invalid (0xFF) - -``` -┌────────────────┬────────┐ -│id (16) │ 0x0F │ -└────────────────┴────────┘ -``` diff --git a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/RntbdTransportClient.pptx b/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/RntbdTransportClient.pptx deleted file mode 100644 index 11eebca00164..000000000000 Binary files a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/RntbdTransportClient.pptx and /dev/null differ diff --git a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/attachments/RntbdTransportClient.sequence-diagram-1fd9c04f-87e6-472e-afe8-8b1ed30685c2.png b/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/attachments/RntbdTransportClient.sequence-diagram-1fd9c04f-87e6-472e-afe8-8b1ed30685c2.png deleted file mode 100755 index 051d4c1ab632..000000000000 Binary files a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/attachments/RntbdTransportClient.sequence-diagram-1fd9c04f-87e6-472e-afe8-8b1ed30685c2.png and /dev/null differ diff --git a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/src/RntbdTransportClient architecture.vsdx b/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/src/RntbdTransportClient architecture.vsdx deleted file mode 100644 index e570a5bb8967..000000000000 Binary files a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/src/RntbdTransportClient architecture.vsdx and /dev/null differ diff --git a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/src/RntbdTransportClient sequence diagram.vsdx b/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/src/RntbdTransportClient sequence diagram.vsdx deleted file mode 100644 index bd353b0f73b2..000000000000 Binary files a/cosmosdb/data-plane/direct-impl/specifications/RntbdTransportClient/src/RntbdTransportClient sequence diagram.vsdx and /dev/null differ diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/ContentSerializationFormat.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/ContentSerializationFormat.java deleted file mode 100644 index fb9a8fe974d3..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/ContentSerializationFormat.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal; - -public enum ContentSerializationFormat { - /** - * Standard JSON RFC UTF-8 text - */ - JsonText, - - /** - * Custom binary for Cosmos DB that encodes a superset of JSON values. - */ - CosmosBinary, -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/EnumerationDirection.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/EnumerationDirection.java deleted file mode 100644 index d4b6aed5351f..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/EnumerationDirection.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal; - -public enum EnumerationDirection { - /** - * Use forward direction - */ - Forward, - - /** - * Use reverse direction - */ - Reverse -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/FanoutOperationState.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/FanoutOperationState.java deleted file mode 100644 index b8c3a4786e80..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/FanoutOperationState.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal; - -public enum FanoutOperationState { - /** - * Fanout operation started - */ - Started, - - /** - * Fanout operation completed - */ - Completed -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/MigrateCollectionDirective.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/MigrateCollectionDirective.java deleted file mode 100644 index 5d3f30231fa1..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/MigrateCollectionDirective.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal; - -public enum MigrateCollectionDirective { - /** - * Move to SSD - */ - Thaw, - - /** - * Move to HDD - */ - Freeze -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/ReadFeedKeyType.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/ReadFeedKeyType.java deleted file mode 100644 index f84a40047e9a..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/ReadFeedKeyType.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Type of Start and End key for ReadFeedKey - */ -public enum ReadFeedKeyType { - /** - * Use resource name - */ - ResourceId, - - /** - * Use effective partition key - */ - EffectivePartitionKey -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/RemoteStorageType.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/RemoteStorageType.java deleted file mode 100644 index e0f65239a64c..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/RemoteStorageType.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal; - -public enum RemoteStorageType { - /** - * Use standard storage - */ - NotSpecified, - - /** - * Use standard storage - */ - Standard, - - /** - * Use premium storage - */ - Premium -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolver.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolver.java deleted file mode 100644 index db65feef97d5..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolver.java +++ /dev/null @@ -1,716 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceId; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalHelper; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.ICollectionRoutingMapCache; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; -import rx.functions.Func1; - -import java.util.concurrent.Callable; - -/** - * Abstracts out the logic to resolve physical replica addresses for the given {@link RxDocumentServiceRequest} - *

- * AddressCache internally maintains CollectionCache, CollectionRoutingMapCache and BackendAddressCache. - * Logic in this class mainly joins these 3 caches and deals with potential staleness of the caches. - */ -public class AddressResolver implements IAddressResolver { - private static Logger logger = LoggerFactory.getLogger(AddressResolver.class); - - private final static PartitionKeyRangeIdentity masterPartitionKeyRangeIdentity = - new PartitionKeyRangeIdentity(PartitionKeyRange.MASTER_PARTITION_KEY_RANGE_ID); - - private RxCollectionCache collectionCache; - private ICollectionRoutingMapCache collectionRoutingMapCache; - private IAddressCache addressCache; - - public AddressResolver() { - } - - public void initializeCaches( - RxCollectionCache collectionCache, - ICollectionRoutingMapCache collectionRoutingMapCache, - IAddressCache addressCache) { - this.collectionCache = collectionCache; - this.addressCache = addressCache; - this.collectionRoutingMapCache = collectionRoutingMapCache; - } - - public Single resolveAsync( - RxDocumentServiceRequest request, - boolean forceRefreshPartitionAddresses) { - - Single resultObs = this.resolveAddressesAndIdentityAsync(request, forceRefreshPartitionAddresses); - - return resultObs.flatMap(result -> { - - try { - this.throwIfTargetChanged(request, result.TargetPartitionKeyRange); - } catch (Exception e) { - return Single.error(e); - } - - request.requestContext.resolvedPartitionKeyRange = result.TargetPartitionKeyRange; - - return Single.just(result.Addresses); - }); - } - - private static boolean isSameCollection(PartitionKeyRange initiallyResolved, PartitionKeyRange newlyResolved) { - if (initiallyResolved == null) { - throw new IllegalArgumentException("parent"); - } - - if (newlyResolved == null) { - return false; - } - - if (Strings.areEqual(initiallyResolved.getId(), PartitionKeyRange.MASTER_PARTITION_KEY_RANGE_ID) && - Strings.areEqual(newlyResolved.getId(), PartitionKeyRange.MASTER_PARTITION_KEY_RANGE_ID)) { - return true; - } - - if (Strings.areEqual(initiallyResolved.getId(), PartitionKeyRange.MASTER_PARTITION_KEY_RANGE_ID) - || Strings.areEqual(newlyResolved.getId(), PartitionKeyRange.MASTER_PARTITION_KEY_RANGE_ID)) { - String message = - "Request was resolved to master partition and then to server partition."; - assert false : message; - logger.warn(message); - return false; - } - - if (ResourceId.parse(initiallyResolved.getResourceId()).getDocumentCollection() - != ResourceId.parse(newlyResolved.getResourceId()).getDocumentCollection()) { - return false; - } - - if (!Strings.areEqual(initiallyResolved.getId(), newlyResolved.getId()) && - !(newlyResolved.getParents() != null && newlyResolved.getParents().contains(initiallyResolved.getId()))) { - // the above condition should be always false in current codebase. - // We don't need to refresh any caches if we resolved to a range which is child of previously resolved range. - // Quorum reads should be handled transparently as child partitions share LSNs with parent partitions which are gone. - String message = - "Request is targeted at a partition key range which is not child of previously targeted range."; - assert false : message; - logger.warn(message); - - return false; - } - - return true; - } - - /** - * Validates if the target partition to which the request is being sent has changed during retry. - *

- * If that happens, the request is no more valid and need to be retried. - * - * @param request Request in progress - * @param targetRange Target partition key range determined by address resolver - * @*/ - private void throwIfTargetChanged(RxDocumentServiceRequest request, PartitionKeyRange targetRange) throws DocumentClientException { - // If new range is child of previous range, we don't need to throw any exceptions - // as LSNs are continued on child ranges. - if (request.requestContext.resolvedPartitionKeyRange != null && - !isSameCollection(request.requestContext.resolvedPartitionKeyRange, targetRange)) { - if (!request.getIsNameBased()) { - String message = String.format( - "Target should not change for non name based requests. Previous target {}, Current {}", - request.requestContext.resolvedPartitionKeyRange, targetRange); - assert false : message; - logger.warn(message); - } - - request.requestContext.resolvedPartitionKeyRange = null; - throw new InvalidPartitionException(RMResources.InvalidTarget, request.getResourceAddress()); - } - } - - private static void ensureRoutingMapPresent( - RxDocumentServiceRequest request, - CollectionRoutingMap routingMap, - DocumentCollection collection) throws DocumentClientException { - if (routingMap == null && request.getIsNameBased() && request.getPartitionKeyRangeIdentity() != null - && request.getPartitionKeyRangeIdentity().getCollectionRid() != null) { - // By design, if partitionkeyrangeid header is present and it contains collectionrid for collection - // which doesn't exist, we return InvalidPartitionException. Backend does the same. - // Caller (client SDK or whoever attached the header) supposedly has outdated collection cache and will refresh it. - // We cannot retry here, as the logic for retry in this case is use-case specific. - logger.debug( - "Routing map for request with partitionkeyrageid {} was not found", - request.getPartitionKeyRangeIdentity().toHeader()); - - InvalidPartitionException invalidPartitionException = new InvalidPartitionException(); - BridgeInternal.setResourceAddress(invalidPartitionException, request.getResourceAddress()); - throw invalidPartitionException; - } - - if (routingMap == null) { - logger.debug( - "Routing map was not found although collection cache is upto date for collection {}", - collection.getResourceId()); - // Routing map not found although collection was resolved correctly. - NotFoundException e = new NotFoundException(); - BridgeInternal.setResourceAddress(e, request.getResourceAddress()); - throw e; - } - } - - private Single tryResolveServerPartitionAsync( - RxDocumentServiceRequest request, - DocumentCollection collection, - CollectionRoutingMap routingMap, - boolean collectionCacheIsUptodate, - boolean collectionRoutingMapCacheIsUptodate, - boolean forceRefreshPartitionAddresses) { - - try { - // Check if this request partitionkeyrange-aware routing logic. We cannot retry here in this case - // and need to bubble up errors. - if (request.getPartitionKeyRangeIdentity() != null) { - return this.tryResolveServerPartitionByPartitionKeyRangeIdAsync( - request, - collection, - routingMap, - collectionCacheIsUptodate, - collectionRoutingMapCacheIsUptodate, - forceRefreshPartitionAddresses); - } - - if (!request.getResourceType().isPartitioned() && - !(request.getResourceType() == ResourceType.StoredProcedure && request.getOperationType() == OperationType.ExecuteJavaScript) && - // Collection head is sent internally for strong consistency given routing hints from original requst, which is for partitioned resource. - !(request.getResourceType() == ResourceType.DocumentCollection && request.getOperationType() == OperationType.Head)) { - logger.error( - "Shouldn't come here for non partitioned resources. resourceType : {}, operationtype:{}, resourceaddress:{}", - request.getResourceType(), - request.getOperationType(), - request.getResourceAddress()); - return Single.error(BridgeInternal.setResourceAddress(new InternalServerErrorException(RMResources.InternalServerError), request.getResourceAddress())); - } - - PartitionKeyRange range; - String partitionKeyString = request.getHeaders().get(HttpConstants.HttpHeaders.PARTITION_KEY); - - if (partitionKeyString != null) { - range = this.tryResolveServerPartitionByPartitionKey( - request, - partitionKeyString, - collectionCacheIsUptodate, - collection, - routingMap); - } else { - range = this.tryResolveSinglePartitionCollection(request, routingMap, collectionCacheIsUptodate); - } - - if (range == null) { - // Collection cache or routing map cache is potentially outdated. Return null - - // upper logic will refresh cache and retry. - return null; - } - - Single addressesObs = this.addressCache.tryGetAddresses( - request, - new PartitionKeyRangeIdentity(collection.getResourceId(), range.getId()), - forceRefreshPartitionAddresses); - - return addressesObs.flatMap(addresses -> { - - if (addresses == null) { - logger.info( - "Could not resolve addresses for identity {}/{}. Potentially collection cache or routing map cache is outdated. Return null - upper logic will refresh and retry. ", - new PartitionKeyRangeIdentity(collection.getResourceId(), range.getId())); - return Single.just(null); - } - - return Single.just(new ResolutionResult(range, addresses)); - }); - - } catch (Exception e) { - return Single.error(e); - } - } - - private PartitionKeyRange tryResolveSinglePartitionCollection( - RxDocumentServiceRequest request, - CollectionRoutingMap routingMap, - boolean collectionCacheIsUptoDate) throws DocumentClientException { - // Neither partitionkey nor partitionkeyrangeid is specified. - // Three options here: - // * This is non-partitioned collection and old client SDK which doesn't send partition key. In - // this case there's single entry in routing map. But can be multiple entries if before that - // existed partitioned collection with same name. - // * This is partitioned collection and old client SDK which doesn't send partition key. - // In this case there can be multiple ranges in routing map. - // * This is partitioned collection and this is custom written REST sdk, which has a bug and doesn't send - // partition key. - // We cannot know for sure whether this is partitioned collection or not, because - // partition key definition cache can be outdated. - // So we route request to the first partition. If this is non-partitioned collection - request will succeed. - // If it is partitioned collection - backend will return bad request as partition key header is required in this case. - if (routingMap.getOrderedPartitionKeyRanges().size() == 1) { - return (PartitionKeyRange) routingMap.getOrderedPartitionKeyRanges().get(0); - } - - if (collectionCacheIsUptoDate) { - throw BridgeInternal.setResourceAddress(new BadRequestException(RMResources.MissingPartitionKeyValue), request.getResourceAddress()); - } else { - return null; - } - } - - private Single resolveMasterResourceAddress(RxDocumentServiceRequest request, - boolean forceRefreshPartitionAddresses) { - assert ReplicatedResourceClient.isReadingFromMaster(request.getResourceType(), request.getOperationType()) - && request.getPartitionKeyRangeIdentity() == null; - - // ServiceIdentity serviceIdentity = this.masterServiceIdentity; - PartitionKeyRangeIdentity partitionKeyRangeIdentity = this.masterPartitionKeyRangeIdentity; - Single addressesObs = this.addressCache.tryGetAddresses( - request, - partitionKeyRangeIdentity, - forceRefreshPartitionAddresses); - - return addressesObs.flatMap(addresses -> { - if (addresses == null) { - logger.warn("Could not get addresses for master partition"); - - // return Observable.error() - NotFoundException e = new NotFoundException(); - BridgeInternal.setResourceAddress(e, request.getResourceAddress()); - return Single.error(e); - } - - PartitionKeyRange partitionKeyRange = new PartitionKeyRange(); - partitionKeyRange.setId(PartitionKeyRange.MASTER_PARTITION_KEY_RANGE_ID); - return Single.just(new ResolutionResult(partitionKeyRange, addresses)); - - }); - } - - private class RefreshState { - - volatile boolean collectionCacheIsUptoDate; - volatile boolean collectionRoutingMapCacheIsUptoDate; - volatile DocumentCollection collection; - volatile CollectionRoutingMap routingMap; - volatile ResolutionResult resolutionResult; - } - - private Single getOrRefreshRoutingMap(RxDocumentServiceRequest request, boolean forceRefreshPartitionAddresses) { - - RefreshState state = new RefreshState(); - - state.collectionCacheIsUptoDate = !request.getIsNameBased() || - (request.getPartitionKeyRangeIdentity() != null && request.getPartitionKeyRangeIdentity().getCollectionRid() != null); - state.collectionRoutingMapCacheIsUptoDate = false; - - Single collectionObs = this.collectionCache.resolveCollectionAsync(request); - - Single stateObs = collectionObs.flatMap(collection -> { - state.collection = collection; - Single routingMapObs = - this.collectionRoutingMapCache.tryLookupAsync(collection.getResourceId(), null, request.forceCollectionRoutingMapRefresh, request.properties); - final DocumentCollection underlyingCollection = collection; - return routingMapObs.flatMap(routingMap -> { - state.routingMap = routingMap; - - if (request.forcePartitionKeyRangeRefresh) { - state.collectionRoutingMapCacheIsUptoDate = true; - request.forcePartitionKeyRangeRefresh = false; - if (routingMap != null) { - return this.collectionRoutingMapCache.tryLookupAsync(underlyingCollection.getResourceId(), routingMap, request.properties) - .map(newRoutingMap -> { - state.routingMap = newRoutingMap; - return state; - }); - } - - } - - return Single.just(state); - }); - }); - - return stateObs.flatMap(newState -> { - - if (newState.routingMap == null && !newState.collectionCacheIsUptoDate) { - // Routing map was not found by resolved collection rid. Maybe collection rid is outdated. - // Refresh collection cache and reresolve routing map. - request.forceNameCacheRefresh = true; - newState.collectionCacheIsUptoDate = true; - newState.collectionRoutingMapCacheIsUptoDate = false; - - Single newCollectionObs = this.collectionCache.resolveCollectionAsync(request); - - return newCollectionObs.flatMap(collection -> { - newState.collection = collection; - Single newRoutingMapObs = this.collectionRoutingMapCache.tryLookupAsync( - collection.getResourceId(), - null, - request.properties); - - return newRoutingMapObs.map(routingMap -> { - newState.routingMap = routingMap; - return newState; - }); - } - ); - - } - - return Single.just(newState); - }); - } - - private Single getStateWithNewRoutingMap(RefreshState state, Single routingMapSingle) { - return routingMapSingle.map(r -> { - state.routingMap = r; - return state; - }); - } - - /** - * Resolves the endpoint of the partition for the given request - * - * @param request Request for which the partition endpoint resolution is to be performed - * @param forceRefreshPartitionAddresses Force refresh the partition's endpoint - * @return ResolutionResult - */ - private Single resolveAddressesAndIdentityAsync( - RxDocumentServiceRequest request, - boolean forceRefreshPartitionAddresses) { - - if (ReplicatedResourceClient.isReadingFromMaster(request.getResourceType(), request.getOperationType()) - && request.getPartitionKeyRangeIdentity() == null) { - return resolveMasterResourceAddress(request, forceRefreshPartitionAddresses); - } - - Single refreshStateObs = this.getOrRefreshRoutingMap(request, forceRefreshPartitionAddresses); - - return refreshStateObs.flatMap( - state -> { - try { - AddressResolver.ensureRoutingMapPresent(request, state.routingMap, state.collection); - - } catch (Exception e) { - return Single.error(e); - } - - // At this point we have both collection and routingMap. - Single resultObs = this.tryResolveServerPartitionAsync( - request, - state.collection, - state.routingMap, - state.collectionCacheIsUptoDate, - state.collectionRoutingMapCacheIsUptoDate, - forceRefreshPartitionAddresses); - - - return resultObs.flatMap(result -> { - Func1> addCollectionRidIfNameBased = funcResolutionResult -> { - assert funcResolutionResult != null; - if (request.getIsNameBased()) { - // Append collection rid. - // If we resolved collection rid incorrectly because of outdated cache, this can lead - // to incorrect routing decisions. But backend will validate collection rid and throw - // InvalidPartitionException if we reach wrong collection. - // Also this header will be used by backend to inject collection rid into metrics for - // throttled requests. - request.getHeaders().put(WFConstants.BackendHeaders.COLLECTION_RID, state.collection.getResourceId()); - } - - return Single.just(funcResolutionResult); - }; - - if (result != null) { - return addCollectionRidIfNameBased.call(result); - } - - // result is null: - assert result == null; - - Func1> ensureCollectionRoutingMapCacheIsUptoDateFunc = funcState -> { - if (!funcState.collectionRoutingMapCacheIsUptoDate) { - funcState.collectionRoutingMapCacheIsUptoDate = true; - Single newRoutingMapObs = this.collectionRoutingMapCache.tryLookupAsync( - funcState.collection.getResourceId(), - funcState.routingMap, - request.properties); - - return getStateWithNewRoutingMap(funcState, newRoutingMapObs); - } else { - return Single.just(state); - } - }; - - Func1> resolveServerPartition = funcState -> { - - try { - AddressResolver.ensureRoutingMapPresent(request, funcState.routingMap, funcState.collection); - } catch (Exception e) { - return Single.error(e); - } - - return this.tryResolveServerPartitionAsync( - request, - funcState.collection, - funcState.routingMap, - true, - true, - forceRefreshPartitionAddresses); - }; - - Func1> onNullThrowNotFound = funcResolutionResult -> { - if (funcResolutionResult == null) { - logger.debug("Couldn't route partitionkeyrange-oblivious request after retry/cache refresh. Collection doesn't exist."); - - // At this point collection cache and routing map caches are refreshed. - // The only reason we will get here is if collection doesn't exist. - // Case when partition-key-range doesn't exist is handled in the corresponding method. - - return Single.error(BridgeInternal.setResourceAddress(new NotFoundException(), request.getResourceAddress())); - } - - return Single.just(funcResolutionResult); - }; - - // Couldn't resolve server partition or its addresses. - // Either collection cache is outdated or routing map cache is outdated. - if (!state.collectionCacheIsUptoDate) { - request.forceNameCacheRefresh = true; - state.collectionCacheIsUptoDate = true; - - Single newCollectionObs = this.collectionCache.resolveCollectionAsync(request); - Single newRefreshStateObs = newCollectionObs.flatMap(collection -> { - state.collection = collection; - - if (collection.getResourceId() != state.routingMap.getCollectionUniqueId()) { - // Collection cache was stale. We resolved to new Rid. routing map cache is potentially stale - // for this new collection rid. Mark it as such. - state.collectionRoutingMapCacheIsUptoDate = false; - Single newRoutingMap = this.collectionRoutingMapCache.tryLookupAsync( - collection.getResourceId(), - null, - request.properties); - - return getStateWithNewRoutingMap(state, newRoutingMap); - } - - return Single.just(state); - }); - - Single newResultObs = newRefreshStateObs.flatMap(ensureCollectionRoutingMapCacheIsUptoDateFunc::call) - .flatMap(resolveServerPartition::call); - - return newResultObs.flatMap(onNullThrowNotFound::call).flatMap(addCollectionRidIfNameBased::call); - - } else { - return ensureCollectionRoutingMapCacheIsUptoDateFunc.call(state) - .flatMap(resolveServerPartition::call).flatMap(onNullThrowNotFound).flatMap(addCollectionRidIfNameBased); - } - }); - } - ); - } - - private ResolutionResult handleRangeAddressResolutionFailure( - RxDocumentServiceRequest request, - boolean collectionCacheIsUpToDate, - boolean routingMapCacheIsUpToDate, - CollectionRoutingMap routingMap) throws DocumentClientException { - // Optimization to not refresh routing map unnecessary. As we keep track of parent child relationships, - // we can determine that a range is gone just by looking up in the routing map. - if (collectionCacheIsUpToDate && routingMapCacheIsUpToDate || - collectionCacheIsUpToDate && routingMap.IsGone(request.getPartitionKeyRangeIdentity().getPartitionKeyRangeId())) { - String errorMessage = String.format( - RMResources.PartitionKeyRangeNotFound, - request.getPartitionKeyRangeIdentity().getPartitionKeyRangeId(), - request.getPartitionKeyRangeIdentity().getCollectionRid()); - throw BridgeInternal.setResourceAddress(new PartitionKeyRangeGoneException(errorMessage), request.getResourceAddress()); - } - - return null; - } - - private Single returnOrError(Callable function) { - try { - return Single.just(function.call()); - } catch (Exception e) { - return Single.error(e); - } - } - - private Single tryResolveServerPartitionByPartitionKeyRangeIdAsync( - RxDocumentServiceRequest request, - DocumentCollection collection, - CollectionRoutingMap routingMap, - boolean collectionCacheIsUpToDate, - boolean routingMapCacheIsUpToDate, - boolean forceRefreshPartitionAddresses) { - - PartitionKeyRange partitionKeyRange = routingMap.getRangeByPartitionKeyRangeId(request.getPartitionKeyRangeIdentity().getPartitionKeyRangeId()); - if (partitionKeyRange == null) { - logger.debug("Cannot resolve range '{}'", request.getPartitionKeyRangeIdentity().toHeader()); - return returnOrError(() -> this.handleRangeAddressResolutionFailure(request, collectionCacheIsUpToDate, routingMapCacheIsUpToDate, routingMap)); - } - - Single addressesObs = this.addressCache.tryGetAddresses( - request, - new PartitionKeyRangeIdentity(collection.getResourceId(), request.getPartitionKeyRangeIdentity().getPartitionKeyRangeId()), - forceRefreshPartitionAddresses); - - return addressesObs.flatMap(addresses -> { - - if (addresses == null) { - logger.debug("Cannot resolve addresses for range '{}'", request.getPartitionKeyRangeIdentity().toHeader()); - - try { - return Single.just(this.handleRangeAddressResolutionFailure(request, collectionCacheIsUpToDate, routingMapCacheIsUpToDate, routingMap)); - } catch (DocumentClientException e) { - return Single.error(e); - } - } - - return Single.just(new ResolutionResult(partitionKeyRange, addresses)); - }); - } - - private PartitionKeyRange tryResolveServerPartitionByPartitionKey( - RxDocumentServiceRequest request, - String partitionKeyString, - boolean collectionCacheUptoDate, - DocumentCollection collection, - CollectionRoutingMap routingMap) throws DocumentClientException { - if (request == null) { - throw new NullPointerException("request"); - } - - if (partitionKeyString == null) { - throw new NullPointerException("partitionKeyString"); - } - - if (collection == null) { - throw new NullPointerException("collection"); - } - - if (routingMap == null) { - throw new NullPointerException("routingMap"); - } - - PartitionKeyInternal partitionKey; - - try { - partitionKey = PartitionKeyInternal.fromJsonString(partitionKeyString); - } catch (Exception ex) { - throw BridgeInternal.setResourceAddress(new BadRequestException( - String.format(RMResources.InvalidPartitionKey, partitionKeyString), - ex), request.getResourceAddress()); - } - - if (partitionKey == null) { - throw new InternalServerErrorException(String.format("partition key is null '%s'", partitionKeyString)); - } - - if (partitionKey.getComponents().size() == collection.getPartitionKey().getPaths().size()) { - // Although we can compute effective partition key here, in general case this Gateway can have outdated - // partition key definition cached - like if collection with same name but with Range partitioning is created. - // In this case server will not pass x-ms-documentdb-collection-rid check and will return back InvalidPartitionException. - // Gateway will refresh its cache and retry. - String effectivePartitionKey = PartitionKeyInternalHelper.getEffectivePartitionKeyString(partitionKey, collection.getPartitionKey()); - - // There should be exactly one range which contains a partition key. Always. - return routingMap.getRangeByEffectivePartitionKey(effectivePartitionKey); - } - - if (collectionCacheUptoDate) { - BadRequestException badRequestException = BridgeInternal.setResourceAddress(new BadRequestException(RMResources.PartitionKeyMismatch), request.getResourceAddress()); - badRequestException.getResponseHeaders().put(WFConstants.BackendHeaders.SUB_STATUS, Integer.toString(HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH)); - - throw badRequestException; - } - - // Partition key supplied has different number paths than locally cached partition key definition. - // Three things can happen: - // 1. User supplied wrong partition key. - // 2. Client SDK has outdated partition key definition cache and extracted wrong value from the document. - // 3. Gateway's cache is outdated. - // - // What we will do is append x-ms-documentdb-collection-rid header and forward it to random collection partition. - // * If collection rid matches, server will send back 400.1001, because it also will not be able to compute - // effective partition key. Gateway will forward this status code to client - client will handle it. - // * If collection rid doesn't match, server will send back InvalidPartiitonException and Gateway will - // refresh name routing cache - this will refresh partition key definition as well, and retry. - - logger.debug( - "Cannot compute effective partition key. Definition has '{}' paths, values supplied has '{}' paths. Will refresh cache and retry.", - collection.getPartitionKey().getPaths().size(), - partitionKey.getComponents().size()); - - return null; - } - - private class ResolutionResult { - public final PartitionKeyRange TargetPartitionKeyRange; - public final AddressInformation[] Addresses; - - public ResolutionResult( - PartitionKeyRange targetPartitionKeyRange, - AddressInformation[] addresses) { - if (targetPartitionKeyRange == null) { - throw new NullPointerException("targetPartitionKeyRange"); - } - - if (addresses == null) { - throw new NullPointerException("addresses"); - } - - this.TargetPartitionKeyRange = targetPartitionKeyRange; - this.Addresses = addresses; - } - } -} - diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelector.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelector.java deleted file mode 100644 index 24727f7a07a7..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelector.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import rx.Single; - -import java.net.URI; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class AddressSelector { - private final IAddressResolver addressResolver; - private final Protocol protocol; - - public AddressSelector(IAddressResolver addressResolver, Protocol protocol) { - this.addressResolver = addressResolver; - this.protocol = protocol; - } - - public Single> resolveAllUriAsync( - RxDocumentServiceRequest request, - boolean includePrimary, - boolean forceRefresh) { - Single> allReplicaAddressesObs = this.resolveAddressesAsync(request, forceRefresh); - return allReplicaAddressesObs.map(allReplicaAddresses -> allReplicaAddresses.stream().filter(a -> includePrimary || !a.isPrimary()) - .map(a -> HttpUtils.toURI(a.getPhysicalUri())).collect(Collectors.toList())); - } - - public Single resolvePrimaryUriAsync(RxDocumentServiceRequest request, boolean forceAddressRefresh) { - Single> replicaAddressesObs = this.resolveAddressesAsync(request, forceAddressRefresh); - return replicaAddressesObs.flatMap(replicaAddresses -> { - try { - return Single.just(AddressSelector.getPrimaryUri(request, replicaAddresses)); - } catch (Exception e) { - return Single.error(e); - } - }); - } - - public static URI getPrimaryUri(RxDocumentServiceRequest request, List replicaAddresses) throws GoneException { - AddressInformation primaryAddress = null; - - if (request.getDefaultReplicaIndex() != null) { - int defaultReplicaIndex = request.getDefaultReplicaIndex(); - if (defaultReplicaIndex >= 0 && defaultReplicaIndex < replicaAddresses.size()) { - primaryAddress = replicaAddresses.get(defaultReplicaIndex); - } - } else { - primaryAddress = replicaAddresses.stream().filter(address -> address.isPrimary() && !address.getPhysicalUri().contains("[")) - .findAny().orElse(null); - } - - if (primaryAddress == null) { - // Primary endpoint (of the desired protocol) was not found. - throw new GoneException(String.format("The requested resource is no longer available at the server. Returned addresses are {%s}", - String.join(",", replicaAddresses.stream().map(address -> address.getPhysicalUri()).collect(Collectors.toList()))), null); - } - - return HttpUtils.toURI(primaryAddress.getPhysicalUri()); - } - - public Single> resolveAddressesAsync(RxDocumentServiceRequest request, boolean forceAddressRefresh) { - Single> resolvedAddressesObs = - (this.addressResolver.resolveAsync(request, forceAddressRefresh)) - .map(addresses -> Arrays.stream(addresses) - .filter(address -> { - return !Strings.isNullOrEmpty(address.getPhysicalUri()) && Strings.areEqualIgnoreCase(address.getProtocolScheme(), this.protocol.scheme()); - }) - .collect(Collectors.toList())); - - return resolvedAddressesObs.map( - resolvedAddresses -> { - List r = resolvedAddresses.stream().filter(address -> !address.isPublic()).collect(Collectors.toList()); - if (r.size() > 0) { - return r; - } else { - return resolvedAddresses.stream().filter(address -> address.isPublic()).collect(Collectors.toList()); - } - } - ); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/BarrierRequestHelper.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/BarrierRequestHelper.java deleted file mode 100644 index dabfb9d2c96e..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/BarrierRequestHelper.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.ResourceId; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.rx.internal.AuthorizationTokenType; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.apache.commons.lang3.NotImplementedException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; -import rx.exceptions.Exceptions; - -import java.util.Map; - -public class BarrierRequestHelper { - private final static Logger logger = LoggerFactory.getLogger(BarrierRequestHelper.class); - - public static Single createAsync( - RxDocumentServiceRequest request, - IAuthorizationTokenProvider authorizationTokenProvider, - Long targetLsn, - Long targetGlobalCommittedLsn) { - - boolean isCollectionHeadRequest = BarrierRequestHelper.isCollectionHeadBarrierRequest( - request.getResourceType(), - request.getOperationType()); - - AuthorizationTokenType originalRequestTokenType = request.authorizationTokenType; - - if (originalRequestTokenType == AuthorizationTokenType.Invalid) { - String message = "AuthorizationTokenType not set for the read request"; - assert false : message; - logger.error(message); - } - - String authorizationToken = Strings.Emtpy; - RxDocumentServiceRequest barrierLsnRequest = null; - if (!isCollectionHeadRequest) { - // DB Feed - barrierLsnRequest = RxDocumentServiceRequest.create( - OperationType.HeadFeed, - (String) null, - (ResourceType) ResourceType.Database, - (Map) null); - } else if (request.getIsNameBased()) { - // Name based server request - - // get the collection full name - // dbs/{id}/colls/{collid}/ - String collectionLink = PathsHelper.getCollectionPath(request.getResourceAddress()); - barrierLsnRequest = RxDocumentServiceRequest.createFromName( - OperationType.Head, - collectionLink, - ResourceType.DocumentCollection); - } else { - // RID based Server request - barrierLsnRequest = RxDocumentServiceRequest.create( - OperationType.Head, - ResourceId.parse(request.getResourceId()).getDocumentCollectionId().toString(), - ResourceType.DocumentCollection, null); - } - - barrierLsnRequest.getHeaders().put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); - - if (targetLsn != null && targetLsn > 0) { - barrierLsnRequest.getHeaders().put(HttpConstants.HttpHeaders.TARGET_LSN, targetLsn.toString()); - } - - if (targetGlobalCommittedLsn != null && targetGlobalCommittedLsn > 0) { - barrierLsnRequest.getHeaders().put(HttpConstants.HttpHeaders.TARGET_GLOBAL_COMMITTED_LSN, targetGlobalCommittedLsn.toString()); - } - - switch (originalRequestTokenType) { - case PrimaryMasterKey: - case PrimaryReadonlyMasterKey: - case SecondaryMasterKey: - case SecondaryReadonlyMasterKey: - authorizationToken = authorizationTokenProvider.getUserAuthorizationToken( - barrierLsnRequest.getResourceAddress(), - isCollectionHeadRequest ? ResourceType.DocumentCollection : ResourceType.Database, - HttpConstants.HttpMethods.HEAD, - barrierLsnRequest.getHeaders(), - originalRequestTokenType, - request.properties); - break; - - - case ResourceToken: - authorizationToken = request.getHeaders().get(HttpConstants.HttpHeaders.AUTHORIZATION); - break; - - default: - String unknownAuthToken = "Unknown authorization token kind for read request"; - assert false : unknownAuthToken; - logger.error(unknownAuthToken); - Exceptions.propagate(new InternalServerErrorException(RMResources.InternalServerError)); - } - - barrierLsnRequest.getHeaders().put(HttpConstants.HttpHeaders.AUTHORIZATION, authorizationToken); - barrierLsnRequest.requestContext = request.requestContext.clone(); - - if (request.getPartitionKeyRangeIdentity() != null) { - barrierLsnRequest.routeTo(request.getPartitionKeyRangeIdentity()); - } - if (request.getHeaders().get(HttpConstants.HttpHeaders.PARTITION_KEY) != null) { - barrierLsnRequest.getHeaders().put(HttpConstants.HttpHeaders.PARTITION_KEY, request.getHeaders().get(HttpConstants.HttpHeaders.PARTITION_KEY)); - } - if (request.getHeaders().get(WFConstants.BackendHeaders.COLLECTION_RID) != null) { - barrierLsnRequest.getHeaders().put(WFConstants.BackendHeaders.COLLECTION_RID, request.getHeaders().get(WFConstants.BackendHeaders.COLLECTION_RID)); - } - - return Single.just(barrierLsnRequest); - } - - static boolean isCollectionHeadBarrierRequest(ResourceType resourceType, OperationType operationType) { - switch (resourceType) { - case Attachment: - case Document: - case Conflict: - case StoredProcedure: - case UserDefinedFunction: - case Trigger: - return true; - case DocumentCollection: - if (operationType != OperationType.ReadFeed && operationType != OperationType.Query && operationType != OperationType.SqlQuery) { - return true; - } else { - return false; - } - case PartitionKeyRange: - // no logic for OperationType.GetSplitPoint and OperationType.AbortSplit - // as they are not applicable to SDK - return false; - default: - return false; - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConflictException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConflictException.java deleted file mode 100644 index 58f7e39d3c72..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConflictException.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class ConflictException extends DocumentClientException { - - private static final long serialVersionUID = 1L; - - public ConflictException() { - this(RMResources.EntityAlreadyExists); - } - - public ConflictException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.CONFLICT, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public ConflictException(String msg) { - super(HttpConstants.StatusCodes.CONFLICT, msg); - } - - public ConflictException(String msg, String resourceAddress) { - super(msg, null, null, HttpConstants.StatusCodes.CONFLICT, resourceAddress); - } - - public ConflictException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public ConflictException(Exception innerException) { - this(RMResources.EntityAlreadyExists, innerException, null, null); - } - - public ConflictException(Error error, Map headers) { - super(HttpConstants.StatusCodes.CONFLICT, error, headers); - } - - public ConflictException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.EntityAlreadyExists, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.CONFLICT, - requestUri); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReader.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReader.java deleted file mode 100644 index ab132ebbafbd..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReader.java +++ /dev/null @@ -1,439 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import java.util.HashMap; -import java.util.List; - -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; - -/* - ConsistencyLevel Replication Mode Desired ReadMode - ------------------- -------------------- --------------------------------------------------------------------------- - Strong Synchronous Read from Read Quorum - Asynchronous Not supported - - Bounded Staleness Synchronous Read from Read Quorum - Asynchronous Read from Read Quorum. Performing read barrier on Primary is unsupported. - - Session Sync/Async Read Any (With LSN Cookie) - Default to Primary as last resort (which should succeed always) - - Eventual Sync/Async Read Any - - Client does validation of unsupported combinations. - - - Preliminaries - ============= - 1. We do primary copy/single master replication. - 2. We do sync or async replication depending on the value of DefaultConsistencyLevel on a database account. - If the database account is configured with DefaultConsistencyLevel = Strong, we do sync replication. By default, for all other values of DefaultConsistencyLevel, we do asynchronous replication. - - Replica set - =========== - We define N as the current number of replicas protecting a partition. - At any given point, the value of N can fluctuate between NMax and NMin. - NMax is called the target replica set size and NMin is called the minimum write availability set size. - NMin and NMax are statically defined whereas N is dynamic. - Dynamic replica set is great for dealing with successive failures. - Since N fluctuates between NMax and NMin, the value of N at the time of calculation of W may not be the same when R is calculated. - This is a side effect of dynamic quorum and requires careful consideration. - - NMin = 2, NMax >= 3 - - Simultaneous Failures - ===================== - In general N replicas imply 2f+1 simultaneous failures - N = 5 allows for 2 simultaneous failures - N = 4 allows for 1 failure - N = 3 allows for 1 failure - N < 3 allows for 0 failures - - Quorums - ======= - W = Write Quorum = Number of replicas which acknowledge a write before the primary can ack the client. It is majority set i.e. N/2 + 1 - R = Read Quorum = Set of replicas such that there is non-empty intersection between W and R that constitute N i.e. R = N -W + 1 - - For sync replication, W is used as a majority quorum. - For async replication, W = 1. We have two LSNs, one is quorum acknowledged LSN (LSN-Q) and another is what is visible to the client (LSN-C). - LSN-Q is the stable LSN which corresponds to the write quorum of Windows Fabric. LSN-C is unstable and corresponds to W=1. - - Assumptions - =========== - Nmin <= N <= Nmax - W >= N/2 + 1 - R = N -W + 1 - - N from read standpoint means number of address from BE which is returning successful response. - Successful reponse: Any BE response containing LSN response header is considered successful reponse. Typically every response other than 410 is treated as succesful response. - - Strong Consistency - ================== - Strong Read requires following guarantees. - * Read value is the latest that has been written. If a write operation finished. Any subsequent reads should see that value. - * Monotonic guarantee. Any read that starts after a previous read operation, should see atleast return equal or higher version of the value. - - To perform strong read we require that atleast R i.e. Read Quorum number of replicas have the value committed. To acheve that such read : - * Read R replicas. If they have the same LSN, use the read result - * If they don't have the same LSN, we will either return the result with the highest LSN observed from those R replicas, after ensuring that LSN - becomes available with R replicas. - * Secondary replicas are always preferred for reading. If R secondaries have returned the result but cannot agree on the resulting LSN, we can include Primary to satisfy read quorum. - * If we only have R replicas (i.e. N==R), we include primary in reading the result and validate N==R. - - Bounded Staleness - ================= - Sync Replication: - Bounded staleness uses the same logic as Strong for cases where the server is using sync replication. - - Async Replication: - For async replication, we make sure that we do not use the Primary as barrier for read quorum. This is because Primary is always going to run ahead (async replication uses W=1 on Primary). - Using primary would voilate the monotonic read guarantees when we fall back to reading from secondary in the subsequent reads as they are always running slower as compared to Primary. - - Session - ======= - We read from secondaries one by one until we find a match for the client's session token (LSN-C). - We go to primary as a last resort which should satisfy LSN-C. - - Availability for Bounded Staleness (for NMax = 4 and NMin = 2): - When there is a partition, the minority quorum can remain available for read as long as N >= 1 - When there is a partition, the minority quorum can remain available for writes as long as N >= 2 - - Eventual - ======== - We can read from any replicas. - - Availability for Bounded Staleness (for NMax = 4 and NMin = 2): - When there is a partition, the minority quorum can remain available for read as long as N >= 1 - When there is a partition, the minority quorum can remain available for writes as long as N >= 2 - - Read Retry logic - ----------------- - For Any NonQuorum Reads(A.K.A ReadAny); AddressCache is refreshed for following condition. - 1) No Secondary Address is found in Address Cache. - 2) Chosen Secondary Returned GoneException/EndpointNotFoundException. - - For Quorum Read address cache is refreshed on following condition. - 1) We found only R secondary where R < RMAX. - 2) We got GoneException/EndpointNotFoundException on all the secondary we contacted. - - */ -/** - * ConsistencyReader has a dependency on both StoreReader and QuorumReader. For Bounded Staleness and Strong Consistency, it uses the Quorum Reader - * to converge on a read from read quorum number of replicas. - * For Session and Eventual Consistency, it directly uses the store reader. - */ -public class ConsistencyReader { - private final static int MAX_NUMBER_OF_SECONDARY_READ_RETRIES = 3; - private final static Logger logger = LoggerFactory.getLogger(ConsistencyReader.class); - - private final AddressSelector addressSelector; - private final GatewayServiceConfigurationReader serviceConfigReader; - private final IAuthorizationTokenProvider authorizationTokenProvider; - private final StoreReader storeReader; - private final QuorumReader quorumReader; - private final Configs configs; - - public ConsistencyReader( - Configs configs, - AddressSelector addressSelector, - ISessionContainer sessionContainer, - TransportClient transportClient, - GatewayServiceConfigurationReader serviceConfigReader, - IAuthorizationTokenProvider authorizationTokenProvider) { - this.configs = configs; - this.addressSelector = addressSelector; - this.serviceConfigReader = serviceConfigReader; - this.authorizationTokenProvider = authorizationTokenProvider; - this.storeReader = createStoreReader(transportClient, addressSelector, sessionContainer); - this.quorumReader = createQuorumReader(transportClient, addressSelector, this.storeReader, serviceConfigReader, authorizationTokenProvider); - } - - public Single readAsync(RxDocumentServiceRequest entity, - TimeoutHelper timeout, - boolean isInRetry, - boolean forceRefresh) { - if (!isInRetry) { - if (timeout.isElapsed()) { - return Single.error(new RequestTimeoutException()); - } - - } else { - if (timeout.isElapsed()) { - return Single.error(new GoneException()); - } - } - - entity.requestContext.timeoutHelper = timeout; - - if (entity.requestContext.requestChargeTracker == null) { - entity.requestContext.requestChargeTracker = new RequestChargeTracker(); - } - - if(entity.requestContext.clientSideRequestStatistics == null) { - entity.requestContext.clientSideRequestStatistics = new ClientSideRequestStatistics(); - } - - entity.requestContext.forceRefreshAddressCache = forceRefresh; - - ValueHolder targetConsistencyLevel = ValueHolder.initialize(null); - ValueHolder useSessionToken = ValueHolder.initialize(null); - ReadMode desiredReadMode; - try { - desiredReadMode = this.deduceReadMode(entity, targetConsistencyLevel, useSessionToken); - } catch (DocumentClientException e) { - return Single.error(e); - } - int maxReplicaCount = this.getMaxReplicaSetSize(entity); - int readQuorumValue = maxReplicaCount - (maxReplicaCount / 2); - - switch (desiredReadMode) { - case Primary: - return this.readPrimaryAsync(entity, useSessionToken.v); - - case Strong: - entity.requestContext.performLocalRefreshOnGoneException = true; - return this.quorumReader.readStrongAsync(entity, readQuorumValue, desiredReadMode); - - case BoundedStaleness: - entity.requestContext.performLocalRefreshOnGoneException = true; - - // for bounded staleness, we are defaulting to read strong for local region reads. - // this can be done since we are always running with majority quorum w = 3 (or 2 during quorum downshift). - // This means that the primary will always be part of the write quorum, and - // therefore can be included for barrier reads. - - // NOTE: this assumes that we are running with SYNC replication (i.e. majority quorum). - // When we run on a minority write quorum(w=2), to ensure monotonic read guarantees - // we always contact two secondary replicas and exclude primary. - // However, this model significantly reduces availability and available throughput for serving reads for bounded staleness during reconfiguration. - // Therefore, to ensure monotonic read guarantee from any replica set we will just use regular quorum read(R=2) since our write quorum is always majority(W=3) - return this.quorumReader.readStrongAsync(entity, readQuorumValue, desiredReadMode); - - case Any: - if (targetConsistencyLevel.v == ConsistencyLevel.Session) { - return this.readSessionAsync(entity, desiredReadMode); - } else { - return this.readAnyAsync(entity, desiredReadMode); - } - - default: - throw new IllegalStateException("invalid operation " + desiredReadMode); - } - } - - private Single readPrimaryAsync(RxDocumentServiceRequest entity, - boolean useSessionToken) { - - Single responseObs = this.storeReader.readPrimaryAsync( - entity, - false /*required valid LSN*/, - useSessionToken); - return responseObs.flatMap(response -> { - try { - return Single.just(response.toResponse()); - } catch (DocumentClientException e) { - // TODO: RxJava1 due to design flaw doesn't allow throwing checked exception - // RxJava2 has fixed this design flaw, - // once we switched to RxJava2 we can get rid of unnecessary catch block - // also we can switch to Observable.map(.) - return Single.error(e); - } - }); - } - - private Single readAnyAsync(RxDocumentServiceRequest entity, - ReadMode readMode) { - Single> responsesObs = this.storeReader.readMultipleReplicaAsync( - entity, - /* includePrimary */ true, - /* replicaCountToRead */ 1, - /* requiresValidLSN*/ false, - /* useSessionToken */ false, - /* readMode */ readMode); - - return responsesObs.flatMap( - responses -> { - if (responses.size() == 0) { - return Single.error(new GoneException(RMResources.Gone)); - } - - try { - return Single.just(responses.get(0).toResponse()); - } catch (DocumentClientException e) { - // TODO: RxJava1 due to design flaw doesn't allow throwing checked exception - // RxJava2 has fixed this design flaw, - // once we switched to RxJava2 we can get rid of unnecessary catch block - // also we can switch to Observable.map(.) - return Single.error(e); - } - } - ); - } - - private Single readSessionAsync(RxDocumentServiceRequest entity, - ReadMode readMode) { - - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - Single> responsesObs = this.storeReader.readMultipleReplicaAsync( - entity, - /* includePrimary */ true, - /* replicaCountToRead */ 1, - /* requiresValidLSN */ true, - /* useSessionToken */ true, - /* readMode */ readMode, - /* checkMinLsn */ true, - /* forceReadAll */ false); - - return responsesObs.flatMap(responses -> { - - if (responses.size() > 0) { - try { - return Single.just(responses.get(0).toResponse(entity.requestContext.requestChargeTracker)); - } catch (NotFoundException notFoundException) { - try { - if (entity.requestContext.sessionToken != null - && responses.get(0).sessionToken != null - && !entity.requestContext.sessionToken.isValid(responses.get(0).sessionToken)) { - logger.warn("Convert to session read exception, request {} Session Lsn {}, responseLSN {}", entity.getResourceAddress(), entity.requestContext.sessionToken.convertToString(), responses.get(0).lsn); - notFoundException.getResponseHeaders().put(WFConstants.BackendHeaders.SUB_STATUS, Integer.toString(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)); - } - return Single.error(notFoundException); - } catch (DocumentClientException e) { - // TODO: RxJava1 due to design flaw doesn't allow throwing checked exception - // so we have to catch and return - // once we move to RxJava2 we can fix this. - return Single.error(e); - } - } catch (DocumentClientException dce) { - // TODO: RxJava1 due to design flaw doesn't allow throwing checked exception - // so we have to catch and return - // once we move to RxJava2 we can fix this. - return Single.error(dce); - } - - } - - // else - HashMap responseHeaders = new HashMap<>(); - responseHeaders.put(WFConstants.BackendHeaders.SUB_STATUS, Integer.toString(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)); - ISessionToken requestSessionToken = entity.requestContext.sessionToken; - logger.warn("Fail the session read {}, request session token {}", entity.getResourceAddress(), requestSessionToken == null ? "" : requestSessionToken.convertToString()); - return Single.error(new NotFoundException(RMResources.ReadSessionNotAvailable, responseHeaders, null)); - }); - } - - ReadMode deduceReadMode(RxDocumentServiceRequest request, - ValueHolder targetConsistencyLevel, - ValueHolder useSessionToken) throws DocumentClientException { - targetConsistencyLevel.v = RequestHelper.GetConsistencyLevelToUse(this.serviceConfigReader, request); - useSessionToken.v = (targetConsistencyLevel.v == ConsistencyLevel.Session); - - if (request.getDefaultReplicaIndex() != null) { - // Don't use session token - this is used by internal scenarios which technically don't intend session read when they target - // request to specific replica. - useSessionToken.v = false; - return ReadMode.Primary; //Let the addressResolver decides which replica to connect to. - } - - switch (targetConsistencyLevel.v) { - case Eventual: - return ReadMode.Any; - - case ConsistentPrefix: - return ReadMode.Any; - - case Session: - return ReadMode.Any; - - case BoundedStaleness: - return ReadMode.BoundedStaleness; - - case Strong: - return ReadMode.Strong; - - default: - throw new IllegalStateException("Invalid Consistency Level " + targetConsistencyLevel.v); - } - } - - public int getMaxReplicaSetSize(RxDocumentServiceRequest entity) { - boolean isMasterResource = ReplicatedResourceClient.isReadingFromMaster(entity.getResourceType(), entity.getOperationType()); - if (isMasterResource) { - return this.serviceConfigReader.getSystemReplicationPolicy().getMaxReplicaSetSize(); - } else { - return this.serviceConfigReader.getUserReplicationPolicy().getMaxReplicaSetSize(); - } - } - - public int getMinReplicaSetSize(RxDocumentServiceRequest entity) { - boolean isMasterResource = ReplicatedResourceClient.isReadingFromMaster(entity.getResourceType(), entity.getOperationType()); - if (isMasterResource) { - return this.serviceConfigReader.getSystemReplicationPolicy().getMinReplicaSetSize(); - } else { - return this.serviceConfigReader.getUserReplicationPolicy().getMinReplicaSetSize(); - } - } - - StoreReader createStoreReader(TransportClient transportClient, - AddressSelector addressSelector, - ISessionContainer sessionContainer) { - return new StoreReader(transportClient, - addressSelector, - sessionContainer); - } - - QuorumReader createQuorumReader(TransportClient transportClient, - AddressSelector addressSelector, - StoreReader storeReader, - GatewayServiceConfigurationReader serviceConfigurationReader, - IAuthorizationTokenProvider authorizationTokenProvider) { - return new QuorumReader(transportClient, - addressSelector, - storeReader, - serviceConfigurationReader, - authorizationTokenProvider, - configs); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriter.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriter.java deleted file mode 100644 index 2710724723c0..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriter.java +++ /dev/null @@ -1,396 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.Integers; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.SessionTokenHelper; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.apache.commons.collections4.ComparatorUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Single; -import rx.schedulers.Schedulers; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; - -/* - * ConsistencyWriter has two modes for writing - local quorum-acked write and globally strong write. - * - * The determination of whether a request is a local quorum-acked write or a globally strong write is through several factors: - * 1. Request.RequestContext.OriginalRequestConsistencyLevel - ensure that original request's consistency level, if set, is strong. - * 2. Default consistency level of the accoutn should be strong. - * 3. Number of read regions returned by write response > 0. - * - * For quorum-acked write: - * We send single request to primary of a single partition, which will take care of replicating to its secondaries. Once write quorum number of replicas commits the write, the write request returns to the user with success. There is no additional handling for this case. - * - * For globally strong write: - * Similarly, we send single request to primary of write region, which will take care of replicating to its secondaries, one of which is XPPrimary. XPPrimary will then replicate to all remote regions, which will all ack from within their region. In the write region, the request returns from the backend once write quorum number of replicas commits the write - but at this time, the response cannot be returned to caller, since linearizability guarantees will be violated. ConsistencyWriter will continuously issue barrier head requests against the partition in question, until GlobalCommittedLsn is at least as big as the lsn of the original response. - * 1. Issue write request to write region - * 2. Receive response from primary of write region, look at GlobalCommittedLsn and LSN headers. - * 3. If GlobalCommittedLSN == LSN, return response to caller - * 4. If GlobalCommittedLSN < LSN, cache LSN in request as SelectedGlobalCommittedLSN, and issue barrier requests against any/all replicas. - * 5. Each barrier response will contain its own LSN and GlobalCommittedLSN, check for any response that satisfies GlobalCommittedLSN >= SelectedGlobalCommittedLSN - * 6. Return to caller on success. - */ -public class ConsistencyWriter { - private final static int MAX_NUMBER_OF_WRITE_BARRIER_READ_RETRIES = 30; - private final static int DELAY_BETWEEN_WRITE_BARRIER_CALLS_IN_MS = 30; - private final static int MAX_SHORT_BARRIER_RETRIES_FOR_MULTI_REGION = 4; - private final static int SHORT_BARRIER_RETRY_INTERVAL_IN_MS_FOR_MULTI_REGION = 10; - - private final Logger logger = LoggerFactory.getLogger(ConsistencyWriter.class); - private final TransportClient transportClient; - private final AddressSelector addressSelector; - private final ISessionContainer sessionContainer; - private final IAuthorizationTokenProvider authorizationTokenProvider; - private final boolean useMultipleWriteLocations; - private final GatewayServiceConfigurationReader serviceConfigReader; - private final StoreReader storeReader; - - public ConsistencyWriter( - AddressSelector addressSelector, - ISessionContainer sessionContainer, - TransportClient transportClient, - IAuthorizationTokenProvider authorizationTokenProvider, - GatewayServiceConfigurationReader serviceConfigReader, - boolean useMultipleWriteLocations) { - this.transportClient = transportClient; - this.addressSelector = addressSelector; - this.sessionContainer = sessionContainer; - this.authorizationTokenProvider = authorizationTokenProvider; - this.useMultipleWriteLocations = useMultipleWriteLocations; - this.serviceConfigReader = serviceConfigReader; - this.storeReader = new StoreReader(transportClient, addressSelector, null /*we need store reader only for global strong, no session is needed*/); - } - - public Single writeAsync( - RxDocumentServiceRequest entity, - TimeoutHelper timeout, - boolean forceRefresh) { - - if (timeout.isElapsed()) { - return Single.error(new RequestTimeoutException()); - } - - String sessionToken = entity.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - - return this.writePrivateAsync(entity, timeout, forceRefresh).doOnEach( - arg -> { - try { - SessionTokenHelper.setOriginalSessionToken(entity, sessionToken); - } catch (Throwable throwable) { - logger.error("Unexpected failure in handling orig [{}]: new [{}]", arg, throwable.getMessage(), throwable); - } - } - ); - } - - Single writePrivateAsync( - RxDocumentServiceRequest request, - TimeoutHelper timeout, - boolean forceRefresh) { - if (timeout.isElapsed()) { - return Single.error(new RequestTimeoutException()); - } - - request.requestContext.timeoutHelper = timeout; - - if (request.requestContext.requestChargeTracker == null) { - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - } - - if (request.requestContext.clientSideRequestStatistics == null) { - request.requestContext.clientSideRequestStatistics = new ClientSideRequestStatistics(); - } - - request.requestContext.forceRefreshAddressCache = forceRefresh; - - if (request.requestContext.globalStrongWriteResponse == null) { - - Single> replicaAddressesObs = this.addressSelector.resolveAddressesAsync(request, forceRefresh); - AtomicReference primaryURI = new AtomicReference<>(); - - return replicaAddressesObs.flatMap(replicaAddresses -> { - try { - List contactedReplicas = new ArrayList<>(); - replicaAddresses.forEach(replicaAddress -> contactedReplicas.add(HttpUtils.toURI(replicaAddress.getPhysicalUri()))); - request.requestContext.clientSideRequestStatistics.setContactedReplicas(contactedReplicas); - return Single.just(AddressSelector.getPrimaryUri(request, replicaAddresses)); - } catch (GoneException e) { - // RxJava1 doesn't allow throwing checked exception from Observable operators - return Single.error(e); - } - }).flatMap(primaryUri -> { - try { - primaryURI.set(primaryUri); - if (this.useMultipleWriteLocations && - RequestHelper.GetConsistencyLevelToUse(this.serviceConfigReader, request) == ConsistencyLevel.Session) { - // Set session token to ensure session consistency for write requests - // when writes can be issued to multiple locations - SessionTokenHelper.setPartitionLocalSessionToken(request, this.sessionContainer); - } else { - // When writes can only go to single location, there is no reason - // to session session token to the server. - SessionTokenHelper.validateAndRemoveSessionToken(request); - } - - } catch (Exception e) { - // RxJava1 doesn't allow throwing checked exception from Observable operators - return Single.error(e); - } - - return this.transportClient.invokeResourceOperationAsync(primaryUri, request) - .doOnError( - t -> { - try { - DocumentClientException ex = Utils.as(t, DocumentClientException.class); - try { - request.requestContext.clientSideRequestStatistics.recordResponse(request, - storeReader.createStoreResult(null, ex, false, false, primaryUri)); - } catch (DocumentClientException e) { - logger.error("Error occurred while recording response", e); - } - String value = ex.getResponseHeaders().get(HttpConstants.HttpHeaders.WRITE_REQUEST_TRIGGER_ADDRESS_REFRESH); - if (!Strings.isNullOrWhiteSpace(value)) { - Integer result = Integers.tryParse(value); - if (result != null && result == 1) { - startBackgroundAddressRefresh(request); - } - } - } catch (Throwable throwable) { - logger.error("Unexpected failure in handling orig [{}]", t.getMessage(), t); - logger.error("Unexpected failure in handling orig [{}] : new [{}]", t.getMessage(), throwable.getMessage(), throwable); - } - } - ); - - }).flatMap(response -> { - try { - request.requestContext.clientSideRequestStatistics.recordResponse(request, - storeReader.createStoreResult(response, null, false, false, primaryURI.get())); - } catch (DocumentClientException e) { - logger.error("Error occurred while recording response", e); - } - return barrierForGlobalStrong(request, response); - }); - } else { - - Single barrierRequestObs = BarrierRequestHelper.createAsync(request, this.authorizationTokenProvider, null, request.requestContext.globalCommittedSelectedLSN); - return barrierRequestObs.flatMap(barrierRequest -> { - return waitForWriteBarrierAsync(barrierRequest, request.requestContext.globalCommittedSelectedLSN) - .flatMap(v -> { - - if (!v.booleanValue()) { - logger.warn("ConsistencyWriter: Write barrier has not been met for global strong request. SelectedGlobalCommittedLsn: {}", request.requestContext.globalCommittedSelectedLSN); - return Single.error(new GoneException(RMResources.GlobalStrongWriteBarrierNotMet)); - } - - return Single.just(request); - }); - }).map(req -> req.requestContext.globalStrongWriteResponse); - } - } - - boolean isGlobalStrongRequest(RxDocumentServiceRequest request, StoreResponse response) { - if (this.serviceConfigReader.getDefaultConsistencyLevel() == ConsistencyLevel.Strong) { - int numberOfReadRegions = -1; - String headerValue = null; - if ((headerValue = response.getHeaderValue(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS)) != null) { - numberOfReadRegions = Integer.parseInt(headerValue); - } - - if (numberOfReadRegions > 0 && this.serviceConfigReader.getDefaultConsistencyLevel() == ConsistencyLevel.Strong) { - return true; - } - } - - return false; - } - - Single barrierForGlobalStrong(RxDocumentServiceRequest request, StoreResponse response) { - try { - if (ReplicatedResourceClient.isGlobalStrongEnabled() && this.isGlobalStrongRequest(request, response)) { - Utils.ValueHolder lsn = Utils.ValueHolder.initialize(-1l); - Utils.ValueHolder globalCommittedLsn = Utils.ValueHolder.initialize(-1l); - - getLsnAndGlobalCommittedLsn(response, lsn, globalCommittedLsn); - if (lsn.v == -1 || globalCommittedLsn.v == -1) { - logger.error("ConsistencyWriter: lsn {} or GlobalCommittedLsn {} is not set for global strong request", - lsn, globalCommittedLsn); - throw new GoneException(RMResources.Gone); - } - - request.requestContext.globalStrongWriteResponse = response; - request.requestContext.globalCommittedSelectedLSN = lsn.v; - - //if necessary we would have already refreshed cache by now. - request.requestContext.forceRefreshAddressCache = false; - - logger.debug("ConsistencyWriter: globalCommittedLsn {}, lsn {}", globalCommittedLsn, lsn); - //barrier only if necessary, i.e. when write region completes write, but read regions have not. - - if (globalCommittedLsn.v < lsn.v) { - Single barrierRequestObs = BarrierRequestHelper.createAsync(request, - this.authorizationTokenProvider, - null, - request.requestContext.globalCommittedSelectedLSN); - - return barrierRequestObs.flatMap(barrierRequest -> { - Single barrierWait = this.waitForWriteBarrierAsync(barrierRequest, request.requestContext.globalCommittedSelectedLSN); - - return barrierWait.flatMap(res -> { - if (!res) { - logger.error("ConsistencyWriter: Write barrier has not been met for global strong request. SelectedGlobalCommittedLsn: {}", - request.requestContext.globalCommittedSelectedLSN); - // RxJava1 doesn't allow throwing checked exception - return Single.error(new GoneException(RMResources.GlobalStrongWriteBarrierNotMet)); - } - - return Single.just(request.requestContext.globalStrongWriteResponse); - }); - - }); - - } else { - return Single.just(request.requestContext.globalStrongWriteResponse); - } - } else { - return Single.just(response); - } - - } catch (DocumentClientException e) { - // RxJava1 doesn't allow throwing checked exception from Observable operators - return Single.error(e); - } - } - - private Single waitForWriteBarrierAsync(RxDocumentServiceRequest barrierRequest, long selectedGlobalCommittedLsn) { - AtomicInteger writeBarrierRetryCount = new AtomicInteger(ConsistencyWriter.MAX_NUMBER_OF_WRITE_BARRIER_READ_RETRIES); - AtomicLong maxGlobalCommittedLsnReceived = new AtomicLong(0); - return Observable.defer(() -> { - if (barrierRequest.requestContext.timeoutHelper.isElapsed()) { - return Observable.error(new RequestTimeoutException()); - } - - Single> storeResultListObs = this.storeReader.readMultipleReplicaAsync( - barrierRequest, - true /*allowPrimary*/, - 1 /*any replica with correct globalCommittedLsn is good enough*/, - false /*requiresValidLsn*/, - false /*useSessionToken*/, - ReadMode.Strong, - false /*checkMinLsn*/, - false /*forceReadAll*/); - return storeResultListObs.flatMap( - responses -> { - if (responses != null && responses.stream().anyMatch(response -> response.globalCommittedLSN >= selectedGlobalCommittedLsn)) { - return Single.just(Boolean.TRUE); - } - - //get max global committed lsn from current batch of responses, then update if greater than max of all batches. - long maxGlobalCommittedLsn = (responses != null || !responses.isEmpty()) ? - (Long) responses.stream().map(s -> s.globalCommittedLSN).max(ComparatorUtils.NATURAL_COMPARATOR).get() : - 0l; - maxGlobalCommittedLsnReceived.set(maxGlobalCommittedLsnReceived.get() > maxGlobalCommittedLsn ? - maxGlobalCommittedLsnReceived.get() : maxGlobalCommittedLsn); - - //only refresh on first barrier call, set to false for subsequent attempts. - barrierRequest.requestContext.forceRefreshAddressCache = false; - - //trace on last retry. - if (writeBarrierRetryCount.getAndDecrement() == 0) { - logger.debug("ConsistencyWriter: WaitForWriteBarrierAsync - Last barrier multi-region strong. Responses: {}", - String.join("; ", responses.stream().map(r -> r.toString()).collect(Collectors.toList()))); - } - - return Single.just(null); - }).toObservable(); - }).repeatWhen(s -> { - if (writeBarrierRetryCount.get() == 0) { - return Observable.empty(); - } else { - - if ((ConsistencyWriter.MAX_NUMBER_OF_WRITE_BARRIER_READ_RETRIES - writeBarrierRetryCount.get()) > ConsistencyWriter.MAX_SHORT_BARRIER_RETRIES_FOR_MULTI_REGION) { - return Observable.timer(ConsistencyWriter.DELAY_BETWEEN_WRITE_BARRIER_CALLS_IN_MS, TimeUnit.MILLISECONDS); - } else { - return Observable.timer(ConsistencyWriter.SHORT_BARRIER_RETRY_INTERVAL_IN_MS_FOR_MULTI_REGION, TimeUnit.MILLISECONDS); - } - } - }).take(1) - .map(r -> { - if (r == null) { - // after retries exhausted print this log and return false - logger.debug("ConsistencyWriter: Highest global committed lsn received for write barrier call is {}", maxGlobalCommittedLsnReceived); - - return false; - } - return r; - }).toSingle(); - } - - static void getLsnAndGlobalCommittedLsn(StoreResponse response, Utils.ValueHolder lsn, Utils.ValueHolder globalCommittedLsn) { - lsn.v = -1l; - globalCommittedLsn.v = -1l; - - String headerValue; - - if ((headerValue = response.getHeaderValue(WFConstants.BackendHeaders.LSN)) != null) { - lsn.v = Long.parseLong(headerValue); - } - - if ((headerValue = response.getHeaderValue(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN)) != null) { - globalCommittedLsn.v = Long.parseLong(headerValue); - } - } - - void startBackgroundAddressRefresh(RxDocumentServiceRequest request) { - this.addressSelector.resolvePrimaryUriAsync(request, true) - .observeOn(Schedulers.io()) - .subscribe( - r -> { - }, - e -> logger.warn( - "Background refresh of the primary address failed with {}", e.getMessage(), e) - ); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/CustomHeaders.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/CustomHeaders.java deleted file mode 100644 index 8f3f3f8e7d6b..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/CustomHeaders.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -public final class CustomHeaders { - - public static final class HttpHeaders { - // Specify whether to exclude system properties while storing the document - public static final String EXCLUDE_SYSTEM_PROPERTIES = "x-ms-exclude-system-properties"; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ErrorUtils.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ErrorUtils.java deleted file mode 100644 index 5fdca7819b13..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ErrorUtils.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Single; - -import java.net.URI; - -public class ErrorUtils { - private static final Logger logger = LoggerFactory.getLogger(TransportClient.class); - - protected static Single getErrorResponseAsync(HttpClientResponse responseMessage) { - - if (responseMessage.getContent() == null) { - return Single.just(StringUtils.EMPTY); - } - - return getErrorFromStream(responseMessage.getContent()); - } - - protected static Single getErrorFromStream(Observable stream) { - return ResponseUtils.toString(stream).toSingle(); - } - - protected static void logGoneException(URI physicalAddress, String activityId) { - logger.trace("Listener not found. Store Physical Address {} ActivityId {}", - physicalAddress, activityId); - } - - protected static void logGoneException(String physicalAddress, String activityId) { - logger.trace("Listener not found. Store Physical Address {} ActivityId {}", - physicalAddress, activityId); - } - - protected static void logException(URI physicalAddress, String activityId) { - logger.trace("Store Request Failed. Store Physical Address {} ActivityId {}", - physicalAddress, activityId); - } - - protected static void logException(String physicalAddress, String activityId) { - logger.trace("Store Request Failed. Store Physical Address {} ActivityId {}", - physicalAddress, activityId); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ForbiddenException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ForbiddenException.java deleted file mode 100644 index d74feb5b911a..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ForbiddenException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -public class ForbiddenException extends DocumentClientException { - public ForbiddenException() { - this(RMResources.Forbidden); - } - - public ForbiddenException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.FORBIDDEN, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public ForbiddenException(String message) { - this(message, (Exception) null, (HttpResponseHeaders) null, null); - } - - public ForbiddenException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public ForbiddenException(String message, HttpResponseHeaders headers, URI requestUri) { - this(message, headers, requestUri != null ? requestUri.toString() : null); - } - - public ForbiddenException(Exception innerException) { - this(RMResources.Forbidden, innerException, null, null); - } - - public ForbiddenException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.Forbidden, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.FORBIDDEN, - requestUri != null ? requestUri.toString() : null); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayAddressCache.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayAddressCache.java deleted file mode 100644 index 3e3053fa7841..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayAddressCache.java +++ /dev/null @@ -1,536 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.Paths; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.AuthorizationTokenType; -import com.microsoft.azure.cosmosdb.rx.internal.Exceptions; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.caches.AsyncCache; -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Completable; -import rx.Observable; -import rx.Single; - -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -public class GatewayAddressCache implements IAddressCache { - private final static Logger logger = LoggerFactory.getLogger(GatewayAddressCache.class); - private final static String protocolFilterFormat = "%s eq %s"; - private final static int DefaultBatchSize = 50; - - private final static int DefaultSuboptimalPartitionForceRefreshIntervalInSeconds = 600; - private final ServiceConfig serviceConfig = ServiceConfig.getInstance(); - - private final String databaseFeedEntryUrl = PathsHelper.generatePath(ResourceType.Database, "", true); - private final URL serviceEndpoint; - private final URL addressEndpoint; - - private final AsyncCache serverPartitionAddressCache; - private final ConcurrentHashMap suboptimalServerPartitionTimestamps; - private final long suboptimalPartitionForceRefreshIntervalInSeconds; - - private final String protocolScheme; - private final String protocolFilter; - private final IAuthorizationTokenProvider tokenProvider; - private final HashMap defaultRequestHeaders; - private final CompositeHttpClient httpClient; - - private volatile Pair masterPartitionAddressCache; - private volatile Instant suboptimalMasterPartitionTimestamp; - - public GatewayAddressCache( - URL serviceEndpoint, - Protocol protocol, - IAuthorizationTokenProvider tokenProvider, - UserAgentContainer userAgent, - CompositeHttpClient httpClient, - long suboptimalPartitionForceRefreshIntervalInSeconds) { - try { - this.addressEndpoint = new URL(serviceEndpoint, Paths.ADDRESS_PATH_SEGMENT); - } catch (MalformedURLException e) { - logger.error("serviceEndpoint {} is invalid", serviceEndpoint, e); - assert false; - throw new IllegalStateException(e); - } - this.tokenProvider = tokenProvider; - this.serviceEndpoint = serviceEndpoint; - this.serverPartitionAddressCache = new AsyncCache<>(); - this.suboptimalServerPartitionTimestamps = new ConcurrentHashMap<>(); - this.suboptimalMasterPartitionTimestamp = Instant.MAX; - - this.suboptimalPartitionForceRefreshIntervalInSeconds = suboptimalPartitionForceRefreshIntervalInSeconds; - - this.protocolScheme = protocol.scheme(); - this.protocolFilter = String.format(GatewayAddressCache.protocolFilterFormat, - Constants.Properties.PROTOCOL, - this.protocolScheme); - - this.httpClient = httpClient; - - if (userAgent == null) { - userAgent = new UserAgentContainer(); - } - - defaultRequestHeaders = new HashMap<>(); - defaultRequestHeaders.put(HttpConstants.HttpHeaders.USER_AGENT, userAgent.getUserAgent()); - - // Set requested API version header for version enforcement. - defaultRequestHeaders.put(HttpConstants.HttpHeaders.VERSION, HttpConstants.Versions.CURRENT_VERSION); - } - - public GatewayAddressCache( - URL serviceEndpoint, - Protocol protocol, - IAuthorizationTokenProvider tokenProvider, - UserAgentContainer userAgent, - CompositeHttpClient httpClient) { - this(serviceEndpoint, - protocol, - tokenProvider, - userAgent, - httpClient, - DefaultSuboptimalPartitionForceRefreshIntervalInSeconds); - } - - private URL getServiceEndpoint() { - return this.serviceEndpoint; - } - - @Override - public Single tryGetAddresses(RxDocumentServiceRequest request, - PartitionKeyRangeIdentity partitionKeyRangeIdentity, - boolean forceRefreshPartitionAddresses) { - - com.microsoft.azure.cosmosdb.rx.internal.Utils.checkNotNullOrThrow(request, "request", ""); - com.microsoft.azure.cosmosdb.rx.internal.Utils.checkNotNullOrThrow(partitionKeyRangeIdentity, "partitionKeyRangeIdentity", ""); - - if (StringUtils.equals(partitionKeyRangeIdentity.getPartitionKeyRangeId(), - PartitionKeyRange.MASTER_PARTITION_KEY_RANGE_ID)) { - - // if that's master partition return master partition address! - return this.resolveMasterAsync(request, forceRefreshPartitionAddresses, request.properties).map(r -> r.getRight()); - } - - Instant suboptimalServerPartitionTimestamp = this.suboptimalServerPartitionTimestamps.get(partitionKeyRangeIdentity); - - if (suboptimalServerPartitionTimestamp != null) { - boolean forceRefreshDueToSuboptimalPartitionReplicaSet = Duration.between(suboptimalServerPartitionTimestamp, Instant.now()).getSeconds() - > this.suboptimalPartitionForceRefreshIntervalInSeconds; - - if (forceRefreshDueToSuboptimalPartitionReplicaSet) { - // Compares the existing value for the specified key with a specified value, - // and if they are equal, updates the key with a third value. - Instant newValue = this.suboptimalServerPartitionTimestamps.computeIfPresent(partitionKeyRangeIdentity, - (key, oldVal) -> { - if (suboptimalServerPartitionTimestamp.equals(oldVal)) { - return Instant.MAX; - } else { - return oldVal; - } - }); - - if (!newValue.equals(suboptimalServerPartitionTimestamp)) { - // the value was replaced; - forceRefreshPartitionAddresses = true; - } - } - } - - final boolean forceRefreshPartitionAddressesModified = forceRefreshPartitionAddresses; - - if (forceRefreshPartitionAddressesModified) { - this.serverPartitionAddressCache.refresh( - partitionKeyRangeIdentity, - () -> this.getAddressesForRangeId( - request, - partitionKeyRangeIdentity.getCollectionRid(), - partitionKeyRangeIdentity.getPartitionKeyRangeId(), - true)); - - this.suboptimalServerPartitionTimestamps.remove(partitionKeyRangeIdentity); - } - - Single addressesObs = this.serverPartitionAddressCache.getAsync( - partitionKeyRangeIdentity, - null, - () -> this.getAddressesForRangeId( - request, - partitionKeyRangeIdentity.getCollectionRid(), - partitionKeyRangeIdentity.getPartitionKeyRangeId(), - false)); - - return addressesObs.map( - addresses -> { - if (notAllReplicasAvailable(addresses)) { - this.suboptimalServerPartitionTimestamps.putIfAbsent(partitionKeyRangeIdentity, Instant.now()); - } - - return addresses; - }).onErrorResumeNext(ex -> { - DocumentClientException dce = com.microsoft.azure.cosmosdb.rx.internal.Utils.as(ex, DocumentClientException.class); - if (dce == null) { - if (forceRefreshPartitionAddressesModified) { - this.suboptimalServerPartitionTimestamps.remove(partitionKeyRangeIdentity); - } - return Single.error(ex); - } else { - assert dce != null; - if (Exceptions.isStatusCode(dce, HttpConstants.StatusCodes.NOTFOUND) || - Exceptions.isStatusCode(dce, HttpConstants.StatusCodes.GONE) || - Exceptions.isSubStatusCode(dce, HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE)) { - //remove from suboptimal cache in case the collection+pKeyRangeId combo is gone. - this.suboptimalServerPartitionTimestamps.remove(partitionKeyRangeIdentity); - return null; - } - return Single.error(ex); - } - - }); - } - - Single> getServerAddressesViaGatewayAsync( - RxDocumentServiceRequest request, - String collectionRid, - List partitionKeyRangeIds, - boolean forceRefresh) { - String entryUrl = PathsHelper.generatePath(ResourceType.Document, collectionRid, true); - HashMap addressQuery = new HashMap<>(); - - addressQuery.put(HttpConstants.QueryStrings.URL, HttpUtils.urlEncode(entryUrl)); - - HashMap headers = new HashMap<>(defaultRequestHeaders); - if (forceRefresh) { - headers.put(HttpConstants.HttpHeaders.FORCE_REFRESH, Boolean.TRUE.toString()); - } - - addressQuery.put(HttpConstants.QueryStrings.FILTER, HttpUtils.urlEncode(this.protocolFilter)); - - addressQuery.put(HttpConstants.QueryStrings.PARTITION_KEY_RANGE_IDS, String.join(",", partitionKeyRangeIds)); - headers.put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); - String token = null; - - token = this.tokenProvider.getUserAuthorizationToken( - collectionRid, - ResourceType.Document, - HttpConstants.HttpMethods.GET, - headers, - AuthorizationTokenType.PrimaryMasterKey, - request.properties); - - if (token == null && request.getIsNameBased()) { - // User doesn't have rid based resource token. Maybe user has name based. - String collectionAltLink = PathsHelper.getCollectionPath(request.getResourceAddress()); - token = this.tokenProvider.getUserAuthorizationToken( - collectionAltLink, - ResourceType.Document, - HttpConstants.HttpMethods.GET, - headers, - AuthorizationTokenType.PrimaryMasterKey, - request.properties); - } - - token = HttpUtils.urlEncode(token); - headers.put(HttpConstants.HttpHeaders.AUTHORIZATION, token); - URL targetEndpoint = Utils.setQuery(this.addressEndpoint.toString(), Utils.createQuery(addressQuery)); - String identifier = logAddressResolutionStart(request, targetEndpoint); - HttpClientRequest httpGet = HttpClientRequest.createGet(targetEndpoint.toString()); - - for (Map.Entry entry : headers.entrySet()) { - httpGet.withHeader(entry.getKey(), entry.getValue()); - } - - RxClient.ServerInfo serverInfo = new RxClient.ServerInfo(targetEndpoint.getHost(), targetEndpoint.getPort()); - Observable> responseObs = this.httpClient.submit(serverInfo, httpGet); - - Single dsrObs = responseObs.toSingle().flatMap(rsp -> - HttpClientUtils.parseResponseAsync(rsp)); - return dsrObs.map( - dsr -> { - logAddressResolutionEnd(request, identifier); - List

addresses = dsr.getQueryResponse(Address.class); - return addresses; - }); - } - - public void dispose() { - // TODO We will implement this in future once we will move to httpClient to CompositeHttpClient - //https://msdata.visualstudio.com/CosmosDB/_workitems/edit/340842 - } - - private Single> resolveMasterAsync(RxDocumentServiceRequest request, boolean forceRefresh, Map properties) { - Pair masterAddressAndRangeInitial = this.masterPartitionAddressCache; - - forceRefresh = forceRefresh || - (masterAddressAndRangeInitial != null && - notAllReplicasAvailable(masterAddressAndRangeInitial.getRight()) && - Duration.between(this.suboptimalMasterPartitionTimestamp, Instant.now()).getSeconds() > this.suboptimalPartitionForceRefreshIntervalInSeconds); - - if (forceRefresh || this.masterPartitionAddressCache == null) { - Single> masterReplicaAddressesObs = this.getMasterAddressesViaGatewayAsync( - request, - ResourceType.Database, - null, - databaseFeedEntryUrl, - forceRefresh, - false, - properties); - - return masterReplicaAddressesObs.map( - masterAddresses -> { - Pair masterAddressAndRangeRes = - this.toPartitionAddressAndRange("", masterAddresses); - this.masterPartitionAddressCache = masterAddressAndRangeRes; - - if (notAllReplicasAvailable(masterAddressAndRangeRes.getRight()) - && this.suboptimalMasterPartitionTimestamp.equals(Instant.MAX)) { - this.suboptimalMasterPartitionTimestamp = Instant.now(); - } else { - this.suboptimalMasterPartitionTimestamp = Instant.MAX; - } - - return masterPartitionAddressCache; - }) - .doOnError( - e -> { - this.suboptimalMasterPartitionTimestamp = Instant.MAX; - }); - } else { - if (notAllReplicasAvailable(masterAddressAndRangeInitial.getRight()) - && this.suboptimalMasterPartitionTimestamp.equals(Instant.MAX)) { - this.suboptimalMasterPartitionTimestamp = Instant.now(); - } - - return Single.just(masterAddressAndRangeInitial); - } - } - - private Single getAddressesForRangeId( - RxDocumentServiceRequest request, - String collectionRid, - String partitionKeyRangeId, - boolean forceRefresh) { - Single> addressResponse = this.getServerAddressesViaGatewayAsync(request, collectionRid, Collections.singletonList(partitionKeyRangeId), forceRefresh); - - Single>> addressInfos = - addressResponse.map( - addresses -> - addresses.stream().filter(addressInfo -> - this.protocolScheme.equals(addressInfo.getProtocolScheme())) - .collect(Collectors.groupingBy( - address -> address.getParitionKeyRangeId())) - .values().stream() - .map(groupedAddresses -> toPartitionAddressAndRange(collectionRid, addresses)) - .collect(Collectors.toList())); - - Single>> result = addressInfos.map(addressInfo -> addressInfo.stream() - .filter(a -> - StringUtils.equals(a.getLeft().getPartitionKeyRangeId(), partitionKeyRangeId)) - .collect(Collectors.toList())); - - return result.flatMap( - list -> { - if (list.isEmpty()) { - - String errorMessage = String.format( - RMResources.PartitionKeyRangeNotFound, - partitionKeyRangeId, - collectionRid); - - PartitionKeyRangeGoneException e = new PartitionKeyRangeGoneException(errorMessage); - BridgeInternal.setResourceAddress(e, collectionRid); - - return Single.error(e); - } else { - return Single.just(list.get(0).getRight()); - } - }); - } - - Single> getMasterAddressesViaGatewayAsync( - RxDocumentServiceRequest request, - ResourceType resourceType, - String resourceAddress, - String entryUrl, - boolean forceRefresh, - boolean useMasterCollectionResolver, - Map properties) { - HashMap queryParameters = new HashMap<>(); - queryParameters.put(HttpConstants.QueryStrings.URL, HttpUtils.urlEncode(entryUrl)); - HashMap headers = new HashMap<>(defaultRequestHeaders); - - if (forceRefresh) { - headers.put(HttpConstants.HttpHeaders.FORCE_REFRESH, Boolean.TRUE.toString()); - } - - if (useMasterCollectionResolver) { - headers.put(HttpConstants.HttpHeaders.USE_MASTER_COLLECTION_RESOLVER, Boolean.TRUE.toString()); - } - - queryParameters.put(HttpConstants.QueryStrings.FILTER, HttpUtils.urlEncode(this.protocolFilter)); - headers.put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); - String token = this.tokenProvider.getUserAuthorizationToken( - resourceAddress, - resourceType, - HttpConstants.HttpMethods.GET, - headers, - AuthorizationTokenType.PrimaryMasterKey, - properties); - - headers.put(HttpConstants.HttpHeaders.AUTHORIZATION, HttpUtils.urlEncode(token)); - URL targetEndpoint = Utils.setQuery(this.addressEndpoint.toString(), Utils.createQuery(queryParameters)); - String identifier = logAddressResolutionStart(request, targetEndpoint); - HttpClientRequest httpGet = HttpClientRequest.createGet(targetEndpoint.toString()); - - for (Map.Entry entry : headers.entrySet()) { - httpGet.withHeader(entry.getKey(), entry.getValue()); - } - - RxClient.ServerInfo serverInfo = new RxClient.ServerInfo(targetEndpoint.getHost(), targetEndpoint.getPort()); - Observable> responseObs = this.httpClient.submit(serverInfo, httpGet); - - Single dsrObs = responseObs.toSingle().flatMap(rsp -> - HttpClientUtils.parseResponseAsync(rsp)); - return dsrObs.map( - dsr -> { - logAddressResolutionEnd(request, identifier); - List
addresses = dsr.getQueryResponse(Address.class); - return addresses; - }); - } - - private Pair toPartitionAddressAndRange(String collectionRid, List
addresses) { - Address address = addresses.get(0); - - AddressInformation[] addressInfos = - addresses.stream().map(addr -> - GatewayAddressCache.toAddressInformation(addr) - ).collect(Collectors.toList()).toArray(new AddressInformation[addresses.size()]); - return Pair.of(new PartitionKeyRangeIdentity(collectionRid, address.getParitionKeyRangeId()), addressInfos); - } - - private static AddressInformation toAddressInformation(Address address) { - return new AddressInformation(true, address.IsPrimary(), address.getPhyicalUri(), address.getProtocolScheme()); - } - - public Completable openAsync( - DocumentCollection collection, - List partitionKeyRangeIdentities) { - List>> tasks = new ArrayList<>(); - int batchSize = GatewayAddressCache.DefaultBatchSize; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create( - OperationType.Read, - // collection.AltLink, - collection.getResourceId(), - ResourceType.DocumentCollection, - // AuthorizationTokenType.PrimaryMasterKey - Collections.EMPTY_MAP); - for (int i = 0; i < partitionKeyRangeIdentities.size(); i += batchSize) { - - int endIndex = i + batchSize; - endIndex = endIndex < partitionKeyRangeIdentities.size() - ? endIndex : partitionKeyRangeIdentities.size(); - - tasks.add(this.getServerAddressesViaGatewayAsync( - request, - collection.getResourceId(), - - partitionKeyRangeIdentities.subList(i, endIndex). - stream().map(range -> range.getPartitionKeyRangeId()).collect(Collectors.toList()), - false).toObservable()); - } - - return Observable.concat(tasks) - .doOnNext(list -> { - List> addressInfos = list.stream() - .filter(addressInfo -> this.protocolScheme.equals(addressInfo.getProtocolScheme())) - .collect(Collectors.groupingBy(address -> address.getParitionKeyRangeId())) - .entrySet().stream().map(group -> toPartitionAddressAndRange(collection.getResourceId(), group.getValue())) - .collect(Collectors.toList()); - - for (Pair addressInfo : addressInfos) { - this.serverPartitionAddressCache.set( - new PartitionKeyRangeIdentity(collection.getResourceId(), addressInfo.getLeft().getPartitionKeyRangeId()), - addressInfo.getRight()); - } - }).toCompletable(); - } - - private boolean notAllReplicasAvailable(AddressInformation[] addressInformations) { - return addressInformations.length < this.serviceConfig.userReplicationPolicy.MaxReplicaSetSize; - } - - private static String logAddressResolutionStart(RxDocumentServiceRequest request, URL targetEndpointUrl) { - try { - if (request.requestContext.clientSideRequestStatistics != null) { - return request.requestContext.clientSideRequestStatistics.recordAddressResolutionStart(targetEndpointUrl.toURI()); - } - } catch (URISyntaxException e) { - throw new IllegalArgumentException(e); - } - return null; - } - - private static void logAddressResolutionEnd(RxDocumentServiceRequest request, String identifier) { - if (request.requestContext.clientSideRequestStatistics != null) { - request.requestContext.clientSideRequestStatistics.recordAddressResolutionEnd(identifier); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfigurationReader.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfigurationReader.java deleted file mode 100644 index 8ce4417065d6..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfigurationReader.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.ReplicationPolicy; -import com.microsoft.azure.cosmosdb.internal.BaseAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.rx.internal.GlobalEndpointManager; - -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.http.HttpMethod; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import rx.Observable; -import rx.Single; -import rx.functions.Action1; - -/** - * This class will read the service configuration from the gateway. - * - * As .Net does code sharing between the SDK and GW there are two implementation to IServiceConfigurationReader - * GatewayServiceConfigurationReader which is for SDK - * DatabaseAccountConfigurationReader which is for GW - * Some of the APIs are not relevant in SDK and due to that in .Net the SDK implementation one throws not-implemented. - * - * In java, as we don't do code sharing - * and we got rid of the interface which is not needed and only implemented the methods in GatewayServiceConfigurationReader - */ -public class GatewayServiceConfigurationReader { - - public static final String GATEWAY_READER_NOT_INITIALIZED = "GatewayServiceConfigurationReader has not been initialized"; - - public ReplicationPolicy userReplicationPolicy; - private ReplicationPolicy systemReplicationPolicy; - private ConsistencyLevel consistencyLevel; - private volatile boolean initialized; - private URI serviceEndpoint; - private final ConnectionPolicy connectionPolicy; - private Map queryEngineConfiguration; - private final BaseAuthorizationTokenProvider baseAuthorizationTokenProvider; - private final boolean hasAuthKeyResourceToken; - private final String authKeyResourceToken; - private CompositeHttpClient httpClient; - - public GatewayServiceConfigurationReader(URI serviceEndpoint, boolean hasResourceToken, String resourceToken, - ConnectionPolicy connectionPolicy, BaseAuthorizationTokenProvider baseAuthorizationTokenProvider, - CompositeHttpClient httpClient) { - this.serviceEndpoint = serviceEndpoint; - this.baseAuthorizationTokenProvider = baseAuthorizationTokenProvider; - this.hasAuthKeyResourceToken = hasResourceToken; - this.authKeyResourceToken = resourceToken; - this.connectionPolicy = connectionPolicy; - this.httpClient = httpClient; - } - - public ReplicationPolicy getUserReplicationPolicy() { - this.throwIfNotInitialized(); - return this.userReplicationPolicy; - } - - public ReplicationPolicy getSystemReplicationPolicy() { - this.throwIfNotInitialized(); - return this.systemReplicationPolicy; - } - - public boolean enableAuthorization() { - return true; - } - - public ConsistencyLevel getDefaultConsistencyLevel() { - this.throwIfNotInitialized(); - return this.consistencyLevel; - } - - public void setDefaultConsistencyLevel(ConsistencyLevel value) { - this.throwIfNotInitialized(); - this.consistencyLevel = value; - } - - public Map getQueryEngineConfiguration() { - this.throwIfNotInitialized(); - return this.queryEngineConfiguration; - } - - private Single getDatabaseAccountAsync(URI serviceEndpoint) { - HttpClientRequest httpRequest = HttpClientRequest.create(HttpMethod.GET, - this.serviceEndpoint.toString()); - - httpRequest.withHeader(HttpConstants.HttpHeaders.VERSION, HttpConstants.Versions.CURRENT_VERSION); - - UserAgentContainer userAgentContainer = new UserAgentContainer(); - String userAgentSuffix = this.connectionPolicy.getUserAgentSuffix(); - if (userAgentSuffix != null && userAgentSuffix.length() > 0) { - userAgentContainer.setSuffix(userAgentSuffix); - } - - httpRequest.withHeader(HttpConstants.HttpHeaders.USER_AGENT, userAgentContainer.getUserAgent()); - httpRequest.withHeader(HttpConstants.HttpHeaders.API_TYPE, Constants.Properties.SQL_API_TYPE); - String authorizationToken = StringUtils.EMPTY; - if (this.hasAuthKeyResourceToken || baseAuthorizationTokenProvider == null) { - authorizationToken = HttpUtils.urlEncode(this.authKeyResourceToken); - } else { - // Retrieve the document service properties. - String xDate = Utils.nowAsRFC1123(); - httpRequest.withHeader(HttpConstants.HttpHeaders.X_DATE, xDate); - Map header = new HashMap<>(); - header.put(HttpConstants.HttpHeaders.X_DATE, xDate); - authorizationToken = baseAuthorizationTokenProvider - .generateKeyAuthorizationSignature(HttpConstants.HttpMethods.GET, serviceEndpoint, header); - } - - httpRequest.withHeader(HttpConstants.HttpHeaders.AUTHORIZATION, authorizationToken); - RxClient.ServerInfo serverInfo = new RxClient.ServerInfo(serviceEndpoint.getHost(), serviceEndpoint.getPort()); - - Observable> clientResponseObservable = this.httpClient.submit(serverInfo, - httpRequest); - return toDatabaseAccountObservable(clientResponseObservable.toSingle()); - } - - public Single initializeReaderAsync() { - try { - return GlobalEndpointManager.getDatabaseAccountFromAnyLocationsAsync(this.serviceEndpoint.toURL(), - - new ArrayList<>(this.connectionPolicy.getPreferredLocations()), url -> { - try { - return getDatabaseAccountAsync(url.toURI()); - } catch (URISyntaxException e) { - throw new IllegalArgumentException("URI " + url); - } - }).doOnSuccess(new Action1() { - - @Override - public void call(DatabaseAccount databaseAccount) { - userReplicationPolicy = BridgeInternal.getReplicationPolicy(databaseAccount); - systemReplicationPolicy = BridgeInternal.getSystemReplicationPolicy(databaseAccount); - queryEngineConfiguration = BridgeInternal.getQueryEngineConfiuration(databaseAccount); - consistencyLevel = BridgeInternal.getConsistencyPolicy(databaseAccount).getDefaultConsistencyLevel(); - initialized = true; - } - }); - } catch (MalformedURLException e) { - throw new IllegalArgumentException(this.serviceEndpoint.toString(), e); - } - } - - private Single toDatabaseAccountObservable( - Single> clientResponseObservable) { - return clientResponseObservable.flatMap(clientResponse -> { - return HttpClientUtils.parseResponseAsync(clientResponse) - .map(rxDocumentServiceResponse -> rxDocumentServiceResponse.getResource(DatabaseAccount.class)); - }); - } - - private void throwIfNotInitialized() { - if (!this.initialized) { - throw new IllegalArgumentException(GATEWAY_READER_NOT_INITIALIZED); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneAndRetryWithRetryPolicy.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneAndRetryWithRetryPolicy.java deleted file mode 100644 index 3f519231d16f..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneAndRetryWithRetryPolicy.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import java.time.Duration; - -import org.apache.commons.lang3.time.StopWatch; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.Quadruple; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import rx.Single; - -public class GoneAndRetryWithRetryPolicy implements IRetryPolicy { - - private final static Logger logger = LoggerFactory.getLogger(GoneAndRetryWithRetryPolicy.class); - private final static int DEFAULT_WAIT_TIME_IN_SECONDS = 30; - private final static int MAXIMUM_BACKOFF_TIME_IN_SECONDS = 15; - private final static int INITIAL_BACKOFF_TIME = 1; - private final static int BACK_OFF_MULTIPLIER = 2; - - private final RxDocumentServiceRequest request; - private volatile int attemptCount = 1; - private volatile int attemptCountInvalidPartition = 1; - private volatile int currentBackoffSeconds = GoneAndRetryWithRetryPolicy.INITIAL_BACKOFF_TIME; - private volatile RetryWithException lastRetryWithException; - private final StopWatch durationTimer = new StopWatch(); - private final int waitTimeInSeconds; - //TODO once this is moved to IRetryPolicy, remove from here. - public static Quadruple INITIAL_ARGUMENT_VALUE_POLICY_ARG = Quadruple.with(false, false, - Duration.ofSeconds(60), 0); - - public GoneAndRetryWithRetryPolicy(RxDocumentServiceRequest request, Integer waitTimeInSeconds) { - this.request = request; - startStopWatch(this.durationTimer); - if (waitTimeInSeconds != null) { - this.waitTimeInSeconds = waitTimeInSeconds; - } else { - this.waitTimeInSeconds = DEFAULT_WAIT_TIME_IN_SECONDS; - } - } - - @Override - public Single shouldRetry(Exception exception) { - DocumentClientException exceptionToThrow = null; - Duration backoffTime = Duration.ofSeconds(0); - Duration timeout = Duration.ofSeconds(0); - boolean forceRefreshAddressCache = false; - if (!(exception instanceof GoneException) && - !(exception instanceof RetryWithException) && - !(exception instanceof PartitionIsMigratingException) && - !(exception instanceof InvalidPartitionException && - (this.request.getPartitionKeyRangeIdentity() == null || - this.request.getPartitionKeyRangeIdentity().getCollectionRid() == null)) && - !(exception instanceof PartitionKeyRangeIsSplittingException)) { - logger.debug("Operation will NOT be retried. Current attempt {}, Exception: {} ", this.attemptCount, - exception); - stopStopWatch(this.durationTimer); - return Single.just(ShouldRetryResult.noRetry()); - } else if (exception instanceof RetryWithException) { - this.lastRetryWithException = (RetryWithException) exception; - } - long remainingSeconds = this.waitTimeInSeconds - this.durationTimer.getTime() / 1000; - int currentRetryAttemptCount = this.attemptCount; - if (this.attemptCount++ > 1) { - if (remainingSeconds <= 0) { - if (exception instanceof GoneException) { - if (this.lastRetryWithException != null) { - logger.warn( - "Received gone exception after backoff/retry including at least one RetryWithException. " - + "Will fail the request with RetryWithException. GoneException: {}. RetryWithException: {}", - exception, this.lastRetryWithException); - exceptionToThrow = this.lastRetryWithException; - } else { - logger.warn("Received gone exception after backoff/retry. Will fail the request. {}", - exception.toString()); - exceptionToThrow = new DocumentClientException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, - exception); - } - - } else if (exception instanceof PartitionKeyRangeGoneException) { - if (this.lastRetryWithException != null) { - logger.warn( - "Received partition key range gone exception after backoff/retry including at least one RetryWithException." - + "Will fail the request with RetryWithException. GoneException: {}. RetryWithException: {}", - exception, this.lastRetryWithException); - exceptionToThrow = this.lastRetryWithException; - } else { - logger.warn( - "Received partition key range gone exception after backoff/retry. Will fail the request. {}", - exception.toString()); - exceptionToThrow = new DocumentClientException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, - exception); - } - } else if (exception instanceof InvalidPartitionException) { - if (this.lastRetryWithException != null) { - logger.warn( - "Received InvalidPartitionException after backoff/retry including at least one RetryWithException. " - + "Will fail the request with RetryWithException. InvalidPartitionException: {}. RetryWithException: {}", - exception, this.lastRetryWithException); - } else { - logger.warn( - "Received invalid collection partition exception after backoff/retry. Will fail the request. {}", - exception.toString()); - exceptionToThrow = new DocumentClientException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, - exception); - } - } else { - logger.warn("Received retrywith exception after backoff/retry. Will fail the request. {}", - exception.toString()); - } - stopStopWatch(this.durationTimer); - return Single.just(ShouldRetryResult.error(exceptionToThrow)); - } - backoffTime = Duration.ofSeconds(Math.min(Math.min(this.currentBackoffSeconds, remainingSeconds), - GoneAndRetryWithRetryPolicy.MAXIMUM_BACKOFF_TIME_IN_SECONDS)); - this.currentBackoffSeconds *= GoneAndRetryWithRetryPolicy.BACK_OFF_MULTIPLIER; - logger.info("BackoffTime: {} seconds.", backoffTime.getSeconds()); - } - - // Calculate the remaining time based after accounting for the backoff that we - // will perform - long timeoutInMillSec = remainingSeconds*1000 - backoffTime.toMillis(); - timeout = timeoutInMillSec > 0 ? Duration.ofMillis(timeoutInMillSec) - : Duration.ofSeconds(GoneAndRetryWithRetryPolicy.MAXIMUM_BACKOFF_TIME_IN_SECONDS); - if (exception instanceof GoneException) { - logger.warn("Received gone exception, will retry, {}", exception.toString()); - forceRefreshAddressCache = true; // indicate we are in retry. - } else if (exception instanceof PartitionIsMigratingException) { - logger.warn("Received PartitionIsMigratingException, will retry, {}", exception.toString()); - this.request.forceCollectionRoutingMapRefresh = true; - forceRefreshAddressCache = true; - } else if (exception instanceof InvalidPartitionException) { - this.request.requestContext.quorumSelectedLSN = -1; - this.request.requestContext.resolvedPartitionKeyRange = null; - this.request.requestContext.quorumSelectedStoreResponse = null; - this.request.requestContext.globalCommittedSelectedLSN = -1; - if (this.attemptCountInvalidPartition++ > 2) { - // for second InvalidPartitionException, stop retrying. - logger.warn("Received second InvalidPartitionException after backoff/retry. Will fail the request. {}", - exception.toString()); - return Single.just(ShouldRetryResult - .error(new DocumentClientException(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, exception))); - } - - if (this.request != null) { - logger.warn("Received invalid collection exception, will retry, {}", exception.toString()); - this.request.forceNameCacheRefresh = true; - } else { - logger.error("Received unexpected invalid collection exception, request should be non-null.", - exception); - return Single.just(ShouldRetryResult - .error(new DocumentClientException(HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR, exception))); - } - forceRefreshAddressCache = false; - } else if (exception instanceof PartitionKeyRangeIsSplittingException) { - this.request.requestContext.resolvedPartitionKeyRange = null; - this.request.requestContext.quorumSelectedLSN = -1; - this.request.requestContext.quorumSelectedStoreResponse = null; - logger.info("Received partition key range splitting exception, will retry, {}", exception.toString()); - this.request.forcePartitionKeyRangeRefresh = true; - forceRefreshAddressCache = false; - } else { - logger.warn("Received retrywith exception, will retry, {}", exception); - // For RetryWithException, prevent the caller - // from refreshing any caches. - forceRefreshAddressCache = false; - } - return Single.just(ShouldRetryResult.retryAfter(backoffTime, - Quadruple.with(forceRefreshAddressCache, true, timeout, currentRetryAttemptCount))); - } - - private void stopStopWatch(StopWatch stopwatch) { - synchronized (stopwatch) { - stopwatch.stop(); - } - } - - private void startStopWatch(StopWatch stopwatch) { - synchronized (stopwatch) { - stopwatch.start(); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientUtils.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientUtils.java deleted file mode 100644 index 29e329d17cbd..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientUtils.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import rx.Single; - -public class HttpClientUtils { - - public static Single parseResponseAsync(HttpClientResponse responseMessage) { - - if (responseMessage.getStatus().code() < HttpConstants.StatusCodes.MINIMUM_STATUSCODE_AS_ERROR_GATEWAY) { - - Single storeResponse = ResponseUtils.toStoreResponse(responseMessage); - return storeResponse.map(sr -> new RxDocumentServiceResponse(sr)); - - // TODO: to break the dependency between RxDocumentServiceResponse and StoreResponse - // we should factor out the RxDocumentServiceResponse(StoreResponse) constructor to a helper class - - } else { - return HttpClientUtils.createDocumentClientException(responseMessage).flatMap(e -> Single.error(e)); - } - } - - private static Single createDocumentClientException(HttpClientResponse responseMessage) { - Single readStream = ResponseUtils.toString(responseMessage.getContent()).toSingle(); - - return readStream.map(body -> { - Error error = new Error(body); - - // TODO: we should set resource address in the Document Client Exception - - return new DocumentClientException(responseMessage.getStatus().code(), error, - HttpUtils.asMap(responseMessage.getHeaders())); - }); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpTransportClient.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpTransportClient.java deleted file mode 100644 index 5e7a354480c5..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpTransportClient.java +++ /dev/null @@ -1,986 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.Integers; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.Lists; -import com.microsoft.azure.cosmosdb.internal.Longs; -import com.microsoft.azure.cosmosdb.internal.MutableVolatile; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.RuntimeConstants; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.HttpClientFactory; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import io.reactivex.netty.protocol.http.client.HttpRequestHeaders; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; - -import java.net.URI; -import java.time.Instant; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static com.microsoft.azure.cosmosdb.internal.Utils.trimBeginningAndEndingSlashes; -/* - * The following code only support Document Write without any error handling support. - */ -public class HttpTransportClient extends TransportClient { - private final Logger logger = LoggerFactory.getLogger(HttpTransportClient.class); - private final CompositeHttpClient httpClient; - private final Map defaultHeaders; - private final Configs configs; - - CompositeHttpClient createHttpClient(int requestTimeout) { - // TODO: use one instance of SSL context everywhere - HttpClientFactory httpClientFactory = new HttpClientFactory(this.configs); - httpClientFactory.withRequestTimeoutInMillis(requestTimeout * 1000); - httpClientFactory.withPoolSize(configs.getDirectHttpsMaxConnectionLimit()); - - return httpClientFactory.toHttpClientBuilder().build(); - } - - public HttpTransportClient(Configs configs, int requestTimeout, UserAgentContainer userAgent) { - this.configs = configs; - this.httpClient = createHttpClient(requestTimeout); - - this.defaultHeaders = new HashMap<>(); - - // Set requested API version header for version enforcement. - this.defaultHeaders.put(HttpConstants.HttpHeaders.VERSION, HttpConstants.Versions.CURRENT_VERSION); - this.defaultHeaders.put(HttpConstants.HttpHeaders.CACHE_CONTROL, HttpConstants.HeaderValues.NoCache); - - if (userAgent == null) { - userAgent = new UserAgentContainer(); - } - - this.defaultHeaders.put(HttpConstants.HttpHeaders.USER_AGENT, userAgent.getUserAgent()); - this.defaultHeaders.put(HttpConstants.HttpHeaders.ACCEPT, RuntimeConstants.MediaTypes.JSON); - } - - @Override - public void close() { - httpClient.shutdown(); - } - - public Single invokeStoreAsync( - URI physicalAddress, - ResourceOperation resourceOperation, - RxDocumentServiceRequest request) { - - try { - - // uuid correlation manager - UUID activityId = UUID.fromString(request.getActivityId()); - - if (resourceOperation.operationType == OperationType.Recreate) { - Map errorResponseHeaders = new HashMap<>(); - errorResponseHeaders.put(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE, "1"); - - logger.error("Received Recreate request on Http client"); - throw new InternalServerErrorException(RMResources.InternalServerError, null, errorResponseHeaders, null); - } - - HttpClientRequest httpRequest = prepareHttpMessage(activityId, physicalAddress, resourceOperation, request); - RxClient.ServerInfo serverInfo = new RxClient.ServerInfo(physicalAddress.getHost(), physicalAddress.getPort()); - - MutableVolatile sendTimeUtc = new MutableVolatile<>(); - - Single> responseMessage = this.httpClient.submit(serverInfo, httpRequest).toSingle(); - responseMessage = responseMessage.doOnSubscribe(() -> { - sendTimeUtc.v = Instant.now(); - this.beforeRequest( - activityId, - httpRequest.getUri(), - request.getResourceType(), - httpRequest.getHeaders()); - }); - - responseMessage = responseMessage.onErrorResumeNext(t -> { - - Exception exception = Utils.as(t, Exception.class); - if (exception == null) { - logger.error("critical failure", t); - t.printStackTrace(); - assert false : "critical failure"; - return Single.error(t); - } - - //Trace.CorrelationManager.ActivityId = activityId; - if (WebExceptionUtility.isWebExceptionRetriable(exception)) { - logger.debug("Received retriable exception {} " + - "sending the request to {}, will re-resolve the address " + - "send time UTC: {}", - exception, - physicalAddress, - sendTimeUtc); - - GoneException goneException = new GoneException( - String.format( - RMResources.ExceptionMessage, - RMResources.Gone), - exception, - null, - physicalAddress); - - return Single.error(goneException); - } else if (request.isReadOnlyRequest()) { - logger.trace("Received exception {} on readonly request" + - "sending the request to {}, will reresolve the address " + - "send time UTC: {}", - exception, - physicalAddress, - sendTimeUtc); - - GoneException goneException = new GoneException( - String.format( - RMResources.ExceptionMessage, - RMResources.Gone), - exception, - null, - physicalAddress); - - return Single.error(goneException); - } else { - // We can't throw a GoneException here because it will cause retry and we don't - // know if the request failed before or after the message got sent to the server. - // So in order to avoid duplicating the request we will not retry. - // TODO: a possible solution for this is to add the ability to send a request to the server - // to check if the previous request was received or not and act accordingly. - ServiceUnavailableException serviceUnavailableException = new ServiceUnavailableException( - String.format( - RMResources.ExceptionMessage, - RMResources.ServiceUnavailable), - exception, - null, - physicalAddress.toString()); - serviceUnavailableException.getResponseHeaders().put(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE, "1"); - serviceUnavailableException.getResponseHeaders().put(HttpConstants.HttpHeaders.WRITE_REQUEST_TRIGGER_ADDRESS_REFRESH, "1"); - return Single.error(serviceUnavailableException); - } - }).doOnSuccess(httpClientResponse -> { - Instant receivedTimeUtc = Instant.now(); - double durationInMilliSeconds = (receivedTimeUtc.toEpochMilli() - sendTimeUtc.v.toEpochMilli()); - this.afterRequest( - activityId, - httpClientResponse.getStatus().code() , - durationInMilliSeconds, - httpClientResponse.getHeaders()); - }).doOnError( e -> { - Instant receivedTimeUtc = Instant.now(); - double durationInMilliSeconds = (receivedTimeUtc.toEpochMilli() - sendTimeUtc.v.toEpochMilli()); - this.afterRequest( - activityId, - 0, - durationInMilliSeconds, - null); - }); - - return responseMessage.flatMap(rsp -> processHttpResponse(request.getResourceAddress(), httpRequest, activityId.toString(), rsp, physicalAddress)); - - } catch (Exception e) { - // TODO improve on exception catching - return Single.error(e); - } - } - - private void beforeRequest(UUID activityId, String uri, ResourceType resourceType, HttpRequestHeaders requestHeaders) { - // TODO: perf counters - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/258624 - } - - private void afterRequest(UUID activityId, - int statusCode, - double durationInMilliSeconds, - HttpResponseHeaders responseHeaders) { - // TODO: perf counters - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/258624 - } - - private static void addHeader(HttpRequestHeaders requestHeaders, String headerName, RxDocumentServiceRequest request) { - String headerValue = request.getHeaders().get(headerName); - if (!Strings.isNullOrEmpty(headerValue)) { - requestHeaders.add(headerName, headerValue); - } - } - - private static void addHeader(HttpRequestHeaders requestHeaders, String headerName, String headerValue) { - if (!Strings.isNullOrEmpty(headerValue)) { - requestHeaders.add(headerName, headerValue); - } - } - - private String GetMatch(RxDocumentServiceRequest request, ResourceOperation resourceOperation) { - switch (resourceOperation.operationType) { - case Delete: - case ExecuteJavaScript: - case Replace: - case Update: - case Upsert: - return request.getHeaders().get(HttpConstants.HttpHeaders.IF_MATCH); - - case Read: - case ReadFeed: - return request.getHeaders().get(HttpConstants.HttpHeaders.IF_NONE_MATCH); - - default: - return null; - } - } - - private HttpClientRequest prepareHttpMessage( - UUID activityId, - URI physicalAddress, - ResourceOperation resourceOperation, - RxDocumentServiceRequest request) throws Exception { - - HttpClientRequest httpRequestMessage = null; - URI requestUri; - HttpMethod method; - - // The StreamContent created below will own and dispose its underlying stream, but we may need to reuse the stream on the - // RxDocumentServiceRequest for future requests. Hence we need to clone without incurring copy cost, so that when - // HttpRequestMessage -> StreamContent -> MemoryStream all get disposed, the original stream will be left open. - switch (resourceOperation.operationType) { - case Create: - requestUri = this.getResourceFeedUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.POST; - assert request.getContent() != null; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - httpRequestMessage.withContent(request.getContent()); - break; - - case ExecuteJavaScript: - requestUri = this.getResourceEntryUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.POST; - assert request.getContent() != null; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - httpRequestMessage.withContent(request.getContent()); - break; - - case Delete: - requestUri = this.getResourceEntryUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.DELETE; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - break; - - case Read: - requestUri = this.getResourceEntryUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.GET; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - break; - - case ReadFeed: - requestUri = this.getResourceFeedUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.GET; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - break; - - case Replace: - requestUri = this.getResourceEntryUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.PUT; - assert request.getContent() != null; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - httpRequestMessage.withContent(request.getContent()); - break; - - case Update: - requestUri = this.getResourceEntryUri(resourceOperation.resourceType, physicalAddress, request); - method = new HttpMethod("PATCH"); - assert request.getContent() != null; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - httpRequestMessage.withContent(request.getContent()); - break; - - case Query: - case SqlQuery: - requestUri = this.getResourceFeedUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.POST; - assert request.getContent() != null; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - httpRequestMessage.withContent(request.getContent()); - HttpTransportClient.addHeader(httpRequestMessage.getHeaders(), HttpConstants.HttpHeaders.CONTENT_TYPE, request); - break; - - case Upsert: - requestUri = this.getResourceFeedUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.POST; - assert request.getContent() != null; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - httpRequestMessage.withContent(request.getContent()); - break; - - case Head: - requestUri = this.getResourceEntryUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.HEAD; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - break; - - case HeadFeed: - requestUri = this.getResourceFeedUri(resourceOperation.resourceType, physicalAddress, request); - method = HttpMethod.HEAD; - httpRequestMessage = HttpClientRequest.create(method, requestUri.toString()); - break; - - default: - assert false : "Unsupported operation type"; - throw new IllegalStateException(); - } - - Map documentServiceRequestHeaders = request.getHeaders(); - HttpRequestHeaders httpRequestHeaders = httpRequestMessage.getHeaders(); - - // add default headers - for(Map.Entry entry: defaultHeaders.entrySet()) { - HttpTransportClient.addHeader(httpRequestHeaders, entry.getKey(), entry.getValue()); - } - - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.VERSION, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.USER_AGENT, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.PAGE_SIZE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.PRE_TRIGGER_INCLUDE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.PRE_TRIGGER_EXCLUDE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.POST_TRIGGER_INCLUDE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.POST_TRIGGER_EXCLUDE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.AUTHORIZATION, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.INDEXING_DIRECTIVE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.MIGRATE_COLLECTION_DIRECTIVE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.SESSION_TOKEN, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.PREFER, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.RESOURCE_TOKEN_EXPIRY, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.ENABLE_SCAN_IN_QUERY, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.EMIT_VERBOSE_TRACES_IN_QUERY, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.CAN_CHARGE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.CAN_THROTTLE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.ENABLE_LOW_PRECISION_ORDER_BY, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.ENABLE_LOGGING, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.IS_READ_ONLY_SCRIPT, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.CONTENT_SERIALIZATION_FORMAT, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.CONTINUATION, request.getContinuation()); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.ACTIVITY_ID, activityId.toString()); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.PARTITION_KEY, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.PARTITION_KEY_RANGE_ID, request); - - String dateHeader = HttpUtils.getDateHeader(documentServiceRequestHeaders); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.X_DATE, dateHeader); - HttpTransportClient.addHeader(httpRequestHeaders, "Match", this.GetMatch(request, resourceOperation)); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.IF_MODIFIED_SINCE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.A_IM, request); - if (!request.getIsNameBased()) { - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.RESOURCE_ID, request.getResourceId()); - } - - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.ENTITY_ID, request.entityId); - - String fanoutRequestHeader = request.getHeaders().get(WFConstants.BackendHeaders.IS_FANOUT_REQUEST); - HttpTransportClient.addHeader(httpRequestMessage.getHeaders(), WFConstants.BackendHeaders.IS_FANOUT_REQUEST, fanoutRequestHeader); - - if (request.getResourceType() == ResourceType.DocumentCollection) { - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.COLLECTION_PARTITION_INDEX, documentServiceRequestHeaders.get(WFConstants.BackendHeaders.COLLECTION_PARTITION_INDEX)); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.COLLECTION_SERVICE_INDEX, documentServiceRequestHeaders.get(WFConstants.BackendHeaders.COLLECTION_SERVICE_INDEX)); - } - - if (documentServiceRequestHeaders.get(WFConstants.BackendHeaders.BIND_REPLICA_DIRECTIVE) != null) { - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.BIND_REPLICA_DIRECTIVE, documentServiceRequestHeaders.get(WFConstants.BackendHeaders.BIND_REPLICA_DIRECTIVE)); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.PRIMARY_MASTER_KEY, documentServiceRequestHeaders.get(WFConstants.BackendHeaders.PRIMARY_MASTER_KEY)); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.SECONDARY_MASTER_KEY, documentServiceRequestHeaders.get(WFConstants.BackendHeaders.SECONDARY_MASTER_KEY)); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.PRIMARY_READONLY_KEY, documentServiceRequestHeaders.get(WFConstants.BackendHeaders.PRIMARY_READONLY_KEY)); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.SECONDARY_READONLY_KEY, documentServiceRequestHeaders.get(WFConstants.BackendHeaders.SECONDARY_READONLY_KEY)); - } - - if (documentServiceRequestHeaders.get(HttpConstants.HttpHeaders.CAN_OFFER_REPLACE_COMPLETE) != null) { - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.CAN_OFFER_REPLACE_COMPLETE, documentServiceRequestHeaders.get(HttpConstants.HttpHeaders.CAN_OFFER_REPLACE_COMPLETE)); - } - - //Query - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.IS_QUERY, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.QUERY, request); - - // Upsert - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.IS_UPSERT, request); - - // SupportSpatialLegacyCoordinates - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.SUPPORT_SPATIAL_LEGACY_COORDINATES, request); - - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.PARTITION_COUNT, request); - - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.COLLECTION_RID, request); - - // Filter by schema - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.FILTER_BY_SCHEMA_RESOURCE_ID, request); - - // UsePolygonsSmallerThanAHemisphere - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.USE_POLYGONS_SMALLER_THAN_AHEMISPHERE, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.GATEWAY_SIGNATURE, request); - - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.POPULATE_QUOTA_INFO, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.POPULATE_QUERY_METRICS, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.FORCE_QUERY_SCAN, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB, request); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.REMOTE_STORAGE_TYPE, request); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.SHARE_THROUGHPUT, request); - - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.POPULATE_PARTITION_STATISTICS, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.POPULATE_COLLECTION_THROUGHPUT_INFO, request); - - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.REMAINING_TIME_IN_MS_ON_CLIENT_REQUEST, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.CLIENT_RETRY_ATTEMPT_COUNT, request); - - // target lsn for head requests. - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.TARGET_LSN, request); - HttpTransportClient.addHeader(httpRequestHeaders, HttpConstants.HttpHeaders.TARGET_GLOBAL_COMMITTED_LSN, request); - - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.FEDERATION_ID_FOR_AUTH, request); - - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.FANOUT_OPERATION_STATE, request); - HttpTransportClient.addHeader(httpRequestHeaders, WFConstants.BackendHeaders.ALLOW_TENTATIVE_WRITES, request); - - HttpTransportClient.addHeader(httpRequestHeaders, CustomHeaders.HttpHeaders.EXCLUDE_SYSTEM_PROPERTIES, request); - - return httpRequestMessage; - } - - static URI getResourceFeedUri(ResourceType resourceType, URI physicalAddress, RxDocumentServiceRequest request) throws Exception { - switch (resourceType) { - case Attachment: - return getAttachmentFeedUri(physicalAddress, request); - case DocumentCollection: - return getCollectionFeedUri(physicalAddress, request); - case Conflict: - return getConflictFeedUri(physicalAddress, request); - case Database: - return getDatabaseFeedUri(physicalAddress); - case Document: - return getDocumentFeedUri(physicalAddress, request); - case Permission: - return getPermissionFeedUri(physicalAddress, request); - case StoredProcedure: - return getStoredProcedureFeedUri(physicalAddress, request); - case Trigger: - return getTriggerFeedUri(physicalAddress, request); - case User: - return getUserFeedUri(physicalAddress, request); - - case UserDefinedFunction: - return getUserDefinedFunctionFeedUri(physicalAddress, request); - case Schema: - return getSchemaFeedUri(physicalAddress, request); - case Offer: - return getOfferFeedUri(physicalAddress, request); - -// Other types: Replica, Module, ModuleCommand, Record, UserDefinedType not applicable to SDK. - - default: - assert false : "Unexpected resource type: " + resourceType; - throw new NotFoundException(); - } - } - - static URI getResourceEntryUri(ResourceType resourceType, URI physicalAddress, RxDocumentServiceRequest request) throws Exception { - switch (resourceType) { - case Attachment: - return getAttachmentEntryUri(physicalAddress, request); - case DocumentCollection: - return getCollectionEntryUri(physicalAddress, request); - case Conflict: - return getConflictEntryUri(physicalAddress, request); - case Database: - return getDatabaseEntryUri(physicalAddress, request); - case Document: - return getDocumentEntryUri(physicalAddress, request); - case Permission: - return getPermissionEntryUri(physicalAddress, request); - case StoredProcedure: - return getStoredProcedureEntryUri(physicalAddress, request); - case Trigger: - return getTriggerEntryUri(physicalAddress, request); - case User: - return getUserEntryUri(physicalAddress, request); - case UserDefinedFunction: - return getUserDefinedFunctionEntryUri(physicalAddress, request); - case Schema: - return getSchemaEntryUri(physicalAddress, request); - case Offer: - return getOfferEntryUri(physicalAddress, request); - -// Other types: Replica, Module, ModuleCommand, Record, UserDefinedType not applicable to SDK. - - default: - assert false: "Unexpected resource type: " + resourceType; - throw new IllegalStateException(); - } - } - - static URI createURI(URI baseAddress, String resourcePath) { - return baseAddress.resolve(HttpUtils.urlEncode(trimBeginningAndEndingSlashes(resourcePath))); - } - - static URI getRootFeedUri(URI baseAddress) { - return baseAddress; - } - - static URI getDatabaseFeedUri(URI baseAddress) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Database, StringUtils.EMPTY, true)); - } - - static URI getDatabaseEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Database, request, false)); - } - - static URI getCollectionFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.DocumentCollection, request, true)); - } - - static URI getStoredProcedureFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.StoredProcedure, request, true)); - } - - static URI getTriggerFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Trigger, request, true)); - } - - static URI getUserDefinedFunctionFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.UserDefinedFunction, request, true)); - } - - static URI getCollectionEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.DocumentCollection, request, false)); - } - - static URI getStoredProcedureEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.StoredProcedure, request, false)); - } - - static URI getTriggerEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Trigger, request, false)); - } - - static URI getUserDefinedFunctionEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.UserDefinedFunction, request, false)); - } - - static URI getDocumentFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Document, request, true)); - } - - static URI getDocumentEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Document, request, false)); - } - - static URI getConflictFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Conflict, request, true)); - } - - static URI getConflictEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Conflict, request, false)); - } - - static URI getAttachmentFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Attachment, request, true)); - } - - static URI getAttachmentEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Attachment, request, false)); - } - - static URI getUserFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.User, request, true)); - } - - static URI getUserEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.User, request, false)); - } - - static URI getPermissionFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Permission, request, true)); - } - - static URI getPermissionEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Permission, request, false)); - } - - static URI getOfferFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Offer, request, true)); - } - - - static URI getSchemaFeedUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Schema, request, true)); - } - - static URI getSchemaEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Schema, request, false)); - } - - static URI getOfferEntryUri(URI baseAddress, RxDocumentServiceRequest request) throws Exception { - return createURI(baseAddress, PathsHelper.generatePath(ResourceType.Offer, request, false)); - } - - static String getHeader(String[] names, String[] values, String name) { - for (int idx = 0; idx < names.length; idx++) { - if (Strings.areEqual(names[idx], name)) { - return values[idx]; - } - } - - return null; - } - - private Single processHttpResponse(String resourceAddress, HttpClientRequest request, String activityId, HttpClientResponse response, URI physicalAddress) { - if (response == null) { - InternalServerErrorException exception = - new InternalServerErrorException( - String.format( - RMResources.ExceptionMessage, - RMResources.InvalidBackendResponse), - null, - physicalAddress); - exception.getResponseHeaders().put(HttpConstants.HttpHeaders.ACTIVITY_ID, - activityId); - exception.getResponseHeaders().put(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE, "1"); - - return Single.error(exception); - } - - // If the status code is < 300 or 304 NotModified (we treat not modified as success) then it means that it's a success code and shouldn't throw. - if (response.getStatus().code() < HttpConstants.StatusCodes.MINIMUM_STATUSCODE_AS_ERROR_GATEWAY || - response.getStatus().code() == HttpConstants.StatusCodes.NOT_MODIFIED) { - return HttpTransportClient.createStoreResponseFromHttpResponse(response); - } - else { - return this.createErrorResponseFromHttpResponse(resourceAddress, activityId, request, response); - } - } - - private Single createErrorResponseFromHttpResponse(String resourceAddress, String activityId, - HttpClientRequest request, - HttpClientResponse response) { - HttpResponseStatus statusCode = response.getStatus(); - Single errorMessageObs = ErrorUtils.getErrorResponseAsync(response); - - return errorMessageObs.flatMap( - errorMessage -> { - long responseLSN = -1; - - List lsnValues; - if ((lsnValues = response.getHeaders().getAll(WFConstants.BackendHeaders.LSN)) != null) { - String temp = lsnValues.isEmpty() ? null : lsnValues.get(0); - responseLSN = Longs.tryParse(temp, responseLSN); - } - - String responsePartitionKeyRangeId = null; - List partitionKeyRangeIdValues; - if ((partitionKeyRangeIdValues = response.getHeaders().getAll(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID)) != null) { - responsePartitionKeyRangeId = Lists.firstOrDefault(partitionKeyRangeIdValues, null); - } - - DocumentClientException exception; - - switch (statusCode.code()) { - case HttpConstants.StatusCodes.UNAUTHORIZED: - exception = new UnauthorizedException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.Unauthorized : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.FORBIDDEN: - exception = new ForbiddenException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.Forbidden : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.NOTFOUND: - // HTTP.SYS returns NotFound (404) if the URI - // is not registered. This is really an indication that - // the replica which registered the URI is not - // available at the server. We detect this case by - // the presence of Content-Type header in the response - // and map it to HTTP Gone (410), which is the more - // appropriate response for this case. - if (response.getContent() != null && response.getHeaders() != null && response.getHeaders().get(HttpConstants.HttpHeaders.CONTENT_TYPE) != null && - !Strings.isNullOrEmpty(response.getHeaders().get(HttpConstants.HttpHeaders.CONTENT_TYPE)) && - Strings.containsIgnoreCase(response.getHeaders().get(HttpConstants.HttpHeaders.CONTENT_TYPE), RuntimeConstants.MediaTypes.TEXT_HTML)) { - // Have the request URL in the exception message for debugging purposes. - exception = new GoneException( - String.format( - RMResources.ExceptionMessage, - RMResources.Gone), - request.getUri()); - exception.getResponseHeaders().put(HttpConstants.HttpHeaders.ACTIVITY_ID, - activityId); - - break; - } else { - exception = new NotFoundException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.NotFound : errorMessage), - response.getHeaders(), - request.getUri()); - break; - } - - case HttpConstants.StatusCodes.BADREQUEST: - exception = new BadRequestException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.BadRequest : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.METHOD_NOT_ALLOWED: - exception = new MethodNotAllowedException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.MethodNotAllowed : errorMessage), - null, - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.GONE: { - - // TODO: update perf counter - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/258624 - ErrorUtils.logGoneException(request.getUri(), activityId); - - Integer nSubStatus = 0; - String valueSubStatus = null; - - valueSubStatus = response.getHeaders().get(WFConstants.BackendHeaders.SUB_STATUS); - if (!Strings.isNullOrEmpty(valueSubStatus)) { - if ((nSubStatus = Integers.tryParse(valueSubStatus)) == null) { - exception = new InternalServerErrorException( - String.format( - RMResources.ExceptionMessage, - RMResources.InvalidBackendResponse), - response.getHeaders(), - request.getUri()); - break; - } - } - - if (nSubStatus == HttpConstants.SubStatusCodes.NAME_CACHE_IS_STALE) { - exception = new InvalidPartitionException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.Gone : errorMessage), - response.getHeaders(), - request.getUri()); - break; - } else if (nSubStatus == HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE) { - exception = new PartitionKeyRangeGoneException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.Gone : errorMessage), - response.getHeaders(), - request.getUri()); - break; - } else if (nSubStatus == HttpConstants.SubStatusCodes.COMPLETING_SPLIT) { - exception = new PartitionKeyRangeIsSplittingException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.Gone : errorMessage), - response.getHeaders(), - request.getUri()); - break; - } else if (nSubStatus == HttpConstants.SubStatusCodes.COMPLETING_PARTITION_MIGRATION) { - exception = new PartitionIsMigratingException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.Gone : errorMessage), - response.getHeaders(), - request.getUri()); - break; - } else { - // Have the request URL in the exception message for debugging purposes. - exception = new GoneException( - String.format( - RMResources.ExceptionMessage, - RMResources.Gone), - response.getHeaders(), - request.getUri()); - - exception.getResponseHeaders().put(HttpConstants.HttpHeaders.ACTIVITY_ID, - activityId); - break; - } - } - - case HttpConstants.StatusCodes.CONFLICT: - exception = new ConflictException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.EntityAlreadyExists : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.PRECONDITION_FAILED: - exception = new PreconditionFailedException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.PreconditionFailed : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.REQUEST_ENTITY_TOO_LARGE: - exception = new RequestEntityTooLargeException( - String.format( - RMResources.ExceptionMessage, - String.format( - RMResources.RequestEntityTooLarge, - HttpConstants.HttpHeaders.PAGE_SIZE)), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.LOCKED: - exception = new LockedException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.Locked : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.SERVICE_UNAVAILABLE: - exception = new ServiceUnavailableException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.ServiceUnavailable : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.REQUEST_TIMEOUT: - exception = new RequestTimeoutException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.RequestTimeout : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.RETRY_WITH: - exception = new RetryWithException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.RetryWith : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - case HttpConstants.StatusCodes.TOO_MANY_REQUESTS: - exception = - new RequestRateTooLargeException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.TooManyRequests : errorMessage), - response.getHeaders(), - request.getUri()); - - List values = response.getHeaders().getAll(HttpConstants.HttpHeaders.RETRY_AFTER_IN_MILLISECONDS); - - if (values == null || values.isEmpty()) { - logger.warn("RequestRateTooLargeException being thrown without RetryAfter."); - } else { - exception.getResponseHeaders().put(HttpConstants.HttpHeaders.RETRY_AFTER_IN_MILLISECONDS, values.get(0)); - } - - break; - - case HttpConstants.StatusCodes.INTERNAL_SERVER_ERROR: - exception = new InternalServerErrorException( - String.format( - RMResources.ExceptionMessage, - Strings.isNullOrEmpty(errorMessage) ? RMResources.InternalServerError : errorMessage), - response.getHeaders(), - request.getUri()); - break; - - default: - logger.error("Unrecognized status code {} returned by backend. ActivityId {}", statusCode, activityId); - ErrorUtils.logException(request.getUri(), activityId); - exception = new InternalServerErrorException( - String.format( - RMResources.ExceptionMessage, - RMResources.InvalidBackendResponse), - response.getHeaders(), - request.getUri()); - break; - } - - BridgeInternal.setLSN(exception, responseLSN); - BridgeInternal.setPartitionKeyRangeId(exception, responsePartitionKeyRangeId); - BridgeInternal.setResourceAddress(exception, resourceAddress); - BridgeInternal.setRequestHeaders(exception, HttpUtils.asMap(request.getHeaders())); - - return Single.error(exception); - } - ); - } - - private static Single createStoreResponseFromHttpResponse( - HttpClientResponse responseMessage) { - - Single storeResponse = ResponseUtils.toStoreResponse(responseMessage); - return storeResponse; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IAddressCache.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IAddressCache.java deleted file mode 100644 index 3e53730b86bc..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IAddressCache.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import rx.Single; - -public interface IAddressCache { - - /** - * Resolves physical addresses by either PartitionKeyRangeIdentity. - * - * - * @param request Request is needed only by GatewayAddressCache in the only case when request is name based and user has name based auth token. - * PartitionkeyRangeIdentity can be used to locate auth token in this case. - * @param partitionKeyRangeIdentity target partition key range Id - * @param forceRefreshPartitionAddresses Whether addresses need to be refreshed as previously resolved addresses were determined to be outdated. - * @return Physical addresses. - */ - Single tryGetAddresses( - RxDocumentServiceRequest request, - PartitionKeyRangeIdentity partitionKeyRangeIdentity, - boolean forceRefreshPartitionAddresses); -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IAddressResolver.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IAddressResolver.java deleted file mode 100644 index d2c5dce2dc49..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IAddressResolver.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import rx.Single; - -public interface IAddressResolver { - Single resolveAsync( - RxDocumentServiceRequest request, - boolean forceRefreshPartitionAddresses); -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IStoreClient.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IStoreClient.java deleted file mode 100644 index a9a1c1fffdae..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/IStoreClient.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import rx.Single; -import rx.functions.Func1; - -public interface IStoreClient { - - Single processMessageAsync( - RxDocumentServiceRequest request, - IRetryPolicy retryPolicy, - Func1> prepareRequestAsyncDelegate); - - default Single processMessageAsync( - RxDocumentServiceRequest request, - Func1> prepareRequestAsyncDelegate) { - return processMessageAsync(request, null, prepareRequestAsyncDelegate); - } - - default Single processMessageAsync( - RxDocumentServiceRequest request, - IRetryPolicy retryPolicy) { - return processMessageAsync(request, retryPolicy, null); - } - - default Single processMessageAsync( - RxDocumentServiceRequest request) { - return processMessageAsync(request, null, null); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/LockedException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/LockedException.java deleted file mode 100644 index 1b996af941a3..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/LockedException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class LockedException extends DocumentClientException { - private static final long serialVersionUID = 1L; - - public LockedException() { - this(RMResources.Locked); - } - - public LockedException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.LOCKED, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public LockedException(String msg) { - super(HttpConstants.StatusCodes.LOCKED, msg); - } - - public LockedException(String msg, String resourceAddress) { - super(msg, null, null, HttpConstants.StatusCodes.LOCKED, resourceAddress); - } - - public LockedException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public LockedException(Exception innerException) { - this(RMResources.Locked, innerException, null, null); - } - - public LockedException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.Locked, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.LOCKED, - requestUri); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MethodNotAllowedException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MethodNotAllowedException.java deleted file mode 100644 index 082789ba3eda..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MethodNotAllowedException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -public class MethodNotAllowedException extends DocumentClientException { - public MethodNotAllowedException() { - this(RMResources.MethodNotAllowed); - } - - public MethodNotAllowedException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.METHOD_NOT_ALLOWED, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public MethodNotAllowedException(String message) { - this(message, (Exception) null, (HttpResponseHeaders) null, null); - } - - public MethodNotAllowedException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public MethodNotAllowedException(String message, HttpResponseHeaders headers, URI requestUri) { - this(message, headers, requestUri != null ? requestUri.toString() : null); - } - - public MethodNotAllowedException(Exception innerException) { - this(RMResources.MethodNotAllowed, innerException, null, null); - } - - public MethodNotAllowedException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.MethodNotAllowed, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.METHOD_NOT_ALLOWED, - requestUri != null ? requestUri.toString() : null); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyRangeGoneException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyRangeGoneException.java deleted file mode 100644 index 3a8531316e03..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyRangeGoneException.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import org.apache.commons.collections4.CollectionUtils; - -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -/** - * This exception is thrown when DocumentServiceRequest contains x-ms-documentdb-partitionkeyrangeid - * header and such range id doesn't exist. - *

- * No retries should be made in this case, as either split or merge might have happened and query/readfeed - * must take appropriate actions. - */ -public class PartitionKeyRangeGoneException extends DocumentClientException { - - public PartitionKeyRangeGoneException() { - this(RMResources.Gone); - } - - public PartitionKeyRangeGoneException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.GONE, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - this.setSubstatus(); - } - - public PartitionKeyRangeGoneException(String message) { - this(message, (Exception) null, null, null); - } - - public PartitionKeyRangeGoneException(String message, Exception innerException) { - this(message, innerException, (HttpResponseHeaders) null, null); - } - - public PartitionKeyRangeGoneException(Exception innerException) { - this(RMResources.Gone, innerException, (HttpResponseHeaders) null, null); - } - - - public PartitionKeyRangeGoneException(String message, HttpResponseHeaders headers, String requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.GONE, requestUri); - this.setSubstatus(); - } - - public PartitionKeyRangeGoneException(String message, Exception innerException, HttpResponseHeaders headers, String requestUri) { - super(message, innerException, HttpUtils.asMap(headers), HttpConstants.StatusCodes.GONE, requestUri); - this.setSubstatus(); - } - - private void setSubstatus() { - this.getResponseHeaders().put(WFConstants.BackendHeaders.SUB_STATUS, Integer.toString(HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE)); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PreconditionFailedException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PreconditionFailedException.java deleted file mode 100644 index 400609c86685..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PreconditionFailedException.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class PreconditionFailedException extends DocumentClientException { - - private static final long serialVersionUID = 1L; - - public PreconditionFailedException() { - this(RMResources.PreconditionFailed); - } - - public PreconditionFailedException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.PRECONDITION_FAILED, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public PreconditionFailedException(String msg) { - super(HttpConstants.StatusCodes.PRECONDITION_FAILED, msg); - } - - public PreconditionFailedException(String msg, String resourceAddress) { - super(msg, null, null, HttpConstants.StatusCodes.PRECONDITION_FAILED, resourceAddress); - } - - public PreconditionFailedException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public PreconditionFailedException(Exception innerException) { - this(RMResources.PreconditionFailed, innerException, null, null); - } - - public PreconditionFailedException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.PreconditionFailed, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.PRECONDITION_FAILED, - requestUri); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QueryRequestPerformanceActivity.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QueryRequestPerformanceActivity.java deleted file mode 100644 index 1673bbc60d76..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QueryRequestPerformanceActivity.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -// TODO troubleshooting info -// https://msdata.visualstudio.com/CosmosDB/_workitems/edit/258624 -public class QueryRequestPerformanceActivity { -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QuorumReader.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QuorumReader.java deleted file mode 100644 index 6028328a6875..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QuorumReader.java +++ /dev/null @@ -1,811 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.JavaStreamUtils; -import com.microsoft.azure.cosmosdb.internal.MutableVolatile; -import com.microsoft.azure.cosmosdb.internal.Quadruple; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.apache.commons.lang3.tuple.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Single; - -import java.util.Comparator; -import java.util.List; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Collectors; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -// -//================================================================================================================= -// Strong read logic: -//================================================================================================================= -// -// ------------------- PerformPrimaryRead------------------------------------------------------------- -// | ^ | -// [RetryOnSecondary] | | -// | [QuorumNotSelected] | -// \/ | \/ -// Start-------------------------->SecondaryQuorumRead-------------[QuorumMet]-------------------------------->Result -// | ^ -// [QuorumSelected] | -// | | -// \/ | -// PrimaryReadBarrier------------------------------------------------------------- -// -//================================================================================================================= -// BoundedStaleness quorum read logic: -//================================================================================================================= -// -// ------------------- PerformPrimaryRead------------------------------------------------------------- -// | ^ | -// [RetryOnSecondary] | | -// | [QuorumNotSelected] | -// \/ | \/ -// Start-------------------------->SecondaryQuorumRead-------------[QuorumMet]-------------------------------->Result -// | ^ -// [QuorumSelected] | -// | | -// | | -// --------------------------------------------------------------------------- -// -/** - * QuorumReader wraps the client side quorum logic on top of the StoreReader - */ -public class QuorumReader { - private final static Logger logger = LoggerFactory.getLogger(QuorumReader.class); - - private final int maxNumberOfReadBarrierReadRetries; - private final int maxNumberOfPrimaryReadRetries; - private final int maxNumberOfReadQuorumRetries; - private final int delayBetweenReadBarrierCallsInMs; - - private final int maxBarrierRetriesForMultiRegion; - private final int barrierRetryIntervalInMsForMultiRegion; - - private final int maxShortBarrierRetriesForMultiRegion; - private final int shortBarrierRetryIntervalInMsForMultiRegion; - - private final StoreReader storeReader; - private final GatewayServiceConfigurationReader serviceConfigReader; - private final IAuthorizationTokenProvider authorizationTokenProvider; - - public QuorumReader( - Configs configs, - TransportClient transportClient, - AddressSelector addressSelector, - StoreReader storeReader, - GatewayServiceConfigurationReader serviceConfigReader, - IAuthorizationTokenProvider authorizationTokenProvider) { - this.storeReader = storeReader; - this.serviceConfigReader = serviceConfigReader; - this.authorizationTokenProvider = authorizationTokenProvider; - - this.maxNumberOfReadBarrierReadRetries = configs.getMaxNumberOfReadBarrierReadRetries(); - this.maxNumberOfPrimaryReadRetries = configs.getMaxNumberOfPrimaryReadRetries(); - this.maxNumberOfReadQuorumRetries = configs.getMaxNumberOfReadQuorumRetries(); - this.delayBetweenReadBarrierCallsInMs = configs.getDelayBetweenReadBarrierCallsInMs(); - this.maxBarrierRetriesForMultiRegion = configs.getMaxBarrierRetriesForMultiRegion(); - this.barrierRetryIntervalInMsForMultiRegion = configs.getBarrierRetryIntervalInMsForMultiRegion(); - this.maxShortBarrierRetriesForMultiRegion = configs.getMaxShortBarrierRetriesForMultiRegion(); - this.shortBarrierRetryIntervalInMsForMultiRegion = configs.getShortBarrierRetryIntervalInMsForMultiRegion(); - } - - public QuorumReader( - TransportClient transportClient, - AddressSelector addressSelector, - StoreReader storeReader, - GatewayServiceConfigurationReader serviceConfigReader, - IAuthorizationTokenProvider authorizationTokenProvider, - Configs configs) { - this(configs, transportClient, addressSelector, storeReader, serviceConfigReader, authorizationTokenProvider); - } - - public Single readStrongAsync( - RxDocumentServiceRequest entity, - int readQuorumValue, - ReadMode readMode) { - final MutableVolatile shouldRetryOnSecondary = new MutableVolatile<>(false); - final MutableVolatile hasPerformedReadFromPrimary = new MutableVolatile<>(false); - - return Observable.defer( - // the following will be repeated till the repeat().takeUntil(.) condition is satisfied. - () -> { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Observable.error(new GoneException()); - } - - shouldRetryOnSecondary.v = false; - Single secondaryQuorumReadResultObs = - this.readQuorumAsync(entity, readQuorumValue, false, readMode); - - return secondaryQuorumReadResultObs.toObservable().flatMap( - secondaryQuorumReadResult -> { - - switch (secondaryQuorumReadResult.quorumResult) { - case QuorumMet: - try { - return Observable.just(secondaryQuorumReadResult.getResponse()); - } catch (DocumentClientException e) { - return Observable.error(e); - } - - case QuorumSelected: - Single barrierRequestObs = BarrierRequestHelper.createAsync( - entity, - this.authorizationTokenProvider, - secondaryQuorumReadResult.selectedLsn, - secondaryQuorumReadResult.globalCommittedSelectedLsn); - - return barrierRequestObs.toObservable().flatMap(barrierRequest -> { - Single readBarrierObs = this.waitForReadBarrierAsync( - barrierRequest, - true /* include primary */, - readQuorumValue, - secondaryQuorumReadResult.selectedLsn, - secondaryQuorumReadResult.globalCommittedSelectedLsn, - readMode); - - return readBarrierObs.toObservable().flatMap( - readBarrier -> { - - if (readBarrier) { - try { - return Observable.just(secondaryQuorumReadResult.getResponse()); - } catch (Exception e) { - return Observable.error(e); - } - } - - // else barrier was not successful - logger.warn( - "QuorumSelected: Could not converge on the LSN {} GlobalCommittedLSN {} after primary read barrier with read quorum {} for strong read, Responses: {}", - secondaryQuorumReadResult.selectedLsn, - secondaryQuorumReadResult.globalCommittedSelectedLsn, - readQuorumValue, - String.join(";", secondaryQuorumReadResult.storeResponses) - ); - - entity.requestContext.quorumSelectedStoreResponse = secondaryQuorumReadResult.selectedResponse; - entity.requestContext.storeResponses = secondaryQuorumReadResult.storeResponses; - entity.requestContext.quorumSelectedLSN = secondaryQuorumReadResult.selectedLsn; - entity.requestContext.globalCommittedSelectedLSN = secondaryQuorumReadResult.globalCommittedSelectedLsn; - - return Observable.empty(); - } - ); - }); - - case QuorumNotSelected: - if (hasPerformedReadFromPrimary.v) { - logger.warn("QuorumNotSelected: Primary read already attempted. Quorum could not be selected after retrying on secondaries."); - return Observable.error(new GoneException(RMResources.ReadQuorumNotMet)); - } - - logger.warn("QuorumNotSelected: Quorum could not be selected with read quorum of {}", readQuorumValue); - Single responseObs = this.readPrimaryAsync(entity, readQuorumValue, false); - - return responseObs.toObservable().flatMap( - response -> { - if (response.isSuccessful && response.shouldRetryOnSecondary) { - assert false : "QuorumNotSelected: PrimaryResult has both Successful and shouldRetryOnSecondary flags set"; - logger.error("PrimaryResult has both Successful and shouldRetryOnSecondary flags set"); - } else if (response.isSuccessful) { - logger.debug("QuorumNotSelected: ReadPrimary successful"); - try { - return Observable.just(response.getResponse()); - } catch (DocumentClientException e) { - return Observable.error(e); - } - } else if (response.shouldRetryOnSecondary) { - shouldRetryOnSecondary.v = true; - logger.warn("QuorumNotSelected: ReadPrimary did not succeed. Will retry on secondary."); - hasPerformedReadFromPrimary.v = true; - } else { - logger.warn("QuorumNotSelected: Could not get successful response from ReadPrimary"); - return Observable.error(new GoneException(String.format(RMResources.ReadQuorumNotMet, readQuorumValue))); - } - - return Observable.empty(); - - } - ); - - default: - logger.error("Unknown ReadQuorum result {}", secondaryQuorumReadResult.quorumResult.toString()); - return Observable.error(new InternalServerErrorException(RMResources.InternalServerError)); - } - - }); - }).repeat(maxNumberOfReadQuorumRetries) - .takeUntil(dummy -> !shouldRetryOnSecondary.v) - .concatWith(Observable.defer(() -> { - logger.warn("Could not complete read quorum with read quorum value of {}", readQuorumValue); - - return Observable.error(new GoneException( - String.format( - RMResources.ReadQuorumNotMet, - readQuorumValue))); - })) - .take(1) - .toSingle(); - } - - private Single readQuorumAsync( - RxDocumentServiceRequest entity, - int readQuorum, - boolean includePrimary, - ReadMode readMode) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - return ensureQuorumSelectedStoreResponse(entity, readQuorum, includePrimary, readMode).flatMap( - res -> { - if (res.getLeft() != null) { - // no need for barrier - return Single.just(res.getKey()); - } - - long readLsn = res.getValue().getValue0(); - long globalCommittedLSN = res.getValue().getValue1(); - StoreResult storeResult = res.getValue().getValue2(); - List storeResponses = res.getValue().getValue3(); - - // ReadBarrier required - Single barrierRequestObs = BarrierRequestHelper.createAsync(entity, this.authorizationTokenProvider, readLsn, globalCommittedLSN); - return barrierRequestObs.flatMap( - barrierRequest -> { - Single waitForObs = this.waitForReadBarrierAsync(barrierRequest, false, readQuorum, readLsn, globalCommittedLSN, readMode); - return waitForObs.flatMap( - waitFor -> { - if (!waitFor) { - return Single.just(new ReadQuorumResult( - entity.requestContext.requestChargeTracker, - ReadQuorumResultKind.QuorumSelected, - readLsn, - globalCommittedLSN, - storeResult, - storeResponses)); - } - - return Single.just(new ReadQuorumResult( - entity.requestContext.requestChargeTracker, - ReadQuorumResultKind.QuorumMet, - readLsn, - globalCommittedLSN, - storeResult, - storeResponses)); - } - ); - } - ); - } - ); - } - - private Single>>> ensureQuorumSelectedStoreResponse(RxDocumentServiceRequest entity, int readQuorum, boolean includePrimary, ReadMode readMode) { - - if (entity.requestContext.quorumSelectedStoreResponse == null) { - Single> responseResultObs = this.storeReader.readMultipleReplicaAsync( - entity, includePrimary, readQuorum, true /*required valid LSN*/, false, readMode); - - return responseResultObs.flatMap( - responseResult -> { - List storeResponses = responseResult.stream().map(response -> response.toString()).collect(Collectors.toList()); - int responseCount = (int) responseResult.stream().filter(response -> response.isValid).count(); - if (responseCount < readQuorum) { - return Single.just(Pair.of(new ReadQuorumResult(entity.requestContext.requestChargeTracker, - ReadQuorumResultKind.QuorumNotSelected, - -1, -1, null, storeResponses), null)); - } - - //either request overrides consistency level with strong, or request does not override and account default consistency level is strong - boolean isGlobalStrongReadCandidate = - (ReplicatedResourceClient.isGlobalStrongEnabled() && this.serviceConfigReader.getDefaultConsistencyLevel() == ConsistencyLevel.Strong) && - (entity.requestContext.originalRequestConsistencyLevel == null || entity.requestContext.originalRequestConsistencyLevel == ConsistencyLevel.Strong); - - ValueHolder readLsn = new ValueHolder(-1); - ValueHolder globalCommittedLSN = new ValueHolder(-1); - ValueHolder storeResult = new ValueHolder(null); - - if (this.isQuorumMet( - responseResult, - readQuorum, - false, - isGlobalStrongReadCandidate, - readLsn, - globalCommittedLSN, - storeResult)) { - return Single.just(Pair.of(new ReadQuorumResult( - entity.requestContext.requestChargeTracker, - ReadQuorumResultKind.QuorumMet, - readLsn.v, - globalCommittedLSN.v, - storeResult.v, - storeResponses), null)); - } - - // at this point, if refresh were necessary, we would have refreshed it in ReadMultipleReplicaAsync - // so set to false here to avoid further refrehses for this request. - entity.requestContext.forceRefreshAddressCache = false; - - Quadruple> state = Quadruple.with(readLsn.v, globalCommittedLSN.v, storeResult.v, storeResponses); - return Single.just(Pair.of(null, state)); - } - ); - } else { - - ValueHolder readLsn = ValueHolder.initialize(entity.requestContext.quorumSelectedLSN); - ValueHolder globalCommittedLSN = ValueHolder.initialize(entity.requestContext.globalCommittedSelectedLSN); - ValueHolder storeResult = ValueHolder.initialize(entity.requestContext.quorumSelectedStoreResponse); - List storeResponses = entity.requestContext.storeResponses; - Quadruple> state = Quadruple.with(readLsn.v, globalCommittedLSN.v, storeResult.v, storeResponses); - - return Single.just(Pair.of(null, state)); - } - } - - /** - * Read and get response from Primary - * - * @param entity - * @param readQuorum - * @param useSessionToken - * @return - */ - private Single readPrimaryAsync( - RxDocumentServiceRequest entity, - int readQuorum, - boolean useSessionToken) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - // We would have already refreshed address before reaching here. Avoid performing here. - entity.requestContext.forceRefreshAddressCache = false; - - Single storeResultObs = this.storeReader.readPrimaryAsync( - entity, true /*required valid LSN*/, useSessionToken); - - return storeResultObs.flatMap( - storeResult -> { - if (!storeResult.isValid) { - try { - return Single.error(storeResult.getException()); - } catch (InternalServerErrorException e) { - return Single.error(e); - } - } - - if (storeResult.currentReplicaSetSize <= 0 || storeResult.lsn < 0 || storeResult.quorumAckedLSN < 0) { - String message = String.format( - "Invalid value received from response header. CurrentReplicaSetSize %d, StoreLSN %d, QuorumAckedLSN %d", - storeResult.currentReplicaSetSize, storeResult.lsn, storeResult.quorumAckedLSN); - - // might not be returned if primary is still building the secondary replicas (during churn) - logger.error(message); - - // throw exception instead of returning inconsistent result. - return Single.error(new GoneException(String.format(RMResources.ReadQuorumNotMet, readQuorum))); - - } - - if (storeResult.currentReplicaSetSize > readQuorum) { - logger.warn( - "Unexpected response. Replica Set size is {} which is greater than min value {}", storeResult.currentReplicaSetSize, readQuorum); - return Single.just(new ReadPrimaryResult(entity.requestContext.requestChargeTracker, /*isSuccessful */ false, - /* shouldRetryOnSecondary: */ true, /* response: */ null)); - } - - // To accommodate for store latency, where an LSN may be acked by not persisted in the store, we compare the quorum acked LSN and store LSN. - // In case of sync replication, the store LSN will follow the quorum committed LSN - // In case of async replication (if enabled for bounded staleness), the store LSN can be ahead of the quorum committed LSN if the primary is able write to faster than secondary acks. - // We pick higher of the 2 LSN and wait for the other to reach that LSN. - if (storeResult.lsn != storeResult.quorumAckedLSN) { - logger.warn("Store LSN {} and quorum acked LSN {} don't match", storeResult.lsn, storeResult.quorumAckedLSN); - long higherLsn = storeResult.lsn > storeResult.quorumAckedLSN ? storeResult.lsn : storeResult.quorumAckedLSN; - - Single waitForLsnRequestObs = BarrierRequestHelper.createAsync(entity, this.authorizationTokenProvider, higherLsn, null); - return waitForLsnRequestObs.flatMap( - waitForLsnRequest -> { - Single primaryWaitForLsnResponseObs = this.waitForPrimaryLsnAsync(waitForLsnRequest, higherLsn, readQuorum); - return primaryWaitForLsnResponseObs.map( - primaryWaitForLsnResponse -> { - if (primaryWaitForLsnResponse == PrimaryReadOutcome.QuorumNotMet) { - return new ReadPrimaryResult( - entity.requestContext.requestChargeTracker, /*(isSuccessful: */ false, /* shouldRetryOnSecondary: */ false, /* response: */null); - } else if (primaryWaitForLsnResponse == PrimaryReadOutcome.QuorumInconclusive) { - return new ReadPrimaryResult( - entity.requestContext.requestChargeTracker, /* isSuccessful: */ false, /* shouldRetryOnSecondary: */ - true, /* response: */ null); - } - - return new ReadPrimaryResult( - entity.requestContext.requestChargeTracker, /* isSuccessful: */ true, /* shouldRetryOnSecondary: */ false, /*response: */ storeResult); - } - ); - } - ); - } - - return Single.just(new ReadPrimaryResult( - /* requestChargeTracker: */ entity.requestContext.requestChargeTracker, /* isSuccessful: */ true, /* shouldRetryOnSecondary:*/ false, - /*response: */ storeResult)); - } - ); - } - - private Single waitForPrimaryLsnAsync( - RxDocumentServiceRequest barrierRequest, - long lsnToWaitFor, - int readQuorum) { - - return Observable.defer(() -> { - if (barrierRequest.requestContext.timeoutHelper.isElapsed()) { - return Observable.error(new GoneException()); - } - - // We would have already refreshed address before reaching here. Avoid performing here. - barrierRequest.requestContext.forceRefreshAddressCache = false; - - Single storeResultObs = this.storeReader.readPrimaryAsync(barrierRequest, true /*required valid LSN*/, false); - - return storeResultObs.toObservable().flatMap( - storeResult -> { - if (!storeResult.isValid) { - try { - return Observable.error(storeResult.getException()); - } catch (InternalServerErrorException e) { - return Observable.error(e); - } - } - - if (storeResult.currentReplicaSetSize > readQuorum) { - logger.warn( - "Unexpected response. Replica Set size is {} which is greater than min value {}", storeResult.currentReplicaSetSize, readQuorum); - return Observable.just(PrimaryReadOutcome.QuorumInconclusive); - } - - // Java this will move to the repeat logic - if (storeResult.lsn < lsnToWaitFor || storeResult.quorumAckedLSN < lsnToWaitFor) { - logger.warn( - "Store LSN {} or quorum acked LSN {} are lower than expected LSN {}", storeResult.lsn, storeResult.quorumAckedLSN, lsnToWaitFor); - - return Observable.timer(delayBetweenReadBarrierCallsInMs, TimeUnit.MILLISECONDS).flatMap(dummy -> Observable.empty()); - } - - return Observable.just(PrimaryReadOutcome.QuorumMet); - } - ); - }).repeat(maxNumberOfPrimaryReadRetries) // Loop for store and quorum LSN to match - .defaultIfEmpty(PrimaryReadOutcome.QuorumNotMet) - .first() - .toSingle(); - - } - - private Single waitForReadBarrierAsync( - RxDocumentServiceRequest barrierRequest, - boolean allowPrimary, - final int readQuorum, - final long readBarrierLsn, - final long targetGlobalCommittedLSN, - ReadMode readMode) { - AtomicInteger readBarrierRetryCount = new AtomicInteger(maxNumberOfReadBarrierReadRetries); - AtomicInteger readBarrierRetryCountMultiRegion = new AtomicInteger(maxBarrierRetriesForMultiRegion); - - AtomicLong maxGlobalCommittedLsn = new AtomicLong(0); - - return Observable.defer(() -> { - - if (barrierRequest.requestContext.timeoutHelper.isElapsed()) { - return Observable.error(new GoneException()); - } - - Single> responsesObs = this.storeReader.readMultipleReplicaAsync( - barrierRequest, allowPrimary, readQuorum, - true /*required valid LSN*/, false /*useSessionToken*/, readMode, false /*checkMinLSN*/, true /*forceReadAll*/); - - return responsesObs.toObservable().flatMap( - responses -> { - - long maxGlobalCommittedLsnInResponses = responses.size() > 0 ? responses.stream() - .mapToLong(response -> response.globalCommittedLSN).max().getAsLong() : 0; - - - if ((responses.stream().filter(response -> response.lsn >= readBarrierLsn).count() >= readQuorum) && - (!(targetGlobalCommittedLSN > 0) || maxGlobalCommittedLsnInResponses >= targetGlobalCommittedLSN)) { - return Observable.just(true); - } - - maxGlobalCommittedLsn.set(maxGlobalCommittedLsn.get() > maxGlobalCommittedLsnInResponses ? - maxGlobalCommittedLsn.get() : maxGlobalCommittedLsnInResponses); - - //only refresh on first barrier call, set to false for subsequent attempts. - barrierRequest.requestContext.forceRefreshAddressCache = false; - - if (readBarrierRetryCount.decrementAndGet() == 0) { - logger.debug("QuorumReader: waitForReadBarrierAsync - Last barrier for single-region requests. Responses: {}", - JavaStreamUtils.toString(responses, "; ")); - - // retries exhausted - return Observable.just(false); - - } else { - // delay - //await Task.Delay(QuorumReader.delayBetweenReadBarrierCallsInMs); - return Observable.empty(); - - } - } - ); - }).repeatWhen(obs -> obs.flatMap(aVoid -> { - return Observable.timer(delayBetweenReadBarrierCallsInMs, TimeUnit.MILLISECONDS); - })) - .take(1) // Retry loop - .flatMap(barrierRequestSucceeded -> - Observable.defer(() -> { - - if (barrierRequestSucceeded) { - return Observable.just(true); - } - - // we will go into global strong read barrier mode for global strong requests after regular barrier calls have been exhausted. - if (targetGlobalCommittedLSN > 0) { - return Observable.defer(() -> { - - if (barrierRequest.requestContext.timeoutHelper.isElapsed()) { - return Observable.error(new GoneException()); - } - - Single> responsesObs = this.storeReader.readMultipleReplicaAsync( - barrierRequest, allowPrimary, readQuorum, - true /*required valid LSN*/, false /*useSessionToken*/, readMode, false /*checkMinLSN*/, true /*forceReadAll*/); - - return responsesObs.toObservable().flatMap( - responses -> { - long maxGlobalCommittedLsnInResponses = responses.size() > 0 ? responses.stream() - .mapToLong(response -> response.globalCommittedLSN).max().getAsLong() : 0; - - if ((responses.stream().filter(response -> response.lsn >= readBarrierLsn).count() >= readQuorum) && - maxGlobalCommittedLsnInResponses >= targetGlobalCommittedLSN) { - return Observable.just(true); - } - - maxGlobalCommittedLsn.set(maxGlobalCommittedLsn.get() > maxGlobalCommittedLsnInResponses ? - maxGlobalCommittedLsn.get() : maxGlobalCommittedLsnInResponses); - - //trace on last retry. - if (readBarrierRetryCountMultiRegion.getAndDecrement() == 0) { - logger.debug("QuorumReader: waitForReadBarrierAsync - Last barrier for mult-region strong requests. Responses: {}", - JavaStreamUtils.toString(responses, "; ")); - return Observable.just(false); - } else { - return Observable.empty(); - } - } - ); - - }).repeatWhen(obs -> obs.flatMap(aVoid -> { - - if ((maxBarrierRetriesForMultiRegion - readBarrierRetryCountMultiRegion.get()) > maxShortBarrierRetriesForMultiRegion) { - return Observable.timer(barrierRetryIntervalInMsForMultiRegion, TimeUnit.MILLISECONDS); - } else { - return Observable.timer(shortBarrierRetryIntervalInMsForMultiRegion, TimeUnit.MILLISECONDS); - } - - }) - // stop predicate, simulating while loop - ).take(1); - } - - return Observable.empty(); - })). - concatWith( - Observable.defer(() -> { - logger.debug("QuorumReader: waitForReadBarrierAsync - TargetGlobalCommittedLsn: {}, MaxGlobalCommittedLsn: {}.", targetGlobalCommittedLSN, maxGlobalCommittedLsn); - return Observable.just(false); - }) - ).take(1).toSingle(); - } - - private boolean isQuorumMet( - List readResponses, - int readQuorum, - boolean isPrimaryIncluded, - boolean isGlobalStrongRead, - ValueHolder readLsn, - ValueHolder globalCommittedLSN, - ValueHolder selectedResponse) { - long maxLsn = 0; - long minLsn = Long.MAX_VALUE; - int replicaCountMaxLsn = 0; - List validReadResponses = readResponses.stream().filter(response -> response.isValid).collect(Collectors.toList()); - int validResponsesCount = validReadResponses.size(); - - if (validResponsesCount == 0) { - readLsn.v = 0l; - globalCommittedLSN.v = -1l; - selectedResponse.v = null; - - return false; - } - - assert !validReadResponses.isEmpty(); - long numberOfReadRegions = validReadResponses.stream().map(res -> res.numberOfReadRegions).max(Comparator.naturalOrder()).get(); - boolean checkForGlobalStrong = isGlobalStrongRead && numberOfReadRegions > 0; - - // Pick any R replicas in the response and check if they are at the same LSN - for (StoreResult response : validReadResponses) { - if (response.lsn == maxLsn) { - replicaCountMaxLsn++; - } else if (response.lsn > maxLsn) { - replicaCountMaxLsn = 1; - maxLsn = response.lsn; - } - - if (response.lsn < minLsn) { - minLsn = response.lsn; - } - } - - final long maxLsnFinal = maxLsn; - selectedResponse.v = validReadResponses.stream().filter(s -> s.lsn == maxLsnFinal).findFirst().get(); - - readLsn.v = selectedResponse.v.itemLSN == -1 ? - maxLsn : Math.min(selectedResponse.v.itemLSN, maxLsn); - globalCommittedLSN.v = checkForGlobalStrong ? readLsn.v : -1l; - - long maxGlobalCommittedLSN = validReadResponses.stream().mapToLong(res -> res.globalCommittedLSN).max().getAsLong(); - - logger.debug("QuorumReader: MaxLSN {} ReplicaCountMaxLSN {} bCheckGlobalStrong {} MaxGlobalCommittedLSN {} NumberOfReadRegions {} SelectedResponseItemLSN {}", - maxLsn, replicaCountMaxLsn, checkForGlobalStrong, maxGlobalCommittedLSN, numberOfReadRegions, selectedResponse.v.itemLSN); - - // quorum is met if one of the following conditions are satisfied: - // 1. readLsn is greater than zero - // AND the number of responses that have the same LSN as the selected response is greater than or equal to the read quorum - // AND if applicable, the max GlobalCommittedLSN of all responses is greater than or equal to the lsn of the selected response. - - // 2. if the request is a point-read request, - // AND there are more than one response in the readResponses - // AND the LSN of the returned resource of the selected response is less than or equal to the minimum lsn of the all the responses, - // AND if applicable, the LSN of the returned resource of the selected response is less than or equal to the minimum globalCommittedLsn of all the responses. - // This means that the returned resource is old enough to have been committed by at least all the received responses, - // which should be larger than or equal to the read quorum, which therefore means we have strong consistency. - boolean isQuorumMet = false; - - if ((readLsn.v > 0 && replicaCountMaxLsn >= readQuorum) && - (!checkForGlobalStrong || maxGlobalCommittedLSN >= maxLsn)) { - isQuorumMet = true; - } - - if (!isQuorumMet && validResponsesCount >= readQuorum && selectedResponse.v.itemLSN != -1 && - (minLsn != Long.MAX_VALUE && selectedResponse.v.itemLSN <= minLsn) && - (!checkForGlobalStrong || (selectedResponse.v.itemLSN <= maxGlobalCommittedLSN))) { - isQuorumMet = true; - } - - return isQuorumMet; - } - - private enum ReadQuorumResultKind { - QuorumMet, - QuorumSelected, - QuorumNotSelected - } - - private abstract class ReadResult { - private final StoreResult response; - private final RequestChargeTracker requestChargeTracker; - - protected ReadResult(RequestChargeTracker requestChargeTracker, StoreResult response) { - this.requestChargeTracker = requestChargeTracker; - this.response = response; - } - - public StoreResponse getResponse() throws DocumentClientException { - if (!this.isValidResult()) { - logger.error("getResponse called for invalid result"); - throw new InternalServerErrorException(RMResources.InternalServerError); - } - - return this.response.toResponse(requestChargeTracker); - } - - protected abstract boolean isValidResult(); - } - - private class ReadQuorumResult extends ReadResult { - public ReadQuorumResult( - RequestChargeTracker requestChargeTracker, - ReadQuorumResultKind QuorumResult, - long selectedLsn, - long globalCommittedSelectedLsn, - StoreResult selectedResponse, - List storeResponses) { - super(requestChargeTracker, selectedResponse); - - this.quorumResult = QuorumResult; - this.selectedLsn = selectedLsn; - this.globalCommittedSelectedLsn = globalCommittedSelectedLsn; - this.selectedResponse = selectedResponse; - this.storeResponses = storeResponses; - } - - public final ReadQuorumResultKind quorumResult; - - /** - * Response selected to lock on the LSN. This is the response with the highest LSN - */ - public final StoreResult selectedResponse; - - /** - * All store responses from Quorum Read. - */ - public final List storeResponses; - - public final long selectedLsn; - - public final long globalCommittedSelectedLsn; - - protected boolean isValidResult() { - return this.quorumResult == ReadQuorumResultKind.QuorumMet || this.quorumResult == ReadQuorumResultKind.QuorumSelected; - } - } - - private class ReadPrimaryResult extends ReadResult { - public final boolean shouldRetryOnSecondary; - public final boolean isSuccessful; - - public ReadPrimaryResult(RequestChargeTracker requestChargeTracker, boolean isSuccessful, boolean shouldRetryOnSecondary, StoreResult response) { - super(requestChargeTracker, response); - this.isSuccessful = isSuccessful; - this.shouldRetryOnSecondary = shouldRetryOnSecondary; - } - - protected boolean isValidResult() { - return isSuccessful; - } - } - - private enum PrimaryReadOutcome { - QuorumNotMet, // Primary LSN is not committed. - QuorumInconclusive, // Secondary replicas are available. Must read R secondary's to deduce current quorum. - QuorumMet, - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReadMode.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReadMode.java deleted file mode 100644 index ebefc977a38b..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReadMode.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -public enum ReadMode { - Primary, // Test hook - Strong, - BoundedStaleness, - Any -} - diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClient.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClient.java deleted file mode 100644 index b8d116ef7408..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClient.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import java.time.Duration; - -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.ReplicatedResourceClientUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.Quadruple; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.internal.BackoffRetryUtility; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import rx.Single; -import rx.functions.Func1; -import rx.functions.Func2; - -/** - * ReplicatedResourceClient uses the ConsistencyReader to make requests to - * backend - */ -public class ReplicatedResourceClient { - private final Logger logger = LoggerFactory.getLogger(ReplicatedResourceClient.class); - private static final int GONE_AND_RETRY_WITH_TIMEOUT_IN_SECONDS = 30; - private static final int STRONG_GONE_AND_RETRY_WITH_RETRY_TIMEOUT_SECONDS = 60; - private static final int MIN_BACKOFF_FOR_FAILLING_BACK_TO_OTHER_REGIONS_FOR_READ_REQUESTS_IN_SECONDS = 1; - - private final AddressSelector addressSelector; - private final ConsistencyReader consistencyReader; - private final ConsistencyWriter consistencyWriter; - private final Protocol protocol; - private final TransportClient transportClient; - private final boolean enableReadRequestsFallback; - private final GatewayServiceConfigurationReader serviceConfigReader; - private final Configs configs; - - public ReplicatedResourceClient( - Configs configs, - AddressSelector addressSelector, - ISessionContainer sessionContainer, - TransportClient transportClient, - GatewayServiceConfigurationReader serviceConfigReader, - IAuthorizationTokenProvider authorizationTokenProvider, - boolean enableReadRequestsFallback, - boolean useMultipleWriteLocations) { - this.configs = configs; - this.protocol = configs.getProtocol(); - this.addressSelector = addressSelector; - if (protocol != Protocol.Https && protocol != Protocol.Tcp) { - throw new IllegalArgumentException("protocol"); - } - - this.transportClient = transportClient; - this.serviceConfigReader = serviceConfigReader; - - this.consistencyReader = new ConsistencyReader(configs, - this.addressSelector, - sessionContainer, - transportClient, - serviceConfigReader, - authorizationTokenProvider); - this.consistencyWriter = new ConsistencyWriter( - this.addressSelector, - sessionContainer, - transportClient, - authorizationTokenProvider, - serviceConfigReader, - useMultipleWriteLocations); - this.enableReadRequestsFallback = enableReadRequestsFallback; - } - - public static boolean isReadingFromMaster(ResourceType resourceType, OperationType operationType) { - return ReplicatedResourceClientUtils.isReadingFromMaster(resourceType, operationType); - } - - public static boolean isMasterResource(ResourceType resourceType) { - return ReplicatedResourceClientUtils.isMasterResource(resourceType); - } - - public static boolean isGlobalStrongEnabled() { - return true; - } - - public Single invokeAsync(RxDocumentServiceRequest request, - Func1> prepareRequestAsyncDelegate) { - Func2, RxDocumentServiceRequest, Single> mainFuncDelegate = ( - Quadruple forceRefreshAndTimeout, - RxDocumentServiceRequest documentServiceRequest) -> { - documentServiceRequest.getHeaders().put(HttpConstants.HttpHeaders.CLIENT_RETRY_ATTEMPT_COUNT, - forceRefreshAndTimeout.getValue3().toString()); - documentServiceRequest.getHeaders().put(HttpConstants.HttpHeaders.REMAINING_TIME_IN_MS_ON_CLIENT_REQUEST, - Long.toString(forceRefreshAndTimeout.getValue2().toMillis())); - return invokeAsync(request, new TimeoutHelper(forceRefreshAndTimeout.getValue2()), - forceRefreshAndTimeout.getValue1(), forceRefreshAndTimeout.getValue0()); - - }; - Func1, Single> funcDelegate = ( - Quadruple forceRefreshAndTimeout) -> { - if (prepareRequestAsyncDelegate != null) { - return prepareRequestAsyncDelegate.call(request).flatMap(responseReq -> { - return mainFuncDelegate.call(forceRefreshAndTimeout, responseReq); - }); - } else { - return mainFuncDelegate.call(forceRefreshAndTimeout, request); - } - - }; - - Func1, Single> inBackoffFuncDelegate = null; - - // we will enable fallback to other regions if the following conditions are met: - // 1. request is a read operation AND - // 2. enableReadRequestsFallback is set to true. (can only ever be true if - // direct mode, on client) - if (request.isReadOnlyRequest() && this.enableReadRequestsFallback) { - if (request.requestContext.clientSideRequestStatistics == null) { - request.requestContext.clientSideRequestStatistics = new ClientSideRequestStatistics(); - } - RxDocumentServiceRequest freshRequest = request.clone(); - inBackoffFuncDelegate = (Quadruple forceRefreshAndTimeout) -> { - RxDocumentServiceRequest readRequestClone = freshRequest.clone(); - - if (prepareRequestAsyncDelegate != null) { - return prepareRequestAsyncDelegate.call(readRequestClone).flatMap(responseReq -> { - logger.trace(String.format("Executing inBackoffAlternateCallbackMethod on readRegionIndex {}", - forceRefreshAndTimeout.getValue3())); - responseReq.requestContext.RouteToLocation(forceRefreshAndTimeout.getValue3(), true); - return invokeAsync(responseReq, new TimeoutHelper(forceRefreshAndTimeout.getValue2()), - forceRefreshAndTimeout.getValue1(), - forceRefreshAndTimeout.getValue0()); - }); - } else { - logger.trace(String.format("Executing inBackoffAlternateCallbackMethod on readRegionIndex {}", - forceRefreshAndTimeout.getValue3())); - readRequestClone.requestContext.RouteToLocation(forceRefreshAndTimeout.getValue3(), true); - return invokeAsync(readRequestClone, new TimeoutHelper(forceRefreshAndTimeout.getValue2()), - forceRefreshAndTimeout.getValue1(), - forceRefreshAndTimeout.getValue0()); - } - - }; - } - - int retryTimeout = this.serviceConfigReader.getDefaultConsistencyLevel() == ConsistencyLevel.Strong ? - ReplicatedResourceClient.STRONG_GONE_AND_RETRY_WITH_RETRY_TIMEOUT_SECONDS : - ReplicatedResourceClient.GONE_AND_RETRY_WITH_TIMEOUT_IN_SECONDS; - - return BackoffRetryUtility.executeAsync(funcDelegate, new GoneAndRetryWithRetryPolicy(request, retryTimeout), - inBackoffFuncDelegate, Duration.ofSeconds( - ReplicatedResourceClient.MIN_BACKOFF_FOR_FAILLING_BACK_TO_OTHER_REGIONS_FOR_READ_REQUESTS_IN_SECONDS)); - } - - private Single invokeAsync(RxDocumentServiceRequest request, TimeoutHelper timeout, - boolean isInRetry, boolean forceRefresh) { - - if (request.getOperationType().equals(OperationType.ExecuteJavaScript)) { - if (request.isReadOnlyScript()) { - return this.consistencyReader.readAsync(request, timeout, isInRetry, forceRefresh); - } else { - return this.consistencyWriter.writeAsync(request, timeout, forceRefresh); - } - } else if (request.getOperationType().isWriteOperation()) { - return this.consistencyWriter.writeAsync(request, timeout, forceRefresh); - } else if (request.isReadOnlyRequest()) { - return this.consistencyReader.readAsync(request, timeout, isInRetry, forceRefresh); - } else { - throw new IllegalArgumentException( - String.format("Unexpected operation type %s", request.getOperationType())); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestEntityTooLargeException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestEntityTooLargeException.java deleted file mode 100644 index 1c8a33835e5e..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestEntityTooLargeException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class RequestEntityTooLargeException extends DocumentClientException { - private static final long serialVersionUID = 1L; - - public RequestEntityTooLargeException() { - this(RMResources.RequestEntityTooLarge); - } - - public RequestEntityTooLargeException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.REQUEST_ENTITY_TOO_LARGE, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public RequestEntityTooLargeException(String msg) { - super(HttpConstants.StatusCodes.REQUEST_ENTITY_TOO_LARGE, msg); - } - - public RequestEntityTooLargeException(String msg, String resourceAddress) { - super(msg, null, null, HttpConstants.StatusCodes.REQUEST_ENTITY_TOO_LARGE, resourceAddress); - } - - public RequestEntityTooLargeException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public RequestEntityTooLargeException(Exception innerException) { - this(RMResources.RequestEntityTooLarge, innerException, null, null); - } - - public RequestEntityTooLargeException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format(RMResources.RequestEntityTooLarge, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.REQUEST_ENTITY_TOO_LARGE, - requestUri); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestHelper.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestHelper.java deleted file mode 100644 index 5eb93d0acd8a..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestHelper.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.apache.commons.lang3.EnumUtils; - -public class RequestHelper { - public static ConsistencyLevel GetConsistencyLevelToUse(GatewayServiceConfigurationReader serviceConfigReader, - RxDocumentServiceRequest request) throws DocumentClientException { - ConsistencyLevel consistencyLevelToUse = serviceConfigReader.getDefaultConsistencyLevel(); - - String requestConsistencyLevelHeaderValue = request.getHeaders().get(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL); - - if (!Strings.isNullOrEmpty(requestConsistencyLevelHeaderValue)) { - ConsistencyLevel requestConsistencyLevel = EnumUtils.getEnum(ConsistencyLevel.class, requestConsistencyLevelHeaderValue); - if (requestConsistencyLevel == null) { - throw new BadRequestException( - String.format( - RMResources.InvalidHeaderValue, - requestConsistencyLevelHeaderValue, - HttpConstants.HttpHeaders.CONSISTENCY_LEVEL)); - } - - consistencyLevelToUse = requestConsistencyLevel; - } - - return consistencyLevelToUse; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestRateTooLargeException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestRateTooLargeException.java deleted file mode 100644 index 1d5c315bade1..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RequestRateTooLargeException.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -public class RequestRateTooLargeException extends DocumentClientException { - - public RequestRateTooLargeException() { - this(RMResources.TooManyRequests, null); - } - - public RequestRateTooLargeException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.NOTFOUND, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public RequestRateTooLargeException(String message, URI requestUri) { - this(message, (Exception) null, (HttpResponseHeaders) null, requestUri); - } - - public RequestRateTooLargeException(String message, - Exception innerException, - URI requestUri) { - this(message, innerException, (HttpResponseHeaders) null, requestUri); - } - - public RequestRateTooLargeException(Exception innerException) { - this(RMResources.TooManyRequests, innerException, (HttpResponseHeaders) null, null); - } - - public RequestRateTooLargeException(String message, HttpResponseHeaders headers, URI requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.TOO_MANY_REQUESTS, requestUri != null ? requestUri.toString() : null); - } - - public RequestRateTooLargeException(String message, HttpResponseHeaders headers, String requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.TOO_MANY_REQUESTS, requestUri); - } - - public RequestRateTooLargeException(String message, - Exception innerException, - HttpResponseHeaders headers, - URI requestUri) { - super(message, innerException, HttpUtils.asMap(headers), HttpConstants.StatusCodes.TOO_MANY_REQUESTS, requestUri != null ? requestUri.toString() : null); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ResourceOperation.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ResourceOperation.java deleted file mode 100644 index e51367dea91d..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ResourceOperation.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; - -public class ResourceOperation { - public final OperationType operationType; - public final ResourceType resourceType; - - public ResourceOperation( - OperationType operationType, - ResourceType resourceType) { - this.operationType = operationType; - this.resourceType = resourceType; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ResponseUtils.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ResponseUtils.java deleted file mode 100644 index c37c7bef907a..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ResponseUtils.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Single; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; - -class ResponseUtils { - private final static int INITIAL_RESPONSE_BUFFER_SIZE = 1024; - private final static Logger logger = LoggerFactory.getLogger(ResponseUtils.class); - - public static Observable toString(Observable contentObservable) { - return contentObservable - .reduce( - new ByteArrayOutputStream(INITIAL_RESPONSE_BUFFER_SIZE), - (out, bb) -> { - try { - bb.readBytes(out, bb.readableBytes()); - return out; - } catch (IOException e) { - throw new RuntimeException(e); - } - }) - .map(out -> { - return new String(out.toByteArray(), StandardCharsets.UTF_8); - }); - } - - public static Single toStoreResponse(HttpClientResponse clientResponse) { - - HttpResponseHeaders httpResponseHeaders = clientResponse.getHeaders(); - HttpResponseStatus httpResponseStatus = clientResponse.getStatus(); - - Observable contentObservable; - - if (clientResponse.getContent() == null) { - // for delete we don't expect any body - contentObservable = Observable.just(null); - } else { - // transforms the observable to Observable - contentObservable = toString(clientResponse.getContent()); - } - - Observable storeResponseObservable = contentObservable - .flatMap(content -> { - try { - // transforms to Observable - StoreResponse rsp = new StoreResponse(httpResponseStatus.code(), HttpUtils.unescape(httpResponseHeaders.entries()), content); - return Observable.just(rsp); - } catch (Exception e) { - return Observable.error(e); - } - }); - - return storeResponseObservable.toSingle(); - } - - private static void validateOrThrow(RxDocumentServiceRequest request, HttpResponseStatus status, HttpResponseHeaders headers, String body, - InputStream inputStream) throws DocumentClientException { - - int statusCode = status.code(); - - if (statusCode >= HttpConstants.StatusCodes.MINIMUM_STATUSCODE_AS_ERROR_GATEWAY) { - if (body == null && inputStream != null) { - try { - body = IOUtils.toString(inputStream, StandardCharsets.UTF_8); - } catch (IOException e) { - logger.error("Failed to get content from the http response", e); - throw new IllegalStateException("Failed to get content from the http response", e); - } finally { - IOUtils.closeQuietly(inputStream); - } - } - - String statusCodeString = status.reasonPhrase() != null - ? status.reasonPhrase().replace(" ", "") - : ""; - Error error = null; - error = (body != null) ? new Error(body) : new Error(); - error = new Error(statusCodeString, - String.format("%s, StatusCode: %s", error.getMessage(), statusCodeString), - error.getPartitionedQueryExecutionInfo()); - - throw new DocumentClientException(statusCode, error, HttpUtils.asMap(headers)); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RetryWithException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RetryWithException.java deleted file mode 100644 index df32963da686..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RetryWithException.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -public class RetryWithException extends DocumentClientException { - - public RetryWithException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.RETRY_WITH, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public RetryWithException(String message, URI requestUri) { - this(message, (Exception) null, (HttpResponseHeaders) null, requestUri); - } - - public RetryWithException(String message, - Exception innerException, - URI requestUri) { - this(message, innerException, (HttpResponseHeaders) null, requestUri); - } - - public RetryWithException(String message, HttpResponseHeaders headers, URI requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.RETRY_WITH, requestUri != null ? requestUri.toString() : null); - } - - public RetryWithException(String message, HttpResponseHeaders headers, String requestUri) { - super(message, null, HttpUtils.asMap(headers), HttpConstants.StatusCodes.RETRY_WITH, requestUri); - } - - public RetryWithException(String message, - Exception innerException, - HttpResponseHeaders headers, - URI requestUri) { - super(message, innerException, HttpUtils.asMap(headers), HttpConstants.StatusCodes.RETRY_WITH, requestUri != null ? requestUri.toString() : null); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RntbdTransportClient.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RntbdTransportClient.java deleted file mode 100644 index adec62b59bef..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RntbdTransportClient.java +++ /dev/null @@ -1,393 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdEndpoint; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdMetrics; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdObjectMapper; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestArgs; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdServiceEndpoint; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.handler.ssl.SslContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; -import rx.SingleEmitter; - -import java.io.IOException; -import java.net.URI; -import java.time.Duration; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdReporter.reportIssueUnless; - -@JsonSerialize(using = RntbdTransportClient.JsonSerializer.class) -public final class RntbdTransportClient extends TransportClient implements AutoCloseable { - - // region Fields - - private static final AtomicLong instanceCount = new AtomicLong(); - private static final Logger logger = LoggerFactory.getLogger(RntbdTransportClient.class); - private static final String namePrefix = RntbdTransportClient.class.getSimpleName() + '-'; - - private final AtomicBoolean closed = new AtomicBoolean(); - private final RntbdEndpoint.Provider endpointProvider; - private final RntbdMetrics metrics; - private final String name; - - // endregion - - // region Constructors - - RntbdTransportClient(final RntbdEndpoint.Provider endpointProvider) { - this.name = RntbdTransportClient.namePrefix + RntbdTransportClient.instanceCount.incrementAndGet(); - this.endpointProvider = endpointProvider; - this.metrics = new RntbdMetrics(this.name); - } - - RntbdTransportClient(final Options options, final SslContext sslContext) { - this(new RntbdServiceEndpoint.Provider(options, sslContext)); - } - - RntbdTransportClient(final Configs configs, final int requestTimeoutInSeconds, final UserAgentContainer userAgent) { - this(new Options.Builder(requestTimeoutInSeconds).userAgent(userAgent).build(), configs.getSslContext()); - } - - // endregion - - // region Methods - - @Override - public void close() { - - logger.debug("\n [{}] CLOSE", this); - - if (this.closed.compareAndSet(false, true)) { - this.endpointProvider.close(); - this.metrics.close(); - return; - } - - logger.debug("\n [{}]\n already closed", this); - } - - @Override - public Single invokeStoreAsync( - final URI physicalAddress, final ResourceOperation unused, final RxDocumentServiceRequest request - ) { - checkNotNull(physicalAddress, "physicalAddress"); - checkNotNull(request, "request"); - this.throwIfClosed(); - - final RntbdRequestArgs requestArgs = new RntbdRequestArgs(request, physicalAddress); - - if (logger.isDebugEnabled()) { - requestArgs.traceOperation(logger, null, "invokeStoreAsync"); - logger.debug("\n [{}]\n {}\n INVOKE_STORE_ASYNC", this, requestArgs); - } - - final RntbdEndpoint endpoint = this.endpointProvider.get(physicalAddress); - this.metrics.incrementRequestCount(); - - final CompletableFuture future = endpoint.request(requestArgs); - - return Single.fromEmitter((SingleEmitter emitter) -> { - - future.whenComplete((response, error) -> { - - requestArgs.traceOperation(logger, null, "emitSingle", response, error); - this.metrics.incrementResponseCount(); - - if (error == null) { - emitter.onSuccess(response); - } else { - if (!(error instanceof DocumentClientException)) { - logger.warn("{} expected failure of {}, not ", requestArgs, DocumentClientException.class, error); - } - this.metrics.incrementErrorResponseCount(); - emitter.onError(error instanceof CompletionException ? error.getCause() : error); - } - - requestArgs.traceOperation(logger, null, "emitSingleComplete"); - }); - }); - } - - @Override - public String toString() { - return RntbdObjectMapper.toJson(this); - } - - private void throwIfClosed() { - checkState(!this.closed.get(), "%s is closed", this); - } - - // endregion - - // region Types - - static final class JsonSerializer extends StdSerializer { - - public JsonSerializer() { - this(null); - } - - public JsonSerializer(Class type) { - super(type); - } - - @Override - public void serialize(RntbdTransportClient value, JsonGenerator generator, SerializerProvider provider) throws IOException { - - generator.writeStartObject(); - - generator.writeArrayFieldStart(value.name); - - value.endpointProvider.list().forEach(endpoint -> { - try { - generator.writeObject(endpoint); - } catch (IOException error) { - logger.error("failed to serialize {} due to ", endpoint.getName(), error); - } - }); - - generator.writeEndArray(); - - generator.writeObjectField("config", value.endpointProvider.config()); - generator.writeObjectField("metrics", value.metrics); - generator.writeEndObject(); - } - } - - public static final class Options { - - // region Fields - - private final String certificateHostNameOverride; - private final int maxChannelsPerEndpoint; - private final int maxRequestsPerChannel; - private final Duration connectionTimeout; - private final int partitionCount; - private final Duration receiveHangDetectionTime; - private final Duration requestTimeout; - private final Duration sendHangDetectionTime; - private final UserAgentContainer userAgent; - - // endregion - - // region Constructors - - private Options(Builder builder) { - - this.certificateHostNameOverride = builder.certificateHostNameOverride; - this.maxChannelsPerEndpoint = builder.maxChannelsPerEndpoint; - this.maxRequestsPerChannel = builder.maxRequestsPerChannel; - this.connectionTimeout = builder.connectionTimeout == null ? builder.requestTimeout : builder.connectionTimeout; - this.partitionCount = builder.partitionCount; - this.requestTimeout = builder.requestTimeout; - this.receiveHangDetectionTime = builder.receiveHangDetectionTime; - this.sendHangDetectionTime = builder.sendHangDetectionTime; - this.userAgent = builder.userAgent; - } - - // endregion - - // region Accessors - - public String getCertificateHostNameOverride() { - return this.certificateHostNameOverride; - } - - public int getMaxChannelsPerEndpoint() { - return this.maxChannelsPerEndpoint; - } - - public int getMaxRequestsPerChannel() { - return this.maxRequestsPerChannel; - } - - public Duration getConnectionTimeout() { - return this.connectionTimeout; - } - - public int getPartitionCount() { - return this.partitionCount; - } - - public Duration getReceiveHangDetectionTime() { - return this.receiveHangDetectionTime; - } - - public Duration getRequestTimeout() { - return this.requestTimeout; - } - - public Duration getSendHangDetectionTime() { - return this.sendHangDetectionTime; - } - - public UserAgentContainer getUserAgent() { - return this.userAgent; - } - - // endregion - - // region Methods - - @Override - public String toString() { - return RntbdObjectMapper.toJson(this); - } - - // endregion - - // region Types - - public static class Builder { - - // region Fields - - private static final UserAgentContainer DEFAULT_USER_AGENT_CONTAINER = new UserAgentContainer(); - private static final Duration SIXTY_FIVE_SECONDS = Duration.ofSeconds(65L); - private static final Duration TEN_SECONDS = Duration.ofSeconds(10L); - - // Required parameters - - private String certificateHostNameOverride = null; - - // Optional parameters - - private int maxChannelsPerEndpoint = 10; - private int maxRequestsPerChannel = 30; - private Duration connectionTimeout = null; - private int partitionCount = 1; - private Duration receiveHangDetectionTime = SIXTY_FIVE_SECONDS; - private Duration requestTimeout; - private Duration sendHangDetectionTime = TEN_SECONDS; - private UserAgentContainer userAgent = DEFAULT_USER_AGENT_CONTAINER; - - // endregion - - // region Constructors - - public Builder(Duration requestTimeout) { - this.requestTimeout(requestTimeout); - } - - public Builder(int requestTimeoutInSeconds) { - this(Duration.ofSeconds(requestTimeoutInSeconds)); - } - - // endregion - - // region Methods - - public Options build() { - return new Options(this); - } - - public Builder certificateHostNameOverride(final String value) { - this.certificateHostNameOverride = value; - return this; - } - - public Builder connectionTimeout(final Duration value) { - checkArgument(value == null || value.compareTo(Duration.ZERO) > 0, "value: %s", value); - this.connectionTimeout = value; - return this; - } - - public Builder maxRequestsPerChannel(final int value) { - checkArgument(value > 0, "value: %s", value); - this.maxRequestsPerChannel = value; - return this; - } - - public Builder maxChannelsPerEndpoint(final int value) { - checkArgument(value > 0, "value: %s", value); - this.maxChannelsPerEndpoint = value; - return this; - } - - public Builder partitionCount(final int value) { - checkArgument(value > 0, "value: %s", value); - this.partitionCount = value; - return this; - } - - public Builder receiveHangDetectionTime(final Duration value) { - - checkNotNull(value, "value: null"); - checkArgument(value.compareTo(Duration.ZERO) > 0, "value: %s", value); - - this.receiveHangDetectionTime = value; - return this; - } - - public Builder requestTimeout(final Duration value) { - - checkNotNull(value, "value: null"); - checkArgument(value.compareTo(Duration.ZERO) > 0, "value: %s", value); - - this.requestTimeout = value; - return this; - } - - public Builder sendHangDetectionTime(final Duration value) { - - checkNotNull(value, "value: null"); - checkArgument(value.compareTo(Duration.ZERO) > 0, "value: %s", value); - - this.sendHangDetectionTime = value; - return this; - } - - public Builder userAgent(final UserAgentContainer value) { - checkNotNull(value, "value: null"); - this.userAgent = value; - return this; - } - - // endregion - } - - // endregion - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServerProperties.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServerProperties.java deleted file mode 100644 index d8a84ba78d61..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServerProperties.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -final public class ServerProperties { - - final private String agent, version; - - public ServerProperties(String agent, String version) { - this.agent = agent; - this.version = version; - } - - public String getAgent() { - return this.agent; - } - - public String getVersion() { - return this.version; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServerStoreModel.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServerStoreModel.java deleted file mode 100644 index c21ad28d13e0..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServerStoreModel.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.RxStoreModel; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.apache.commons.lang3.EnumUtils; -import rx.Observable; -import rx.Single; - -public class ServerStoreModel implements RxStoreModel { - private final StoreClient storeClient; - - public ServerStoreModel(StoreClient storeClient) { - this.storeClient = storeClient; - } - - public Observable processMessage(RxDocumentServiceRequest request) { - String requestConsistencyLevelHeaderValue = request.getHeaders().get(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL); - - request.requestContext.originalRequestConsistencyLevel = null; - - if (!Strings.isNullOrEmpty(requestConsistencyLevelHeaderValue)) { - ConsistencyLevel requestConsistencyLevel; - - if ((requestConsistencyLevel = EnumUtils.getEnum(ConsistencyLevel.class, requestConsistencyLevelHeaderValue)) == null) { - return Observable.error(new BadRequestException( - String.format( - RMResources.InvalidHeaderValue, - requestConsistencyLevelHeaderValue, - HttpConstants.HttpHeaders.CONSISTENCY_LEVEL))); - } - - request.requestContext.originalRequestConsistencyLevel = requestConsistencyLevel; - } - - if (ReplicatedResourceClient.isMasterResource(request.getResourceType())) { - request.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Strong.toString()); - } - - Single response = this.storeClient.processMessageAsync(request); - return response.toObservable(); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServiceConfig.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServiceConfig.java deleted file mode 100644 index 25ae57544ce5..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServiceConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -class ServiceConfig { - final static ServiceConfig instance = new ServiceConfig(); - public SystemReplicationPolicy systemReplicationPolicy = new SystemReplicationPolicy(); - public SystemReplicationPolicy userReplicationPolicy = new SystemReplicationPolicy(); - - public static ServiceConfig getInstance() { - return instance; - } - - class SystemReplicationPolicy { - public static final int MaxReplicaSetSize = 4; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServiceUnavailableException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServiceUnavailableException.java deleted file mode 100644 index e028912a9068..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ServiceUnavailableException.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -public class ServiceUnavailableException extends DocumentClientException { - public ServiceUnavailableException() { - this(RMResources.ServiceUnavailable); - } - - public ServiceUnavailableException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.NOTFOUND, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public ServiceUnavailableException(String message) { - this(message, (Exception) null, (HttpResponseHeaders) null, null); - } - - public ServiceUnavailableException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public ServiceUnavailableException(String message, HttpResponseHeaders headers, URI requestUri) { - this(message, headers, requestUri != null ? requestUri.toString() : null); - } - - public ServiceUnavailableException(Exception innerException) { - this(RMResources.ServiceUnavailable, innerException, null, null); - } - - public ServiceUnavailableException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.ServiceUnavailable, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.SERVICE_UNAVAILABLE, - requestUri != null ? requestUri.toString() : null); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreClient.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreClient.java deleted file mode 100644 index f51634e9a31c..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreClient.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.SessionContainer; -import com.microsoft.azure.cosmosdb.internal.SessionTokenHelper; -import com.microsoft.azure.cosmosdb.rx.internal.BackoffRetryUtility; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.Exceptions; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.apache.commons.lang3.math.NumberUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; -import rx.functions.Func0; -import rx.functions.Func1; - -import java.util.HashMap; -import java.util.Map; - -/** - * Instantiated to issue direct connectivity requests to the backend on: - * - Gateway (for gateway mode clients) - * - Client (for direct mode clients) - * StoreClient uses the ReplicatedResourceClient to make requests to the backend. - */ -public class StoreClient implements IStoreClient { - private final Logger logger = LoggerFactory.getLogger(StoreClient.class); - private final GatewayServiceConfigurationReader serviceConfigurationReader; - - private final SessionContainer sessionContainer; - private final ReplicatedResourceClient replicatedResourceClient; - private final TransportClient transportClient; - private final String ZERO_PARTITION_KEY_RANGE = "0"; - - public StoreClient( - Configs configs, - IAddressResolver addressResolver, - SessionContainer sessionContainer, - GatewayServiceConfigurationReader serviceConfigurationReader, IAuthorizationTokenProvider userTokenProvider, - TransportClient transportClient, - boolean useMultipleWriteLocations) { - this.transportClient = transportClient; - this.sessionContainer = sessionContainer; - this.serviceConfigurationReader = serviceConfigurationReader; - this.replicatedResourceClient = new ReplicatedResourceClient( - configs, - new AddressSelector(addressResolver, configs.getProtocol()), - sessionContainer, - this.transportClient, - serviceConfigurationReader, - userTokenProvider, - false, - useMultipleWriteLocations); - } - - @Override - public Single processMessageAsync(RxDocumentServiceRequest request, IRetryPolicy retryPolicy, Func1> prepareRequestAsyncDelegate) { - if (request == null) { - throw new NullPointerException("request"); - } - - Func0> storeResponseDelegate = () -> this.replicatedResourceClient.invokeAsync(request, prepareRequestAsyncDelegate); - - Single storeResponse = retryPolicy != null - ? BackoffRetryUtility.executeRetry(storeResponseDelegate, retryPolicy) - : storeResponseDelegate.call(); - - storeResponse = storeResponse.doOnError(e -> { - try { - DocumentClientException exception = Utils.as(e, DocumentClientException.class); - - if (exception == null) { - return; - } - - exception.setClientSideRequestStatistics(request.requestContext.clientSideRequestStatistics); - - handleUnsuccessfulStoreResponse(request, exception); - } catch (Throwable throwable) { - logger.error("Unexpected failure in handling orig [{}]", e.getMessage(), e); - logger.error("Unexpected failure in handling orig [{}] : new [{}]", e.getMessage(), throwable.getMessage(), throwable); - } - } - ); - - return storeResponse.flatMap(sr -> { - try { - return Single.just(this.completeResponse(sr, request)); - } catch (Exception e) { - return Single.error(e); - } - }); - } - - private void handleUnsuccessfulStoreResponse(RxDocumentServiceRequest request, DocumentClientException exception) { - this.updateResponseHeader(request, exception.getResponseHeaders()); - if ((!ReplicatedResourceClient.isMasterResource(request.getResourceType())) && - (Exceptions.isStatusCode(exception, HttpConstants.StatusCodes.PRECONDITION_FAILED) || Exceptions.isStatusCode(exception, HttpConstants.StatusCodes.CONFLICT) || - (Exceptions.isStatusCode(exception, HttpConstants.StatusCodes.NOTFOUND) && - !Exceptions.isSubStatusCode(exception, HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)))) { - this.captureSessionToken(request, exception.getResponseHeaders()); - } - } - - private RxDocumentServiceResponse completeResponse( - StoreResponse storeResponse, - RxDocumentServiceRequest request) throws InternalServerErrorException { - if (storeResponse.getResponseHeaderNames().length != storeResponse.getResponseHeaderValues().length) { - throw new InternalServerErrorException(RMResources.InvalidBackendResponse); - } - - Map headers = new HashMap<>(storeResponse.getResponseHeaderNames().length); - for (int idx = 0; idx < storeResponse.getResponseHeaderNames().length; idx++) { - String name = storeResponse.getResponseHeaderNames()[idx]; - String value = storeResponse.getResponseHeaderValues()[idx]; - - headers.put(name, value); - } - - this.updateResponseHeader(request, headers); - this.captureSessionToken(request, headers); - storeResponse.setClientSideRequestStatistics(request.requestContext.clientSideRequestStatistics); - return new RxDocumentServiceResponse(storeResponse); - } - - private long getLSN(Map headers) { - long defaultValue = -1; - String value = headers.get(WFConstants.BackendHeaders.LSN); - - if (!Strings.isNullOrEmpty(value)) { - return NumberUtils.toLong(value, defaultValue); - - } - - return defaultValue; - } - - private void updateResponseHeader(RxDocumentServiceRequest request, Map headers) { - String requestConsistencyLevel = request.getHeaders().get(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL); - - boolean sessionConsistency = - this.serviceConfigurationReader.getDefaultConsistencyLevel() == ConsistencyLevel.Session || - (!Strings.isNullOrEmpty(requestConsistencyLevel) - && Strings.areEqualIgnoreCase(requestConsistencyLevel, ConsistencyLevel.Session.name())); - - long storeLSN = this.getLSN(headers); - if (storeLSN == -1) { - return; - } - - String partitionKeyRangeId = headers.get(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID); - - if (Strings.isNullOrEmpty(partitionKeyRangeId)) { - String inputSession = request.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - if (!Strings.isNullOrEmpty(inputSession) - && inputSession.indexOf(ISessionToken.PARTITION_KEY_RANGE_SESSION_SEPARATOR) >= 1) { - partitionKeyRangeId = inputSession.substring(0, - inputSession.indexOf(ISessionToken.PARTITION_KEY_RANGE_SESSION_SEPARATOR)); - } else { - partitionKeyRangeId = ZERO_PARTITION_KEY_RANGE; - } - } - - ISessionToken sessionToken = null; - String sessionTokenResponseHeader = headers.get(HttpConstants.HttpHeaders.SESSION_TOKEN); - if (!Strings.isNullOrEmpty(sessionTokenResponseHeader)) { - sessionToken = SessionTokenHelper.parse(sessionTokenResponseHeader); - } - - if (sessionToken != null) { - headers.put(HttpConstants.HttpHeaders.SESSION_TOKEN, String.format( - "%s:%s", - partitionKeyRangeId, - sessionToken.convertToString())); - } - - headers.remove(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID); - } - - private void captureSessionToken(RxDocumentServiceRequest request, Map headers) { - if (request.getResourceType() == ResourceType.DocumentCollection - && request.getOperationType() == OperationType.Delete) { - String resourceId; - if (request.getIsNameBased()) { - resourceId = headers.get(HttpConstants.HttpHeaders.OWNER_ID); - } else { - resourceId = request.getResourceId(); - } - this.sessionContainer.clearTokenByResourceId(resourceId); - } else { - this.sessionContainer.setSessionToken(request, headers); - } - } - - // TODO RNTBD support - // https://msdata.visualstudio.com/CosmosDB/SDK/_workitems/edit/262496 -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreClientFactory.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreClientFactory.java deleted file mode 100644 index 7409f7f8e005..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreClientFactory.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.internal.SessionContainer; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; - -// TODO: DANOBLE: no support for ICommunicationEventSource ask Ji -// Links: -// https://msdata.visualstudio.com/CosmosDB/SDK/_workitems/edit/262496 - -public class StoreClientFactory implements AutoCloseable { - private final Configs configs; - private final int maxConcurrentConnectionOpenRequests; - private final int requestTimeoutInSeconds; - private final Protocol protocol; - private final TransportClient transportClient; - private volatile boolean isClosed; - - public StoreClientFactory( - Configs configs, - int requestTimeoutInSeconds, - int maxConcurrentConnectionOpenRequests, - UserAgentContainer userAgent) { - - this.configs = configs; - this.protocol = configs.getProtocol(); - this.requestTimeoutInSeconds = requestTimeoutInSeconds; - this.maxConcurrentConnectionOpenRequests = maxConcurrentConnectionOpenRequests; - - if (protocol == Protocol.Https) { - this.transportClient = new HttpTransportClient(configs, requestTimeoutInSeconds, userAgent); - } else if (protocol == Protocol.Tcp){ - this.transportClient = new RntbdTransportClient(configs, requestTimeoutInSeconds, userAgent); - } else { - throw new IllegalArgumentException(String.format("protocol: %s", this.protocol)); - } - } - - public void close() throws Exception { - this.transportClient.close(); - this.isClosed = true; - } - - // TODO wew don't have support for the following yet - // TODO enableReadRequestsFallback ask Ji - // TODO useFallbackClient ask Ji - public StoreClient createStoreClient( - IAddressResolver addressResolver, - SessionContainer sessionContainer, - GatewayServiceConfigurationReader serviceConfigurationReader, - IAuthorizationTokenProvider authorizationTokenProvider, - boolean useMultipleWriteLocations) { - this.throwIfClosed(); - - return new StoreClient(configs, - addressResolver, - sessionContainer, - serviceConfigurationReader, - authorizationTokenProvider, - this.transportClient, - useMultipleWriteLocations); - } - - private void throwIfClosed() { - if (isClosed) { - throw new IllegalStateException("storeClient already closed!"); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReader.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReader.java deleted file mode 100644 index b9d92218f315..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReader.java +++ /dev/null @@ -1,896 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.Integers; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.MutableVolatile; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.SessionTokenHelper; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Single; -import rx.exceptions.CompositeException; -import rx.schedulers.Schedulers; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -import static com.microsoft.azure.cosmosdb.rx.internal.Exceptions.isSubStatusCode; - -public class StoreReader { - private final Logger logger = LoggerFactory.getLogger(StoreReader.class); - private final TransportClient transportClient; - private final AddressSelector addressSelector; - private final ISessionContainer sessionContainer; - private String lastReadAddress; - - public StoreReader( - TransportClient transportClient, - AddressSelector addressSelector, - ISessionContainer sessionContainer) { - this.transportClient = transportClient; - this.addressSelector = addressSelector; - this.sessionContainer = sessionContainer; - } - - public Single> readMultipleReplicaAsync( - RxDocumentServiceRequest entity, - boolean includePrimary, - int replicaCountToRead, - boolean requiresValidLsn, - boolean useSessionToken, - ReadMode readMode) { - return readMultipleReplicaAsync(entity, includePrimary, replicaCountToRead, requiresValidLsn, useSessionToken, readMode, false, false); - } - - /** - * Makes requests to multiple replicas at once and returns responses - * @param entity RxDocumentServiceRequest - * @param includePrimary flag to indicate whether to indicate primary replica in the reads - * @param replicaCountToRead number of replicas to read from - * @param requiresValidLsn flag to indicate whether a valid lsn is required to consider a response as valid - * @param useSessionToken flag to indicate whether to use session token - * @param readMode Read mode - * @param checkMinLSN set minimum required session lsn - * @param forceReadAll reads from all available replicas to gather result from readsToRead number of replicas - * @return ReadReplicaResult which indicates the LSN and whether Quorum was Met / Not Met etc - */ - public Single> readMultipleReplicaAsync( - RxDocumentServiceRequest entity, - boolean includePrimary, - int replicaCountToRead, - boolean requiresValidLsn, - boolean useSessionToken, - ReadMode readMode, - boolean checkMinLSN, - boolean forceReadAll) { - - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - String originalSessionToken = entity.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - - if (entity.requestContext.clientSideRequestStatistics == null) { - entity.requestContext.clientSideRequestStatistics = new ClientSideRequestStatistics(); - } - - Single readQuorumResultObs = this.readMultipleReplicasInternalAsync( - entity, includePrimary, replicaCountToRead, requiresValidLsn, useSessionToken, readMode, checkMinLSN, forceReadAll); - - return readQuorumResultObs.flatMap(readQuorumResult -> { - if (entity.requestContext.performLocalRefreshOnGoneException && - readQuorumResult.retryWithForceRefresh && - !entity.requestContext.forceRefreshAddressCache) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - entity.requestContext.forceRefreshAddressCache = true; - - return this.readMultipleReplicasInternalAsync( - entity, includePrimary, replicaCountToRead, requiresValidLsn, useSessionToken, readMode, false /*checkMinLSN*/, forceReadAll) - .map(r -> r.responses); - } else { - return Single.just(readQuorumResult.responses); - } - }).toObservable().doAfterTerminate(() -> { - SessionTokenHelper.setOriginalSessionToken(entity, originalSessionToken); - }).toSingle(); - } - - private Observable earlyResultIfNotEnoughReplicas(List replicaAddresses, - RxDocumentServiceRequest request, - int replicaCountToRead) { - if (replicaAddresses.size() < replicaCountToRead) { - // if not enough replicas, return ReadReplicaResult - if (!request.requestContext.forceRefreshAddressCache) { - return Observable.just(new ReadReplicaResult(true /*retryWithForceRefresh*/, Collections.emptyList())); - } else { - return Observable.just(new ReadReplicaResult(false /*retryWithForceRefresh*/, Collections.emptyList())); - } - } else { - // if there are enough replicas, move on - return Observable.empty(); - } - } - - private Observable toStoreResult(RxDocumentServiceRequest request, - Pair, URI> storeRespAndURI, - ReadMode readMode, - boolean requiresValidLsn) { - - return storeRespAndURI.getLeft() - .flatMap(storeResponse -> { - try { - StoreResult storeResult = this.createStoreResult( - storeResponse, - null, requiresValidLsn, - readMode != ReadMode.Strong, - storeRespAndURI.getRight()); - - request.requestContext.clientSideRequestStatistics.getContactedReplicas().add(storeRespAndURI.getRight()); - return Observable.just(storeResult); - } catch (Exception e) { - // RxJava1 doesn't allow throwing checked exception from Observable operators - return Observable.error(e); - } - } - ).onErrorResumeNext(t -> { - - try { - logger.debug("Exception {} is thrown while doing readMany", t); - Exception storeException = Utils.as(t, Exception.class); - if (storeException == null) { - return Observable.error(t); - } - -// Exception storeException = readTask.Exception != null ? readTask.Exception.InnerException : null; - StoreResult storeResult = this.createStoreResult( - null, - storeException, requiresValidLsn, - readMode != ReadMode.Strong, - null); - if (storeException instanceof TransportException) { - request.requestContext.clientSideRequestStatistics.getFailedReplicas().add(storeRespAndURI.getRight()); - } - return Observable.just(storeResult); - } catch (Exception e) { - // RxJava1 doesn't allow throwing checked exception from Observable operators - return Observable.error(e); - } - }); - } - - private Observable> readFromReplicas(List resultCollector, - List resolveApiResults, - final AtomicInteger replicasToRead, - RxDocumentServiceRequest entity, - boolean includePrimary, - int replicaCountToRead, - boolean requiresValidLsn, - boolean useSessionToken, - ReadMode readMode, - boolean checkMinLSN, - boolean forceReadAll, - final MutableVolatile requestSessionToken, - final MutableVolatile hasGoneException, - boolean enforceSessionCheck, - final MutableVolatile shortCircut) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Observable.error(new GoneException()); - } - List, URI>> readStoreTasks = new ArrayList<>(); - int uriIndex = StoreReader.generateNextRandom(resolveApiResults.size()); - - while (resolveApiResults.size() > 0) { - uriIndex = uriIndex % resolveApiResults.size(); - URI uri = resolveApiResults.get(uriIndex); - Pair, URI> res; - try { - res = this.readFromStoreAsync(resolveApiResults.get(uriIndex), - entity); - - } catch (Exception e) { - res = Pair.of(Single.error(e), uri); - } - - readStoreTasks.add(Pair.of(res.getLeft().toObservable(), res.getRight())); - resolveApiResults.remove(uriIndex); - - - if (!forceReadAll && readStoreTasks.size() == replicasToRead.get()) { - break; - } - } - - replicasToRead.set(readStoreTasks.size() >= replicasToRead.get() ? 0 : replicasToRead.get() - readStoreTasks.size()); - - - List> storeResult = readStoreTasks - .stream() - .map(item -> toStoreResult(entity, item, readMode, requiresValidLsn)) - .collect(Collectors.toList()); - Observable allStoreResults = Observable.merge(storeResult); - - return allStoreResults.toList().onErrorResumeNext(e -> { - if (e instanceof CompositeException) { - logger.info("Captured composite exception"); - CompositeException compositeException = (CompositeException) e; - List exceptions = compositeException.getExceptions(); - assert exceptions != null && !exceptions.isEmpty(); - return Observable.error(exceptions.get(0)); - } - - return Observable.error(e); - }).map(newStoreResults -> { - for (StoreResult srr : newStoreResults) { - - entity.requestContext.requestChargeTracker.addCharge(srr.requestCharge); - entity.requestContext.clientSideRequestStatistics.recordResponse(entity, srr); - if (srr.isValid) { - - try { - - if (requestSessionToken.v == null - || (srr.sessionToken != null && requestSessionToken.v.isValid(srr.sessionToken)) - || (!enforceSessionCheck && !srr.isNotFoundException)) { - resultCollector.add(srr); - } - - } catch (Exception e) { - // TODO: what to do on exception? - } - } - - hasGoneException.v = hasGoneException.v || (srr.isGoneException && !srr.isInvalidPartitionException); - - if (resultCollector.size() >= replicaCountToRead) { - if (hasGoneException.v && !entity.requestContext.performedBackgroundAddressRefresh) { - this.startBackgroundAddressRefresh(entity); - entity.requestContext.performedBackgroundAddressRefresh = true; - } - - shortCircut.v = new ReadReplicaResult(false, resultCollector); - replicasToRead.set(0); - return resultCollector; - } - - // Remaining replicas - replicasToRead.set(replicaCountToRead - resultCollector.size()); - } - return resultCollector; - }); - } - - private ReadReplicaResult createReadReplicaResult(List responseResult, - int replicaCountToRead, - int resolvedAddressCount, - boolean hasGoneException, - RxDocumentServiceRequest entity) throws DocumentClientException { - if (responseResult.size() < replicaCountToRead) { - logger.debug("Could not get quorum number of responses. " + - "ValidResponsesReceived: {} ResponsesExpected: {}, ResolvedAddressCount: {}, ResponsesString: {}", - responseResult.size(), - replicaCountToRead, - resolvedAddressCount, - String.join(";", responseResult.stream().map(r -> r.toString()).collect(Collectors.toList()))); - - if (hasGoneException) { - if (!entity.requestContext.performLocalRefreshOnGoneException) { - // If we are not supposed to act upon GoneExceptions here, just throw them - throw new GoneException(); - } else if (!entity.requestContext.forceRefreshAddressCache) { - // We could not obtain valid read quorum number of responses even when we went through all the secondary addresses - // Attempt force refresh and start over again. - return new ReadReplicaResult(true, responseResult); - } - } - } - - return new ReadReplicaResult(false, responseResult); - } - - /** - * Makes requests to multiple replicas at once and returns responses - * @param entity DocumentServiceRequest - * @param includePrimary flag to indicate whether to indicate primary replica in the reads - * @param replicaCountToRead number of replicas to read from - * @param requiresValidLsn flag to indicate whether a valid lsn is required to consider a response as valid - * @param useSessionToken flag to indicate whether to use session token - * @param readMode Read mode - * @param checkMinLSN set minimum required session lsn - * @param forceReadAll will read from all available replicas to put together result from readsToRead number of replicas - * @return ReadReplicaResult which indicates the LSN and whether Quorum was Met / Not Met etc - */ - private Single readMultipleReplicasInternalAsync(RxDocumentServiceRequest entity, - boolean includePrimary, - int replicaCountToRead, - boolean requiresValidLsn, - boolean useSessionToken, - ReadMode readMode, - boolean checkMinLSN, - boolean forceReadAll) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - String requestedCollectionId = null; - - if (entity.forceNameCacheRefresh) { - requestedCollectionId = entity.requestContext.resolvedCollectionRid; - } - - Single> resolveApiResultsObs = this.addressSelector.resolveAllUriAsync( - entity, - includePrimary, - entity.requestContext.forceRefreshAddressCache); - - if (!StringUtils.isEmpty(requestedCollectionId) && !StringUtils.isEmpty(entity.requestContext.resolvedCollectionRid)) { - if (!requestedCollectionId.equals(entity.requestContext.resolvedCollectionRid)) { - this.sessionContainer.clearTokenByResourceId(requestedCollectionId); - } - } - - return resolveApiResultsObs.toObservable() - .map(list -> Collections.synchronizedList(new ArrayList<>(list))) - .flatMap( - resolveApiResults -> { - try { - MutableVolatile requestSessionToken = new MutableVolatile<>(); - if (useSessionToken) { - SessionTokenHelper.setPartitionLocalSessionToken(entity, this.sessionContainer); - if (checkMinLSN) { - requestSessionToken.v = entity.requestContext.sessionToken; - } - } else { - entity.getHeaders().remove(HttpConstants.HttpHeaders.SESSION_TOKEN); - } - - Observable y = earlyResultIfNotEnoughReplicas(resolveApiResults, entity, replicaCountToRead); - return y.switchIfEmpty( - Observable.defer(() -> { - - List storeResultList = Collections.synchronizedList(new ArrayList<>()); - AtomicInteger replicasToRead = new AtomicInteger(replicaCountToRead); - - // string clientVersion = entity.Headers[HttpConstants.HttpHeaders.Version]; - // enforceSessionCheck = string.IsNullOrEmpty(clientVersion) ? false : VersionUtility.IsLaterThan(clientVersion, HttpConstants.Versions.v2016_05_30); - // TODO: enforceSessionCheck is true, replace with true - boolean enforceSessionCheck = true; - - MutableVolatile hasGoneException = new MutableVolatile(false); - MutableVolatile shortCircuitResult = new MutableVolatile(); - - return Observable.defer(() -> - readFromReplicas( - storeResultList, - resolveApiResults, - replicasToRead, - entity, - includePrimary, - replicaCountToRead, - requiresValidLsn, - useSessionToken, - readMode, - checkMinLSN, - forceReadAll, - requestSessionToken, - hasGoneException, - enforceSessionCheck, - shortCircuitResult)) - // repeat().takeUntil() simulate a while loop pattern - .repeat() - .takeUntil(x -> { - // Loop until we have the read quorum number of valid responses or if we have read all the replicas - if (replicasToRead.get() > 0 && resolveApiResults.size() > 0) { - // take more from the source observable - return false; - } else { - // enough result - return true; - } - }) - .toCompletable() - .andThen( - Observable.defer(() -> { - try { - // TODO: some fields which get updated need to be thread-safe - return Observable.just(createReadReplicaResult(storeResultList, replicaCountToRead, resolveApiResults.size(), hasGoneException.v, entity)); - } catch (Exception e) { - return Observable.error(e); - } - } - )); - })); - } catch (Exception e) { - return Observable.error(e); - } - } - ).toSingle(); - } - - public Single readPrimaryAsync( - RxDocumentServiceRequest entity, - boolean requiresValidLsn, - boolean useSessionToken) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - String originalSessionToken = entity.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - if (entity.requestContext.clientSideRequestStatistics == null) { - entity.requestContext.clientSideRequestStatistics = new ClientSideRequestStatistics(); - } - - return this.readPrimaryInternalAsync( - entity, requiresValidLsn, useSessionToken).flatMap( - readQuorumResult -> { - - if (entity.requestContext.performLocalRefreshOnGoneException && - readQuorumResult.retryWithForceRefresh && - !entity.requestContext.forceRefreshAddressCache) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - entity.requestContext.forceRefreshAddressCache = true; - return this.readPrimaryInternalAsync(entity, requiresValidLsn, useSessionToken); - } else { - return Single.just(readQuorumResult); - } - } - ).flatMap(readQuorumResult -> { - - // RxJava1 doesn't allow throwing Typed Exception from Observable.map(.) - // this is a design flaw which was fixed in RxJava2. - - // as our core is built on top of RxJava1 here we had to use Observable.flatMap(.) not map(.) - // once we switch to RxJava2 we can move to Observable.map(.) - // https://github.com/ReactiveX/RxJava/wiki/What's-different-in-2.0#functional-interfaces - if (readQuorumResult.responses.size() == 0) { - return Single.error(new GoneException(RMResources.Gone)); - } - - return Single.just(readQuorumResult.responses.get(0)); - - }).doOnEach(arg -> { - try { - SessionTokenHelper.setOriginalSessionToken(entity, originalSessionToken); - } catch (Throwable throwable) { - logger.error("Unexpected failure in handling orig [{}]: new [{}]", arg, throwable.getMessage(), throwable); - } - } - ); - } - - private Single readPrimaryInternalAsync( - RxDocumentServiceRequest entity, - boolean requiresValidLsn, - boolean useSessionToken) { - if (entity.requestContext.timeoutHelper.isElapsed()) { - return Single.error(new GoneException()); - } - - Single primaryUriObs = this.addressSelector.resolvePrimaryUriAsync( - entity, - entity.requestContext.forceRefreshAddressCache); - - Single storeResultObs = primaryUriObs.flatMap( - primaryUri -> { - try { - if (useSessionToken) { - SessionTokenHelper.setPartitionLocalSessionToken(entity, this.sessionContainer); - } else { - // Remove whatever session token can be there in headers. - // We don't need it. If it is global - backend will not undersand it. - // But there's no point in producing partition local sesison token. - entity.getHeaders().remove(HttpConstants.HttpHeaders.SESSION_TOKEN); - } - - - Pair, URI> storeResponseObsAndUri = this.readFromStoreAsync(primaryUri, entity); - - return storeResponseObsAndUri.getLeft().flatMap( - storeResponse -> { - - try { - StoreResult storeResult = this.createStoreResult( - storeResponse != null ? storeResponse : null, - null, requiresValidLsn, - true, - storeResponse != null ? storeResponseObsAndUri.getRight() : null); - return Single.just(storeResult); - } catch (DocumentClientException e) { - return Single.error(e); - } - } - - ); - - } catch (DocumentClientException e) { - // RxJava1 doesn't allow throwing checked exception from Observable:map - return Single.error(e); - } - - } - ).onErrorResumeNext(t -> { - logger.debug("Exception {} is thrown while doing Read Primary", t); - - Exception storeTaskException = Utils.as(t, Exception.class); - if (storeTaskException == null) { - return Single.error(t); - } - - try { - StoreResult storeResult = this.createStoreResult( - null, - storeTaskException, requiresValidLsn, - true, - null); - return Single.just(storeResult); - } catch (DocumentClientException e) { - // RxJava1 doesn't allow throwing checked exception from Observable operators - return Single.error(e); - } - }); - - return storeResultObs.map(storeResult -> { - entity.requestContext.clientSideRequestStatistics.recordResponse(entity, storeResult); - entity.requestContext.requestChargeTracker.addCharge(storeResult.requestCharge); - - if (storeResult.isGoneException && !storeResult.isInvalidPartitionException) { - return new ReadReplicaResult(true, Collections.emptyList()); - } - - return new ReadReplicaResult(false, Collections.singletonList(storeResult)); - }); - } - - private Pair, URI> readFromStoreAsync( - URI physicalAddress, - RxDocumentServiceRequest request) throws DocumentClientException { - - if (request.requestContext.timeoutHelper.isElapsed()) { - throw new GoneException(); - } - - //QueryRequestPerformanceActivity activity = null; - // TODO: ifNoneMatch and maxPageSize are not used in the .Net code. check with Ji - String ifNoneMatch = request.getHeaders().get(HttpConstants.HttpHeaders.IF_NONE_MATCH); - String continuation = null; - String maxPageSize = null; - - // TODO: is this needed - this.lastReadAddress = physicalAddress.toString(); - - if (request.getOperationType() == OperationType.ReadFeed || - request.getOperationType() == OperationType.Query) { - continuation = request.getHeaders().get(HttpConstants.HttpHeaders.CONTINUATION); - maxPageSize = request.getHeaders().get(HttpConstants.HttpHeaders.PAGE_SIZE); - - if (continuation != null && continuation.contains(";")) { - String[] parts = StringUtils.split(continuation, ';'); - if (parts.length < 3) { - throw new BadRequestException(String.format( - RMResources.InvalidHeaderValue, - continuation, - HttpConstants.HttpHeaders.CONTINUATION)); - } - - continuation = parts[0]; - } - - request.setContinuation(continuation); - - // TODO: troubleshooting - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/258624 - //activity = CustomTypeExtensions.StartActivity(request); - } - - switch (request.getOperationType()) { - case Read: - case Head: { - Single storeResponseObs = this.transportClient.invokeResourceOperationAsync( - physicalAddress, - request); - - return Pair.of(storeResponseObs, physicalAddress); - - } - - case ReadFeed: - case HeadFeed: - case Query: - case SqlQuery: - case ExecuteJavaScript: { - Single storeResponseObs = StoreReader.completeActivity(this.transportClient.invokeResourceOperationAsync( - physicalAddress, - request), null); - // TODO activity); - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/258624 - return Pair.of(storeResponseObs, physicalAddress); - } - - default: - throw new IllegalStateException(String.format("Unexpected operation type {%s}", request.getOperationType())); - } - } - - - private static Single completeActivity(Single task, Object activity) { - // TODO: client statistics - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/258624 - return task; - } - - StoreResult createStoreResult(StoreResponse storeResponse, - Exception responseException, - boolean requiresValidLsn, - boolean useLocalLSNBasedHeaders, - URI storePhysicalAddress) throws DocumentClientException { - - if (responseException == null) { - String headerValue = null; - long quorumAckedLSN = -1; - int currentReplicaSetSize = -1; - int currentWriteQuorum = -1; - long globalCommittedLSN = -1; - int numberOfReadRegions = -1; - long itemLSN = -1; - if ((headerValue = storeResponse.getHeaderValue( - useLocalLSNBasedHeaders ? WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN : WFConstants.BackendHeaders.QUORUM_ACKED_LSN)) != null) { - quorumAckedLSN = Long.parseLong(headerValue); - } - - if ((headerValue = storeResponse.getHeaderValue(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE)) != null) { - currentReplicaSetSize = Integer.parseInt(headerValue); - } - - if ((headerValue = storeResponse.getHeaderValue(WFConstants.BackendHeaders.CURRENT_WRITE_QUORUM)) != null) { - currentWriteQuorum = Integer.parseInt(headerValue); - } - - double requestCharge = 0; - if ((headerValue = storeResponse.getHeaderValue(HttpConstants.HttpHeaders.REQUEST_CHARGE)) != null) { - requestCharge = Double.parseDouble(headerValue); - } - - if ((headerValue = storeResponse.getHeaderValue(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS)) != null) { - numberOfReadRegions = Integer.parseInt(headerValue); - } - - if ((headerValue = storeResponse.getHeaderValue(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN)) != null) { - globalCommittedLSN = Long.parseLong(headerValue); - } - - if ((headerValue = storeResponse.getHeaderValue( - useLocalLSNBasedHeaders ? WFConstants.BackendHeaders.ITEM_LOCAL_LSN : WFConstants.BackendHeaders.ITEM_LSN)) != null) { - itemLSN = Long.parseLong(headerValue); - } - - long lsn = -1; - if (useLocalLSNBasedHeaders) { - if ((headerValue = storeResponse.getHeaderValue(WFConstants.BackendHeaders.LOCAL_LSN)) != null) { - lsn = Long.parseLong(headerValue); - } - } else { - lsn = storeResponse.getLSN(); - } - - ISessionToken sessionToken = null; - // Session token response header is introduced from version HttpConstants.Versions.v2018_06_18 onwards. - // Previously it was only a request header - if ((headerValue = storeResponse.getHeaderValue(HttpConstants.HttpHeaders.SESSION_TOKEN)) != null) { - sessionToken = SessionTokenHelper.parse(headerValue); - } - - return new StoreResult( - /* storeResponse: */storeResponse, - /* exception: */ null, - /* partitionKeyRangeId: */ storeResponse.getPartitionKeyRangeId(), - /* lsn: */ lsn, - /* quorumAckedLsn: */ quorumAckedLSN, - /* requestCharge: */ requestCharge, - /* currentReplicaSetSize: */ currentReplicaSetSize, - /* currentWriteQuorum: */ currentWriteQuorum, - /* isValid: */true, - /* storePhysicalAddress: */ storePhysicalAddress, - /* globalCommittedLSN: */ globalCommittedLSN, - /* numberOfReadRegions: */ numberOfReadRegions, - /* itemLSN: */ itemLSN, - /* sessionToken: */ sessionToken); - } else { - DocumentClientException documentClientException = Utils.as(responseException, DocumentClientException.class); - if (documentClientException != null) { - StoreReader.verifyCanContinueOnException(documentClientException); - long quorumAckedLSN = -1; - int currentReplicaSetSize = -1; - int currentWriteQuorum = -1; - long globalCommittedLSN = -1; - int numberOfReadRegions = -1; - String headerValue = documentClientException.getResponseHeaders().get(useLocalLSNBasedHeaders ? WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN : WFConstants.BackendHeaders.QUORUM_ACKED_LSN); - if (!Strings.isNullOrEmpty(headerValue)) { - quorumAckedLSN = Long.parseLong(headerValue); - } - - headerValue = documentClientException.getResponseHeaders().get(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE); - if (!Strings.isNullOrEmpty(headerValue)) { - currentReplicaSetSize = Integer.parseInt(headerValue); - } - - headerValue = documentClientException.getResponseHeaders().get(WFConstants.BackendHeaders.CURRENT_WRITE_QUORUM); - if (!Strings.isNullOrEmpty(headerValue)) { - currentReplicaSetSize = Integer.parseInt(headerValue); - } - - double requestCharge = 0; - headerValue = documentClientException.getResponseHeaders().get(HttpConstants.HttpHeaders.REQUEST_CHARGE); - if (!Strings.isNullOrEmpty(headerValue)) { - requestCharge = Double.parseDouble(headerValue); - } - - headerValue = documentClientException.getResponseHeaders().get(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS); - if (!Strings.isNullOrEmpty(headerValue)) { - numberOfReadRegions = Integer.parseInt(headerValue); - } - - headerValue = documentClientException.getResponseHeaders().get(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN); - if (!Strings.isNullOrEmpty(headerValue)) { - globalCommittedLSN = Integer.parseInt(headerValue); - } - - long lsn = -1; - if (useLocalLSNBasedHeaders) { - headerValue = documentClientException.getResponseHeaders().get(WFConstants.BackendHeaders.LOCAL_LSN); - if (!Strings.isNullOrEmpty(headerValue)) { - lsn = Long.parseLong(headerValue); - } - } else { - lsn = BridgeInternal.getLSN(documentClientException); - } - - ISessionToken sessionToken = null; - - // Session token response header is introduced from version HttpConstants.Versions.v2018_06_18 onwards. - // Previously it was only a request header - headerValue = documentClientException.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - if (!Strings.isNullOrEmpty(headerValue)) { - sessionToken = SessionTokenHelper.parse(headerValue); - } - - return new StoreResult( - /* storeResponse: */ (StoreResponse) null, - /* exception: */ documentClientException, - /* partitionKeyRangeId: */BridgeInternal.getPartitionKeyRangeId(documentClientException), - /* lsn: */ lsn, - /* quorumAckedLsn: */ quorumAckedLSN, - /* requestCharge: */ requestCharge, - /* currentReplicaSetSize: */ currentReplicaSetSize, - /* currentWriteQuorum: */ currentWriteQuorum, - /* isValid: */!requiresValidLsn - || ((documentClientException.getStatusCode() != HttpConstants.StatusCodes.GONE || isSubStatusCode(documentClientException, HttpConstants.SubStatusCodes.NAME_CACHE_IS_STALE)) - && lsn >= 0), - // TODO: verify where exception.RequestURI is supposed to be set in .Net - /* storePhysicalAddress: */ storePhysicalAddress == null ? BridgeInternal.getRequestUri(documentClientException) : storePhysicalAddress, - /* globalCommittedLSN: */ globalCommittedLSN, - /* numberOfReadRegions: */ numberOfReadRegions, - /* itemLSN: */ -1, - sessionToken); - } else { - logger.error("Unexpected exception {} received while reading from store.", responseException.getMessage(), responseException); - return new StoreResult( - /* storeResponse: */ null, - /* exception: */ new InternalServerErrorException(RMResources.InternalServerError), - /* partitionKeyRangeId: */ (String) null, - /* lsn: */ -1, - /* quorumAckedLsn: */ -1, - /* requestCharge: */ 0, - /* currentReplicaSetSize: */ 0, - /* currentWriteQuorum: */ 0, - /* isValid: */ false, - /* storePhysicalAddress: */ storePhysicalAddress, - /* globalCommittedLSN: */-1, - /* numberOfReadRegions: */ 0, - /* itemLSN: */ -1, - /* sessionToken: */ null); - } - } - } - - void startBackgroundAddressRefresh(RxDocumentServiceRequest request) { - this.addressSelector.resolveAllUriAsync(request, true, true) - .observeOn(Schedulers.io()) - .subscribe( - r -> { - }, - e -> logger.warn( - "Background refresh of the addresses failed with {}", e.getMessage(), e) - ); - } - - private static int generateNextRandom(int maxValue) { - // The benefit of using ThreadLocalRandom.current() over Random is - // avoiding the synchronization contention due to multi-threading. - return ThreadLocalRandom.current().nextInt(maxValue); - } - - static void verifyCanContinueOnException(DocumentClientException ex) throws DocumentClientException { - if (ex instanceof PartitionKeyRangeGoneException) { - throw ex; - } - - if (ex instanceof PartitionKeyRangeIsSplittingException) { - throw ex; - } - - if (ex instanceof PartitionIsMigratingException) { - throw ex; - } - - String value = ex.getResponseHeaders().get(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE); - if (Strings.isNullOrWhiteSpace(value)) { - return; - } - - Integer result = Integers.tryParse(value); - if (result != null && result == 1) { - throw ex; - } - - return; - } - - private class ReadReplicaResult { - public ReadReplicaResult(boolean retryWithForceRefresh, List responses) { - this.retryWithForceRefresh = retryWithForceRefresh; - this.responses = responses; - } - - public final boolean retryWithForceRefresh; - public final List responses; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportClient.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportClient.java deleted file mode 100644 index b25cbe351722..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportClient.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import rx.Single; - -import java.net.URI; - -public abstract class TransportClient implements AutoCloseable { - - // Uses requests's ResourceOperation to determine the operation - public Single invokeResourceOperationAsync(URI physicalAddress, RxDocumentServiceRequest request) { - return this.invokeStoreAsync(physicalAddress, new ResourceOperation(request.getOperationType(), request.getResourceType()), request); - } - - protected abstract Single invokeStoreAsync( - URI physicalAddress, - ResourceOperation resourceOperation, - RxDocumentServiceRequest request); -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportException.java deleted file mode 100644 index c1e3a499a018..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportException.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.Error; -import io.netty.handler.codec.http.HttpResponseStatus; - -import java.util.Map; - -public class TransportException extends Exception { - - final private Error error; - final private Map headers; - final private HttpResponseStatus status; - - public TransportException(HttpResponseStatus status, ObjectNode details, Map headers) { - - super("TODO: DANOBLE: format message string based on headers, and status information"); - this.error = BridgeInternal.createError(details); - this.headers = headers; - this.status = status; - } - - public Error getError() { - return error; - } - - public Map getHeaders() { - return headers; - } - - public HttpResponseStatus getStatus() { - return status; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/UnauthorizedException.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/UnauthorizedException.java deleted file mode 100644 index 5caf0c8b5916..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/UnauthorizedException.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -public class UnauthorizedException extends DocumentClientException { - - public UnauthorizedException() { - this(RMResources.Unauthorized); - } - - public UnauthorizedException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.UNAUTHORIZED, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public UnauthorizedException(String message) { - this(message, (Exception) null, (HttpResponseHeaders) null, null); - } - - public UnauthorizedException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public UnauthorizedException(String message, HttpResponseHeaders headers, URI requestUri) { - this(message, headers, requestUri != null ? requestUri.toString() : null); - } - - public UnauthorizedException(Exception innerException) { - this(RMResources.Unauthorized, innerException, null, null); - } - - public UnauthorizedException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.Unauthorized, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.UNAUTHORIZED, - requestUri != null ? requestUri.toString() : null); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdClientChannelHandler.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdClientChannelHandler.java deleted file mode 100644 index 7ea0ab72d948..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdClientChannelHandler.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.EventLoop; -import io.netty.channel.pool.ChannelPool; -import io.netty.channel.pool.ChannelPoolHandler; -import io.netty.handler.logging.LoggingHandler; -import io.netty.handler.ssl.SslHandler; -import io.netty.handler.timeout.ReadTimeoutHandler; -import io.netty.handler.timeout.WriteTimeoutHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.net.ssl.SSLEngine; -import java.util.concurrent.TimeUnit; - -import static com.google.common.base.Preconditions.checkNotNull; - -public class RntbdClientChannelHandler extends ChannelInitializer implements ChannelPoolHandler { - - private static Logger logger = LoggerFactory.getLogger(RntbdClientChannelHandler.class); - private final RntbdEndpoint.Config config; - - RntbdClientChannelHandler(final RntbdEndpoint.Config config) { - checkNotNull(config, "config"); - this.config = config; - } - - /** - * Called by {@link ChannelPool#acquire} after a {@link Channel} is acquired - *

- * This method is called within the {@link EventLoop} of the {@link Channel}. - * - * @param channel a channel that was just acquired - */ - @Override - public void channelAcquired(final Channel channel) throws Exception { - logger.trace("{} CHANNEL ACQUIRED", channel); - } - - /** - * Called by {@link ChannelPool#release} after a {@link Channel} is created - *

- * This method is called within the {@link EventLoop} of the {@link Channel}. - * - * @param channel a channel that was just created - */ - @Override - public void channelCreated(final Channel channel) throws Exception { - logger.trace("{} CHANNEL CREATED", channel); - this.initChannel(channel); - } - - /** - * Called by {@link ChannelPool#release} after a {@link Channel} is released - *

- * This method is called within the {@link EventLoop} of the {@link Channel}. - * - * @param channel a channel that was just released - */ - @Override - public void channelReleased(final Channel channel) throws Exception { - logger.trace("{} CHANNEL RELEASED", channel); - } - - /** - * Called by @{ChannelPipeline} initializer after the current channel is registered to an event loop. - *

- * This method constructs this pipeline: - *

{@code
-     * ChannelPipeline {
-     *     (ReadTimeoutHandler#0 = io.netty.handler.timeout.ReadTimeoutHandler),
-     *     (SslHandler#0 = io.netty.handler.ssl.SslHandler),
-     *     (RntbdContextNegotiator#0 = com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdContextNegotiator),
-     *     (RntbdResponseDecoder#0 = com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdResponseDecoder),
-     *     (RntbdRequestEncoder#0 = com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestEncoder),
-     *     (WriteTimeoutHandler#0 = io.netty.handler.timeout.WriteTimeoutHandler),
-     *     (RntbdRequestManager#0 = com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestManager),
-     *     (SimpleChannelPool$1#0 = io.netty.channel.pool.SimpleChannelPool$1)
-     * }
-     * }
- * - * @param channel a channel that was just registered with an event loop - */ - @Override - protected void initChannel(final Channel channel) { - - checkNotNull(channel); - - assert channel.isRegistered(); - assert channel.isOpen(); - assert !channel.isActive(); - - final RntbdRequestManager requestManager = new RntbdRequestManager(); - final long readerIdleTime = this.config.getReceiveHangDetectionTime(); - final long writerIdleTime = this.config.getSendHangDetectionTime(); - final ChannelPipeline pipeline = channel.pipeline(); - - pipeline.addFirst( - new RntbdContextNegotiator(requestManager, this.config.getUserAgent()), - new RntbdResponseDecoder(), - new RntbdRequestEncoder(), - new WriteTimeoutHandler(writerIdleTime, TimeUnit.NANOSECONDS), - requestManager - ); - - if (this.config.getWireLogLevel() != null) { - pipeline.addFirst(new LoggingHandler(this.config.getWireLogLevel())); - } - - final SSLEngine sslEngine = this.config.getSslContext().newEngine(channel.alloc()); - - pipeline.addFirst( - new ReadTimeoutHandler(readerIdleTime, TimeUnit.NANOSECONDS), - new SslHandler(sslEngine) - ); - } - -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdClientChannelPool.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdClientChannelPool.java deleted file mode 100644 index e1ef4d31f9ee..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdClientChannelPool.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import io.netty.bootstrap.Bootstrap; -import io.netty.channel.Channel; -import io.netty.channel.ChannelId; -import io.netty.channel.pool.ChannelHealthChecker; -import io.netty.channel.pool.FixedChannelPool; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.Promise; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; - -@JsonSerialize(using = RntbdClientChannelPool.JsonSerializer.class) -public final class RntbdClientChannelPool extends FixedChannelPool { - - private static final Logger logger = LoggerFactory.getLogger(RntbdClientChannelPool.class); - private static final AtomicReference pendingAcquireCount = new AtomicReference<>(); - - private final ConcurrentHashMap atCapacity; - private final AtomicInteger availableChannelCount; - private final AtomicBoolean closed; - private final int maxRequestsPerChannel; - - /** - * Creates a new instance using the {@link ChannelHealthChecker#ACTIVE} - * - * @param bootstrap the {@link Bootstrap} that is used for connections - * @param config the {@link RntbdEndpoint.Config} that is used for the channel pool instance created - */ - RntbdClientChannelPool(final Bootstrap bootstrap, final RntbdEndpoint.Config config) { - - super(bootstrap, new RntbdClientChannelHandler(config), ChannelHealthChecker.ACTIVE, null, - -1L, config.getMaxChannelsPerEndpoint(), Integer.MAX_VALUE, true - ); - - this.maxRequestsPerChannel = config.getMaxRequestsPerChannel(); - this.availableChannelCount = new AtomicInteger(); - this.atCapacity = new ConcurrentHashMap<>(); - this.closed = new AtomicBoolean(); - } - - @Override - public Future acquire(Promise promise) { - this.throwIfClosed(); - return super.acquire(promise); - } - - @Override - public Future release(Channel channel, Promise promise) { - this.throwIfClosed(); - return super.release(channel, promise); - } - - @Override - public void close() { - - if (this.closed.compareAndSet(false, true)) { - - if (!this.atCapacity.isEmpty()) { - - for (Channel channel : this.atCapacity.values()) { - super.offerChannel(channel); - } - - this.atCapacity.clear(); - } - - this.availableChannelCount.set(0); - super.close(); - } - } - - public int availableChannelCount() { - return this.availableChannelCount.get(); - } - - public int pendingAcquireCount() { - - Field field = pendingAcquireCount.get(); - - if (field == null) { - - synchronized (pendingAcquireCount) { - - field = pendingAcquireCount.get(); - - if (field == null) { - field = FieldUtils.getDeclaredField(FixedChannelPool.class, "pendingAcquireCount", true); - pendingAcquireCount.set(field); - } - } - - } - try { - return (int)FieldUtils.readField(field, this); - } catch (IllegalAccessException error) { - logger.error("could not access field due to ", error); - } - - return -1; - } - - /** - * Poll a {@link Channel} out of internal storage to reuse it - *

- * Maintainers: Implementations of this method must be thread-safe. - * - * @return a value of {@code null}, if no {@link Channel} is ready to be reused - */ - @Override - protected synchronized Channel pollChannel() { - - final Channel channel = super.pollChannel(); - - if (channel != null) { - this.availableChannelCount.decrementAndGet(); - return channel; - } - - if (this.atCapacity.isEmpty()) { - return null; - } - - return this.atCapacity.search(Long.MAX_VALUE, (id, value) -> { - if (pendingRequestCount(value) < this.maxRequestsPerChannel) { - this.availableChannelCount.decrementAndGet(); - this.atCapacity.remove(id); - return value; - } - return null; - }); - } - - /** - * Offer a {@link Channel} back to the internal storage - *

- * Maintainers: Implementations of this method must be thread-safe. - * - * @param channel the {@link Channel} to return to internal storage - * @return {@code true}, if the {@link Channel} could be added to internal storage; otherwise {@code false} - */ - @Override - protected synchronized boolean offerChannel(final Channel channel) { - - checkArgument(channel.isActive(), "%s inactive", channel); - final boolean offered; - - if (pendingRequestCount(channel) >= this.maxRequestsPerChannel) { - this.atCapacity.put(channel.id(), channel); - offered = true; - } else { - offered = super.offerChannel(channel); - } - - if (offered) { - this.availableChannelCount.incrementAndGet(); - } - - return offered; - } - - @Override - public String toString() { - return RntbdObjectMapper.toJson(this); - } - - private static int pendingRequestCount(final Channel channel) { - return channel.pipeline().get(RntbdRequestManager.class).getPendingRequestCount(); - } - - private void throwIfClosed() { - checkState(!this.closed.get(), "%s is closed", this); - } - - // region Types - - static final class JsonSerializer extends StdSerializer { - - public JsonSerializer() { - this(null); - } - - public JsonSerializer(Class type) { - super(type); - } - - @Override - public void serialize(RntbdClientChannelPool value, JsonGenerator generator, SerializerProvider provider) throws IOException { - - generator.writeStartObject(); - generator.writeNumberField("acquiredChannelCount", value.acquiredChannelCount()); - generator.writeNumberField("availableChannelCount", value.availableChannelCount()); - generator.writeNumberField("maxRequestsPerChannel", value.maxRequestsPerChannel); - generator.writeNumberField("pendingAcquisitionCount", value.pendingAcquireCount()); - generator.writeBooleanField("isClosed", value.closed.get()); - generator.writeEndObject(); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdConstants.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdConstants.java deleted file mode 100644 index e57e7660f274..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdConstants.java +++ /dev/null @@ -1,750 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; - -import java.util.EnumSet; -import java.util.stream.Collector; - -final class RntbdConstants { - - static final int CurrentProtocolVersion = 0x00000001; - - private RntbdConstants() { - } - - public enum RntbdConsistencyLevel { - - Strong((byte)0x00), - BoundedStaleness((byte)0x01), - Session((byte)0x02), - Eventual((byte)0x03), - ConsistentPrefix((byte)0x04), - - Invalid((byte)0xFF); - - private final byte id; - - RntbdConsistencyLevel(final byte id) { - this.id = id; - } - - public byte id() { - return this.id; - } - } - - public enum RntbdContentSerializationFormat { - - JsonText((byte)0x00), - CosmosBinary((byte)0x01), - - Invalid((byte)0xFF); - - private final byte id; - - RntbdContentSerializationFormat(final byte id) { - this.id = id; - } - - public byte id() { - return this.id; - } - } - - enum RntbdContextHeader implements RntbdHeader { - - ProtocolVersion((short)0x0000, RntbdTokenType.ULong, false), - ClientVersion((short)0x0001, RntbdTokenType.SmallString, false), - ServerAgent((short)0x0002, RntbdTokenType.SmallString, true), - ServerVersion((short)0x0003, RntbdTokenType.SmallString, true), - IdleTimeoutInSeconds((short)0x0004, RntbdTokenType.ULong, false), - UnauthenticatedTimeoutInSeconds((short)0x0005, RntbdTokenType.ULong, false); - - public static final ImmutableMap map; - public static final ImmutableSet set = Sets.immutableEnumSet(EnumSet.allOf(RntbdContextHeader.class)); - - static { - final Collector> collector = ImmutableMap.toImmutableMap(RntbdContextHeader::id, h -> h); - map = set.stream().collect(collector); - } - - private final short id; - private final boolean isRequired; - private final RntbdTokenType type; - - RntbdContextHeader(final short id, final RntbdTokenType type, final boolean isRequired) { - this.id = id; - this.type = type; - this.isRequired = isRequired; - } - - public boolean isRequired() { - return this.isRequired; - } - - public short id() { - return this.id; - } - - public RntbdTokenType type() { - return this.type; - } - } - - enum RntbdContextRequestHeader implements RntbdHeader { - - ProtocolVersion((short)0x0000, RntbdTokenType.ULong, true), - ClientVersion((short)0x0001, RntbdTokenType.SmallString, true), - UserAgent((short)0x0002, RntbdTokenType.SmallString, true); - - public static final ImmutableMap map; - public static final ImmutableSet set = Sets.immutableEnumSet(EnumSet.allOf(RntbdContextRequestHeader.class)); - - static { - final Collector> collector = ImmutableMap.toImmutableMap(h -> h.id(), h -> h); - map = set.stream().collect(collector); - } - - private final short id; - private final boolean isRequired; - private final RntbdTokenType type; - - RntbdContextRequestHeader(final short id, final RntbdTokenType type, final boolean isRequired) { - this.id = id; - this.type = type; - this.isRequired = isRequired; - } - - public boolean isRequired() { - return this.isRequired; - } - - public short id() { - return this.id; - } - - public RntbdTokenType type() { - return this.type; - } - } - - public enum RntbdEnumerationDirection { - - Invalid((byte)0x00), - - Forward((byte)0x01), - Reverse((byte)0x02); - - private final byte id; - - RntbdEnumerationDirection(final byte id) { - this.id = id; - } - - public byte id() { - return this.id; - } - } - - public enum RntbdFanoutOperationState { - - Started((byte)0x01), - Completed((byte)0x02); - - private final byte id; - - RntbdFanoutOperationState(final byte id) { - this.id = id; - } - - public byte id() { - return this.id; - } - } - - enum RntbdIndexingDirective { - - Default((byte)0x00), - Include((byte)0x01), - Exclude((byte)0x02), - Invalid((byte)0xFF); - - private final byte id; - - RntbdIndexingDirective(final byte id) { - this.id = id; - } - - public static RntbdIndexingDirective fromId(final byte id) { - switch (id) { - case (byte)0x00: - return Default; - case (byte)0x01: - return Include; - case (byte)0x02: - return Exclude; - case (byte)0xFF: - return Invalid; - } - throw new IllegalArgumentException("id"); - } - - public byte id() { - return this.id; - } - } - - public enum RntbdMigrateCollectionDirective { - - Thaw((byte)0x00), - Freeze((byte)0x01), - - Invalid((byte)0xFF); - - private final byte id; - - RntbdMigrateCollectionDirective(final byte id) { - this.id = id; - } - - public byte id() { - return this.id; - } - } - - enum RntbdOperationType { - - Connection((short)0x0000), - Create((short)0x0001), - Update((short)0x0002), - Read((short)0x0003), - ReadFeed((short)0x0004), - Delete((short)0x0005), - Replace((short)0x0006), - // Obsolete and now undefined: JPathQuery((short)0x0007), - ExecuteJavaScript((short)0x0008), - SQLQuery((short)0x0009), - Pause((short)0x000A), - Resume((short)0x000B), - Stop((short)0x000C), - Recycle((short)0x000D), - Crash((short)0x000E), - Query((short)0x000F), - ForceConfigRefresh((short)0x0010), - Head((short)0x0011), - HeadFeed((short)0x0012), - Upsert((short)0x0013), - Recreate((short)0x0014), - Throttle((short)0x0015), - GetSplitPoint((short)0x0016), - PreCreateValidation((short)0x0017), - BatchApply((short)0x0018), - AbortSplit((short)0x0019), - CompleteSplit((short)0x001A), - OfferUpdateOperation((short)0x001B), - OfferPreGrowValidation((short)0x001C), - BatchReportThroughputUtilization((short)0x001D), - CompletePartitionMigration((short)0x001E), - AbortPartitionMigration((short)0x001F), - PreReplaceValidation((short)0x0020), - AddComputeGatewayRequestCharges((short)0x0021), - MigratePartition((short)0x0022); - - private final short id; - - RntbdOperationType(final short id) { - this.id = id; - } - - public static RntbdOperationType fromId(final short id) throws IllegalArgumentException { - - switch (id) { - case 0x0000: - return RntbdOperationType.Connection; - case 0x0001: - return RntbdOperationType.Create; - case 0x0002: - return RntbdOperationType.Update; - case 0x0003: - return RntbdOperationType.Read; - case 0x0004: - return RntbdOperationType.ReadFeed; - case 0x0005: - return RntbdOperationType.Delete; - case 0x0006: - return RntbdOperationType.Replace; - // Obsolete and now undefined: case 0x0007: return RntbdOperationType.JPathQuery; - case 0x0008: - return RntbdOperationType.ExecuteJavaScript; - case 0x0009: - return RntbdOperationType.SQLQuery; - case 0x000A: - return RntbdOperationType.Pause; - case 0x000B: - return RntbdOperationType.Resume; - case 0x000C: - return RntbdOperationType.Stop; - case 0x000D: - return RntbdOperationType.Recycle; - case 0x000E: - return RntbdOperationType.Crash; - case 0x000F: - return RntbdOperationType.Query; - case 0x0010: - return RntbdOperationType.ForceConfigRefresh; - case 0x0011: - return RntbdOperationType.Head; - case 0x0012: - return RntbdOperationType.HeadFeed; - case 0x0013: - return RntbdOperationType.Upsert; - case 0x0014: - return RntbdOperationType.Recreate; - case 0x0015: - return RntbdOperationType.Throttle; - case 0x0016: - return RntbdOperationType.GetSplitPoint; - case 0x0017: - return RntbdOperationType.PreCreateValidation; - case 0x0018: - return RntbdOperationType.BatchApply; - case 0x0019: - return RntbdOperationType.AbortSplit; - case 0x001A: - return RntbdOperationType.CompleteSplit; - case 0x001B: - return RntbdOperationType.OfferUpdateOperation; - case 0x001C: - return RntbdOperationType.OfferPreGrowValidation; - case 0x001D: - return RntbdOperationType.BatchReportThroughputUtilization; - case 0x001E: - return RntbdOperationType.CompletePartitionMigration; - case 0x001F: - return RntbdOperationType.AbortPartitionMigration; - case 0x0020: - return RntbdOperationType.PreReplaceValidation; - case 0x0021: - return RntbdOperationType.AddComputeGatewayRequestCharges; - case 0x0022: - return RntbdOperationType.MigratePartition; - } - throw new IllegalArgumentException("id"); - } - - public short id() { - return this.id; - } - } - - public enum RntbdReadFeedKeyType { - - Invalid((byte)0x00), - ResourceId((byte)0x01), - EffectivePartitionKey((byte)0x02); - - private final byte id; - - RntbdReadFeedKeyType(final byte id) { - this.id = id; - } - - public byte id() { - return this.id; - } - } - - public enum RntbdRemoteStorageType { - - Invalid((byte)0x00), - NotSpecified((byte)0x01), - Standard((byte)0x02), - Premium((byte)0x03); - - private final byte id; - - RntbdRemoteStorageType(final byte id) { - this.id = id; - } - - public byte id() { - return this.id; - } - } - - public enum RntbdRequestHeader implements RntbdHeader { - - ResourceId((short)0x0000, RntbdTokenType.Bytes, false), - AuthorizationToken((short)0x0001, RntbdTokenType.String, false), - PayloadPresent((short)0x0002, RntbdTokenType.Byte, true), - Date((short)0x0003, RntbdTokenType.SmallString, false), - PageSize((short)0x0004, RntbdTokenType.ULong, false), - SessionToken((short)0x0005, RntbdTokenType.String, false), - ContinuationToken((short)0x0006, RntbdTokenType.String, false), - IndexingDirective((short)0x0007, RntbdTokenType.Byte, false), - Match((short)0x0008, RntbdTokenType.String, false), - PreTriggerInclude((short)0x0009, RntbdTokenType.String, false), - PostTriggerInclude((short)0x000A, RntbdTokenType.String, false), - IsFanout((short)0x000B, RntbdTokenType.Byte, false), - CollectionPartitionIndex((short)0x000C, RntbdTokenType.ULong, false), - CollectionServiceIndex((short)0x000D, RntbdTokenType.ULong, false), - PreTriggerExclude((short)0x000E, RntbdTokenType.String, false), - PostTriggerExclude((short)0x000F, RntbdTokenType.String, false), - ConsistencyLevel((short)0x0010, RntbdTokenType.Byte, false), - EntityId((short)0x0011, RntbdTokenType.String, false), - ResourceSchemaName((short)0x0012, RntbdTokenType.SmallString, false), - ReplicaPath((short)0x0013, RntbdTokenType.String, true), - ResourceTokenExpiry((short)0x0014, RntbdTokenType.ULong, false), - DatabaseName((short)0x0015, RntbdTokenType.String, false), - CollectionName((short)0x0016, RntbdTokenType.String, false), - DocumentName((short)0x0017, RntbdTokenType.String, false), - AttachmentName((short)0x0018, RntbdTokenType.String, false), - UserName((short)0x0019, RntbdTokenType.String, false), - PermissionName((short)0x001A, RntbdTokenType.String, false), - StoredProcedureName((short)0x001B, RntbdTokenType.String, false), - UserDefinedFunctionName((short)0x001C, RntbdTokenType.String, false), - TriggerName((short)0x001D, RntbdTokenType.String, false), - EnableScanInQuery((short)0x001E, RntbdTokenType.Byte, false), - EmitVerboseTracesInQuery((short)0x001F, RntbdTokenType.Byte, false), - ConflictName((short)0x0020, RntbdTokenType.String, false), - BindReplicaDirective((short)0x0021, RntbdTokenType.String, false), - PrimaryMasterKey((short)0x0022, RntbdTokenType.String, false), - SecondaryMasterKey((short)0x0023, RntbdTokenType.String, false), - PrimaryReadonlyKey((short)0x0024, RntbdTokenType.String, false), - SecondaryReadonlyKey((short)0x0025, RntbdTokenType.String, false), - ProfileRequest((short)0x0026, RntbdTokenType.Byte, false), - EnableLowPrecisionOrderBy((short)0x0027, RntbdTokenType.Byte, false), - ClientVersion((short)0x0028, RntbdTokenType.SmallString, false), - CanCharge((short)0x0029, RntbdTokenType.Byte, false), - CanThrottle((short)0x002A, RntbdTokenType.Byte, false), - PartitionKey((short)0x002B, RntbdTokenType.String, false), - PartitionKeyRangeId((short)0x002C, RntbdTokenType.String, false), - NotUsed2D((short)0x002D, RntbdTokenType.Invalid, false), - NotUsed2E((short)0x002E, RntbdTokenType.Invalid, false), - NotUsed2F((short)0x002F, RntbdTokenType.Invalid, false), - // not used 0x0030, - MigrateCollectionDirective((short)0x0031, RntbdTokenType.Byte, false), - NotUsed32((short)0x0032, RntbdTokenType.Invalid, false), - SupportSpatialLegacyCoordinates((short)0x0033, RntbdTokenType.Byte, false), - PartitionCount((short)0x0034, RntbdTokenType.ULong, false), - CollectionRid((short)0x0035, RntbdTokenType.String, false), - PartitionKeyRangeName((short)0x0036, RntbdTokenType.String, false), - // not used((short)0x0037), RoundTripTimeInMsec - // not used((short)0x0038), RequestMessageSentTime - // not used((short)0x0039), RequestMessageTimeOffset - SchemaName((short)0x003A, RntbdTokenType.String, false), - FilterBySchemaRid((short)0x003B, RntbdTokenType.String, false), - UsePolygonsSmallerThanAHemisphere((short)0x003C, RntbdTokenType.Byte, false), - GatewaySignature((short)0x003D, RntbdTokenType.String, false), - EnableLogging((short)0x003E, RntbdTokenType.Byte, false), - A_IM((short)0x003F, RntbdTokenType.String, false), - PopulateQuotaInfo((short)0x0040, RntbdTokenType.Byte, false), - DisableRUPerMinuteUsage((short)0x0041, RntbdTokenType.Byte, false), - PopulateQueryMetrics((short)0x0042, RntbdTokenType.Byte, false), - ResponseContinuationTokenLimitInKb((short)0x0043, RntbdTokenType.ULong, false), - PopulatePartitionStatistics((short)0x0044, RntbdTokenType.Byte, false), - RemoteStorageType((short)0x0045, RntbdTokenType.Byte, false), - CollectionRemoteStorageSecurityIdentifier((short)0x0046, RntbdTokenType.String, false), - IfModifiedSince((short)0x0047, RntbdTokenType.String, false), - PopulateCollectionThroughputInfo((short)0x0048, RntbdTokenType.Byte, false), - RemainingTimeInMsOnClientRequest((short)0x0049, RntbdTokenType.ULong, false), - ClientRetryAttemptCount((short)0x004A, RntbdTokenType.ULong, false), - TargetLsn((short)0x004B, RntbdTokenType.LongLong, false), - TargetGlobalCommittedLsn((short)0x004C, RntbdTokenType.LongLong, false), - TransportRequestID((short)0x004D, RntbdTokenType.ULong, false), - RestoreMetadaFilter((short)0x004E, RntbdTokenType.String, false), - RestoreParams((short)0x004F, RntbdTokenType.String, false), - ShareThroughput((short)0x0050, RntbdTokenType.Byte, false), - PartitionResourceFilter((short)0x0051, RntbdTokenType.String, false), - IsReadOnlyScript((short)0x0052, RntbdTokenType.Byte, false), - IsAutoScaleRequest((short)0x0053, RntbdTokenType.Byte, false), - ForceQueryScan((short)0x0054, RntbdTokenType.Byte, false), - // not used((short)0x0055), LeaseSeqNumber - CanOfferReplaceComplete((short)0x0056, RntbdTokenType.Byte, false), - ExcludeSystemProperties((short)0x0057, RntbdTokenType.Byte, false), - BinaryId((short)0x0058, RntbdTokenType.Bytes, false), - TimeToLiveInSeconds((short)0x0059, RntbdTokenType.Long, false), - EffectivePartitionKey((short)0x005A, RntbdTokenType.Bytes, false), - BinaryPassthroughRequest((short)0x005B, RntbdTokenType.Byte, false), - UserDefinedTypeName((short)0x005C, RntbdTokenType.String, false), - EnableDynamicRidRangeAllocation((short)0x005D, RntbdTokenType.Byte, false), - EnumerationDirection((short)0x005E, RntbdTokenType.Byte, false), - StartId((short)0x005F, RntbdTokenType.Bytes, false), - EndId((short)0x0060, RntbdTokenType.Bytes, false), - FanoutOperationState((short)0x0061, RntbdTokenType.Byte, false), - StartEpk((short)0x0062, RntbdTokenType.Bytes, false), - EndEpk((short)0x0063, RntbdTokenType.Bytes, false), - ReadFeedKeyType((short)0x0064, RntbdTokenType.Byte, false), - ContentSerializationFormat((short)0x0065, RntbdTokenType.Byte, false), - AllowTentativeWrites((short)0x0066, RntbdTokenType.Byte, false), - IsUserRequest((short)0x0067, RntbdTokenType.Byte, false), - SharedOfferThroughput((short)0x0068, RntbdTokenType.ULong, false); - - public static final ImmutableMap map; - public static final ImmutableSet set = Sets.immutableEnumSet(EnumSet.allOf(RntbdRequestHeader.class)); - - static { - final Collector> collector = ImmutableMap.toImmutableMap(RntbdRequestHeader::id, h -> h); - map = set.stream().collect(collector); - } - - private final short id; - private final boolean isRequired; - private final RntbdTokenType type; - - RntbdRequestHeader(final short id, final RntbdTokenType type, final boolean isRequired) { - this.id = id; - this.type = type; - this.isRequired = isRequired; - } - - public boolean isRequired() { - return this.isRequired; - } - - public short id() { - return this.id; - } - - public RntbdTokenType type() { - return this.type; - } - } - - enum RntbdResourceType { - - Connection((short)0x0000), - Database((short)0x0001), - Collection((short)0x0002), - Document((short)0x0003), - Attachment((short)0x0004), - User((short)0x0005), - Permission((short)0x0006), - StoredProcedure((short)0x0007), - Conflict((short)0x0008), - Trigger((short)0x0009), - UserDefinedFunction((short)0x000A), - Module((short)0x000B), - Replica((short)0x000C), - ModuleCommand((short)0x000D), - Record((short)0x000E), - Offer((short)0x000F), - PartitionSetInformation((short)0x0010), - XPReplicatorAddress((short)0x0011), - MasterPartition((short)0x0012), - ServerPartition((short)0x0013), - DatabaseAccount((short)0x0014), - Topology((short)0x0015), - PartitionKeyRange((short)0x0016), - // Obsolete and now undefined: Timestamp((short)0x0017), - Schema((short)0x0018), - BatchApply((short)0x0019), - RestoreMetadata((short)0x001A), - ComputeGatewayCharges((short)0x001B), - RidRange((short)0x001C), - UserDefinedType((short)0x001D); - - private final short id; - - RntbdResourceType(final short id) { - this.id = id; - } - - public static RntbdResourceType fromId(final short id) throws IllegalArgumentException { - switch (id) { - case 0x0000: - return RntbdResourceType.Connection; - case 0x0001: - return RntbdResourceType.Database; - case 0x0002: - return RntbdResourceType.Collection; - case 0x0003: - return RntbdResourceType.Document; - case 0x0004: - return RntbdResourceType.Attachment; - case 0x0005: - return RntbdResourceType.User; - case 0x0006: - return RntbdResourceType.Permission; - case 0x0007: - return RntbdResourceType.StoredProcedure; - case 0x0008: - return RntbdResourceType.Conflict; - case 0x0009: - return RntbdResourceType.Trigger; - case 0x000A: - return RntbdResourceType.UserDefinedFunction; - case 0x000B: - return RntbdResourceType.Module; - case 0x000C: - return RntbdResourceType.Replica; - case 0x000D: - return RntbdResourceType.ModuleCommand; - case 0x000E: - return RntbdResourceType.Record; - case 0x000F: - return RntbdResourceType.Offer; - case 0x0010: - return RntbdResourceType.PartitionSetInformation; - case 0x0011: - return RntbdResourceType.XPReplicatorAddress; - case 0x0012: - return RntbdResourceType.MasterPartition; - case 0x0013: - return RntbdResourceType.ServerPartition; - case 0x0014: - return RntbdResourceType.DatabaseAccount; - case 0x0015: - return RntbdResourceType.Topology; - case 0x0016: - return RntbdResourceType.PartitionKeyRange; - // Obsolete and now undefined: case 0x0017: return RntbdResourceType.Timestamp; - case 0x0018: - return RntbdResourceType.Schema; - case 0x0019: - return RntbdResourceType.BatchApply; - case 0x001A: - return RntbdResourceType.RestoreMetadata; - case 0x001B: - return RntbdResourceType.ComputeGatewayCharges; - case 0x001C: - return RntbdResourceType.RidRange; - case 0x001D: - return RntbdResourceType.UserDefinedType; - } - throw new IllegalArgumentException(String.format("id: %d", id)); - } - - public short id() { - return this.id; - } - } - - public enum RntbdResponseHeader implements RntbdHeader { - - PayloadPresent((short)0x0000, RntbdTokenType.Byte, true), - // not used((short)0x0001), - LastStateChangeDateTime((short)0x0002, RntbdTokenType.SmallString, false), - ContinuationToken((short)0x0003, RntbdTokenType.String, false), - ETag((short)0x0004, RntbdTokenType.String, false), - // not used((short)0x005,) - // not used((short)0x006,) - ReadsPerformed((short)0x0007, RntbdTokenType.ULong, false), - WritesPerformed((short)0x0008, RntbdTokenType.ULong, false), - QueriesPerformed((short)0x0009, RntbdTokenType.ULong, false), - IndexTermsGenerated((short)0x000A, RntbdTokenType.ULong, false), - ScriptsExecuted((short)0x000B, RntbdTokenType.ULong, false), - RetryAfterMilliseconds((short)0x000C, RntbdTokenType.ULong, false), - IndexingDirective((short)0x000D, RntbdTokenType.Byte, false), - StorageMaxResoureQuota((short)0x000E, RntbdTokenType.String, false), - StorageResourceQuotaUsage((short)0x000F, RntbdTokenType.String, false), - SchemaVersion((short)0x0010, RntbdTokenType.SmallString, false), - CollectionPartitionIndex((short)0x0011, RntbdTokenType.ULong, false), - CollectionServiceIndex((short)0x0012, RntbdTokenType.ULong, false), - LSN((short)0x0013, RntbdTokenType.LongLong, false), - ItemCount((short)0x0014, RntbdTokenType.ULong, false), - RequestCharge((short)0x0015, RntbdTokenType.Double, false), - // not used((short)0x0016), - OwnerFullName((short)0x0017, RntbdTokenType.String, false), - OwnerId((short)0x0018, RntbdTokenType.String, false), - DatabaseAccountId((short)0x0019, RntbdTokenType.String, false), - QuorumAckedLSN((short)0x001A, RntbdTokenType.LongLong, false), - RequestValidationFailure((short)0x001B, RntbdTokenType.Byte, false), - SubStatus((short)0x001C, RntbdTokenType.ULong, false), - CollectionUpdateProgress((short)0x001D, RntbdTokenType.ULong, false), - CurrentWriteQuorum((short)0x001E, RntbdTokenType.ULong, false), - CurrentReplicaSetSize((short)0x001F, RntbdTokenType.ULong, false), - CollectionLazyIndexProgress((short)0x0020, RntbdTokenType.ULong, false), - PartitionKeyRangeId((short)0x0021, RntbdTokenType.String, false), - // not used((short)0x0022), RequestMessageReceivedTime - // not used((short)0x0023), ResponseMessageSentTime - // not used((short)0x0024), ResponseMessageTimeOffset - LogResults((short)0x0025, RntbdTokenType.String, false), - XPRole((short)0x0026, RntbdTokenType.ULong, false), - IsRUPerMinuteUsed((short)0x0027, RntbdTokenType.Byte, false), - QueryMetrics((short)0x0028, RntbdTokenType.String, false), - GlobalCommittedLSN((short)0x0029, RntbdTokenType.LongLong, false), - NumberOfReadRegions((short)0x0030, RntbdTokenType.ULong, false), - OfferReplacePending((short)0x0031, RntbdTokenType.Byte, false), - ItemLSN((short)0x0032, RntbdTokenType.LongLong, false), - RestoreState((short)0x0033, RntbdTokenType.String, false), - CollectionSecurityIdentifier((short)0x0034, RntbdTokenType.String, false), - TransportRequestID((short)0x0035, RntbdTokenType.ULong, false), - ShareThroughput((short)0x0036, RntbdTokenType.Byte, false), - // not used((short)0x0037), LeaseSeqNumber - DisableRntbdChannel((short)0x0038, RntbdTokenType.Byte, false), - ServerDateTimeUtc((short)0x0039, RntbdTokenType.SmallString, false), - LocalLSN((short)0x003A, RntbdTokenType.LongLong, false), - QuorumAckedLocalLSN((short)0x003B, RntbdTokenType.LongLong, false), - ItemLocalLSN((short)0x003C, RntbdTokenType.LongLong, false), - HasTentativeWrites((short)0x003D, RntbdTokenType.Byte, false), - SessionToken((short)0x003E, RntbdTokenType.String, false); - - public static final ImmutableMap map; - public static final ImmutableSet set = Sets.immutableEnumSet(EnumSet.allOf(RntbdResponseHeader.class)); - - static { - final Collector> collector = ImmutableMap.toImmutableMap(RntbdResponseHeader::id, header -> header); - map = set.stream().collect(collector); - } - - private final short id; - private final boolean isRequired; - private final RntbdTokenType type; - - RntbdResponseHeader(final short id, final RntbdTokenType type, final boolean isRequired) { - this.id = id; - this.type = type; - this.isRequired = isRequired; - } - - public boolean isRequired() { - return this.isRequired; - } - - public short id() { - return this.id; - } - - public RntbdTokenType type() { - return this.type; - } - } - - interface RntbdHeader { - - boolean isRequired(); - - short id(); - - String name(); - - RntbdTokenType type(); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContext.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContext.java deleted file mode 100644 index bd506d1425af..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContext.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.ServerProperties; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.TransportException; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.CorruptedFrameException; -import io.netty.handler.codec.http.HttpResponseStatus; - -import java.util.Collections; -import java.util.HashMap; -import java.util.UUID; - -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.CurrentProtocolVersion; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdContextHeader; - -public final class RntbdContext { - - private final RntbdResponseStatus frame; - private final Headers headers; - - private RntbdContext(final RntbdResponseStatus frame, final Headers headers) { - - this.frame = frame; - this.headers = headers; - } - - @JsonProperty - UUID getActivityId() { - return this.frame.getActivityId(); - } - - @JsonProperty - String getClientVersion() { - return this.headers.clientVersion.getValue(String.class); - } - - @JsonProperty - long getIdleTimeoutInSeconds() { - return this.headers.idleTimeoutInSeconds.getValue(Long.class); - } - - @JsonProperty - int getProtocolVersion() { - return this.headers.protocolVersion.getValue(Long.class).intValue(); - } - - @JsonProperty - ServerProperties getServerProperties() { - return new ServerProperties( - this.headers.serverAgent.getValue(String.class), - this.headers.serverVersion.getValue(String.class) - ); - } - - String getServerVersion() { - return this.headers.serverVersion.getValue(String.class); - } - - @JsonProperty - int getStatusCode() { - return this.frame.getStatusCode(); - } - - @JsonProperty - long getUnauthenticatedTimeoutInSeconds() { - return this.headers.unauthenticatedTimeoutInSeconds.getValue(Long.class); - } - - static RntbdContext decode(final ByteBuf in) throws TransportException { - - in.markReaderIndex(); - - final RntbdResponseStatus frame = RntbdResponseStatus.decode(in); - final int statusCode = frame.getStatusCode(); - final int headersLength = frame.getHeadersLength(); - - if (statusCode < 200 || statusCode >= 400) { - if (!RntbdFramer.canDecodePayload(in, in.readerIndex() + headersLength)) { - in.resetReaderIndex(); - return null; - } - } - - final Headers headers = Headers.decode(in.readSlice(headersLength)); - - if (statusCode < 200 || statusCode >= 400) { - - final ObjectNode details = RntbdObjectMapper.readTree(in.readSlice(in.readIntLE())); - final HashMap map = new HashMap<>(4); - - if (headers.clientVersion.isPresent()) { - map.put("requiredClientVersion", headers.clientVersion.getValue()); - } - - if (headers.protocolVersion.isPresent()) { - map.put("requiredProtocolVersion", headers.protocolVersion.getValue()); - } - - if (headers.serverAgent.isPresent()) { - map.put("serverAgent", headers.serverAgent.getValue()); - } - - if (headers.serverVersion.isPresent()) { - map.put("serverVersion", headers.serverVersion.getValue()); - } - - throw new TransportException(frame.getStatus(), details, Collections.unmodifiableMap(map)); - } - - return new RntbdContext(frame, headers); - } - - public void encode(final ByteBuf out) { - - final int start = out.writerIndex(); - - this.frame.encode(out); - this.headers.encode(out); - - final int length = out.writerIndex() - start; - - if (length != this.frame.getLength()) { - throw new IllegalStateException(); - } - } - - public static RntbdContext from(final RntbdContextRequest request, final ServerProperties properties, final HttpResponseStatus status) { - - // NOTE TO CODE REVIEWERS - // ---------------------- - // In its current form this method is meant to enable a limited set of test scenarios. It will be revised as - // required to support test scenarios as they are developed. - - final Headers headers = new Headers(); - - headers.clientVersion.setValue(request.getClientVersion()); - headers.idleTimeoutInSeconds.setValue(0); - headers.protocolVersion.setValue(CurrentProtocolVersion); - headers.serverAgent.setValue(properties.getAgent()); - headers.serverVersion.setValue(properties.getVersion()); - headers.unauthenticatedTimeoutInSeconds.setValue(0); - - final int length = RntbdResponseStatus.LENGTH + headers.computeLength(); - final UUID activityId = request.getActivityId(); - - final RntbdResponseStatus frame = new RntbdResponseStatus(length, status, activityId); - - return new RntbdContext(frame, headers); - } - - @Override - public String toString() { - final ObjectWriter writer = RntbdObjectMapper.writer(); - try { - return writer.writeValueAsString(this); - } catch (final JsonProcessingException error) { - throw new CorruptedFrameException(error); - } - } - - private static final class Headers extends RntbdTokenStream { - - RntbdToken clientVersion; - RntbdToken idleTimeoutInSeconds; - RntbdToken protocolVersion; - RntbdToken serverAgent; - RntbdToken serverVersion; - RntbdToken unauthenticatedTimeoutInSeconds; - - Headers() { - - super(RntbdContextHeader.set, RntbdContextHeader.map); - - this.clientVersion = this.get(RntbdContextHeader.ClientVersion); - this.idleTimeoutInSeconds = this.get(RntbdContextHeader.IdleTimeoutInSeconds); - this.protocolVersion = this.get(RntbdContextHeader.ProtocolVersion); - this.serverAgent = this.get(RntbdContextHeader.ServerAgent); - this.serverVersion = this.get(RntbdContextHeader.ServerVersion); - this.unauthenticatedTimeoutInSeconds = this.get(RntbdContextHeader.UnauthenticatedTimeoutInSeconds); - } - - static Headers decode(final ByteBuf in) { - final Headers headers = new Headers(); - Headers.decode(in, headers); - return headers; - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextDecoder.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextDecoder.java deleted file mode 100644 index 8aea47b4881d..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextDecoder.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -class RntbdContextDecoder extends ByteToMessageDecoder { - - private static final Logger logger = LoggerFactory.getLogger(RntbdContextDecoder.class); - - /** - * Deserialize from an input {@link ByteBuf} to an {@link RntbdContext} instance - *

- * This method fulfills the promise of an {@link RntbdContext} instance. It does not pass the instance down the - * pipeline. - * - * @param context the {@link ChannelHandlerContext} to which this {@link ByteToMessageDecoder} belongs - * @param in the {@link ByteBuf} from which to readTree data - * @param out the {@link List} to which decoded messages should be added - * @throws Exception thrown if an error occurs - */ - @Override - protected void decode(final ChannelHandlerContext context, final ByteBuf in, final List out) throws Exception { - - if (RntbdFramer.canDecodeHead(in)) { - - final RntbdContext rntbdContext = RntbdContext.decode(in); - context.fireUserEventTriggered(rntbdContext); - in.discardReadBytes(); - - logger.debug("{} DECODE COMPLETE: {}", context.channel(), rntbdContext); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextNegotiator.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextNegotiator.java deleted file mode 100644 index bd5f5a079c14..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextNegotiator.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.Utils; -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPromise; -import io.netty.channel.CombinedChannelDuplexHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.concurrent.CompletableFuture; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -public final class RntbdContextNegotiator extends CombinedChannelDuplexHandler { - - private static final Logger logger = LoggerFactory.getLogger(RntbdContextNegotiator.class); - private final RntbdRequestManager manager; - private final UserAgentContainer userAgent; - - private volatile boolean pendingRntbdContextRequest = true; - - public RntbdContextNegotiator(final RntbdRequestManager manager, final UserAgentContainer userAgent) { - - super(new RntbdContextDecoder(), new RntbdContextRequestEncoder()); - - checkNotNull(manager, "manager"); - checkNotNull(userAgent, "userAgent"); - - this.manager = manager; - this.userAgent = userAgent; - } - - /** - * Called once a write operation is made. The write operation will write the messages through the - * {@link ChannelPipeline}. Those are then ready to be flushed to the actual {@link Channel} once - * {@link Channel#flush()} is called - * - * @param context the {@link ChannelHandlerContext} for which the write operation is made - * @param message the message to write - * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs - */ - @Override - public void write( - final ChannelHandlerContext context, final Object message, final ChannelPromise promise - ) throws Exception { - - checkArgument(message instanceof ByteBuf, "message: %s", message.getClass()); - final ByteBuf out = (ByteBuf)message; - - if (this.manager.hasRntbdContext()) { - context.writeAndFlush(out, promise); - } else { - if (this.pendingRntbdContextRequest) { - // Thread safe: netty guarantees that no channel handler methods are called concurrently - this.startRntbdContextRequest(context); - this.pendingRntbdContextRequest = false; - } - this.manager.pendWrite(out, promise); - } - } - - // region Privates - - private void startRntbdContextRequest(final ChannelHandlerContext context) throws Exception { - - logger.debug("{} START CONTEXT REQUEST", context.channel()); - - final Channel channel = context.channel(); - final RntbdContextRequest request = new RntbdContextRequest(Utils.randomUUID(), this.userAgent); - final CompletableFuture contextRequestFuture = this.manager.getRntbdContextRequestFuture(); - - super.write(context, request, channel.newPromise().addListener((ChannelFutureListener)future -> { - - if (future.isSuccess()) { - contextRequestFuture.complete(request); - return; - } - - if (future.isCancelled()) { - contextRequestFuture.cancel(true); - return; - } - - contextRequestFuture.completeExceptionally(future.cause()); - })); - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequest.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequest.java deleted file mode 100644 index 8c22180925e2..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.CorruptedFrameException; - -import java.nio.charset.StandardCharsets; -import java.util.UUID; - -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.Versions; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.CurrentProtocolVersion; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdContextRequestHeader; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdOperationType; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdResourceType; - -public final class RntbdContextRequest { - - @JsonProperty - private final UUID activityId; - - @JsonProperty - private final Headers headers; - - RntbdContextRequest(final UUID activityId, final UserAgentContainer userAgent) { - this(activityId, new Headers(userAgent)); - } - - private RntbdContextRequest(final UUID activityId, final Headers headers) { - this.activityId = activityId; - this.headers = headers; - } - - public UUID getActivityId() { - return this.activityId; - } - - public String getClientVersion() { - return this.headers.clientVersion.getValue(String.class); - } - - public static RntbdContextRequest decode(final ByteBuf in) { - - final int resourceOperationTypeCode = in.getInt(in.readerIndex() + Integer.BYTES); - - if (resourceOperationTypeCode != 0) { - final String reason = String.format("resourceOperationCode=0x%08X", resourceOperationTypeCode); - throw new IllegalStateException(reason); - } - - final int start = in.readerIndex(); - final int expectedLength = in.readIntLE(); - - final RntbdRequestFrame header = RntbdRequestFrame.decode(in); - final Headers headers = Headers.decode(in.readSlice(expectedLength - (in.readerIndex() - start))); - - final int observedLength = in.readerIndex() - start; - - if (observedLength != expectedLength) { - final String reason = String.format("expectedLength=%d, observeredLength=%d", expectedLength, observedLength); - throw new IllegalStateException(reason); - } - - in.discardReadBytes(); - return new RntbdContextRequest(header.getActivityId(), headers); - } - - public void encode(final ByteBuf out) { - - final int expectedLength = RntbdRequestFrame.LENGTH + this.headers.computeLength(); - final int start = out.writerIndex(); - - out.writeIntLE(expectedLength); - - final RntbdRequestFrame header = new RntbdRequestFrame(this.getActivityId(), RntbdOperationType.Connection, RntbdResourceType.Connection); - header.encode(out); - this.headers.encode(out); - - final int observedLength = out.writerIndex() - start; - - if (observedLength != expectedLength) { - final String reason = String.format("expectedLength=%d, observeredLength=%d", expectedLength, observedLength); - throw new IllegalStateException(reason); - } - } - - @Override - public String toString() { - final ObjectWriter writer = RntbdObjectMapper.writer(); - try { - return writer.writeValueAsString(this); - } catch (final JsonProcessingException error) { - throw new CorruptedFrameException(error); - } - } - - private static final class Headers extends RntbdTokenStream { - - private static final byte[] ClientVersion = Versions.CURRENT_VERSION.getBytes(StandardCharsets.UTF_8); - - @JsonProperty - RntbdToken clientVersion; - - @JsonProperty - RntbdToken protocolVersion; - - @JsonProperty - RntbdToken userAgent; - - Headers(final UserAgentContainer container) { - - this(); - - this.clientVersion.setValue(ClientVersion); - this.protocolVersion.setValue(CurrentProtocolVersion); - this.userAgent.setValue(container.getUserAgent()); - } - - private Headers() { - - super(RntbdContextRequestHeader.set, RntbdContextRequestHeader.map); - - this.clientVersion = this.get(RntbdContextRequestHeader.ClientVersion); - this.protocolVersion = this.get(RntbdContextRequestHeader.ProtocolVersion); - this.userAgent = this.get(RntbdContextRequestHeader.UserAgent); - } - - static Headers decode(final ByteBuf in) { - return Headers.decode(in, new Headers()); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequestDecoder.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequestDecoder.java deleted file mode 100644 index eeb951e727d7..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequestDecoder.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; - -import java.util.List; - -public class RntbdContextRequestDecoder extends ByteToMessageDecoder { - - public RntbdContextRequestDecoder() { - this.setSingleDecode(true); - } - - /** - * Prepare for decoding an @{link RntbdContextRequest} or fire a channel readTree event to pass the input message along - * - * @param context the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to - * @param message the message to be decoded - * @throws Exception thrown if an error occurs - */ - @Override - public void channelRead(final ChannelHandlerContext context, final Object message) throws Exception { - - if (message instanceof ByteBuf) { - - final ByteBuf in = (ByteBuf)message; - final int resourceOperationType = in.getInt(in.readerIndex() + Integer.BYTES); - - if (resourceOperationType == 0) { - assert this.isSingleDecode(); - super.channelRead(context, message); - return; - } - } - context.fireChannelRead(message); - } - - /** - * Decode an RntbdContextRequest from an {@link ByteBuf} stream - *

- * This method will be called till either an input {@link ByteBuf} has nothing to readTree on return from this method or - * till nothing is readTree from the input {@link ByteBuf}. - * - * @param context the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to - * @param in the {@link ByteBuf} from which to readTree data - * @param out the {@link List} to which decoded messages should be added - * @throws IllegalStateException thrown if an error occurs - */ - @Override - protected void decode(final ChannelHandlerContext context, final ByteBuf in, final List out) throws IllegalStateException { - - final RntbdContextRequest request; - in.markReaderIndex(); - - try { - request = RntbdContextRequest.decode(in); - } catch (final IllegalStateException error) { - in.resetReaderIndex(); - throw error; - } - - in.discardReadBytes(); - out.add(request); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequestEncoder.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequestEncoder.java deleted file mode 100644 index f078811f5b84..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdContextRequestEncoder.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -final class RntbdContextRequestEncoder extends MessageToByteEncoder { - - private static final Logger Logger = LoggerFactory.getLogger(RntbdContextRequestEncoder.class); - - /** - * Returns {@code true} if the given message is an @{link RntbdContextRequest} instance - *

- * If {@code false} this message should be passed to the next @{link ChannelOutboundHandler} in the pipeline. - * - * @param message the message to encode - * @return @{code true}, if the given message is an an @{link RntbdContextRequest} instance; otherwise @{false} - */ - @Override - public boolean acceptOutboundMessage(final Object message) { - return message instanceof RntbdContextRequest; - } - - /** - * Encode an @{link RntbdContextRequest} message into a {@link ByteBuf} - *

- * This method will be called for each written message that can be handled by this encoder. - * - * @param context the {@link ChannelHandlerContext} which this {@link MessageToByteEncoder} belongs to - * @param message the message to encode - * @param out the {@link ByteBuf} into which the encoded message will be written - * @throws IllegalStateException is thrown if an error occurs - */ - @Override - protected void encode(final ChannelHandlerContext context, final Object message, final ByteBuf out) throws IllegalStateException { - - final RntbdContextRequest request = (RntbdContextRequest)message; - out.markWriterIndex(); - - try { - request.encode(out); - } catch (final IllegalStateException error) { - out.resetWriterIndex(); - throw error; - } - - Logger.debug("{}: ENCODE COMPLETE: request={}", context.channel(), request); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdEndpoint.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdEndpoint.java deleted file mode 100644 index 27cf10d49070..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdEndpoint.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.ssl.SslContext; - -import java.net.URI; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.RntbdTransportClient.Options; - -public interface RntbdEndpoint extends AutoCloseable { - - String getName(); - - @Override - void close() throws RuntimeException; - - CompletableFuture request(RntbdRequestArgs requestArgs); - - interface Provider extends AutoCloseable { - - @Override - void close() throws RuntimeException; - - Config config(); - - int count(); - - RntbdEndpoint get(URI physicalAddress); - - Stream list(); - } - - final class Config { - - private final Options options; - private final SslContext sslContext; - private final LogLevel wireLogLevel; - - public Config(final Options options, final SslContext sslContext, final LogLevel wireLogLevel) { - - checkNotNull(options, "options"); - checkNotNull(sslContext, "sslContext"); - - this.options = options; - this.sslContext = sslContext; - this.wireLogLevel = wireLogLevel; - } - - public int getConnectionTimeout() { - final long value = this.options.getConnectionTimeout().toMillis(); - assert value <= Integer.MAX_VALUE; - return (int)value; - } - - public int getMaxChannelsPerEndpoint() { - return this.options.getMaxChannelsPerEndpoint(); - } - - public int getMaxRequestsPerChannel() { - return this.options.getMaxRequestsPerChannel(); - } - - public long getReceiveHangDetectionTime() { - return this.options.getReceiveHangDetectionTime().toNanos(); - } - - public long getRequestTimeout() { - return this.options.getRequestTimeout().toNanos(); - } - - public long getSendHangDetectionTime() { - return this.options.getSendHangDetectionTime().toNanos(); - } - - public SslContext getSslContext() { - return this.sslContext; - } - - public UserAgentContainer getUserAgent() { - return this.options.getUserAgent(); - } - - public LogLevel getWireLogLevel() { - return this.wireLogLevel; - } - - @Override - public String toString() { - return RntbdObjectMapper.toJson(this); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdFramer.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdFramer.java deleted file mode 100644 index 2b38ceb4c3ff..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdFramer.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.CorruptedFrameException; - -import static com.google.common.base.Preconditions.checkNotNull; - -final class RntbdFramer { - - private RntbdFramer() { - } - - static boolean canDecodeHead(final ByteBuf in) throws CorruptedFrameException { - - checkNotNull(in, "in"); - - if (in.readableBytes() < RntbdResponseStatus.LENGTH) { - return false; - } - - final int start = in.readerIndex(); - final long length = in.getUnsignedIntLE(start); - - if (length > Integer.MAX_VALUE) { - final String reason = String.format("Head frame length exceeds Integer.MAX_VALUE, %d: %d", - Integer.MAX_VALUE, length - ); - throw new CorruptedFrameException(reason); - } - - if (length < Integer.BYTES) { - final String reason = String.format("Head frame length is less than size of length field, %d: %d", - Integer.BYTES, length - ); - throw new CorruptedFrameException(reason); - } - - return length <= in.readableBytes(); - } - - static boolean canDecodePayload(final ByteBuf in, final int start) { - - checkNotNull(in, "in"); - - final int readerIndex = in.readerIndex(); - - if (start < readerIndex) { - throw new IllegalArgumentException("start < in.readerIndex()"); - } - - final int offset = start - readerIndex; - - if (in.readableBytes() - offset < Integer.BYTES) { - return false; - } - - final long length = in.getUnsignedIntLE(start); - - if (length > Integer.MAX_VALUE) { - final String reason = String.format("Payload frame length exceeds Integer.MAX_VALUE, %d: %d", - Integer.MAX_VALUE, length - ); - throw new CorruptedFrameException(reason); - } - - return offset + Integer.BYTES + length <= in.readableBytes(); - } - - static boolean canDecodePayload(final ByteBuf in) { - return canDecodePayload(in, in.readerIndex()); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdMetrics.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdMetrics.java deleted file mode 100644 index a0fef0c4a43e..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdMetrics.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.codahale.metrics.Gauge; -import com.codahale.metrics.Meter; -import com.codahale.metrics.MetricFilter; -import com.codahale.metrics.MetricRegistry; -import com.codahale.metrics.RatioGauge; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.google.common.base.Stopwatch; - -import java.time.Duration; - -@JsonPropertyOrder({ - "lifetime", "requests", "responses", "errorResponses", "responseRate", "completionRate", "throughput" -}) -public final class RntbdMetrics implements AutoCloseable { - - // region Fields - - private static final MetricRegistry registry = new MetricRegistry(); - - private final Gauge completionRate; - private final Meter errorResponses; - private final Stopwatch lifetime; - private final String prefix; - private final Meter requests; - private final Gauge responseRate; - private final Meter responses; - - // endregion - - // region Constructors - - public RntbdMetrics(final String name) { - - this.lifetime = Stopwatch.createStarted(); - this.prefix = name + '.'; - - this.requests = registry.register(this.prefix + "requests", new Meter()); - this.responses = registry.register(this.prefix + "responses", new Meter()); - this.errorResponses = registry.register(this.prefix + "errorResponses", new Meter()); - this.responseRate = registry.register(this.prefix + "responseRate", new ResponseRate(this)); - this.completionRate = registry.register(this.prefix + "completionRate", new CompletionRate(this)); - } - - // endregion - - // region Accessors - - public double getCompletionRate() { - return this.completionRate.getValue(); - } - - public long getErrorResponses() { - return this.errorResponses.getCount(); - } - - public double getLifetime() { - final Duration elapsed = this.lifetime.elapsed(); - return elapsed.getSeconds() + (1E-9D * elapsed.getNano()); - } - - public long getRequests() { - return this.requests.getCount(); - } - - public double getResponseRate() { - return this.responseRate.getValue(); - } - - public long getResponses() { - return this.responses.getCount(); - } - - public double getThroughput() { - return this.responses.getMeanRate(); - } - - // endregion - - // region Methods - - @Override - public void close() { - registry.removeMatching(MetricFilter.startsWith(this.prefix)); - } - - public final void incrementErrorResponseCount() { - this.errorResponses.mark(); - } - - public final void incrementRequestCount() { - this.requests.mark(); - } - - public final void incrementResponseCount() { - this.responses.mark(); - } - - @Override - public String toString() { - return RntbdObjectMapper.toJson(this); - } - - // endregion - - private static final class CompletionRate extends RatioGauge { - - private final RntbdMetrics metrics; - - private CompletionRate(RntbdMetrics metrics) { - this.metrics = metrics; - } - - @Override - protected Ratio getRatio() { - return Ratio.of(this.metrics.responses.getCount() - this.metrics.errorResponses.getCount(), - this.metrics.requests.getCount()); - } - } - - private static final class ResponseRate extends RatioGauge { - - private final RntbdMetrics metrics; - - private ResponseRate(RntbdMetrics metrics) { - this.metrics = metrics; - } - - @Override - protected Ratio getRatio() { - return Ratio.of(this.metrics.responses.getCount(), this.metrics.requests.getCount()); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdObjectMapper.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdObjectMapper.java deleted file mode 100644 index 6b9c7d984373..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdObjectMapper.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.node.JsonNodeType; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.ser.PropertyFilter; -import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.handler.codec.CorruptedFrameException; -import io.netty.handler.codec.EncoderException; - -import java.io.IOException; -import java.io.InputStream; - -import static com.google.common.base.Preconditions.checkNotNull; - -public final class RntbdObjectMapper { - - private static final SimpleFilterProvider filterProvider; - private static final ObjectMapper objectMapper; - private static final ObjectWriter objectWriter; - - static { - objectMapper = new ObjectMapper().setFilterProvider(filterProvider = new SimpleFilterProvider()); - objectWriter = objectMapper.writer(); - } - - private RntbdObjectMapper() { - } - - static ObjectNode readTree(final RntbdResponse response) { - checkNotNull(response, "response"); - return readTree(response.getContent()); - } - - static ObjectNode readTree(final ByteBuf in) { - - checkNotNull(in, "in"); - final JsonNode node; - - try (final InputStream istream = new ByteBufInputStream(in)) { - node = objectMapper.readTree(istream); - } catch (final IOException error) { - throw new CorruptedFrameException(error); - } - - if (node.isObject()) { - return (ObjectNode)node; - } - - final String cause = String.format("Expected %s, not %s", JsonNodeType.OBJECT, node.getNodeType()); - throw new CorruptedFrameException(cause); - } - - static void registerPropertyFilter(final Class type, final Class filter) { - - checkNotNull(type, "type"); - checkNotNull(filter, "filter"); - - try { - filterProvider.addFilter(type.getSimpleName(), filter.newInstance()); - } catch (final ReflectiveOperationException error) { - throw new IllegalStateException(error); - } - } - - public static String toJson(Object value) { - try { - return objectWriter.writeValueAsString(value); - } catch (final JsonProcessingException error) { - throw new EncoderException(error); - } - } - - public static ObjectWriter writer() { - return objectWriter; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdReporter.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdReporter.java deleted file mode 100644 index 5f0ee7d3de0e..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdReporter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.slf4j.Logger; -import org.slf4j.helpers.FormattingTuple; -import org.slf4j.helpers.MessageFormatter; - -import java.nio.file.Paths; - -public final class RntbdReporter { - - private static final String codeSource = Paths.get( - RntbdReporter.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getFileName().toString(); - - private RntbdReporter() { - } - - public static void reportIssue(Logger logger, Object subject, String format, Object... arguments) { - if (logger.isErrorEnabled()) { - doReportIssue(logger, subject, format, arguments); - } - } - - public static void reportIssueUnless( - boolean predicate, Logger logger, Object subject, String format, Object... arguments - ) { - if (!predicate && logger.isErrorEnabled()) { - doReportIssue(logger, subject, format, arguments); - } - } - - private static void doReportIssue(Logger logger, Object subject, String format, Object[] arguments) { - - FormattingTuple formattingTuple = MessageFormatter.arrayFormat(format, arguments); - StackTraceElement[] stackTraceElements = new Exception().getStackTrace(); - Throwable throwable = formattingTuple.getThrowable(); - - if (throwable == null) { - logger.error("Report this {} issue to ensure it is addressed:\n[{}]\n[{}]\n[{}]", - codeSource, subject, stackTraceElements[2], formattingTuple.getMessage() - ); - } else { - logger.error("Report this {} issue to ensure it is addressed:\n[{}]\n[{}]\n[{}{}{}]", - codeSource, subject, stackTraceElements[2], formattingTuple.getMessage(), - throwable, ExceptionUtils.getStackTrace(throwable) - ); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequest.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequest.java deleted file mode 100644 index 90f041a305f5..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.buffer.ByteBuf; - -import java.util.UUID; - -import static com.google.common.base.Preconditions.checkNotNull; - -public final class RntbdRequest { - - private static final byte[] EmptyByteArray = {}; - - private final RntbdRequestFrame frame; - private final RntbdRequestHeaders headers; - private final byte[] payload; - - private RntbdRequest(final RntbdRequestFrame frame, final RntbdRequestHeaders headers, final byte[] payload) { - - checkNotNull(frame, "frame"); - checkNotNull(headers, "headers"); - - this.frame = frame; - this.headers = headers; - this.payload = payload == null ? EmptyByteArray : payload; - } - - public UUID getActivityId() { - return this.frame.getActivityId(); - } - - static RntbdRequest decode(final ByteBuf in) { - - final int resourceOperationCode = in.getInt(in.readerIndex() + Integer.BYTES); - - if (resourceOperationCode == 0) { - final String reason = String.format("resourceOperationCode=0x%08X", resourceOperationCode); - throw new IllegalStateException(reason); - } - - final int start = in.readerIndex(); - final int expectedLength = in.readIntLE(); - - final RntbdRequestFrame header = RntbdRequestFrame.decode(in); - final RntbdRequestHeaders metadata = RntbdRequestHeaders.decode(in); - final ByteBuf payloadBuf = in.readSlice(expectedLength - (in.readerIndex() - start)); - - final int observedLength = in.readerIndex() - start; - - if (observedLength != expectedLength) { - final String reason = String.format("expectedLength=%d, observedLength=%d", expectedLength, observedLength); - throw new IllegalStateException(reason); - } - - final byte[] payload = new byte[payloadBuf.readableBytes()]; - payloadBuf.readBytes(payload); - in.discardReadBytes(); - - return new RntbdRequest(header, metadata, payload); - } - - void encode(final ByteBuf out) { - - final int expectedLength = RntbdRequestFrame.LENGTH + this.headers.computeLength(); - final int start = out.readerIndex(); - - out.writeIntLE(expectedLength); - this.frame.encode(out); - this.headers.encode(out); - - assert out.writerIndex() - start == expectedLength; - - if (this.payload.length > 0) { - out.writeIntLE(this.payload.length); - out.writeBytes(this.payload); - } - } - - public static RntbdRequest from(final RntbdRequestArgs args) { - - final RxDocumentServiceRequest serviceRequest = args.getServiceRequest(); - - final RntbdRequestFrame frame = new RntbdRequestFrame( - args.getActivityId(), - serviceRequest.getOperationType(), - serviceRequest.getResourceType()); - - final RntbdRequestHeaders headers = new RntbdRequestHeaders(args, frame); - - return new RntbdRequest(frame, headers, serviceRequest.getContent()); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestArgs.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestArgs.java deleted file mode 100644 index 226259c6e229..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestArgs.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.google.common.base.Stopwatch; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.channel.ChannelHandlerContext; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; - -import java.math.BigDecimal; -import java.net.URI; -import java.time.Duration; -import java.util.UUID; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkNotNull; - -public final class RntbdRequestArgs { - - private static final String className = RntbdRequestArgs.class.getCanonicalName(); - - private final UUID activityId; - private final long birthTime; - private final Stopwatch lifetime; - private final URI physicalAddress; - private final String replicaPath; - private final RxDocumentServiceRequest serviceRequest; - - public RntbdRequestArgs(final RxDocumentServiceRequest serviceRequest, final URI physicalAddress) { - this.activityId = UUID.fromString(serviceRequest.getActivityId()); - this.birthTime = System.nanoTime(); - this.lifetime = Stopwatch.createStarted(); - this.physicalAddress = physicalAddress; - this.replicaPath = StringUtils.stripEnd(physicalAddress.getPath(), "/"); - this.serviceRequest = serviceRequest; - } - - public UUID getActivityId() { - return this.activityId; - } - - public long getBirthTime() { - return this.birthTime; - } - - public Duration getLifetime() { - return this.lifetime.elapsed(); - } - - public String getReplicaPath() { - return this.replicaPath; - } - - public URI getPhysicalAddress() { - return this.physicalAddress; - } - - public RxDocumentServiceRequest getServiceRequest() { - return this.serviceRequest; - } - - @Override - public String toString() { - return '[' + RntbdRequestArgs.className + '(' + this.serviceRequest.getActivityId() - + ", origin: " + this.physicalAddress.getScheme() + "://" + this.physicalAddress.getAuthority() - + ", operationType: " + this.serviceRequest.getOperationType() - + ", resourceType: " + this.serviceRequest.getResourceType() - + ", replicaPath: " + this.replicaPath - + ", lifetime: " + this.getLifetime() - + ")]"; - } - - public void traceOperation(final Logger logger, final ChannelHandlerContext context, final String operationName, final Object... args) { - - checkNotNull(logger, "logger"); - - if (logger.isTraceEnabled()) { - final BigDecimal lifetime = BigDecimal.valueOf(this.lifetime.elapsed().toNanos(), 6); - logger.trace("{},{},\"{}({})\",\"{}\",\"{}\"", this.birthTime, lifetime, operationName, - Stream.of(args).map(arg -> - arg == null ? "null" : arg.toString()).collect(Collectors.joining(",") - ), - this, context - ); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestDecoder.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestDecoder.java deleted file mode 100644 index 3f1de9c65c24..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestDecoder.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; - -import java.util.List; - -public final class RntbdRequestDecoder extends ByteToMessageDecoder { - /** - * Prepare for decoding an @{link RntbdRequest} or fire a channel readTree event to pass the input message along - * - * @param context the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to - * @param message the message to be decoded - * @throws Exception thrown if an error occurs - */ - @Override - public void channelRead(final ChannelHandlerContext context, final Object message) throws Exception { - - if (message instanceof ByteBuf) { - - final ByteBuf in = (ByteBuf)message; - final int resourceOperationType = in.getInt(in.readerIndex() + Integer.BYTES); - - if (resourceOperationType != 0) { - super.channelRead(context, message); - return; - } - } - - context.fireChannelRead(message); - } - - /** - * Decode the input {@link ByteBuf} to an RntbdRequest instance - *

- * This method will be called till either the input {@link ByteBuf} has nothing to readTree after return from this - * method or till nothing was readTree from the input {@link ByteBuf}. - * - * @param context the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to - * @param in the {@link ByteBuf} from which to readTree data - * @param out the {@link List} to which decoded messages should be added - * @throws IllegalStateException thrown if an error occurs - */ - @Override - protected void decode(final ChannelHandlerContext context, final ByteBuf in, final List out) throws IllegalStateException { - - final RntbdRequest request; - in.markReaderIndex(); - - try { - request = RntbdRequest.decode(in); - } catch (final IllegalStateException error) { - in.resetReaderIndex(); - throw error; - } - - in.discardReadBytes(); - out.add(request); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestEncoder.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestEncoder.java deleted file mode 100644 index 247ca7d19878..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestEncoder.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelOutboundHandler; -import io.netty.handler.codec.MessageToByteEncoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class RntbdRequestEncoder extends MessageToByteEncoder { - - private static final Logger logger = LoggerFactory.getLogger(RntbdRequestEncoder.class); - - /** - * Returns {@code true} if the given message is an @{link RntbdRequest} instance - *

- * If {@code false} this message should be passed to the next {@link ChannelOutboundHandler} in the pipeline. - * - * @param message the message to encode - * @return {@code true}, if the given message is an an {@link RntbdRequest} instance; otherwise @{false} - */ - @Override - public boolean acceptOutboundMessage(final Object message) { - return message instanceof RntbdRequestArgs; - } - - /** - * Encode a message into a {@link ByteBuf} - *

- * This method will be called for each message that can be written by this encoder. - * - * @param context the {@link ChannelHandlerContext} which this {@link MessageToByteEncoder} belongs encode - * @param message the message to encode - * @param out the {@link ByteBuf} into which the encoded message will be written - */ - @Override - protected void encode(final ChannelHandlerContext context, final Object message, final ByteBuf out) throws Exception { - - final RntbdRequest request = RntbdRequest.from((RntbdRequestArgs)message); - final int start = out.writerIndex(); - - try { - request.encode(out); - } catch (final Throwable error) { - out.writerIndex(start); - throw error; - } - - if (logger.isDebugEnabled()) { - final int length = out.writerIndex() - start; - logger.debug("{}: ENCODE COMPLETE: length={}, request={}", context.channel(), length, request); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestFrame.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestFrame.java deleted file mode 100644 index 80c181d5bfb2..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestFrame.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import io.netty.buffer.ByteBuf; - -import java.util.Locale; -import java.util.UUID; - -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdOperationType; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdResourceType; - -final class RntbdRequestFrame { - - // region Fields - - static final int LENGTH = Integer.BYTES // messageLength - + Short.BYTES // resourceType - + Short.BYTES // operationType - + 2 * Long.BYTES; // activityId - - private final UUID activityId; - private final RntbdOperationType operationType; - private final RntbdResourceType resourceType; - - // region Constructors - - RntbdRequestFrame(final UUID activityId, final OperationType operationType, final ResourceType resourceType) { - this(activityId, map(operationType), map(resourceType)); - } - - RntbdRequestFrame(final UUID activityId, final RntbdOperationType operationType, final RntbdResourceType resourceType) { - this.activityId = activityId; - this.operationType = operationType; - this.resourceType = resourceType; - } - - // endregion - - // region Methods - - UUID getActivityId() { - return this.activityId; - } - - RntbdOperationType getOperationType() { - return this.operationType; - } - - RntbdResourceType getResourceType() { - return this.resourceType; - } - - static RntbdRequestFrame decode(final ByteBuf in) { - - final RntbdResourceType resourceType = RntbdResourceType.fromId(in.readShortLE()); - final RntbdOperationType operationType = RntbdOperationType.fromId(in.readShortLE()); - final UUID activityId = RntbdUUID.decode(in); - - return new RntbdRequestFrame(activityId, operationType, resourceType); - } - - void encode(final ByteBuf out) { - out.writeShortLE(this.resourceType.id()); - out.writeShortLE(this.operationType.id()); - RntbdUUID.encode(this.activityId, out); - } - - private static RntbdResourceType map(final ResourceType resourceType) { - - switch (resourceType) { - case Attachment: - return RntbdResourceType.Attachment; - case DocumentCollection: - return RntbdResourceType.Collection; - case Conflict: - return RntbdResourceType.Conflict; - case Database: - return RntbdResourceType.Database; - case Document: - return RntbdResourceType.Document; - case Module: - return RntbdResourceType.Module; - case ModuleCommand: - return RntbdResourceType.ModuleCommand; - case Record: - return RntbdResourceType.Record; - case Permission: - return RntbdResourceType.Permission; - case Replica: - return RntbdResourceType.Replica; - case StoredProcedure: - return RntbdResourceType.StoredProcedure; - case Trigger: - return RntbdResourceType.Trigger; - case User: - return RntbdResourceType.User; - case UserDefinedType: - return RntbdResourceType.UserDefinedType; - case UserDefinedFunction: - return RntbdResourceType.UserDefinedFunction; - case Offer: - return RntbdResourceType.Offer; - case PartitionSetInformation: - return RntbdResourceType.PartitionSetInformation; - case XPReplicatorAddress: - return RntbdResourceType.XPReplicatorAddress; - case MasterPartition: - return RntbdResourceType.MasterPartition; - case ServerPartition: - return RntbdResourceType.ServerPartition; - case DatabaseAccount: - return RntbdResourceType.DatabaseAccount; - case Topology: - return RntbdResourceType.Topology; - case PartitionKeyRange: - return RntbdResourceType.PartitionKeyRange; - case Schema: - return RntbdResourceType.Schema; - case BatchApply: - return RntbdResourceType.BatchApply; - case RestoreMetadata: - return RntbdResourceType.RestoreMetadata; - case ComputeGatewayCharges: - return RntbdResourceType.ComputeGatewayCharges; - case RidRange: - return RntbdResourceType.RidRange; - default: - final String reason = String.format(Locale.ROOT, "Unrecognized resource type: %s", resourceType); - throw new UnsupportedOperationException(reason); - } - } - - private static RntbdOperationType map(final OperationType operationType) { - - switch (operationType) { - case Crash: - return RntbdOperationType.Crash; - case Create: - return RntbdOperationType.Create; - case Delete: - return RntbdOperationType.Delete; - case ExecuteJavaScript: - return RntbdOperationType.ExecuteJavaScript; - case Query: - return RntbdOperationType.Query; - case Pause: - return RntbdOperationType.Pause; - case Read: - return RntbdOperationType.Read; - case ReadFeed: - return RntbdOperationType.ReadFeed; - case Recreate: - return RntbdOperationType.Recreate; - case Recycle: - return RntbdOperationType.Recycle; - case Replace: - return RntbdOperationType.Replace; - case Resume: - return RntbdOperationType.Resume; - case Stop: - return RntbdOperationType.Stop; - case SqlQuery: - return RntbdOperationType.SQLQuery; - case Update: - return RntbdOperationType.Update; - case ForceConfigRefresh: - return RntbdOperationType.ForceConfigRefresh; - case Head: - return RntbdOperationType.Head; - case HeadFeed: - return RntbdOperationType.HeadFeed; - case Upsert: - return RntbdOperationType.Upsert; - case Throttle: - return RntbdOperationType.Throttle; - case PreCreateValidation: - return RntbdOperationType.PreCreateValidation; - case GetSplitPoint: - return RntbdOperationType.GetSplitPoint; - case AbortSplit: - return RntbdOperationType.AbortSplit; - case CompleteSplit: - return RntbdOperationType.CompleteSplit; - case BatchApply: - return RntbdOperationType.BatchApply; - case OfferUpdateOperation: - return RntbdOperationType.OfferUpdateOperation; - case OfferPreGrowValidation: - return RntbdOperationType.OfferPreGrowValidation; - case BatchReportThroughputUtilization: - return RntbdOperationType.BatchReportThroughputUtilization; - case AbortPartitionMigration: - return RntbdOperationType.AbortPartitionMigration; - case CompletePartitionMigration: - return RntbdOperationType.CompletePartitionMigration; - case PreReplaceValidation: - return RntbdOperationType.PreReplaceValidation; - case MigratePartition: - return RntbdOperationType.MigratePartition; - case AddComputeGatewayRequestCharges: - return RntbdOperationType.AddComputeGatewayRequestCharges; - default: - final String reason = String.format(Locale.ROOT, "Unrecognized operation type: %s", operationType); - throw new UnsupportedOperationException(reason); - } - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestFramer.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestFramer.java deleted file mode 100644 index 21a64a554ee1..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestFramer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.handler.codec.LengthFieldBasedFrameDecoder; - -import java.nio.ByteOrder; - -public final class RntbdRequestFramer extends LengthFieldBasedFrameDecoder { - - public RntbdRequestFramer() { - super(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 0, Integer.BYTES, -Integer.BYTES, 0, true); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestHeaders.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestHeaders.java deleted file mode 100644 index bac0da32f9b6..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestHeaders.java +++ /dev/null @@ -1,1272 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - - -import com.fasterxml.jackson.annotation.JsonFilter; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.IndexingDirective; -import com.microsoft.azure.cosmosdb.internal.ContentSerializationFormat; -import com.microsoft.azure.cosmosdb.internal.EnumerationDirection; -import com.microsoft.azure.cosmosdb.internal.FanoutOperationState; -import com.microsoft.azure.cosmosdb.internal.MigrateCollectionDirective; -import com.microsoft.azure.cosmosdb.internal.Paths; -import com.microsoft.azure.cosmosdb.internal.ReadFeedKeyType; -import com.microsoft.azure.cosmosdb.internal.RemoteStorageType; -import com.microsoft.azure.cosmosdb.internal.ResourceId; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.buffer.ByteBuf; -import org.apache.commons.lang3.EnumUtils; -import org.apache.commons.lang3.StringUtils; - -import java.util.Base64; -import java.util.Locale; -import java.util.Map; -import java.util.function.Supplier; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.HttpHeaders; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants.BackendHeaders; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdConsistencyLevel; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdContentSerializationFormat; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdEnumerationDirection; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdFanoutOperationState; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdIndexingDirective; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdMigrateCollectionDirective; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdOperationType; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdReadFeedKeyType; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdRemoteStorageType; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdRequestHeader; - -@JsonFilter("RntbdToken") -final class RntbdRequestHeaders extends RntbdTokenStream { - - // region Fields - - private static final String UrlTrim = "/+"; - - // endregion - - // region Constructors - - RntbdRequestHeaders(final RntbdRequestArgs args, final RntbdRequestFrame frame) { - - this(); - - checkNotNull(args, "args"); - checkNotNull(frame, "frame"); - - final RxDocumentServiceRequest request = args.getServiceRequest(); - final byte[] content = request.getContent(); - - this.getPayloadPresent().setValue(content != null && content.length > 0); - this.getReplicaPath().setValue(args.getReplicaPath()); - - final Map headers = request.getHeaders(); - - // Special-case headers - - this.addAimHeader(headers); - this.addAllowScanOnQuery(headers); - this.addBinaryIdIfPresent(headers); - this.addCanCharge(headers); - this.addCanOfferReplaceComplete(headers); - this.addCanThrottle(headers); - this.addCollectionRemoteStorageSecurityIdentifier(headers); - this.addConsistencyLevelHeader(headers); - this.addContentSerializationFormat(headers); - this.addContinuationToken(request); - this.addDateHeader(headers); - this.addDisableRUPerMinuteUsage(headers); - this.addEmitVerboseTracesInQuery(headers); - this.addEnableLogging(headers); - this.addEnableLowPrecisionOrderBy(headers); - this.addEntityId(headers); - this.addEnumerationDirection(headers); - this.addExcludeSystemProperties(headers); - this.addFanoutOperationStateHeader(headers); - this.addIfModifiedSinceHeader(headers); - this.addIndexingDirectiveHeader(headers); - this.addIsAutoScaleRequest(headers); - this.addIsFanout(headers); - this.addIsReadOnlyScript(headers); - this.addIsUserRequest(headers); - this.addMatchHeader(headers, frame.getOperationType()); - this.addMigrateCollectionDirectiveHeader(headers); - this.addPageSize(headers); - this.addPopulateCollectionThroughputInfo(headers); - this.addPopulatePartitionStatistics(headers); - this.addPopulateQueryMetrics(headers); - this.addPopulateQuotaInfo(headers); - this.addProfileRequest(headers); - this.addQueryForceScan(headers); - this.addRemoteStorageType(headers); - this.addResourceIdOrPathHeaders(request); - this.addResponseContinuationTokenLimitInKb(headers); - this.addShareThroughput(headers); - this.addStartAndEndKeys(headers); - this.addSupportSpatialLegacyCoordinates(headers); - this.addUsePolygonsSmallerThanAHemisphere(headers); - - // Normal headers (Strings, Ints, Longs, etc.) - - this.fillTokenFromHeader(headers, this::getAllowTentativeWrites, BackendHeaders.ALLOW_TENTATIVE_WRITES); - this.fillTokenFromHeader(headers, this::getAuthorizationToken, HttpHeaders.AUTHORIZATION); - this.fillTokenFromHeader(headers, this::getBinaryPassThroughRequest, BackendHeaders.BINARY_PASSTHROUGH_REQUEST); - this.fillTokenFromHeader(headers, this::getBindReplicaDirective, BackendHeaders.BIND_REPLICA_DIRECTIVE); - this.fillTokenFromHeader(headers, this::getClientRetryAttemptCount, HttpHeaders.CLIENT_RETRY_ATTEMPT_COUNT); - this.fillTokenFromHeader(headers, this::getCollectionPartitionIndex, BackendHeaders.COLLECTION_PARTITION_INDEX); - this.fillTokenFromHeader(headers, this::getCollectionRid, BackendHeaders.COLLECTION_RID); - this.fillTokenFromHeader(headers, this::getCollectionServiceIndex, BackendHeaders.COLLECTION_SERVICE_INDEX); - this.fillTokenFromHeader(headers, this::getEffectivePartitionKey, BackendHeaders.EFFECTIVE_PARTITION_KEY); - this.fillTokenFromHeader(headers, this::getEnableDynamicRidRangeAllocation, BackendHeaders.ENABLE_DYNAMIC_RID_RANGE_ALLOCATION); - this.fillTokenFromHeader(headers, this::getFilterBySchemaRid, HttpHeaders.FILTER_BY_SCHEMA_RESOURCE_ID); - this.fillTokenFromHeader(headers, this::getGatewaySignature, HttpHeaders.GATEWAY_SIGNATURE); - this.fillTokenFromHeader(headers, this::getPartitionCount, BackendHeaders.PARTITION_COUNT); - this.fillTokenFromHeader(headers, this::getPartitionKey, HttpHeaders.PARTITION_KEY); - this.fillTokenFromHeader(headers, this::getPartitionKeyRangeId, HttpHeaders.PARTITION_KEY_RANGE_ID); - this.fillTokenFromHeader(headers, this::getPartitionResourceFilter, BackendHeaders.PARTITION_RESOURCE_FILTER); - this.fillTokenFromHeader(headers, this::getPostTriggerExclude, HttpHeaders.POST_TRIGGER_EXCLUDE); - this.fillTokenFromHeader(headers, this::getPostTriggerInclude, HttpHeaders.POST_TRIGGER_INCLUDE); - this.fillTokenFromHeader(headers, this::getPreTriggerExclude, HttpHeaders.PRE_TRIGGER_EXCLUDE); - this.fillTokenFromHeader(headers, this::getPreTriggerInclude, HttpHeaders.PRE_TRIGGER_INCLUDE); - this.fillTokenFromHeader(headers, this::getPrimaryMasterKey, BackendHeaders.PRIMARY_MASTER_KEY); - this.fillTokenFromHeader(headers, this::getPrimaryReadonlyKey, BackendHeaders.PRIMARY_READONLY_KEY); - this.fillTokenFromHeader(headers, this::getRemainingTimeInMsOnClientRequest, HttpHeaders.REMAINING_TIME_IN_MS_ON_CLIENT_REQUEST); - this.fillTokenFromHeader(headers, this::getResourceSchemaName, BackendHeaders.RESOURCE_SCHEMA_NAME); - this.fillTokenFromHeader(headers, this::getResourceTokenExpiry, HttpHeaders.RESOURCE_TOKEN_EXPIRY); - this.fillTokenFromHeader(headers, this::getRestoreMetadataFilter, HttpHeaders.RESTORE_METADATA_FILTER); - this.fillTokenFromHeader(headers, this::getRestoreParams, BackendHeaders.RESTORE_PARAMS); - this.fillTokenFromHeader(headers, this::getSecondaryMasterKey, BackendHeaders.SECONDARY_MASTER_KEY); - this.fillTokenFromHeader(headers, this::getSecondaryReadonlyKey, BackendHeaders.SECONDARY_READONLY_KEY); - this.fillTokenFromHeader(headers, this::getSessionToken, HttpHeaders.SESSION_TOKEN); - this.fillTokenFromHeader(headers, this::getSharedOfferThroughput, HttpHeaders.SHARED_OFFER_THROUGHPUT); - this.fillTokenFromHeader(headers, this::getTargetGlobalCommittedLsn, HttpHeaders.TARGET_GLOBAL_COMMITTED_LSN); - this.fillTokenFromHeader(headers, this::getTargetLsn, HttpHeaders.TARGET_LSN); - this.fillTokenFromHeader(headers, this::getTimeToLiveInSeconds, BackendHeaders.TIME_TO_LIVE_IN_SECONDS); - this.fillTokenFromHeader(headers, this::getTransportRequestID, HttpHeaders.TRANSPORT_REQUEST_ID); - - // Will be null in case of direct, which is fine - BE will use the value slice the connection context this. - // When this is used in Gateway, the header value will be populated with the proxied HTTP request's header, - // and BE will respect the per-request value. - - this.fillTokenFromHeader(headers, this::getClientVersion, HttpHeaders.VERSION); - } - - private RntbdRequestHeaders() { - super(RntbdRequestHeader.set, RntbdRequestHeader.map); - } - - // endregion - - // region Methods - - static RntbdRequestHeaders decode(final ByteBuf in) { - final RntbdRequestHeaders metadata = new RntbdRequestHeaders(); - return RntbdRequestHeaders.decode(in, metadata); - } - - // endregion - - // region Privates - - private RntbdToken getAIM() { - return this.get(RntbdRequestHeader.A_IM); - } - - private RntbdToken getAllowTentativeWrites() { - return this.get(RntbdRequestHeader.AllowTentativeWrites); - } - - private RntbdToken getAttachmentName() { - return this.get(RntbdRequestHeader.AttachmentName); - } - - private RntbdToken getAuthorizationToken() { - return this.get(RntbdRequestHeader.AuthorizationToken); - } - - private RntbdToken getBinaryId() { - return this.get(RntbdRequestHeader.BinaryId); - } - - private RntbdToken getBinaryPassThroughRequest() { - return this.get(RntbdRequestHeader.BinaryPassthroughRequest); - } - - private RntbdToken getBindReplicaDirective() { - return this.get(RntbdRequestHeader.BindReplicaDirective); - } - - private RntbdToken getCanCharge() { - return this.get(RntbdRequestHeader.CanCharge); - } - - private RntbdToken getCanOfferReplaceComplete() { - return this.get(RntbdRequestHeader.CanOfferReplaceComplete); - } - - private RntbdToken getCanThrottle() { - return this.get(RntbdRequestHeader.CanThrottle); - } - - private RntbdToken getClientRetryAttemptCount() { - return this.get(RntbdRequestHeader.ClientRetryAttemptCount); - } - - private RntbdToken getClientVersion() { - return this.get(RntbdRequestHeader.ClientVersion); - } - - private RntbdToken getCollectionName() { - return this.get(RntbdRequestHeader.CollectionName); - } - - private RntbdToken getCollectionPartitionIndex() { - return this.get(RntbdRequestHeader.CollectionPartitionIndex); - } - - private RntbdToken getCollectionRemoteStorageSecurityIdentifier() { - return this.get(RntbdRequestHeader.CollectionRemoteStorageSecurityIdentifier); - } - - private RntbdToken getCollectionRid() { - return this.get(RntbdRequestHeader.CollectionRid); - } - - private RntbdToken getCollectionServiceIndex() { - return this.get(RntbdRequestHeader.CollectionServiceIndex); - } - - private RntbdToken getConflictName() { - return this.get(RntbdRequestHeader.ConflictName); - } - - private RntbdToken getConsistencyLevel() { - return this.get(RntbdRequestHeader.ConsistencyLevel); - } - - private RntbdToken getContentSerializationFormat() { - return this.get(RntbdRequestHeader.ContentSerializationFormat); - } - - private RntbdToken getContinuationToken() { - return this.get(RntbdRequestHeader.ContinuationToken); - } - - private RntbdToken getDatabaseName() { - return this.get(RntbdRequestHeader.DatabaseName); - } - - private RntbdToken getDate() { - return this.get(RntbdRequestHeader.Date); - } - - private RntbdToken getDisableRUPerMinuteUsage() { - return this.get(RntbdRequestHeader.DisableRUPerMinuteUsage); - } - - private RntbdToken getDocumentName() { - return this.get(RntbdRequestHeader.DocumentName); - } - - private RntbdToken getEffectivePartitionKey() { - return this.get(RntbdRequestHeader.EffectivePartitionKey); - } - - private RntbdToken getEmitVerboseTracesInQuery() { - return this.get(RntbdRequestHeader.EmitVerboseTracesInQuery); - } - - private RntbdToken getEnableDynamicRidRangeAllocation() { - return this.get(RntbdRequestHeader.EnableDynamicRidRangeAllocation); - } - - private RntbdToken getEnableLogging() { - return this.get(RntbdRequestHeader.EnableLogging); - } - - private RntbdToken getEnableLowPrecisionOrderBy() { - return this.get(RntbdRequestHeader.EnableLowPrecisionOrderBy); - } - - private RntbdToken getEnableScanInQuery() { - return this.get(RntbdRequestHeader.EnableScanInQuery); - } - - private RntbdToken getEndEpk() { - return this.get(RntbdRequestHeader.EndEpk); - } - - private RntbdToken getEndId() { - return this.get(RntbdRequestHeader.EndId); - } - - private RntbdToken getEntityId() { - return this.get(RntbdRequestHeader.EntityId); - } - - private RntbdToken getEnumerationDirection() { - return this.get(RntbdRequestHeader.EnumerationDirection); - } - - private RntbdToken getExcludeSystemProperties() { - return this.get(RntbdRequestHeader.ExcludeSystemProperties); - } - - private RntbdToken getFanoutOperationState() { - return this.get(RntbdRequestHeader.FanoutOperationState); - } - - private RntbdToken getFilterBySchemaRid() { - return this.get(RntbdRequestHeader.FilterBySchemaRid); - } - - private RntbdToken getForceQueryScan() { - return this.get(RntbdRequestHeader.ForceQueryScan); - } - - private RntbdToken getGatewaySignature() { - return this.get(RntbdRequestHeader.GatewaySignature); - } - - private RntbdToken getIfModifiedSince() { - return this.get(RntbdRequestHeader.IfModifiedSince); - } - - private RntbdToken getIndexingDirective() { - return this.get(RntbdRequestHeader.IndexingDirective); - } - - private RntbdToken getIsAutoScaleRequest() { - return this.get(RntbdRequestHeader.IsAutoScaleRequest); - } - - private RntbdToken getIsFanout() { - return this.get(RntbdRequestHeader.IsFanout); - } - - private RntbdToken getIsReadOnlyScript() { - return this.get(RntbdRequestHeader.IsReadOnlyScript); - } - - private RntbdToken getIsUserRequest() { - return this.get(RntbdRequestHeader.IsUserRequest); - } - - private RntbdToken getMatch() { - return this.get(RntbdRequestHeader.Match); - } - - private RntbdToken getMigrateCollectionDirective() { - return this.get(RntbdRequestHeader.MigrateCollectionDirective); - } - - private RntbdToken getPageSize() { - return this.get(RntbdRequestHeader.PageSize); - } - - private RntbdToken getPartitionCount() { - return this.get(RntbdRequestHeader.PartitionCount); - } - - private RntbdToken getPartitionKey() { - return this.get(RntbdRequestHeader.PartitionKey); - } - - private RntbdToken getPartitionKeyRangeId() { - return this.get(RntbdRequestHeader.PartitionKeyRangeId); - } - - private RntbdToken getPartitionKeyRangeName() { - return this.get(RntbdRequestHeader.PartitionKeyRangeName); - } - - private RntbdToken getPartitionResourceFilter() { - return this.get(RntbdRequestHeader.PartitionResourceFilter); - } - - private RntbdToken getPayloadPresent() { - return this.get(RntbdRequestHeader.PayloadPresent); - } - - private RntbdToken getPermissionName() { - return this.get(RntbdRequestHeader.PermissionName); - } - - private RntbdToken getPopulateCollectionThroughputInfo() { - return this.get(RntbdRequestHeader.PopulateCollectionThroughputInfo); - } - - private RntbdToken getPopulatePartitionStatistics() { - return this.get(RntbdRequestHeader.PopulatePartitionStatistics); - } - - private RntbdToken getPopulateQueryMetrics() { - return this.get(RntbdRequestHeader.PopulateQueryMetrics); - } - - private RntbdToken getPopulateQuotaInfo() { - return this.get(RntbdRequestHeader.PopulateQuotaInfo); - } - - private RntbdToken getPostTriggerExclude() { - return this.get(RntbdRequestHeader.PostTriggerExclude); - } - - private RntbdToken getPostTriggerInclude() { - return this.get(RntbdRequestHeader.PostTriggerInclude); - } - - private RntbdToken getPreTriggerExclude() { - return this.get(RntbdRequestHeader.PreTriggerExclude); - } - - private RntbdToken getPreTriggerInclude() { - return this.get(RntbdRequestHeader.PreTriggerInclude); - } - - private RntbdToken getPrimaryMasterKey() { - return this.get(RntbdRequestHeader.PrimaryMasterKey); - } - - private RntbdToken getPrimaryReadonlyKey() { - return this.get(RntbdRequestHeader.PrimaryReadonlyKey); - } - - private RntbdToken getProfileRequest() { - return this.get(RntbdRequestHeader.ProfileRequest); - } - - private RntbdToken getReadFeedKeyType() { - return this.get(RntbdRequestHeader.ReadFeedKeyType); - } - - private RntbdToken getRemainingTimeInMsOnClientRequest() { - return this.get(RntbdRequestHeader.RemainingTimeInMsOnClientRequest); - } - - private RntbdToken getRemoteStorageType() { - return this.get(RntbdRequestHeader.RemoteStorageType); - } - - private RntbdToken getReplicaPath() { - return this.get(RntbdRequestHeader.ReplicaPath); - } - - private RntbdToken getResourceId() { - return this.get(RntbdRequestHeader.ResourceId); - } - - private RntbdToken getResourceSchemaName() { - return this.get(RntbdRequestHeader.ResourceSchemaName); - } - - private RntbdToken getResourceTokenExpiry() { - return this.get(RntbdRequestHeader.ResourceTokenExpiry); - } - - private RntbdToken getResponseContinuationTokenLimitInKb() { - return this.get(RntbdRequestHeader.ResponseContinuationTokenLimitInKb); - } - - private RntbdToken getRestoreMetadataFilter() { - return this.get(RntbdRequestHeader.RestoreMetadaFilter); - } - - private RntbdToken getRestoreParams() { - return this.get(RntbdRequestHeader.RestoreParams); - } - - private RntbdToken getSchemaName() { - return this.get(RntbdRequestHeader.SchemaName); - } - - private RntbdToken getSecondaryMasterKey() { - return this.get(RntbdRequestHeader.SecondaryMasterKey); - } - - private RntbdToken getSecondaryReadonlyKey() { - return this.get(RntbdRequestHeader.SecondaryReadonlyKey); - } - - private RntbdToken getSessionToken() { - return this.get(RntbdRequestHeader.SessionToken); - } - - private RntbdToken getShareThroughput() { - return this.get(RntbdRequestHeader.ShareThroughput); - } - - private RntbdToken getSharedOfferThroughput() { - return this.get(RntbdRequestHeader.SharedOfferThroughput); - } - - private RntbdToken getStartEpk() { - return this.get(RntbdRequestHeader.StartEpk); - } - - private RntbdToken getStartId() { - return this.get(RntbdRequestHeader.StartId); - } - - private RntbdToken getStoredProcedureName() { - return this.get(RntbdRequestHeader.StoredProcedureName); - } - - private RntbdToken getSupportSpatialLegacyCoordinates() { - return this.get(RntbdRequestHeader.SupportSpatialLegacyCoordinates); - } - - private RntbdToken getTargetGlobalCommittedLsn() { - return this.get(RntbdRequestHeader.TargetGlobalCommittedLsn); - } - - private RntbdToken getTargetLsn() { - return this.get(RntbdRequestHeader.TargetLsn); - } - - private RntbdToken getTimeToLiveInSeconds() { - return this.get(RntbdRequestHeader.TimeToLiveInSeconds); - } - - private RntbdToken getTransportRequestID() { - return this.get(RntbdRequestHeader.TransportRequestID); - } - - private RntbdToken getTriggerName() { - return this.get(RntbdRequestHeader.TriggerName); - } - - private RntbdToken getUsePolygonsSmallerThanAHemisphere() { - return this.get(RntbdRequestHeader.UsePolygonsSmallerThanAHemisphere); - } - - private RntbdToken getUserDefinedFunctionName() { - return this.get(RntbdRequestHeader.UserDefinedFunctionName); - } - - private RntbdToken getUserDefinedTypeName() { - return this.get(RntbdRequestHeader.UserDefinedTypeName); - } - - private RntbdToken getUserName() { - return this.get(RntbdRequestHeader.UserName); - } - - private void addAimHeader(final Map headers) { - - final String value = headers.get(HttpHeaders.A_IM); - - if (StringUtils.isNotEmpty(value)) { - this.getAIM().setValue(value); - } - } - - private void addAllowScanOnQuery(final Map headers) { - final String value = headers.get(HttpHeaders.ENABLE_SCAN_IN_QUERY); - if (StringUtils.isNotEmpty(value)) { - this.getEnableScanInQuery().setValue(Boolean.parseBoolean(value)); - } - } - - private void addBinaryIdIfPresent(final Map headers) { - final String value = headers.get(BackendHeaders.BINARY_ID); - if (StringUtils.isNotEmpty(value)) { - this.getBinaryId().setValue(Base64.getDecoder().decode(value)); - } - } - - private void addCanCharge(final Map headers) { - final String value = headers.get(HttpHeaders.CAN_CHARGE); - if (StringUtils.isNotEmpty(value)) { - this.getCanCharge().setValue(Boolean.parseBoolean(value)); - } - } - - private void addCanOfferReplaceComplete(final Map headers) { - final String value = headers.get(HttpHeaders.CAN_OFFER_REPLACE_COMPLETE); - if (StringUtils.isNotEmpty(value)) { - this.getCanOfferReplaceComplete().setValue(Boolean.parseBoolean(value)); - } - } - - private void addCanThrottle(final Map headers) { - final String value = headers.get(HttpHeaders.CAN_THROTTLE); - if (StringUtils.isNotEmpty(value)) { - this.getCanThrottle().setValue(Boolean.parseBoolean(value)); - } - } - - private void addCollectionRemoteStorageSecurityIdentifier(final Map headers) { - final String value = headers.get(HttpHeaders.COLLECTION_REMOTE_STORAGE_SECURITY_IDENTIFIER); - if (StringUtils.isNotEmpty(value)) { - this.getCollectionRemoteStorageSecurityIdentifier().setValue(value); - } - } - - private void addConsistencyLevelHeader(final Map headers) { - - final String value = headers.get(HttpHeaders.CONSISTENCY_LEVEL); - - if (StringUtils.isNotEmpty(value)) { - - final ConsistencyLevel level = EnumUtils.getEnumIgnoreCase(ConsistencyLevel.class, value); - - if (level == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - HttpHeaders.CONSISTENCY_LEVEL, - value); - throw new IllegalStateException(reason); - } - - switch (level) { - case Strong: - this.getConsistencyLevel().setValue(RntbdConsistencyLevel.Strong.id()); - break; - case BoundedStaleness: - this.getConsistencyLevel().setValue(RntbdConsistencyLevel.BoundedStaleness.id()); - break; - case Session: - this.getConsistencyLevel().setValue(RntbdConsistencyLevel.Session.id()); - break; - case Eventual: - this.getConsistencyLevel().setValue(RntbdConsistencyLevel.Eventual.id()); - break; - case ConsistentPrefix: - this.getConsistencyLevel().setValue(RntbdConsistencyLevel.ConsistentPrefix.id()); - break; - default: - assert false; - break; - } - } - } - - private void addContentSerializationFormat(final Map headers) { - - final String value = headers.get(HttpHeaders.CONTENT_SERIALIZATION_FORMAT); - - if (StringUtils.isNotEmpty(value)) { - - final ContentSerializationFormat format = EnumUtils.getEnumIgnoreCase(ContentSerializationFormat.class, value); - - if (format == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - HttpHeaders.CONTENT_SERIALIZATION_FORMAT, - value); - throw new IllegalStateException(reason); - } - - switch (format) { - case JsonText: - this.getContentSerializationFormat().setValue(RntbdContentSerializationFormat.JsonText.id()); - break; - case CosmosBinary: - this.getContentSerializationFormat().setValue(RntbdContentSerializationFormat.CosmosBinary.id()); - break; - default: - assert false; - } - } - } - - private void addContinuationToken(final RxDocumentServiceRequest request) { - final String value = request.getContinuation(); - if (StringUtils.isNotEmpty(value)) { - this.getContinuationToken().setValue(value); - } - } - - private void addDateHeader(final Map headers) { - - // Since the HTTP date header is overridden by some proxies/http client libraries, we support an additional date - // header and prefer that to the (regular) date header - - String value = headers.get(HttpHeaders.X_DATE); - - if (StringUtils.isEmpty(value)) { - value = headers.get(HttpHeaders.HTTP_DATE); - } - - if (StringUtils.isNotEmpty(value)) { - this.getDate().setValue(value); - } - } - - private void addDisableRUPerMinuteUsage(final Map headers) { - final String value = headers.get(HttpHeaders.DISABLE_RU_PER_MINUTE_USAGE); - if (StringUtils.isNotEmpty(value)) { - this.getDisableRUPerMinuteUsage().setValue(Boolean.parseBoolean(value)); - } - } - - private void addEmitVerboseTracesInQuery(final Map headers) { - final String value = headers.get(HttpHeaders.EMIT_VERBOSE_TRACES_IN_QUERY); - if (StringUtils.isNotEmpty(value)) { - this.getEmitVerboseTracesInQuery().setValue(Boolean.parseBoolean(value)); - } - } - - private void addEnableLogging(final Map headers) { - final String value = headers.get(HttpHeaders.ENABLE_LOGGING); - if (StringUtils.isNotEmpty(value)) { - this.getEnableLogging().setValue(Boolean.parseBoolean(value)); - } - } - - private void addEnableLowPrecisionOrderBy(final Map headers) { - final String value = headers.get(HttpHeaders.ENABLE_LOW_PRECISION_ORDER_BY); - if (StringUtils.isNotEmpty(value)) { - this.getEnableLowPrecisionOrderBy().setValue(Boolean.parseBoolean(value)); - } - } - - private void addEntityId(final Map headers) { - final String value = headers.get(BackendHeaders.ENTITY_ID); - if (StringUtils.isNotEmpty(value)) { - this.getEntityId().setValue(value); - } - } - - private void addEnumerationDirection(final Map headers) { - - final String value = headers.get(HttpHeaders.ENUMERATION_DIRECTION); - - if (StringUtils.isNotEmpty(value)) { - - final EnumerationDirection direction = EnumUtils.getEnumIgnoreCase(EnumerationDirection.class, value); - - if (direction == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - HttpHeaders.ENUMERATION_DIRECTION, - value); - throw new IllegalStateException(reason); - } - - switch (direction) { - case Forward: - this.getEnumerationDirection().setValue(RntbdEnumerationDirection.Forward.id()); - break; - case Reverse: - this.getEnumerationDirection().setValue(RntbdEnumerationDirection.Reverse.id()); - break; - default: - assert false; - } - } - } - - private void addExcludeSystemProperties(final Map headers) { - final String value = headers.get(BackendHeaders.EXCLUDE_SYSTEM_PROPERTIES); - if (StringUtils.isNotEmpty(value)) { - this.getExcludeSystemProperties().setValue(Boolean.parseBoolean(value)); - } - } - - private void addFanoutOperationStateHeader(final Map headers) { - - final String value = headers.get(BackendHeaders.FANOUT_OPERATION_STATE); - - if (StringUtils.isNotEmpty(value)) { - - final FanoutOperationState format = EnumUtils.getEnumIgnoreCase(FanoutOperationState.class, value); - - if (format == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - BackendHeaders.FANOUT_OPERATION_STATE, - value); - throw new IllegalStateException(reason); - } - - switch (format) { - case Started: - this.getFanoutOperationState().setValue(RntbdFanoutOperationState.Started.id()); - break; - case Completed: - this.getFanoutOperationState().setValue(RntbdFanoutOperationState.Completed.id()); - break; - default: - assert false; - } - } - } - - private void addIfModifiedSinceHeader(final Map headers) { - final String value = headers.get(HttpHeaders.IF_MODIFIED_SINCE); - if (StringUtils.isNotEmpty(value)) { - this.getIfModifiedSince().setValue(value); - } - } - - private void addIndexingDirectiveHeader(final Map headers) { - - final String value = headers.get(HttpHeaders.INDEXING_DIRECTIVE); - - if (StringUtils.isNotEmpty(value)) { - - final IndexingDirective directive = EnumUtils.getEnumIgnoreCase(IndexingDirective.class, value); - - if (directive == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - HttpHeaders.INDEXING_DIRECTIVE, - value); - throw new IllegalStateException(reason); - } - - switch (directive) { - case Default: - this.getIndexingDirective().setValue(RntbdIndexingDirective.Default.id()); - break; - case Exclude: - this.getIndexingDirective().setValue(RntbdIndexingDirective.Exclude.id()); - break; - case Include: - this.getIndexingDirective().setValue(RntbdIndexingDirective.Include.id()); - break; - default: - assert false; - } - } - } - - private void addIsAutoScaleRequest(final Map headers) { - final String value = headers.get(HttpHeaders.IS_AUTO_SCALE_REQUEST); - if (StringUtils.isNotEmpty(value)) { - this.getIsAutoScaleRequest().setValue(Boolean.parseBoolean(value)); - } - } - - private void addIsFanout(final Map headers) { - final String value = headers.get(BackendHeaders.IS_FANOUT_REQUEST); - if (StringUtils.isNotEmpty(value)) { - this.getIsFanout().setValue(Boolean.parseBoolean(value)); - } - } - - private void addIsReadOnlyScript(final Map headers) { - final String value = headers.get(HttpHeaders.IS_READ_ONLY_SCRIPT); - if (StringUtils.isNotEmpty(value)) { - this.getIsReadOnlyScript().setValue(Boolean.parseBoolean(value)); - } - } - - private void addIsUserRequest(final Map headers) { - final String value = headers.get(BackendHeaders.IS_USER_REQUEST); - if (StringUtils.isNotEmpty(value)) { - this.getIsUserRequest().setValue(Boolean.parseBoolean(value)); - } - } - - private void addMatchHeader(final Map headers, final RntbdOperationType operationType) { - - String match = null; - - switch (operationType) { - case Read: - case ReadFeed: - match = headers.get(HttpHeaders.IF_NONE_MATCH); - break; - default: - match = headers.get(HttpHeaders.IF_MATCH); - break; - } - - if (StringUtils.isNotEmpty(match)) { - this.getMatch().setValue(match); - } - } - - private void addMigrateCollectionDirectiveHeader(final Map headers) { - - final String value = headers.get(HttpHeaders.MIGRATE_COLLECTION_DIRECTIVE); - - if (StringUtils.isNotEmpty(value)) { - - final MigrateCollectionDirective directive = EnumUtils.getEnumIgnoreCase(MigrateCollectionDirective.class, value); - - if (directive == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - HttpHeaders.MIGRATE_COLLECTION_DIRECTIVE, - value); - throw new IllegalStateException(reason); - } - - switch (directive) { - case Freeze: - this.getMigrateCollectionDirective().setValue(RntbdMigrateCollectionDirective.Freeze.id()); - break; - case Thaw: - this.getMigrateCollectionDirective().setValue(RntbdMigrateCollectionDirective.Thaw.id()); - break; - default: - assert false; - break; - } - } - } - - private void addPageSize(final Map headers) { - - final String value = headers.get(HttpHeaders.PAGE_SIZE); - - if (StringUtils.isNotEmpty(value)) { - final long aLong = parseLong(HttpHeaders.PAGE_SIZE, value, -1, 0xFFFFFFFFL); - this.getPageSize().setValue((int)(aLong < 0 ? 0xFFFFFFFFL : aLong)); - } - } - - private void addPopulateCollectionThroughputInfo(final Map headers) { - final String value = headers.get(HttpHeaders.POPULATE_COLLECTION_THROUGHPUT_INFO); - if (StringUtils.isNotEmpty(value)) { - this.getPopulateCollectionThroughputInfo().setValue(Boolean.parseBoolean(value)); - } - } - - private void addPopulatePartitionStatistics(final Map headers) { - final String value = headers.get(HttpHeaders.POPULATE_PARTITION_STATISTICS); - if (StringUtils.isNotEmpty(value)) { - this.getPopulatePartitionStatistics().setValue(Boolean.parseBoolean(value)); - } - } - - private void addPopulateQueryMetrics(final Map headers) { - final String value = headers.get(HttpHeaders.POPULATE_QUERY_METRICS); - if (StringUtils.isNotEmpty(value)) { - this.getPopulateQueryMetrics().setValue(Boolean.parseBoolean(value)); - } - } - - private void addPopulateQuotaInfo(final Map headers) { - final String value = headers.get(HttpHeaders.POPULATE_QUOTA_INFO); - if (StringUtils.isNotEmpty(value)) { - this.getPopulateQuotaInfo().setValue(Boolean.parseBoolean(value)); - } - } - - private void addProfileRequest(final Map headers) { - final String value = headers.get(HttpHeaders.PROFILE_REQUEST); - if (StringUtils.isNotEmpty(value)) { - this.getProfileRequest().setValue(Boolean.parseBoolean(value)); - } - } - - private void addQueryForceScan(final Map headers) { - final String value = headers.get(HttpHeaders.FORCE_QUERY_SCAN); - if (StringUtils.isNotEmpty(value)) { - this.getForceQueryScan().setValue(Boolean.parseBoolean(value)); - } - } - - private void addRemoteStorageType(final Map headers) { - - final String value = headers.get(BackendHeaders.REMOTE_STORAGE_TYPE); - - if (StringUtils.isNotEmpty(value)) { - - final RemoteStorageType type = EnumUtils.getEnumIgnoreCase(RemoteStorageType.class, value); - - if (type == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - BackendHeaders.REMOTE_STORAGE_TYPE, - value); - throw new IllegalStateException(reason); - } - - switch (type) { - case Standard: - this.getRemoteStorageType().setValue(RntbdRemoteStorageType.Standard.id()); - break; - case Premium: - this.getRemoteStorageType().setValue(RntbdRemoteStorageType.Premium.id()); - break; - default: - assert false; - } - } - } - - private void addResourceIdOrPathHeaders(final RxDocumentServiceRequest request) { - - final String value = request.getResourceId(); - - if (StringUtils.isNotEmpty(value)) { - // Name-based can also have ResourceId because gateway might have generated it - this.getResourceId().setValue(ResourceId.parse(request.getResourceType(), value)); - } - - if (request.getIsNameBased()) { - - // Assumption: format is like "dbs/dbName/colls/collName/docs/docName" or "/dbs/dbName/colls/collName", - // not "apps/appName/partitions/partitionKey/replicas/replicaId/dbs/dbName" - - final String address = request.getResourceAddress(); - final String[] fragments = address.split(UrlTrim); - int count = fragments.length; - int index = 0; - - if (count > 0 && fragments[0].isEmpty()) { - ++index; - --count; - } - - if (count >= 2) { - switch (fragments[index]) { - case Paths.DATABASES_PATH_SEGMENT: - this.getDatabaseName().setValue(fragments[index + 1]); - break; - default: - final String reason = String.format(Locale.ROOT, RMResources.InvalidResourceAddress, - value, address); - throw new IllegalStateException(reason); - } - } - - if (count >= 4) { - switch (fragments[index + 2]) { - case Paths.COLLECTIONS_PATH_SEGMENT: - this.getCollectionName().setValue(fragments[index + 3]); - break; - case Paths.USERS_PATH_SEGMENT: - this.getUserName().setValue(fragments[index + 3]); - break; - case Paths.USER_DEFINED_TYPES_PATH_SEGMENT: - this.getUserDefinedTypeName().setValue(fragments[index + 3]); - break; - } - } - - if (count >= 6) { - switch (fragments[index + 4]) { - case Paths.DOCUMENTS_PATH_SEGMENT: - this.getDocumentName().setValue(fragments[index + 5]); - break; - case Paths.STORED_PROCEDURES_PATH_SEGMENT: - this.getStoredProcedureName().setValue(fragments[index + 5]); - break; - case Paths.PERMISSIONS_PATH_SEGMENT: - this.getPermissionName().setValue(fragments[index + 5]); - break; - case Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT: - this.getUserDefinedFunctionName().setValue(fragments[index + 5]); - break; - case Paths.TRIGGERS_PATH_SEGMENT: - this.getTriggerName().setValue(fragments[index + 5]); - break; - case Paths.CONFLICTS_PATH_SEGMENT: - this.getConflictName().setValue(fragments[index + 5]); - break; - case Paths.PARTITION_KEY_RANGES_PATH_SEGMENT: - this.getPartitionKeyRangeName().setValue(fragments[index + 5]); - break; - case Paths.SCHEMAS_PATH_SEGMENT: - this.getSchemaName().setValue(fragments[index + 5]); - break; - } - } - - if (count >= 8) { - switch (fragments[index + 6]) { - case Paths.ATTACHMENTS_PATH_SEGMENT: - this.getAttachmentName().setValue(fragments[index + 7]); - break; - } - } - } - } - - private void addResponseContinuationTokenLimitInKb(final Map headers) { - - final String value = headers.get(HttpHeaders.RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB); - - if (StringUtils.isNotEmpty(value)) { - final long aLong = parseLong(HttpHeaders.RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB, value, 0, 0xFFFFFFFFL); - this.getResponseContinuationTokenLimitInKb().setValue((int)(aLong < 0 ? 0xFFFFFFFFL : aLong)); - } - } - - private void addShareThroughput(final Map headers) { - final String value = headers.get(BackendHeaders.SHARE_THROUGHPUT); - if (StringUtils.isNotEmpty(value)) { - this.getShareThroughput().setValue(Boolean.parseBoolean(value)); - } - } - - private void addStartAndEndKeys(final Map headers) { - - String value = headers.get(HttpHeaders.READ_FEED_KEY_TYPE); - - if (StringUtils.isNotEmpty(value)) { - - final ReadFeedKeyType type = EnumUtils.getEnumIgnoreCase(ReadFeedKeyType.class, value); - - if (type == null) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, - HttpHeaders.READ_FEED_KEY_TYPE, - value); - throw new IllegalStateException(reason); - } - - switch (type) { - case ResourceId: - this.getReadFeedKeyType().setValue(RntbdReadFeedKeyType.ResourceId.id()); - break; - case EffectivePartitionKey: - this.getReadFeedKeyType().setValue(RntbdReadFeedKeyType.EffectivePartitionKey.id()); - break; - default: - assert false; - } - } - - final Base64.Decoder decoder = Base64.getDecoder(); - - value = headers.get(HttpHeaders.START_ID); - - if (StringUtils.isNotEmpty(value)) { - this.getStartId().setValue(decoder.decode(value)); - } - - value = headers.get(HttpHeaders.END_ID); - - if (StringUtils.isNotEmpty(value)) { - this.getEndId().setValue(decoder.decode(value)); - } - - value = headers.get(HttpHeaders.START_EPK); - - if (StringUtils.isNotEmpty(value)) { - this.getStartEpk().setValue(decoder.decode(value)); - } - - value = headers.get(HttpHeaders.END_EPK); - - if (StringUtils.isNotEmpty(value)) { - this.getEndEpk().setValue(decoder.decode(value)); - } - } - - private void addSupportSpatialLegacyCoordinates(final Map headers) { - final String value = headers.get(HttpHeaders.SUPPORT_SPATIAL_LEGACY_COORDINATES); - if (StringUtils.isNotEmpty(value)) { - this.getSupportSpatialLegacyCoordinates().setValue(Boolean.parseBoolean(value)); - } - } - - private void addUsePolygonsSmallerThanAHemisphere(final Map headers) { - final String value = headers.get(HttpHeaders.USE_POLYGONS_SMALLER_THAN_AHEMISPHERE); - if (StringUtils.isNotEmpty(value)) { - this.getUsePolygonsSmallerThanAHemisphere().setValue(Boolean.parseBoolean(value)); - } - } - - private void fillTokenFromHeader(final Map headers, final Supplier supplier, final String name) { - - final String value = headers.get(name); - - if (StringUtils.isNotEmpty(value)) { - - final RntbdToken token = supplier.get(); - - switch (token.getType()) { - - case SmallString: - case String: - case ULongString: { - - token.setValue(value); - break; - } - case Byte: { - - token.setValue(Boolean.parseBoolean(value)); - break; - } - case Double: { - - token.setValue(parseDouble(name, value)); - break; - } - case Long: { - - final long aLong = parseLong(name, value, Integer.MIN_VALUE, Integer.MAX_VALUE); - token.setValue(aLong); - break; - } - case ULong: { - - final long aLong = parseLong(name, value, 0, 0xFFFFFFFFL); - token.setValue(aLong); - break; - } - case LongLong: { - - final long aLong = parseLong(name, value); - token.setValue(aLong); - break; - } - default: { - assert false : "Recognized header has neither special-case nor default handling to convert " - + "from header String to RNTBD token"; - break; - } - } - } - } - - private static double parseDouble(final String name, final String value) { - - final double aDouble; - - try { - aDouble = Double.parseDouble(value); - } catch (final NumberFormatException error) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, name, value); - throw new IllegalStateException(reason); - } - return aDouble; - } - - private static long parseLong(final String name, final String value) { - final long aLong; - try { - aLong = Long.parseLong(value); - } catch (final NumberFormatException error) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, name, value); - throw new IllegalStateException(reason); - } - return aLong; - } - - private static long parseLong(final String name, final String value, final long min, final long max) { - final long aLong = parseLong(name, value); - if (!(min <= aLong && aLong <= max)) { - final String reason = String.format(Locale.ROOT, RMResources.InvalidRequestHeaderValue, name, aLong); - throw new IllegalStateException(reason); - } - return aLong; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestManager.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestManager.java deleted file mode 100644 index 10c81f854a05..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestManager.java +++ /dev/null @@ -1,774 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.google.common.base.Strings; -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.ConflictException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.ForbiddenException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GoneException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.LockedException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.MethodNotAllowedException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.PartitionKeyRangeGoneException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.PreconditionFailedException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.RequestEntityTooLargeException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.RequestRateTooLargeException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.RequestTimeoutException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.RetryWithException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.ServiceUnavailableException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.UnauthorizedException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdResponseHeader; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelException; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandler; -import io.netty.channel.ChannelOption; -import io.netty.channel.ChannelOutboundHandler; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.ChannelPromise; -import io.netty.channel.CoalescingBufferQueue; -import io.netty.channel.EventLoop; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.util.ReferenceCountUtil; -import io.netty.util.Timeout; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.math.BigDecimal; -import java.net.SocketAddress; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.CancellationException; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionException; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.StatusCodes; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdReporter.reportIssue; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdReporter.reportIssueUnless; - -public final class RntbdRequestManager implements ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler { - - // region Fields - - private static final Logger logger = LoggerFactory.getLogger(RntbdRequestManager.class); - - private final CompletableFuture contextFuture = new CompletableFuture<>(); - private final CompletableFuture contextRequestFuture = new CompletableFuture<>(); - private final ConcurrentHashMap pendingRequests = new ConcurrentHashMap<>(); - - private boolean closingExceptionally = false; - private ChannelHandlerContext context; - private RntbdRequestRecord pendingRequest; - private CoalescingBufferQueue pendingWrites; - - // endregion - - // region ChannelHandler methods - - /** - * Gets called after the {@link ChannelHandler} was added to the actual context and it's ready to handle events. - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - */ - @Override - public void handlerAdded(final ChannelHandlerContext context) throws Exception { - this.traceOperation(context, "handlerAdded"); - } - - /** - * Gets called after the {@link ChannelHandler} was removed from the actual context and it doesn't handle events - * anymore. - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - */ - @Override - public void handlerRemoved(final ChannelHandlerContext context) throws Exception { - this.traceOperation(context, "handlerRemoved"); - } - - // endregion - - // region ChannelInboundHandler methods - - /** - * The {@link Channel} of the {@link ChannelHandlerContext} is now active - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - */ - @Override - public void channelActive(final ChannelHandlerContext context) throws Exception { - this.traceOperation(this.context, "channelActive"); - context.fireChannelActive(); - } - - /** - * Completes all pending requests exceptionally when a channel reaches the end of its lifetime - *

- * This method will only be called after the channel is closed. - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - */ - @Override - public void channelInactive(final ChannelHandlerContext context) throws Exception { - this.traceOperation(this.context, "channelInactive"); - this.completeAllPendingRequestsExceptionally(context, ClosedWithPendingRequestsException.INSTANCE); - context.fireChannelInactive(); - } - - @Override - public void channelRead(final ChannelHandlerContext context, final Object message) throws Exception { - - this.traceOperation(context, "channelRead"); - - if (message instanceof RntbdResponse) { - try { - this.messageReceived(context, (RntbdResponse)message); - } finally { - ReferenceCountUtil.release(message); - } - this.traceOperation(context, "channelReadComplete"); - return; - } - - final String reason = Strings.lenientFormat("expected message of type %s, not %s", RntbdResponse.class, message.getClass()); - throw new IllegalStateException(reason); - } - - /** - * Invoked when the last message read by the current read operation has been consumed - *

- * If {@link ChannelOption#AUTO_READ} is off, no further attempt to read an inbound data from the current - * {@link Channel} will be made until {@link ChannelHandlerContext#read} is called. This leaves time - * for outbound messages to be written. - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - */ - @Override - public void channelReadComplete(final ChannelHandlerContext context) throws Exception { - this.traceOperation(context, "channelReadComplete"); - context.fireChannelReadComplete(); - } - - /** - * Constructs a {@link CoalescingBufferQueue} for buffering encoded requests until we have an {@link RntbdRequest} - *

- * This method then calls {@link ChannelHandlerContext#fireChannelRegistered()} to forward to the next - * {@link ChannelInboundHandler} in the {@link ChannelPipeline}. - *

- * Sub-classes may override this method to change behavior. - * - * @param context the {@link ChannelHandlerContext} for which the bind operation is made - */ - @Override - public void channelRegistered(final ChannelHandlerContext context) throws Exception { - - this.traceOperation(context, "channelRegistered"); - - if (!(this.context == null && this.pendingWrites == null)) { - throw new IllegalStateException(); - } - - this.pendingWrites = new CoalescingBufferQueue(context.channel()); - this.context = context; - context.fireChannelRegistered(); - } - - /** - * The {@link Channel} of the {@link ChannelHandlerContext} was unregistered from its {@link EventLoop} - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - */ - @Override - public void channelUnregistered(final ChannelHandlerContext context) throws Exception { - - this.traceOperation(context, "channelUnregistered"); - - if (this.context == null || this.pendingWrites == null || !this.pendingWrites.isEmpty()) { - throw new IllegalStateException(); - } - - this.pendingWrites = null; - this.context = null; - context.fireChannelUnregistered(); - } - - /** - * Gets called once the writable state of a {@link Channel} changed. You can check the state with - * {@link Channel#isWritable()}. - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - */ - @Override - public void channelWritabilityChanged(final ChannelHandlerContext context) throws Exception { - this.traceOperation(context, "channelWritabilityChanged"); - context.fireChannelWritabilityChanged(); - } - - /** - * Processes {@link ChannelHandlerContext#fireExceptionCaught(Throwable)} in the {@link ChannelPipeline} - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - * @param cause Exception caught - */ - @Override - @SuppressWarnings("deprecation") - public void exceptionCaught(final ChannelHandlerContext context, final Throwable cause) throws Exception { - - // TODO: DANOBLE: replace RntbdRequestManager.exceptionCaught with read/write listeners - // Notes: - // ChannelInboundHandler.exceptionCaught is deprecated and--today, prior to deprecation--only catches read-- - // i.e., inbound--exceptions. - // Replacements: - // * read listener: unclear as there is no obvious replacement - // * write listener: implemented by RntbdTransportClient.DefaultEndpoint.doWrite - // Links: - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/373213 - - this.traceOperation(context, "exceptionCaught", cause); - - if (!this.closingExceptionally) { - reportIssueUnless(cause != ClosedWithPendingRequestsException.INSTANCE, logger, context, - "expected an exception other than ", ClosedWithPendingRequestsException.INSTANCE); - this.completeAllPendingRequestsExceptionally(context, cause); - context.close(); - } - } - - /** - * Processes inbound events triggered by channel handlers in the {@link RntbdClientChannelHandler} pipeline - *

- * All but inbound request management events are ignored. - * - * @param context {@link ChannelHandlerContext} to which this {@link RntbdRequestManager} belongs - * @param event An object representing a user event - */ - @Override - public void userEventTriggered(final ChannelHandlerContext context, final Object event) { - - this.traceOperation(context, "userEventTriggered", event); - - if (event instanceof RntbdContext) { - this.completeRntbdContextFuture(context, (RntbdContext)event); - return; - } - - context.fireUserEventTriggered(event); - } - - // endregion - - // region ChannelOutboundHandler methods - - /** - * Called once a bind operation is made. - * - * @param context the {@link ChannelHandlerContext} for which the bind operation is made - * @param localAddress the {@link SocketAddress} to which it should bound - * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs - */ - @Override - public void bind(final ChannelHandlerContext context, final SocketAddress localAddress, final ChannelPromise promise) throws Exception { - this.traceOperation(context, "bind"); - context.bind(localAddress, promise); - } - - /** - * Called once a close operation is made. - * - * @param context the {@link ChannelHandlerContext} for which the close operation is made - * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs - */ - @Override - public void close(final ChannelHandlerContext context, final ChannelPromise promise) throws Exception { - this.traceOperation(context, "close"); - context.close(promise); - } - - /** - * Called once a connect operation is made. - * - * @param context the {@link ChannelHandlerContext} for which the connect operation is made - * @param remoteAddress the {@link SocketAddress} to which it should connect - * @param localAddress the {@link SocketAddress} which is used as source on connect - * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs - */ - @Override - public void connect(final ChannelHandlerContext context, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) throws Exception { - this.traceOperation(context, "connect"); - context.connect(remoteAddress, localAddress, promise); - } - - /** - * Called once a deregister operation is made from the current registered {@link EventLoop}. - * - * @param context the {@link ChannelHandlerContext} for which the close operation is made - * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs - */ - @Override - public void deregister(final ChannelHandlerContext context, final ChannelPromise promise) throws Exception { - this.traceOperation(context, "deregister"); - context.deregister(promise); - } - - /** - * Called once a disconnect operation is made. - * - * @param context the {@link ChannelHandlerContext} for which the disconnect operation is made - * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs - */ - @Override - public void disconnect(final ChannelHandlerContext context, final ChannelPromise promise) throws Exception { - this.traceOperation(context, "disconnect"); - context.disconnect(promise); - } - - /** - * Called once a flush operation is made - *

- * The flush operation will try to flush out all previous written messages that are pending. - * - * @param context the {@link ChannelHandlerContext} for which the flush operation is made - * @throws Exception thrown if an error occurs - */ - @Override - public void flush(final ChannelHandlerContext context) throws Exception { - this.traceOperation(context, "flush"); - context.flush(); - } - - /** - * Intercepts {@link ChannelHandlerContext#read} - * - * @param context the {@link ChannelHandlerContext} for which the read operation is made - */ - @Override - public void read(final ChannelHandlerContext context) throws Exception { - this.traceOperation(context, "read"); - context.read(); - } - - /** - * Called once a write operation is made - *

- * The write operation will send messages through the {@link ChannelPipeline} which are then ready to be flushed - * to the actual {@link Channel}. This will occur when {@link Channel#flush} is called. - * - * @param context the {@link ChannelHandlerContext} for which the write operation is made - * @param message the message to write - * @param promise the {@link ChannelPromise} to notify once the operation completes - * @throws Exception thrown if an error occurs - */ - @Override - public void write(final ChannelHandlerContext context, final Object message, final ChannelPromise promise) throws Exception { - - // TODO: DANOBLE: Ensure that all write errors are reported with a root cause of type EncoderException - - this.traceOperation(context, "write", message); - - if (message instanceof RntbdRequestRecord) { - context.write(this.addPendingRequestRecord((RntbdRequestRecord)message), promise); - } else { - final String reason = Strings.lenientFormat("Expected message of type %s, not %s", RntbdRequestArgs.class, message.getClass()); - this.exceptionCaught(context, new IllegalStateException(reason)); - } - } - - // endregion - - // region Private and package private methods - - int getPendingRequestCount() { - return this.pendingRequests.size(); - } - - CompletableFuture getRntbdContextRequestFuture() { - return this.contextRequestFuture; - } - - boolean hasRntbdContext() { - return this.contextFuture.getNow(null) != null; - } - - void pendWrite(final ByteBuf out, final ChannelPromise promise) { - - checkNotNull(out, "out"); - checkNotNull(promise, "promise"); - checkState(this.pendingWrites != null, "pendingWrite: null"); - - this.pendingWrites.add(out, promise); - } - - private RntbdRequestArgs addPendingRequestRecord(final RntbdRequestRecord requestRecord) { - - // TODO: DANOBLE: Consider revising the implementation of RntbdRequestManager.addPendingRequestRecord - // At a minimum consider these issues: - // * Do we have a requirement to support multiple concurrent operations for a single activityId? - // * Should we replace, renew, or maintain a list of pending requests for each activityId? - // We currently fail when we find an existing request record. - // Links: - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/378801 - - this.pendingRequest = this.pendingRequests.compute(requestRecord.getActivityId(), (activityId, current) -> { - - checkArgument(current == null, "current: expected no request record, not %s", current); - - final Timeout pendingRequestTimeout = requestRecord.newTimeout(timeout -> { - this.pendingRequests.remove(activityId); - requestRecord.expire(); - }); - - requestRecord.whenComplete((response, error) -> { - this.pendingRequests.remove(activityId); - pendingRequestTimeout.cancel(); - }); - - return requestRecord; - }); - - return this.pendingRequest.getArgs(); - } - - private Optional getRntbdContext() { - return Optional.of(this.contextFuture.getNow(null)); - } - - private void completeAllPendingRequestsExceptionally(final ChannelHandlerContext context, final Throwable throwable) { - - checkNotNull(throwable, "throwable: null"); - - if (this.closingExceptionally) { - checkArgument(throwable == ClosedWithPendingRequestsException.INSTANCE, "throwable: %s", throwable); - return; - } - - this.closingExceptionally = true; - - if (!this.pendingWrites.isEmpty()) { - this.pendingWrites.releaseAndFailAll(context, ClosedWithPendingRequestsException.INSTANCE); - } - - if (!this.pendingRequests.isEmpty()) { - - final Channel channel = context.channel(); - - if (!this.contextRequestFuture.isDone()) { - this.contextRequestFuture.completeExceptionally(throwable); - } - - if (!this.contextFuture.isDone()) { - this.contextFuture.completeExceptionally(throwable); - } - - Exception contextRequestException = null; - - if (this.contextRequestFuture.isCompletedExceptionally()) { - try { - this.contextRequestFuture.get(); - } catch (final CancellationException error) { - logger.debug("\n {} closed: context send cancelled", channel); - contextRequestException = error; - } catch (final Throwable error) { - final String message = Strings.lenientFormat("context send failed due to %s", error); - logger.debug("\n {} closed: {}", channel, message); - contextRequestException = new ChannelException(message, error); - } - } else if (this.contextFuture.isCompletedExceptionally()) { - try { - this.contextFuture.get(); - } catch (final CancellationException error) { - logger.debug("\n {} closed: context receive cancelled", channel); - contextRequestException = error; - } catch (final Throwable error) { - final String message = Strings.lenientFormat("context receive failed due to %s", error); - logger.debug("\n {} closed: {}", channel, message); - contextRequestException = new ChannelException(message, error); - } - } - - final String origin = "rntbd:/" + channel.remoteAddress(); - final int count = this.pendingRequests.size(); - final String message; - - if (contextRequestException == null) { - message = Strings.lenientFormat("%s channel closed with %s pending requests", channel, count); - } else { - message = Strings.lenientFormat("%s context request failed with %s pending requests", channel, count); - } - - final Exception reason; - - if (throwable == ClosedWithPendingRequestsException.INSTANCE && contextRequestException != null) { - reason = contextRequestException; - } else { - reason = throwable instanceof Exception ? (Exception)throwable : new ChannelException(throwable); - } - - for (final RntbdRequestRecord requestRecord : this.pendingRequests.values()) { - - final RntbdRequestArgs args = requestRecord.getArgs(); - final String requestUri = origin + args.getReplicaPath(); - final Map headers = args.getServiceRequest().getHeaders(); - - final GoneException cause = new GoneException(message, reason, headers, requestUri); - BridgeInternal.setRequestHeaders(cause, headers); - requestRecord.completeExceptionally(cause); - } - } - } - - private void completeRntbdContextFuture(final ChannelHandlerContext context, final RntbdContext value) { - - checkNotNull(context, "context"); - checkNotNull(value, "value"); - - if (this.contextFuture.isDone()) { - throw new IllegalStateException(Strings.lenientFormat("rntbdContextFuture: %s", this.contextFuture)); - } - - this.contextFuture.complete(value); - - final RntbdContextNegotiator negotiator = context.channel().pipeline().get(RntbdContextNegotiator.class); - negotiator.removeInboundHandler(); - negotiator.removeOutboundHandler(); - - if (!this.pendingWrites.isEmpty()) { - this.pendingWrites.writeAndRemoveAll(context); - } - } - - /** - * This method is called for each incoming message of type {@link StoreResponse} to complete a request - * - * @param context {@link ChannelHandlerContext} encode to which this {@link RntbdRequestManager} belongs - * @param response the message encode handle - */ - private void messageReceived(final ChannelHandlerContext context, final RntbdResponse response) { - - final UUID activityId = response.getActivityId(); - final RntbdRequestRecord pendingRequest = this.pendingRequests.get(activityId); - - if (pendingRequest == null) { - logger.warn("[activityId: {}] no request pending", activityId); - return; - } - - final HttpResponseStatus status = response.getStatus(); - - if (HttpResponseStatus.OK.code() <= status.code() && status.code() < HttpResponseStatus.MULTIPLE_CHOICES.code()) { - - final StoreResponse storeResponse = response.toStoreResponse(this.contextFuture.getNow(null)); - pendingRequest.complete(storeResponse); - - } else { - - // Map response to a DocumentClientException - - final DocumentClientException cause; - - // ..Fetch required header values - - final long lsn = response.getHeader(RntbdResponseHeader.LSN); - final String partitionKeyRangeId = response.getHeader(RntbdResponseHeader.PartitionKeyRangeId); - - // ..Create Error instance - - final Error error = response.hasPayload() ? - BridgeInternal.createError(RntbdObjectMapper.readTree(response)) : - new Error(Integer.toString(status.code()), status.reasonPhrase(), status.codeClass().name()); - - // ..Map RNTBD response headers to HTTP response headers - - final Map responseHeaders = response.getHeaders().asMap( - this.getRntbdContext().orElseThrow(IllegalStateException::new), activityId - ); - - // ..Create DocumentClientException based on status and sub-status codes - - switch (status.code()) { - - case StatusCodes.BADREQUEST: - cause = new BadRequestException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.CONFLICT: - cause = new ConflictException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.FORBIDDEN: - cause = new ForbiddenException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.GONE: - - final int subStatusCode = Math.toIntExact(response.getHeader(RntbdResponseHeader.SubStatus)); - - switch (subStatusCode) { - case SubStatusCodes.COMPLETING_SPLIT: - cause = new PartitionKeyRangeIsSplittingException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - case SubStatusCodes.COMPLETING_PARTITION_MIGRATION: - cause = new PartitionIsMigratingException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - case SubStatusCodes.NAME_CACHE_IS_STALE: - cause = new InvalidPartitionException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - case SubStatusCodes.PARTITION_KEY_RANGE_GONE: - cause = new PartitionKeyRangeGoneException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - default: - cause = new GoneException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - } - break; - - case StatusCodes.INTERNAL_SERVER_ERROR: - cause = new InternalServerErrorException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.LOCKED: - cause = new LockedException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.METHOD_NOT_ALLOWED: - cause = new MethodNotAllowedException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.NOTFOUND: - cause = new NotFoundException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.PRECONDITION_FAILED: - cause = new PreconditionFailedException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.REQUEST_ENTITY_TOO_LARGE: - cause = new RequestEntityTooLargeException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.REQUEST_TIMEOUT: - cause = new RequestTimeoutException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.RETRY_WITH: - cause = new RetryWithException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.SERVICE_UNAVAILABLE: - cause = new ServiceUnavailableException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.TOO_MANY_REQUESTS: - cause = new RequestRateTooLargeException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - case StatusCodes.UNAUTHORIZED: - cause = new UnauthorizedException(error, lsn, partitionKeyRangeId, responseHeaders); - break; - - default: - cause = new DocumentClientException(status.code(), error, responseHeaders); - break; - } - - logger.trace("{}[activityId: {}, statusCode: {}, subStatusCode: {}] ", - context.channel(), cause.getActivityId(), cause.getStatusCode(), cause.getSubStatusCode(), cause - ); - - pendingRequest.completeExceptionally(cause); - } - } - - private void traceOperation(final ChannelHandlerContext context, final String operationName, final Object... args) { - - if (logger.isTraceEnabled()) { - - final long birthTime; - final BigDecimal lifetime; - - if (this.pendingRequest == null) { - birthTime = System.nanoTime(); - lifetime = BigDecimal.ZERO; - } else { - birthTime = this.pendingRequest.getBirthTime(); - lifetime = BigDecimal.valueOf(this.pendingRequest.getLifetime().toNanos(), 6); - } - - logger.trace("{},{},\"{}({})\",\"{}\",\"{}\"", birthTime, lifetime, operationName, Stream.of(args).map(arg -> - arg == null ? "null" : arg.toString()).collect(Collectors.joining(",") - ), this.pendingRequest, context - ); - } - } - - // endregion - - // region Types - - private static class ClosedWithPendingRequestsException extends RuntimeException { - - static ClosedWithPendingRequestsException INSTANCE = new ClosedWithPendingRequestsException(); - - // TODO: DANOBLE: Consider revising strategy for closing an RntbdTransportClient with pending requests - // One possibility: - // A channel associated with an RntbdTransportClient will not be closed immediately, if there are any pending - // requests on it. Instead it will be scheduled to close after the request timeout interval (default: 60s) has - // elapsed. - // Algorithm: - // When the RntbdTransportClient is closed, it closes each of its RntbdServiceEndpoint instances. In turn each - // RntbdServiceEndpoint closes its RntbdClientChannelPool. The RntbdClientChannelPool.close method should - // schedule closure of any channel with pending requests for later; when the request timeout interval has - // elapsed or--ideally--when all pending requests have completed. - // Links: - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/388987 - - private ClosedWithPendingRequestsException() { - } - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestRecord.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestRecord.java deleted file mode 100644 index 108a8e106b9a..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestRecord.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.RequestTimeoutException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import io.netty.util.Timeout; -import io.netty.util.TimerTask; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.Duration; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.TimeUnit; - -import static com.google.common.base.Preconditions.checkNotNull; - -public final class RntbdRequestRecord extends CompletableFuture { - - private static final Logger logger = LoggerFactory.getLogger(RntbdRequestRecord.class); - - private final RntbdRequestArgs args; - private final RntbdRequestTimer timer; - - public RntbdRequestRecord(final RntbdRequestArgs args, final RntbdRequestTimer timer) { - - checkNotNull(args, "args"); - checkNotNull(timer, "timer"); - - this.args = args; - this.timer = timer; - } - - public UUID getActivityId() { - return this.args.getActivityId(); - } - - public RntbdRequestArgs getArgs() { - return this.args; - } - - public long getBirthTime() { - return this.args.getBirthTime(); - } - - public Duration getLifetime() { - return this.args.getLifetime(); - } - - public void expire() { - final RequestTimeoutException error = new RequestTimeoutException( - String.format("Request timeout interval (%,d ms) elapsed", - this.timer.getRequestTimeout(TimeUnit.MILLISECONDS)), - this.args.getPhysicalAddress()); - BridgeInternal.setRequestHeaders(error, this.args.getServiceRequest().getHeaders()); - this.completeExceptionally(error); - } - - public Timeout newTimeout(final TimerTask task) { - return this.timer.newTimeout(task); - } - - @Override - public String toString() { - return this.args.toString(); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestTimer.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestTimer.java deleted file mode 100644 index 7217dfc7f73d..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdRequestTimer.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.util.HashedWheelTimer; -import io.netty.util.Timeout; -import io.netty.util.Timer; -import io.netty.util.TimerTask; - -import java.util.concurrent.TimeUnit; - -public final class RntbdRequestTimer implements AutoCloseable { - - private static final long FIVE_MILLISECONDS = 5000000L; - private final long requestTimeout; - private final Timer timer; - - public RntbdRequestTimer(final long requestTimeout) { - - // Inspection of the HashWheelTimer code indicates that our choice of a 5 millisecond timer resolution ensures - // a request will timeout within 10 milliseconds of the specified requestTimeout interval. This is because - // cancellation of a timeout takes two timer resolution units to complete. - - this.timer = new HashedWheelTimer(FIVE_MILLISECONDS, TimeUnit.NANOSECONDS); - this.requestTimeout = requestTimeout; - } - - public long getRequestTimeout(TimeUnit unit) { - return unit.convert(requestTimeout, TimeUnit.NANOSECONDS); - } - - @Override - public void close() throws RuntimeException { - this.timer.stop(); - } - - public Timeout newTimeout(final TimerTask task) { - return this.timer.newTimeout(task, this.requestTimeout, TimeUnit.NANOSECONDS); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponse.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponse.java deleted file mode 100644 index 77142964209a..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponse.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; -import io.netty.buffer.EmptyByteBuf; -import io.netty.handler.codec.CorruptedFrameException; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.util.ReferenceCounted; -import io.netty.util.ResourceLeakDetector; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdResponseHeader; -import static java.lang.Math.min; - -@JsonPropertyOrder({ "frame", "headers", "content" }) -public final class RntbdResponse implements ReferenceCounted { - - // region Fields - - @JsonProperty - @JsonSerialize(using = PayloadSerializer.class) - private final ByteBuf content; - - @JsonProperty - private final RntbdResponseStatus frame; - - @JsonProperty - private final RntbdResponseHeaders headers; - - private AtomicInteger referenceCount = new AtomicInteger(); - - // endregion - - public RntbdResponse(final UUID activityId, final int statusCode, final Map map, final ByteBuf content) { - - this.headers = RntbdResponseHeaders.fromMap(map, content.readableBytes() > 0); - this.content = content.retain(); - - final HttpResponseStatus status = HttpResponseStatus.valueOf(statusCode); - final int length = RntbdResponseStatus.LENGTH + this.headers.computeLength(); - - this.frame = new RntbdResponseStatus(length, status, activityId); - } - - private RntbdResponse(final RntbdResponseStatus frame, final RntbdResponseHeaders headers, final ByteBuf content) { - - this.frame = frame; - this.headers = headers; - this.content = content.retain(); - } - - public UUID getActivityId() { - return this.frame.getActivityId(); - } - - @JsonIgnore - public ByteBuf getContent() { - return this.content; - } - - @JsonIgnore - public RntbdResponseHeaders getHeaders() { - return this.headers; - } - - @JsonIgnore - public HttpResponseStatus getStatus() { - return this.frame.getStatus(); - } - - static RntbdResponse decode(final ByteBuf in) { - - in.markReaderIndex(); - - final RntbdResponseStatus frame = RntbdResponseStatus.decode(in); - final RntbdResponseHeaders headers = RntbdResponseHeaders.decode(in.readSlice(frame.getHeadersLength())); - - final boolean hasPayload = headers.isPayloadPresent(); - final ByteBuf content; - - if (hasPayload) { - - if (!RntbdFramer.canDecodePayload(in)) { - in.resetReaderIndex(); - return null; - } - - content = in.readSlice(in.readIntLE()); - - } else { - - content = new EmptyByteBuf(in.alloc()); - } - - return new RntbdResponse(frame, headers, content); - } - - public void encode(final ByteBuf out) { - - final int start = out.writerIndex(); - - this.frame.encode(out); - this.headers.encode(out); - - final int length = out.writerIndex() - start; - - if (length != this.frame.getLength()) { - throw new IllegalStateException(); - } - - if (this.hasPayload()) { - out.writeIntLE(this.content.readableBytes()); - out.writeBytes(this.content); - } else if (this.content.readableBytes() > 0) { - throw new IllegalStateException(); - } - } - - @JsonIgnore - public T getHeader(final RntbdResponseHeader header) { - final T value = (T)this.headers.get(header).getValue(); - return value; - } - - public boolean hasPayload() { - return this.headers.isPayloadPresent(); - } - - /** - * Returns the reference count of this object. If {@code 0}, it means this object has been deallocated. - */ - @Override - public int refCnt() { - return this.referenceCount.get(); - } - - /** - * Decreases the reference count by {@code 1} and deallocate this object if the reference count reaches {@code 0} - * - * @return {@code true} if and only if the reference count became {@code 0} and this object is de-allocated - */ - @Override - public boolean release() { - return this.release(1); - } - - /** - * Decreases the reference count by {@code decrement} and de-allocates this object if the reference count reaches {@code 0} - * - * @param decrement amount of the decrease - * @return {@code true} if and only if the reference count became {@code 0} and this object has been de-allocated - */ - @Override - public boolean release(final int decrement) { - - return this.referenceCount.getAndAccumulate(decrement, (value, n) -> { - value = value - min(value, n); - if (value == 0) { - assert this.headers != null && this.content != null; - this.headers.releaseBuffers(); - this.content.release(); - } - return value; - }) == 0; - } - - /** - * Increases the reference count by {@code 1}. - */ - @Override - public ReferenceCounted retain() { - this.referenceCount.incrementAndGet(); - return this; - } - - /** - * Increases the reference count by the specified {@code increment}. - * - * @param increment amount of the increase - */ - @Override - public ReferenceCounted retain(final int increment) { - this.referenceCount.addAndGet(increment); - return this; - } - - StoreResponse toStoreResponse(final RntbdContext context) { - - checkNotNull(context, "context"); - final int length = this.content.readableBytes(); - - return new StoreResponse( - this.getStatus().code(), - this.headers.asList(context, this.getActivityId()), - length == 0 ? null : this.content.readCharSequence(length, StandardCharsets.UTF_8).toString() - ); - } - - @Override - public String toString() { - final ObjectWriter writer = RntbdObjectMapper.writer(); - try { - return writer.writeValueAsString(this); - } catch (final JsonProcessingException error) { - throw new CorruptedFrameException(error); - } - } - - /** - * Records the current access location of this object for debugging purposes - *

- * If this object is determined to be leaked, the information recorded by this operation will be provided to you - * via {@link ResourceLeakDetector}. This method is a shortcut to {@link #touch(Object) touch(null)}. - */ - @Override - public ReferenceCounted touch() { - return this; - } - - /** - * Records the current access location of this object with additional arbitrary information for debugging purposes - *

- * If this object is determined to be leaked, the information recorded by this operation will be - * provided to you via {@link ResourceLeakDetector}. - * - * @param hint information useful for debugging (unused) - */ - @Override - public ReferenceCounted touch(final Object hint) { - return this; - } - - private static class PayloadSerializer extends StdSerializer { - - public PayloadSerializer() { - super(ByteBuf.class, true); - } - - @Override - public void serialize(final ByteBuf value, final JsonGenerator generator, final SerializerProvider provider) throws IOException { - - final int length = value.readableBytes(); - - generator.writeStartObject(); - generator.writeObjectField("length", length); - generator.writeObjectField("content", ByteBufUtil.hexDump(value, 0, length)); - generator.writeEndObject(); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseDecoder.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseDecoder.java deleted file mode 100644 index d813233255c3..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseDecoder.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public final class RntbdResponseDecoder extends ByteToMessageDecoder { - - private static final Logger Logger = LoggerFactory.getLogger(RntbdResponseDecoder.class); - - /** - * Deserialize from an input {@link ByteBuf} to an {@link RntbdResponse} instance - *

- * This method is called till it reads no bytes from the {@link ByteBuf} or there is no more data to be readTree. - * - * @param context the {@link ChannelHandlerContext} to which this {@link RntbdResponseDecoder} belongs - * @param in the {@link ByteBuf} to which data to be decoded is readTree - * @param out the {@link List} to which decoded messages are added - */ - @Override - protected void decode(final ChannelHandlerContext context, final ByteBuf in, final List out) { - - if (RntbdFramer.canDecodeHead(in)) { - - final RntbdResponse response = RntbdResponse.decode(in); - - if (response != null) { - Logger.debug("{} DECODE COMPLETE: {}", context.channel(), response); - in.discardReadBytes(); - out.add(response.retain()); - } - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseHeaders.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseHeaders.java deleted file mode 100644 index ef459591e8f2..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseHeaders.java +++ /dev/null @@ -1,535 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.annotation.JsonFilter; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.CorruptedFrameException; - -import java.math.BigDecimal; -import java.util.AbstractMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.function.BiConsumer; -import java.util.function.Function; - -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.HttpHeaders; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants.BackendHeaders; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdIndexingDirective; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdResponseHeader; - -@JsonFilter("RntbdToken") -class RntbdResponseHeaders extends RntbdTokenStream { - - // region Fields - - @JsonProperty - private final RntbdToken LSN; - @JsonProperty - private final RntbdToken collectionLazyIndexProgress; - @JsonProperty - private final RntbdToken collectionPartitionIndex; - @JsonProperty - private final RntbdToken collectionSecurityIdentifier; - @JsonProperty - private final RntbdToken collectionServiceIndex; - @JsonProperty - private final RntbdToken collectionUpdateProgress; - @JsonProperty - private final RntbdToken continuationToken; - @JsonProperty - private final RntbdToken currentReplicaSetSize; - @JsonProperty - private final RntbdToken currentWriteQuorum; - @JsonProperty - private final RntbdToken databaseAccountId; - @JsonProperty - private final RntbdToken disableRntbdChannel; - @JsonProperty - private final RntbdToken eTag; - @JsonProperty - private final RntbdToken globalCommittedLSN; - @JsonProperty - private final RntbdToken hasTentativeWrites; - @JsonProperty - private final RntbdToken indexTermsGenerated; - @JsonProperty - private final RntbdToken indexingDirective; - @JsonProperty - private final RntbdToken isRUPerMinuteUsed; - @JsonProperty - private final RntbdToken itemCount; - @JsonProperty - private final RntbdToken itemLSN; - @JsonProperty - private final RntbdToken itemLocalLSN; - @JsonProperty - private final RntbdToken lastStateChangeDateTime; - @JsonProperty - private final RntbdToken localLSN; - @JsonProperty - private final RntbdToken logResults; - @JsonProperty - private final RntbdToken numberOfReadRegions; - @JsonProperty - private final RntbdToken offerReplacePending; - @JsonProperty - private final RntbdToken ownerFullName; - @JsonProperty - private final RntbdToken ownerId; - @JsonProperty - private final RntbdToken partitionKeyRangeId; - @JsonProperty - private final RntbdToken payloadPresent; - @JsonProperty - private final RntbdToken queriesPerformed; - @JsonProperty - private final RntbdToken queryMetrics; - @JsonProperty - private final RntbdToken quorumAckedLSN; - @JsonProperty - private final RntbdToken quorumAckedLocalLSN; - @JsonProperty - private final RntbdToken readsPerformed; - @JsonProperty - private final RntbdToken requestCharge; - @JsonProperty - private final RntbdToken requestValidationFailure; - @JsonProperty - private final RntbdToken restoreState; - @JsonProperty - private final RntbdToken retryAfterMilliseconds; - @JsonProperty - private final RntbdToken schemaVersion; - @JsonProperty - private final RntbdToken scriptsExecuted; - @JsonProperty - private final RntbdToken serverDateTimeUtc; - @JsonProperty - private final RntbdToken sessionToken; - @JsonProperty - private final RntbdToken shareThroughput; - @JsonProperty - private final RntbdToken storageMaxResoureQuota; - @JsonProperty - private final RntbdToken storageResourceQuotaUsage; - @JsonProperty - private final RntbdToken subStatus; - @JsonProperty - private final RntbdToken transportRequestID; - @JsonProperty - private final RntbdToken writesPerformed; - @JsonProperty - private final RntbdToken xpRole; - - // endregion - - private RntbdResponseHeaders() { - - super(RntbdResponseHeader.set, RntbdResponseHeader.map); - - this.LSN = this.get(RntbdResponseHeader.LSN); - this.collectionLazyIndexProgress = this.get(RntbdResponseHeader.CollectionLazyIndexProgress); - this.collectionPartitionIndex = this.get(RntbdResponseHeader.CollectionPartitionIndex); - this.collectionSecurityIdentifier = this.get(RntbdResponseHeader.CollectionSecurityIdentifier); - this.collectionServiceIndex = this.get(RntbdResponseHeader.CollectionServiceIndex); - this.collectionUpdateProgress = this.get(RntbdResponseHeader.CollectionUpdateProgress); - this.continuationToken = this.get(RntbdResponseHeader.ContinuationToken); - this.currentReplicaSetSize = this.get(RntbdResponseHeader.CurrentReplicaSetSize); - this.currentWriteQuorum = this.get(RntbdResponseHeader.CurrentWriteQuorum); - this.databaseAccountId = this.get(RntbdResponseHeader.DatabaseAccountId); - this.disableRntbdChannel = this.get(RntbdResponseHeader.DisableRntbdChannel); - this.eTag = this.get(RntbdResponseHeader.ETag); - this.globalCommittedLSN = this.get(RntbdResponseHeader.GlobalCommittedLSN); - this.hasTentativeWrites = this.get(RntbdResponseHeader.HasTentativeWrites); - this.indexTermsGenerated = this.get(RntbdResponseHeader.IndexTermsGenerated); - this.indexingDirective = this.get(RntbdResponseHeader.IndexingDirective); - this.isRUPerMinuteUsed = this.get(RntbdResponseHeader.IsRUPerMinuteUsed); - this.itemCount = this.get(RntbdResponseHeader.ItemCount); - this.itemLSN = this.get(RntbdResponseHeader.ItemLSN); - this.itemLocalLSN = this.get(RntbdResponseHeader.ItemLocalLSN); - this.lastStateChangeDateTime = this.get(RntbdResponseHeader.LastStateChangeDateTime); - this.localLSN = this.get(RntbdResponseHeader.LocalLSN); - this.logResults = this.get(RntbdResponseHeader.LogResults); - this.numberOfReadRegions = this.get(RntbdResponseHeader.NumberOfReadRegions); - this.offerReplacePending = this.get(RntbdResponseHeader.OfferReplacePending); - this.ownerFullName = this.get(RntbdResponseHeader.OwnerFullName); - this.ownerId = this.get(RntbdResponseHeader.OwnerId); - this.partitionKeyRangeId = this.get(RntbdResponseHeader.PartitionKeyRangeId); - this.payloadPresent = this.get(RntbdResponseHeader.PayloadPresent); - this.queriesPerformed = this.get(RntbdResponseHeader.QueriesPerformed); - this.queryMetrics = this.get(RntbdResponseHeader.QueryMetrics); - this.quorumAckedLSN = this.get(RntbdResponseHeader.QuorumAckedLSN); - this.quorumAckedLocalLSN = this.get(RntbdResponseHeader.QuorumAckedLocalLSN); - this.readsPerformed = this.get(RntbdResponseHeader.ReadsPerformed); - this.requestCharge = this.get(RntbdResponseHeader.RequestCharge); - this.requestValidationFailure = this.get(RntbdResponseHeader.RequestValidationFailure); - this.restoreState = this.get(RntbdResponseHeader.RestoreState); - this.retryAfterMilliseconds = this.get(RntbdResponseHeader.RetryAfterMilliseconds); - this.schemaVersion = this.get(RntbdResponseHeader.SchemaVersion); - this.scriptsExecuted = this.get(RntbdResponseHeader.ScriptsExecuted); - this.serverDateTimeUtc = this.get(RntbdResponseHeader.ServerDateTimeUtc); - this.sessionToken = this.get(RntbdResponseHeader.SessionToken); - this.shareThroughput = this.get(RntbdResponseHeader.ShareThroughput); - this.storageMaxResoureQuota = this.get(RntbdResponseHeader.StorageMaxResoureQuota); - this.storageResourceQuotaUsage = this.get(RntbdResponseHeader.StorageResourceQuotaUsage); - this.subStatus = this.get(RntbdResponseHeader.SubStatus); - this.transportRequestID = this.get(RntbdResponseHeader.TransportRequestID); - this.writesPerformed = this.get(RntbdResponseHeader.WritesPerformed); - this.xpRole = this.get(RntbdResponseHeader.XPRole); - } - - boolean isPayloadPresent() { - return this.payloadPresent.isPresent() && this.payloadPresent.getValue(Byte.class) != 0x00; - } - - List> asList(final RntbdContext context, final UUID activityId) { - - final ImmutableList.Builder> builder = ImmutableList.builderWithExpectedSize(this.computeCount() + 2); - builder.add(new Entry(HttpHeaders.SERVER_VERSION, context.getServerVersion())); - builder.add(new Entry(HttpHeaders.ACTIVITY_ID, activityId.toString())); - - this.collectEntries((token, toEntry) -> { - if (token.isPresent()) { - builder.add(toEntry.apply(token)); - } - }); - - return builder.build(); - } - - public Map asMap(final RntbdContext context, final UUID activityId) { - - final ImmutableMap.Builder builder = ImmutableMap.builderWithExpectedSize(this.computeCount() + 2); - builder.put(new Entry(HttpHeaders.SERVER_VERSION, context.getServerVersion())); - builder.put(new Entry(HttpHeaders.ACTIVITY_ID, activityId.toString())); - - this.collectEntries((token, toEntry) -> { - if (token.isPresent()) { - builder.put(toEntry.apply(token)); - } - }); - - return builder.build(); - } - - static RntbdResponseHeaders decode(final ByteBuf in) { - final RntbdResponseHeaders headers = new RntbdResponseHeaders(); - RntbdTokenStream.decode(in, headers); - return headers; - } - - public static RntbdResponseHeaders fromMap(final Map map, final boolean payloadPresent) { - - final RntbdResponseHeaders headers = new RntbdResponseHeaders(); - headers.payloadPresent.setValue(payloadPresent); - headers.setValues(map); - - return headers; - } - - public void setValues(final Map headers) { - - this.mapValue(this.LSN, BackendHeaders.LSN, Long::parseLong, headers); - this.mapValue(this.collectionLazyIndexProgress, HttpHeaders.COLLECTION_LAZY_INDEXING_PROGRESS, Integer::parseInt, headers); - this.mapValue(this.collectionLazyIndexProgress, BackendHeaders.COLLECTION_PARTITION_INDEX, Integer::parseInt, headers); - this.mapValue(this.collectionSecurityIdentifier, BackendHeaders.COLLECTION_SECURITY_IDENTIFIER, String::toString, headers); - this.mapValue(this.collectionServiceIndex, BackendHeaders.COLLECTION_SERVICE_INDEX, Integer::parseInt, headers); - this.mapValue(this.collectionUpdateProgress, HttpHeaders.COLLECTION_INDEX_TRANSFORMATION_PROGRESS, Integer::parseInt, headers); - this.mapValue(this.continuationToken, HttpHeaders.CONTINUATION, String::toString, headers); - this.mapValue(this.currentReplicaSetSize, BackendHeaders.CURRENT_REPLICA_SET_SIZE, Integer::parseInt, headers); - this.mapValue(this.currentWriteQuorum, BackendHeaders.CURRENT_WRITE_QUORUM, Integer::parseInt, headers); - this.mapValue(this.databaseAccountId, BackendHeaders.DATABASE_ACCOUNT_ID, String::toString, headers); - this.mapValue(this.disableRntbdChannel, HttpHeaders.DISABLE_RNTBD_CHANNEL, Boolean::parseBoolean, headers); - this.mapValue(this.eTag, HttpHeaders.E_TAG, String::toString, headers); - this.mapValue(this.globalCommittedLSN, BackendHeaders.GLOBAL_COMMITTED_LSN, Long::parseLong, headers); - this.mapValue(this.hasTentativeWrites, BackendHeaders.HAS_TENTATIVE_WRITES, Boolean::parseBoolean, headers); - this.mapValue(this.indexingDirective, HttpHeaders.INDEXING_DIRECTIVE, RntbdIndexingDirective::valueOf, headers); - this.mapValue(this.isRUPerMinuteUsed, BackendHeaders.IS_RU_PER_MINUTE_USED, Byte::parseByte, headers); - this.mapValue(this.itemCount, HttpHeaders.ITEM_COUNT, Integer::parseInt, headers); - this.mapValue(this.itemLSN, BackendHeaders.ITEM_LSN, Long::parseLong, headers); - this.mapValue(this.itemLocalLSN, BackendHeaders.ITEM_LOCAL_LSN, Long::parseLong, headers); - this.mapValue(this.lastStateChangeDateTime, HttpHeaders.LAST_STATE_CHANGE_UTC, String::toString, headers); - this.mapValue(this.lastStateChangeDateTime, HttpHeaders.LAST_STATE_CHANGE_UTC, String::toString, headers); - this.mapValue(this.localLSN, BackendHeaders.LOCAL_LSN, Long::parseLong, headers); - this.mapValue(this.logResults, HttpHeaders.LOG_RESULTS, String::toString, headers); - this.mapValue(this.numberOfReadRegions, BackendHeaders.NUMBER_OF_READ_REGIONS, Integer::parseInt, headers); - this.mapValue(this.offerReplacePending, BackendHeaders.OFFER_REPLACE_PENDING, Boolean::parseBoolean, headers); - this.mapValue(this.ownerFullName, HttpHeaders.OWNER_FULL_NAME, String::toString, headers); - this.mapValue(this.ownerId, HttpHeaders.OWNER_ID, String::toString, headers); - this.mapValue(this.partitionKeyRangeId, BackendHeaders.PARTITION_KEY_RANGE_ID, String::toString, headers); - this.mapValue(this.queryMetrics, BackendHeaders.QUERY_METRICS, String::toString, headers); - this.mapValue(this.quorumAckedLSN, BackendHeaders.QUORUM_ACKED_LSN, Long::parseLong, headers); - this.mapValue(this.quorumAckedLocalLSN, BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long::parseLong, headers); - this.mapValue(this.requestCharge, HttpHeaders.REQUEST_CHARGE, Double::parseDouble, headers); - this.mapValue(this.requestValidationFailure, BackendHeaders.REQUEST_VALIDATION_FAILURE, Byte::parseByte, headers); - this.mapValue(this.restoreState, BackendHeaders.RESTORE_STATE, String::toString, headers); - this.mapValue(this.retryAfterMilliseconds, HttpHeaders.RETRY_AFTER_IN_MILLISECONDS, Integer::parseInt, headers); - this.mapValue(this.schemaVersion, HttpHeaders.SCHEMA_VERSION, String::toString, headers); - this.mapValue(this.serverDateTimeUtc, HttpHeaders.X_DATE, String::toString, headers); - this.mapValue(this.sessionToken, HttpHeaders.SESSION_TOKEN, String::toString, headers); - this.mapValue(this.shareThroughput, BackendHeaders.SHARE_THROUGHPUT, Boolean::parseBoolean, headers); - this.mapValue(this.storageMaxResoureQuota, HttpHeaders.MAX_RESOURCE_QUOTA, String::toString, headers); - this.mapValue(this.storageResourceQuotaUsage, HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE, String::toString, headers); - this.mapValue(this.subStatus, BackendHeaders.SUB_STATUS, Integer::parseInt, headers); - this.mapValue(this.transportRequestID, HttpHeaders.TRANSPORT_REQUEST_ID, Integer::parseInt, headers); - this.mapValue(this.xpRole, BackendHeaders.XP_ROLE, Integer::parseInt, headers); - } - - @Override - public String toString() { - final ObjectWriter writer = RntbdObjectMapper.writer(); - try { - return writer.writeValueAsString(this); - } catch (final JsonProcessingException error) { - throw new CorruptedFrameException(error); - } - } - - private void collectEntries(final BiConsumer>> collector) { - - collector.accept(this.LSN, token -> - toLongEntry(BackendHeaders.LSN, token) - ); - - collector.accept(this.collectionLazyIndexProgress, token -> - toIntegerEntry(HttpHeaders.COLLECTION_LAZY_INDEXING_PROGRESS, token) - ); - - collector.accept(this.collectionPartitionIndex, token -> - toIntegerEntry(BackendHeaders.COLLECTION_PARTITION_INDEX, token) - ); - - collector.accept(this.collectionSecurityIdentifier, token -> - toStringEntry(BackendHeaders.COLLECTION_SECURITY_IDENTIFIER, token) - ); - - collector.accept(this.collectionServiceIndex, token -> - toIntegerEntry(BackendHeaders.COLLECTION_SERVICE_INDEX, token) - ); - - collector.accept(this.collectionUpdateProgress, token -> - toIntegerEntry(HttpHeaders.COLLECTION_INDEX_TRANSFORMATION_PROGRESS, token) - ); - - collector.accept(this.continuationToken, token -> - toStringEntry(HttpHeaders.CONTINUATION, token) - ); - - collector.accept(this.currentReplicaSetSize, token -> - toIntegerEntry(BackendHeaders.CURRENT_REPLICA_SET_SIZE, token) - ); - - collector.accept(this.currentWriteQuorum, token -> - toIntegerEntry(BackendHeaders.CURRENT_WRITE_QUORUM, token) - ); - - collector.accept(this.databaseAccountId, token -> - toStringEntry(BackendHeaders.DATABASE_ACCOUNT_ID, token) - ); - - collector.accept(this.disableRntbdChannel, token -> - toBooleanEntry(HttpHeaders.DISABLE_RNTBD_CHANNEL, token) - ); - - collector.accept(this.eTag, token -> - toStringEntry(HttpHeaders.E_TAG, token) - ); - - collector.accept(this.globalCommittedLSN, token -> - toLongEntry(BackendHeaders.GLOBAL_COMMITTED_LSN, token) - ); - - collector.accept(this.hasTentativeWrites, token -> - toBooleanEntry(BackendHeaders.HAS_TENTATIVE_WRITES, token) - ); - - collector.accept(this.indexingDirective, token -> - new Entry(HttpHeaders.INDEXING_DIRECTIVE, RntbdIndexingDirective.fromId(token.getValue(Byte.class)).name()) - ); - - collector.accept(this.isRUPerMinuteUsed, token -> - toByteEntry(BackendHeaders.IS_RU_PER_MINUTE_USED, token) - ); - - collector.accept(this.itemCount, token -> - toIntegerEntry(HttpHeaders.ITEM_COUNT, token) - ); - - collector.accept(this.itemLSN, token -> - toLongEntry(BackendHeaders.ITEM_LSN, token) - ); - - collector.accept(this.itemLocalLSN, token -> - toLongEntry(BackendHeaders.ITEM_LOCAL_LSN, token) - ); - - collector.accept(this.lastStateChangeDateTime, token -> - toStringEntry(HttpHeaders.LAST_STATE_CHANGE_UTC, token) - ); - - collector.accept(this.localLSN, token -> - toLongEntry(BackendHeaders.LOCAL_LSN, token) - ); - - collector.accept(this.logResults, token -> - toStringEntry(HttpHeaders.LOG_RESULTS, token) - ); - - collector.accept(this.numberOfReadRegions, token -> - toIntegerEntry(BackendHeaders.NUMBER_OF_READ_REGIONS, token) - ); - - collector.accept(this.offerReplacePending, token -> - toBooleanEntry(BackendHeaders.OFFER_REPLACE_PENDING, token) - ); - - collector.accept(this.ownerFullName, token -> - toStringEntry(HttpHeaders.OWNER_FULL_NAME, token) - ); - - collector.accept(this.ownerId, token -> - toStringEntry(HttpHeaders.OWNER_ID, token) - ); - - collector.accept(this.partitionKeyRangeId, token -> - toStringEntry(BackendHeaders.PARTITION_KEY_RANGE_ID, token) - ); - - collector.accept(this.queryMetrics, token -> - toStringEntry(BackendHeaders.QUERY_METRICS, token) - ); - - collector.accept(this.quorumAckedLSN, token -> - toLongEntry(BackendHeaders.QUORUM_ACKED_LSN, token) - ); - - collector.accept(this.quorumAckedLocalLSN, token -> - toLongEntry(BackendHeaders.QUORUM_ACKED_LOCAL_LSN, token) - ); - - collector.accept(this.requestCharge, token -> - toCurrencyEntry(HttpHeaders.REQUEST_CHARGE, token) - ); - - collector.accept(this.requestValidationFailure, token -> - toByteEntry(BackendHeaders.REQUEST_VALIDATION_FAILURE, token) - ); - - collector.accept(this.restoreState, token -> - toStringEntry(BackendHeaders.RESTORE_STATE, token) - ); - - collector.accept(this.retryAfterMilliseconds, token -> - toIntegerEntry(HttpHeaders.RETRY_AFTER_IN_MILLISECONDS, token) - ); - - collector.accept(this.schemaVersion, token -> - toStringEntry(HttpHeaders.SCHEMA_VERSION, token) - ); - - collector.accept(this.serverDateTimeUtc, token -> - toStringEntry(HttpHeaders.X_DATE, token) - ); - - collector.accept(this.sessionToken, token -> - this.toSessionTokenEntry(HttpHeaders.SESSION_TOKEN, token) - ); - - collector.accept(this.shareThroughput, token -> - toBooleanEntry(BackendHeaders.SHARE_THROUGHPUT, token) - ); - - collector.accept(this.storageMaxResoureQuota, token -> - toStringEntry(HttpHeaders.MAX_RESOURCE_QUOTA, token) - ); - - collector.accept(this.storageResourceQuotaUsage, token -> - toStringEntry(HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE, token) - ); - - collector.accept(this.subStatus, token -> - toIntegerEntry(BackendHeaders.SUB_STATUS, token) - ); - - collector.accept(this.transportRequestID, token -> - toIntegerEntry(HttpHeaders.TRANSPORT_REQUEST_ID, token) - ); - - collector.accept(this.xpRole, token -> - toIntegerEntry(BackendHeaders.XP_ROLE, token) - ); - } - - private void mapValue(final RntbdToken token, final String name, final Function parse, final Map headers) { - - final String value = headers.get(name); - - if (value != null) { - token.setValue(parse.apply(value)); - } - } - - private static Map.Entry toBooleanEntry(final String name, final RntbdToken token) { - return new Entry(name, String.valueOf(token.getValue(Byte.class) != 0)); - } - - private static Map.Entry toByteEntry(final String name, final RntbdToken token) { - return new Entry(name, Byte.toString(token.getValue(Byte.class))); - } - - private static Map.Entry toCurrencyEntry(final String name, final RntbdToken token) { - final BigDecimal value = new BigDecimal(Math.round(token.getValue(Double.class) * 100D)).scaleByPowerOfTen(-2); - return new Entry(name, value.toString()); - } - - private static Map.Entry toIntegerEntry(final String name, final RntbdToken token) { - return new Entry(name, Long.toString(token.getValue(Long.class))); - } - - private static Map.Entry toLongEntry(final String name, final RntbdToken token) { - return new Entry(name, Long.toString(token.getValue(Long.class))); - } - - private Map.Entry toSessionTokenEntry(final String name, final RntbdToken token) { - return new Entry(name, this.partitionKeyRangeId.getValue(String.class) + ":" + this.sessionToken.getValue(String.class)); - } - - private static Map.Entry toStringEntry(final String name, final RntbdToken token) { - return new Entry(name, token.getValue(String.class)); - } - - private static final class Entry extends AbstractMap.SimpleImmutableEntry { - Entry(final String name, final String value) { - super(name, value); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseStatus.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseStatus.java deleted file mode 100644 index f5473084f4a0..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdResponseStatus.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectWriter; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.CorruptedFrameException; -import io.netty.handler.codec.http.HttpResponseStatus; - -import java.util.UUID; - -@JsonPropertyOrder({ "length", "status", "activityId" }) -final class RntbdResponseStatus { - - // region Fields - - static final int LENGTH = Integer.BYTES // length - + Integer.BYTES // status - + 2 * Long.BYTES; // activityId - - @JsonProperty("activityId") - private final UUID activityId; - - @JsonProperty("length") - private final int length; - - private final HttpResponseStatus status; - - // endregion - - RntbdResponseStatus(final int length, final HttpResponseStatus status, final UUID activityId) { - this.length = length; - this.status = status; - this.activityId = activityId; - } - - public UUID getActivityId() { - return this.activityId; - } - - int getHeadersLength() { - return this.length - LENGTH; - } - - public int getLength() { - return this.length; - } - - public HttpResponseStatus getStatus() { - return this.status; - } - - @JsonProperty("status") - public int getStatusCode() { - return this.status.code(); - } - - static RntbdResponseStatus decode(final ByteBuf in) { - - final long length = in.readUnsignedIntLE(); - - if (!(LENGTH <= length && length <= Integer.MAX_VALUE)) { - final String reason = String.format("frame length: %d", length); - throw new CorruptedFrameException(reason); - } - - final int code = in.readIntLE(); - final HttpResponseStatus status = HttpResponseStatus.valueOf(code); - - if (status == null) { - final String reason = String.format("status code: %d", code); - throw new CorruptedFrameException(reason); - } - - final UUID activityId = RntbdUUID.decode(in); - return new RntbdResponseStatus((int)length, status, activityId); - } - - void encode(final ByteBuf out) { - out.writeIntLE(this.getLength()); - out.writeIntLE(this.getStatusCode()); - RntbdUUID.encode(this.getActivityId(), out); - } - - @Override - public String toString() { - final ObjectWriter writer = RntbdObjectMapper.writer(); - try { - return writer.writeValueAsString(this); - } catch (final JsonProcessingException error) { - throw new CorruptedFrameException(error); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdServiceEndpoint.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdServiceEndpoint.java deleted file mode 100644 index 8c89a207f762..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdServiceEndpoint.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; -import com.google.common.collect.ImmutableMap; -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GoneException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.RntbdTransportClient.Options; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import io.netty.bootstrap.Bootstrap; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelOption; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.ssl.SslContext; -import io.netty.util.concurrent.DefaultThreadFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.SocketAddress; -import java.net.URI; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Stream; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Preconditions.checkState; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdReporter.reportIssue; - -@JsonSerialize(using = RntbdServiceEndpoint.JsonSerializer.class) -public final class RntbdServiceEndpoint implements RntbdEndpoint { - - private static final AtomicLong instanceCount = new AtomicLong(); - private static final Logger logger = LoggerFactory.getLogger(RntbdServiceEndpoint.class); - private static final String namePrefix = RntbdServiceEndpoint.class.getSimpleName() + '-'; - - private final RntbdClientChannelPool channelPool; - private final AtomicBoolean closed; - private final RntbdMetrics metrics; - private final String name; - private final SocketAddress remoteAddress; - private final RntbdRequestTimer requestTimer; - - // region Constructors - - private RntbdServiceEndpoint( - final Config config, final NioEventLoopGroup group, final RntbdRequestTimer timer, final URI physicalAddress - ) { - - final Bootstrap bootstrap = new Bootstrap() - .channel(NioSocketChannel.class) - .group(group) - .option(ChannelOption.AUTO_READ, true) - .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeout()) - .option(ChannelOption.SO_KEEPALIVE, true) - .remoteAddress(physicalAddress.getHost(), physicalAddress.getPort()); - - this.name = RntbdServiceEndpoint.namePrefix + instanceCount.incrementAndGet(); - this.channelPool = new RntbdClientChannelPool(bootstrap, config); - this.remoteAddress = bootstrap.config().remoteAddress(); - this.metrics = new RntbdMetrics(this.name); - this.closed = new AtomicBoolean(); - this.requestTimer = timer; - } - - // endregion - - // region Accessors - - @Override - public String getName() { - return this.name; - } - - // endregion - - // region Methods - - @Override - public void close() { - if (this.closed.compareAndSet(false, true)) { - this.channelPool.close(); - this.metrics.close(); - } - } - - public CompletableFuture request(final RntbdRequestArgs args) { - - this.throwIfClosed(); - - if (logger.isDebugEnabled()) { - args.traceOperation(logger, null, "request"); - logger.debug("\n {}\n {}\n REQUEST", this, args); - } - - final RntbdRequestRecord requestRecord = this.write(args); - this.metrics.incrementRequestCount(); - - return requestRecord.whenComplete((response, error) -> { - - args.traceOperation(logger, null, "requestComplete", response, error); - this.metrics.incrementResponseCount(); - - if (error != null) { - this.metrics.incrementErrorResponseCount(); - } - - if (logger.isDebugEnabled()) { - if (error == null) { - final int status = response.getStatus(); - logger.debug("\n [{}]\n {}\n request succeeded with response status: {}", this, args, status); - } else { - logger.debug("\n [{}]\n {}\n request failed due to ", this, args, error); - } - } - }); - } - - @Override - public String toString() { - return RntbdObjectMapper.toJson(this); - } - - // endregion - - // region Privates - - private void releaseToPool(final Channel channel) { - - logger.debug("\n [{}]\n {}\n RELEASE", this, channel); - - this.channelPool.release(channel).addListener(future -> { - if (logger.isDebugEnabled()) { - if (future.isSuccess()) { - logger.debug("\n [{}]\n {}\n release succeeded", this, channel); - } else { - logger.debug("\n [{}]\n {}\n release failed due to {}", this, channel, future.cause()); - } - } - }); - } - - private void throwIfClosed() { - checkState(!this.closed.get(), "%s is closed", this); - } - - private RntbdRequestRecord write(final RntbdRequestArgs requestArgs) { - - final RntbdRequestRecord requestRecord = new RntbdRequestRecord(requestArgs, this.requestTimer); - logger.debug("\n [{}]\n {}\n WRITE", this, requestArgs); - - this.channelPool.acquire().addListener(connected -> { - - if (connected.isSuccess()) { - - requestArgs.traceOperation(logger, null, "write"); - final Channel channel = (Channel)connected.get(); - this.releaseToPool(channel); - - channel.write(requestRecord).addListener((ChannelFuture future) -> { - requestArgs.traceOperation(logger, null, "writeComplete", channel); - if (!future.isSuccess()) { - this.metrics.incrementErrorResponseCount(); - } - }); - - return; - } - - final UUID activityId = requestArgs.getActivityId(); - final Throwable cause = connected.cause(); - - if (connected.isCancelled()) { - - logger.debug("\n [{}]\n {}\n write cancelled: {}", this, requestArgs, cause); - requestRecord.cancel(true); - - } else { - - logger.debug("\n [{}]\n {}\n write failed due to {} ", this, requestArgs, cause); - final String reason = cause.getMessage(); - - final GoneException goneException = new GoneException( - String.format("failed to establish connection to %s: %s", this.remoteAddress, reason), - cause instanceof Exception ? (Exception)cause : new IOException(reason, cause), - ImmutableMap.of(HttpConstants.HttpHeaders.ACTIVITY_ID, activityId.toString()), - requestArgs.getReplicaPath() - ); - - BridgeInternal.setRequestHeaders(goneException, requestArgs.getServiceRequest().getHeaders()); - requestRecord.completeExceptionally(goneException); - } - }); - - return requestRecord; - } - - // endregion - - // region Types - - static final class JsonSerializer extends StdSerializer { - - public JsonSerializer() { - this(null); - } - - public JsonSerializer(Class type) { - super(type); - } - - @Override - public void serialize(RntbdServiceEndpoint value, JsonGenerator generator, SerializerProvider provider) - throws IOException { - - generator.writeStartObject(); - generator.writeStringField(value.name, value.remoteAddress.toString()); - generator.writeObjectField("channelPool", value.channelPool); - generator.writeEndObject(); - } - } - - public static final class Provider implements RntbdEndpoint.Provider { - - private static final Logger logger = LoggerFactory.getLogger(Provider.class); - - private final AtomicBoolean closed = new AtomicBoolean(); - private final Config config; - private final ConcurrentHashMap endpoints = new ConcurrentHashMap<>(); - private final NioEventLoopGroup eventLoopGroup; - private final RntbdRequestTimer requestTimer; - - public Provider(final Options options, final SslContext sslContext) { - - checkNotNull(options, "options"); - checkNotNull(sslContext, "sslContext"); - - final DefaultThreadFactory threadFactory = new DefaultThreadFactory("CosmosEventLoop", true); - final int threadCount = Runtime.getRuntime().availableProcessors(); - final LogLevel wireLogLevel; - - if (logger.isTraceEnabled()) { - wireLogLevel = LogLevel.TRACE; - } else if (logger.isDebugEnabled()) { - wireLogLevel = LogLevel.DEBUG; - } else { - wireLogLevel = null; - } - - this.config = new Config(options, sslContext, wireLogLevel); - this.requestTimer = new RntbdRequestTimer(config.getRequestTimeout()); - this.eventLoopGroup = new NioEventLoopGroup(threadCount, threadFactory); - } - - @Override - public void close() throws RuntimeException { - - if (this.closed.compareAndSet(false, true)) { - - this.requestTimer.close(); - - for (final RntbdEndpoint endpoint : this.endpoints.values()) { - endpoint.close(); - } - - this.eventLoopGroup.shutdownGracefully().addListener(future -> { - if (future.isSuccess()) { - logger.debug("\n [{}]\n closed endpoints", this); - return; - } - logger.error("\n [{}]\n failed to close endpoints due to ", this, future.cause()); - }); - return; - } - - logger.debug("\n [{}]\n already closed", this); - } - - @Override - public Config config() { - return this.config; - } - - @Override - public int count() { - return this.endpoints.size(); - } - - @Override - public RntbdEndpoint get(URI physicalAddress) { - return endpoints.computeIfAbsent(physicalAddress.getAuthority(), authority -> - new RntbdServiceEndpoint(config, eventLoopGroup, requestTimer, physicalAddress) - ); - } - - @Override - public Stream list() { - return this.endpoints.values().stream(); - } - - private void deleteEndpoint(final URI physicalAddress) { - - // TODO: DANOBLE: Utilize this method of tearing down unhealthy endpoints - // Specifically, ensure that this method is called when a Read/WriteTimeoutException occurs or a health - // check request fails. This perhaps likely requires a change to RntbdClientChannelPool. - // Links: - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/331552 - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/331593 - - checkNotNull(physicalAddress, "physicalAddress: %s", physicalAddress); - - final String authority = physicalAddress.getAuthority(); - final RntbdEndpoint endpoint = this.endpoints.remove(authority); - - if (endpoint != null) { - endpoint.close(); - } - } - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdToken.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdToken.java deleted file mode 100644 index 555d0338a413..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdToken.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.ser.PropertyWriter; -import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.CorruptedFrameException; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdHeader; - -@JsonPropertyOrder({ "id", "name", "type", "present", "required", "value" }) -final class RntbdToken { - - // region Fields - - private static final int HEADER_LENGTH = Short.BYTES + Byte.BYTES; - - static { - RntbdObjectMapper.registerPropertyFilter(RntbdToken.class, RntbdToken.PropertyFilter.class); - } - - private final RntbdHeader header; - private int length; - private Object value; - - // endregion - - private RntbdToken(final RntbdHeader header) { - checkNotNull(header, "header"); - this.header = header; - this.value = null; - this.length = Integer.MIN_VALUE; - } - - @JsonProperty - final short getId() { - return this.header.id(); - } - - // region Accessors - - @JsonProperty - final String getName() { - return this.header.name(); - } - - @JsonProperty - final RntbdTokenType getType() { - return this.header.type(); - } - - @JsonProperty - final Object getValue() { - - if (this.value == null) { - return this.header.type().codec().defaultValue(); - } - - if (this.value instanceof ByteBuf) { - final ByteBuf buffer = (ByteBuf)this.value; - this.value = this.header.type().codec().read(buffer); - buffer.release(); - } else { - this.value = this.header.type().codec().convert(this.value); - } - - return this.value; - } - - @JsonProperty - final void setValue(final Object value) { - this.ensureValid(value); - this.length = Integer.MIN_VALUE; - this.value = value; - } - - @JsonProperty - final boolean isPresent() { - return this.value != null; - } - - @JsonProperty - final boolean isRequired() { - return this.header.isRequired(); - } - - final int computeLength() { - - if (!this.isPresent()) { - return 0; - } - - if (this.value instanceof ByteBuf) { - final ByteBuf buffer = (ByteBuf)this.value; - assert buffer.readerIndex() == 0; - return HEADER_LENGTH + buffer.readableBytes(); - } - - if (this.length == Integer.MIN_VALUE) { - this.length = HEADER_LENGTH + this.header.type().codec().computeLength(this.value); - } - - return this.length; - } - - // endregion - - // region Methods - - static RntbdToken create(final RntbdHeader header) { - return new RntbdToken(header); - } - - void decode(final ByteBuf in) { - - checkNotNull(in, "in"); - - if (this.value instanceof ByteBuf) { - ((ByteBuf)this.value).release(); - } - - this.value = this.header.type().codec().readSlice(in).retain(); // No data transfer until the first call to RntbdToken.getValue - } - - final void encode(final ByteBuf out) { - - checkNotNull(out, "out"); - - if (!this.isPresent()) { - if (this.isRequired()) { - final String message = String.format("Missing value for required header: %s", this); - throw new IllegalStateException(message); - } - return; - } - - out.writeShortLE(this.getId()); - out.writeByte(this.getType().id()); - - if (this.value instanceof ByteBuf) { - out.writeBytes((ByteBuf)this.value); - } else { - this.ensureValid(this.value); - this.header.type().codec().write(this.value, out); - } - } - - final T getValue(final Class cls) { - return cls.cast(this.getValue()); - } - - final void releaseBuffer() { - if (this.value instanceof ByteBuf) { - final ByteBuf buffer = (ByteBuf)this.value; - buffer.release(); - } - } - - @Override - public String toString() { - final ObjectWriter writer = RntbdObjectMapper.writer(); - try { - return writer.writeValueAsString(this); - } catch (final JsonProcessingException error) { - throw new CorruptedFrameException(error); - } - } - - private void ensureValid(final Object value) { - - checkNotNull(value, "value"); - - if (!this.header.type().codec().isValid(value)) { - final String reason = String.format("value: %s", value.getClass()); - throw new IllegalArgumentException(reason); - } - } - - // endregion - - // region Types - - static class PropertyFilter extends SimpleBeanPropertyFilter { - - @Override - public void serializeAsField(final Object object, final JsonGenerator generator, final SerializerProvider provider, final PropertyWriter writer) throws Exception { - - if (generator.canOmitFields()) { - - final Object value = writer.getMember().getValue(object); - - if (value instanceof RntbdToken && !((RntbdToken)value).isPresent()) { - return; - } - } - - writer.serializeAsField(object, generator, provider); - } - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdTokenStream.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdTokenStream.java deleted file mode 100644 index 6926876ebf54..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdTokenStream.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import io.netty.buffer.ByteBuf; - -import java.util.stream.Collector; - -import static com.google.common.base.Preconditions.checkNotNull; -import static com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdConstants.RntbdHeader; - -abstract class RntbdTokenStream & RntbdHeader> { - - final ImmutableMap headers; - final ImmutableMap tokens; - - RntbdTokenStream(final ImmutableSet headers, final ImmutableMap ids) { - - checkNotNull(headers, "headers"); - checkNotNull(ids, "ids"); - - final Collector> collector = Maps.toImmutableEnumMap(h -> h, RntbdToken::create); - this.tokens = headers.stream().collect(collector); - this.headers = ids; - } - - final int computeCount() { - - int count = 0; - - for (final RntbdToken token : this.tokens.values()) { - if (token.isPresent()) { - ++count; - } - } - - return count; - } - - final int computeLength() { - - int total = 0; - - for (final RntbdToken token : this.tokens.values()) { - total += token.computeLength(); - } - - return total; - } - - static > T decode(final ByteBuf in, final T stream) { - - while (in.readableBytes() > 0) { - - final short id = in.readShortLE(); - final RntbdTokenType type = RntbdTokenType.fromId(in.readByte()); - - RntbdToken token = stream.tokens.get(stream.headers.get(id)); - - if (token == null) { - token = RntbdToken.create(new UndefinedHeader(id, type)); - } - - token.decode(in); - } - - for (final RntbdToken token : stream.tokens.values()) { - if (!token.isPresent() && token.isRequired()) { - final String reason = String.format("Required token not found on RNTBD stream: type: %s, identifier: %s", - token.getType(), token.getId()); - throw new IllegalStateException(reason); - } - } - - return stream; - } - - final void encode(final ByteBuf out) { - for (final RntbdToken token : this.tokens.values()) { - token.encode(out); - } - } - - final RntbdToken get(final T header) { - return this.tokens.get(header); - } - - final void releaseBuffers() { - for (final RntbdToken token : this.tokens.values()) { - token.releaseBuffer(); - } - } - - private static final class UndefinedHeader implements RntbdHeader { - - private final short id; - private final RntbdTokenType type; - - UndefinedHeader(final short id, final RntbdTokenType type) { - this.id = id; - this.type = type; - } - - @Override - public boolean isRequired() { - return false; - } - - @Override - public short id() { - return this.id; - } - - @Override - public String name() { - return "Undefined"; - } - - @Override - public RntbdTokenType type() { - return this.type; - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdTokenType.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdTokenType.java deleted file mode 100644 index c6b76693087c..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdTokenType.java +++ /dev/null @@ -1,838 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import com.google.common.base.Utf8; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufUtil; -import io.netty.handler.codec.CorruptedFrameException; - -import java.nio.charset.StandardCharsets; -import java.util.UUID; - -enum RntbdTokenType { - - // All values are encoded as little endian byte sequences except for Guid - // Guid values are serialized in Microsoft GUID byte order - // Reference: GUID structure and System.Guid type - - Byte((byte)0x00, RntbdByte.codec), // byte => byte - UShort((byte)0x01, RntbdUnsignedShort.codec), // short => int - ULong((byte)0x02, RntbdUnsignedInteger.codec), // int => long - Long((byte)0x03, RntbdInteger.codec), // int => int - ULongLong((byte)0x04, RntbdLong.codec), // long => long - LongLong((byte)0x05, RntbdLong.codec), // long => long - - Guid((byte)0x06, RntbdGuid.codec), // byte[16] => UUID - SmallString((byte)0x07, RntbdShortString.codec), // (byte, byte[0..255]) => String - String((byte)0x08, RntbdString.codec), // (short, byte[0..64KiB]) => String - ULongString((byte)0x09, RntbdLongString.codec), // (int, byte[0..2GiB-1]) => String - - SmallBytes((byte)0x0A, RntbdShortBytes.codec), // (byte, byte[0..255]) => byte[] - Bytes((byte)0x0B, RntbdBytes.codec), // (short, byte[0..64KiB]) => byte[] - ULongBytes((byte)0x0C, RntbdLongBytes.codec), // (int, byte[0..2GiB-1]) => byte[] - - Float((byte)0x0D, RntbdFloat.codec), // float => float - Double((byte)0x0E, RntbdDouble.codec), // double => double - - Invalid((byte)0xFF, RntbdNone.codec); // no data - - // region Implementation - - private Codec codec; - private byte id; - - RntbdTokenType(final byte id, final Codec codec) { - this.codec = codec; - this.id = id; - } - - public Codec codec() { - return this.codec; - } - - public static RntbdTokenType fromId(final byte value) { - - for (final RntbdTokenType tokenType : RntbdTokenType.values()) { - if (value == tokenType.id) { - return tokenType; - } - } - return Invalid; - } - - public byte id() { - return this.id; - } - - // endregion - - // region Types - - public interface Codec { - - int computeLength(Object value); - - Object convert(Object value); - - Object defaultValue(); - - boolean isValid(Object value); - - Object read(ByteBuf in); - - ByteBuf readSlice(ByteBuf in); - - void write(Object value, ByteBuf out); - } - - private static class RntbdByte implements Codec { - - public static final Codec codec = new RntbdByte(); - - private RntbdByte() { - } - - @Override - public final int computeLength(final Object value) { - return java.lang.Byte.BYTES; - } - - @Override - public final Object convert(final Object value) { - - assert this.isValid(value); - - if (value instanceof Number) { - return ((Number)value).byteValue(); - } - return (boolean)value ? (byte)0x01 : (byte)0x00; - } - - @Override - public final Object defaultValue() { - return (byte)0; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof Number || value instanceof Boolean; - } - - @Override - public final Object read(final ByteBuf in) { - return in.readByte(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(java.lang.Byte.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - out.writeByte(value instanceof Byte ? (byte)value : ((boolean)value ? 0x01 : 0x00)); - } - } - - private static class RntbdBytes implements Codec { - - public static final Codec codec = new RntbdBytes(); - private static final byte[] defaultValue = {}; - - private RntbdBytes() { - } - - @Override - public int computeLength(final Object value) { - assert this.isValid(value); - return Short.BYTES + ((byte[])value).length; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return value; - } - - @Override - public final Object defaultValue() { - return defaultValue; - } - - @Override - public boolean isValid(final Object value) { - return value instanceof byte[] && ((byte[])value).length < 0xFFFF; - } - - @Override - public Object read(final ByteBuf in) { - final int length = in.readUnsignedShortLE(); - return in.readBytes(length); - } - - @Override - public ByteBuf readSlice(final ByteBuf in) { - final int length = in.getUnsignedShortLE(in.readerIndex()); - return in.readSlice(Short.BYTES + length); - } - - @Override - public void write(final Object value, final ByteBuf out) { - - assert this.isValid(value); - - final byte[] bytes = (byte[])value; - final int length = bytes.length; - - if (length > 0xFFFF) { - throw new IllegalStateException(); - } - - out.writeShortLE((short)length); - out.writeBytes(bytes); - } - } - - private static class RntbdDouble implements Codec { - - public static final Codec codec = new RntbdDouble(); - - private RntbdDouble() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return java.lang.Double.BYTES; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return ((Number)value).doubleValue(); - } - - @Override - public final Object defaultValue() { - return 0.0D; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof Number; - } - - @Override - public final Object read(final ByteBuf in) { - return in.readDoubleLE(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(java.lang.Double.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - out.writeDoubleLE(((Number)value).doubleValue()); - } - } - - private static class RntbdFloat implements Codec { - - public static final Codec codec = new RntbdFloat(); - - private RntbdFloat() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return java.lang.Float.BYTES; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return ((Number)value).floatValue(); - } - - @Override - public final Object defaultValue() { - return 0.0F; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof Number; - } - - @Override - public final Object read(final ByteBuf in) { - return in.readFloatLE(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(java.lang.Float.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - out.writeFloatLE(((Number)value).floatValue()); - } - } - - private static class RntbdGuid implements Codec { - - public static final Codec codec = new RntbdGuid(); - - private RntbdGuid() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return 2 * java.lang.Long.BYTES; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return value; - } - - @Override - public final Object defaultValue() { - return RntbdUUID.EMPTY; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof UUID; - } - - @Override - public final Object read(final ByteBuf in) { - return RntbdUUID.decode(in); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(2 * java.lang.Long.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - RntbdUUID.encode((UUID)value, out); - } - } - - private static class RntbdInteger implements Codec { - - public static final Codec codec = new RntbdInteger(); - - private RntbdInteger() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return Integer.BYTES; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return ((Number)value).intValue(); - } - - @Override - public final Object defaultValue() { - return 0; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof Number; - } - - @Override - public final Object read(final ByteBuf in) { - return in.readIntLE(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(Integer.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - out.writeIntLE(((Number)value).intValue()); - } - } - - private static class RntbdLong implements Codec { - - public static final Codec codec = new RntbdLong(); - - private RntbdLong() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return java.lang.Long.BYTES; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return ((Number)value).longValue(); - } - - @Override - public final Object defaultValue() { - return 0L; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof Number; - } - - @Override - public final Object read(final ByteBuf in) { - return in.readLongLE(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(java.lang.Long.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - out.writeLongLE(((Number)value).longValue()); - } - } - - private static class RntbdLongBytes extends RntbdBytes { - - public static final Codec codec = new RntbdLongBytes(); - - private RntbdLongBytes() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return Integer.BYTES + ((byte[])value).length; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof byte[] && ((byte[])value).length < 0xFFFF; - } - - @Override - public final Object read(final ByteBuf in) { - - final long length = in.readUnsignedIntLE(); - - if (length > Integer.MAX_VALUE) { - throw new IllegalStateException(); - } - return in.readBytes((int)length); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - - final long length = in.getUnsignedIntLE(in.readerIndex()); - - if (length > Integer.MAX_VALUE) { - throw new IllegalStateException(); - } - return in.readSlice(Integer.BYTES + (int)length); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - - assert this.isValid(value); - - final byte[] bytes = (byte[])value; - out.writeIntLE(bytes.length); - out.writeBytes(bytes); - } - } - - private static class RntbdLongString extends RntbdString { - - public static final Codec codec = new RntbdLongString(); - - private RntbdLongString() { - } - - @Override - public final int computeLength(final Object value) { - return Integer.BYTES + this.computeLength(value, Integer.MAX_VALUE); - } - - @Override - public final Object read(final ByteBuf in) { - - final long length = in.readUnsignedIntLE(); - - if (length > Integer.MAX_VALUE) { - throw new IllegalStateException(); - } - - return in.readCharSequence((int)length, StandardCharsets.UTF_8).toString(); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - - final int length = this.computeLength(value, Integer.MAX_VALUE); - out.writeIntLE(length); - writeValue(out, value, length); - } - } - - private static class RntbdNone implements Codec { - - public static final Codec codec = new RntbdNone(); - - @Override - public final int computeLength(final Object value) { - return 0; - } - - @Override - public final Object convert(final Object value) { - return null; - } - - @Override - public final Object defaultValue() { - return null; - } - - @Override - public final boolean isValid(final Object value) { - return true; - } - - @Override - public final Object read(final ByteBuf in) { - return null; - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return null; - } - - @Override - public final void write(final Object value, final ByteBuf out) { - } - } - - private static class RntbdShortBytes extends RntbdBytes { - - public static final Codec codec = new RntbdShortBytes(); - - private RntbdShortBytes() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return java.lang.Byte.BYTES + ((byte[])value).length; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof byte[] && ((byte[])value).length < 0xFFFF; - } - - @Override - public final Object read(final ByteBuf in) { - - final int length = in.readUnsignedByte(); - final byte[] bytes = new byte[length]; - in.readBytes(bytes); - - return bytes; - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(java.lang.Byte.BYTES + in.getUnsignedByte(in.readerIndex())); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - - assert this.isValid(value); - - final byte[] bytes = (byte[])value; - final int length = bytes.length; - - if (length > 0xFF) { - throw new IllegalStateException(); - } - - out.writeByte((byte)length); - out.writeBytes(bytes); - } - } - - private static class RntbdShortString extends RntbdString { - - public static final Codec codec = new RntbdShortString(); - - private RntbdShortString() { - } - - @Override - public final int computeLength(final Object value) { - return java.lang.Byte.BYTES + this.computeLength(value, 0xFF); - } - - @Override - public final Object read(final ByteBuf in) { - return in.readCharSequence(in.readUnsignedByte(), StandardCharsets.UTF_8).toString(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(java.lang.Byte.BYTES + in.getUnsignedByte(in.readerIndex())); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - - final int length = this.computeLength(value, 0xFF); - out.writeByte(length); - writeValue(out, value, length); - } - } - - private static class RntbdString implements Codec { - - public static final Codec codec = new RntbdString(); - - private RntbdString() { - } - - final int computeLength(final Object value, final int maxLength) { - - assert this.isValid(value); - final int length; - - if (value instanceof String) { - - final String string = (String)value; - length = Utf8.encodedLength(string); - - } else { - - final byte[] string = (byte[])value; - - if (!Utf8.isWellFormed(string)) { - final String reason = java.lang.String.format("UTF-8 byte string is ill-formed: %s", ByteBufUtil.hexDump(string)); - throw new CorruptedFrameException(reason); - } - - length = string.length; - } - - if (length > maxLength) { - final String reason = java.lang.String.format("UTF-8 byte string exceeds %d bytes: %d bytes", maxLength, length); - throw new CorruptedFrameException(reason); - } - - return length; - } - - @Override - public int computeLength(final Object value) { - return Short.BYTES + this.computeLength(value, 0xFFFF); - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return value instanceof String ? value : new String((byte[])value, StandardCharsets.UTF_8); - } - - @Override - public final Object defaultValue() { - return ""; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof String || value instanceof byte[]; - } - - @Override - public Object read(final ByteBuf in) { - final int length = in.readUnsignedShortLE(); - return in.readCharSequence(length, StandardCharsets.UTF_8).toString(); - } - - @Override - public ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(Short.BYTES + in.getUnsignedShortLE(in.readerIndex())); - } - - @Override - public void write(final Object value, final ByteBuf out) { - - final int length = this.computeLength(value, 0xFFFF); - out.writeShortLE(length); - writeValue(out, value, length); - } - - static void writeValue(final ByteBuf out, final Object value, final int length) { - - final int start = out.writerIndex(); - - if (value instanceof String) { - out.writeCharSequence((String)value, StandardCharsets.UTF_8); - } else { - out.writeBytes((byte[])value); - } - - assert out.writerIndex() - start == length; - } - } - - private static class RntbdUnsignedInteger implements Codec { - - public static final Codec codec = new RntbdUnsignedInteger(); - - private RntbdUnsignedInteger() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return Integer.BYTES; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return ((Number)value).longValue() & 0xFFFFFFFFL; - } - - @Override - public final Object defaultValue() { - return 0L; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof Number; - } - - @Override - public final Object read(final ByteBuf in) { - return in.readUnsignedIntLE(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(Integer.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - out.writeIntLE(((Number)value).intValue()); - } - } - - private static class RntbdUnsignedShort implements Codec { - - public static final Codec codec = new RntbdUnsignedShort(); - - private RntbdUnsignedShort() { - } - - @Override - public final int computeLength(final Object value) { - assert this.isValid(value); - return Short.BYTES; - } - - @Override - public final Object convert(final Object value) { - assert this.isValid(value); - return ((Number)value).intValue() & 0xFFFF; - } - - @Override - public final Object defaultValue() { - return 0; - } - - @Override - public final boolean isValid(final Object value) { - return value instanceof Number; - } - - @Override - public final Object read(final ByteBuf in) { - return in.readUnsignedShortLE(); - } - - @Override - public final ByteBuf readSlice(final ByteBuf in) { - return in.readSlice(Short.BYTES); - } - - @Override - public final void write(final Object value, final ByteBuf out) { - assert this.isValid(value); - out.writeShortLE(((Number)value).shortValue()); - } - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdUUID.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdUUID.java deleted file mode 100644 index 20c9f1233528..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/rntbd/RntbdUUID.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.handler.codec.CorruptedFrameException; - -import java.util.UUID; - -import static com.google.common.base.Preconditions.checkNotNull; - -public final class RntbdUUID { - - public static final UUID EMPTY = new UUID(0L, 0L); - - private RntbdUUID() { - } - - /** - * Decode a {@link UUID} as serialized by Microsoft APIs like {@code System.Guid.ToByteArray} - * - * @param bytes a {@link byte} array containing the serialized {@link UUID} to be decoded - * @return a new {@link UUID} - */ - public static UUID decode(final byte[] bytes) { - return decode(Unpooled.wrappedBuffer(bytes)); - } - - /** - * Decode a {@link UUID} as serialized by Microsoft APIs like {@code System.Guid.ToByteArray} - * - * @param in a {@link ByteBuf} containing the serialized {@link UUID} to be decoded - * @return a new {@link UUID} - */ - public static UUID decode(final ByteBuf in) { - - checkNotNull(in, "in"); - - if (in.readableBytes() < 2 * Long.BYTES) { - final String reason = String.format("invalid frame length: %d", in.readableBytes()); - throw new CorruptedFrameException(reason); - } - - long mostSignificantBits = in.readUnsignedIntLE() << 32; - - mostSignificantBits |= (0x000000000000FFFFL & in.readShortLE()) << 16; - mostSignificantBits |= (0x000000000000FFFFL & in.readShortLE()); - - long leastSignificantBits = (0x000000000000FFFFL & in.readShortLE()) << (32 + 16); - - for (int shift = 32 + 8; shift >= 0; shift -= 8) { - leastSignificantBits |= (0x00000000000000FFL & in.readByte()) << shift; - } - - return new UUID(mostSignificantBits, leastSignificantBits); - } - - /** - * Encodes a {@link UUID} as serialized by Microsoft APIs like {@code System.Guid.ToByteArray} - * - * @param uuid a {@link UUID} to be encoded - * @return a new byte array containing the encoded - */ - public static byte[] encode(final UUID uuid) { - final byte[] bytes = new byte[2 * Integer.BYTES]; - encode(uuid, Unpooled.wrappedBuffer(bytes)); - return bytes; - } - - /** - * Encodes a {@link UUID} as serialized by Microsoft APIs like {@code System.Guid.ToByteArray} - * - * @param uuid a {@link UUID} to be encoded - * @param out an output {@link ByteBuf} - */ - public static void encode(final UUID uuid, final ByteBuf out) { - - final long mostSignificantBits = uuid.getMostSignificantBits(); - - out.writeIntLE((int)((mostSignificantBits & 0xFFFFFFFF00000000L) >>> 32)); - out.writeShortLE((short)((mostSignificantBits & 0x00000000FFFF0000L) >>> 16)); - out.writeShortLE((short)(mostSignificantBits & 0x000000000000FFFFL)); - - final long leastSignificantBits = uuid.getLeastSignificantBits(); - - out.writeShortLE((short)((leastSignificantBits & 0xFFFF000000000000L) >>> (32 + 16))); - out.writeShort((short)((leastSignificantBits & 0x0000FFFF00000000L) >>> 32)); - out.writeInt((int)(leastSignificantBits & 0x00000000FFFFFFFFL)); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/Int128.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/Int128.java deleted file mode 100644 index c74a4ff99a01..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/Int128.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - - -import java.math.BigInteger; - -public class Int128 { - - private final BigInteger value; - - private static final BigInteger MaxBigIntValue = - new BigInteger(new byte[] { - (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, - (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 - }); - - public static final Int128 MaxValue = new Int128( - new BigInteger(new byte[] { - (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - }) - ); - - private Int128(BigInteger value) { - this.value = value.remainder(MaxBigIntValue); - } - - public Int128(int n) { - this(BigInteger.valueOf(n)); - } - - public Int128(byte[] data) { - if (data.length != 16) { - throw new IllegalArgumentException("data"); - } - - this.value = new BigInteger(data); - - if (this.value.compareTo(MaxValue.value) > 0) { - throw new IllegalArgumentException(); - } - } - - public static Int128 multiply(Int128 left, Int128 right) { - return new Int128(left.value.multiply(right.value)); - } - - public static Int128 add(Int128 left, Int128 right) { - return new Int128(left.value.add(right.value)); - } - - public static Int128 subtract(Int128 left, Int128 right) { - return new Int128(left.value.subtract(right.value)); - } - - public static Int128 div (Int128 left, Int128 right) { - return new Int128(left.value.divide(right.value)); - } - - public static boolean gt(Int128 left, Int128 right) { - return left.value.compareTo(right.value) > 0; - } - - public static boolean lt(Int128 left, Int128 right) { - return left.value.compareTo(right.value) < 0; - } - - public byte[] bytes() { - byte[] bytes = this.value.toByteArray(); - if (bytes.length < 16) { - byte[] paddedBytes = new byte[16]; - System.arraycopy(bytes, 0, paddedBytes, 0, bytes.length); - return paddedBytes; - } - - return bytes; - } - -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MurmurHash3_128.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MurmurHash3_128.java deleted file mode 100644 index 06224c795a64..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MurmurHash3_128.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -public class MurmurHash3_128 { - - public static UInt128 hash128(byte[] bytes) { - return hash128(bytes, bytes.length, new UInt128(0, 0)); - } - - public static UInt128 hash128(byte[] bytes, int length, UInt128 seed) { - final long c1 = 0x87c37b91114253d5L; - final long c2 = 0x4cf5ad432745937fL; - - long h1 = seed.high; - long h2 = seed.low; - - // body - int position; - for (position = 0; position < length - 15; position += 16) { - long k1 = getLittleEndianLong(bytes, position); - long k2 = getLittleEndianLong(bytes, position + 8); - - // k1, h1 - k1 *= c1; - k1 = rotateLeft64(k1, 31); - k1 *= c2; - - h1 ^= k1; - h1 = rotateLeft64(h1, 27); - h1 += h2; - h1 = h1 * 5 + 0x52dce729; - - // k2, h2 - k2 *= c2; - k2 = rotateLeft64(k2, 33); - k2 *= c1; - - h2 ^= k2; - h2 = rotateLeft64(h2, 31); - h2 += h1; - h2 = h2 * 5 + 0x38495ab5; - } - - - { - // tail - long k1 = 0; - long k2 = 0; - - int n = length & 15; - if (n >= 15) k2 ^= (bytes[position + 14] & 0xffL) << 48; - if (n >= 14) k2 ^= (bytes[position + 13] & 0xffL) << 40; - if (n >= 13) k2 ^= (bytes[position + 12] & 0xffL) << 32; - if (n >= 12) k2 ^= (bytes[position + 11] & 0xffL) << 24; - if (n >= 11) k2 ^= (bytes[position + 10] & 0xffL) << 16; - if (n >= 10) k2 ^= (bytes[position + 9] & 0xffL) << 8; - if (n >= 9) k2 ^= (bytes[position + 8] & 0xffL) << 0; - - k2 *= c2; - k2 = rotateLeft64(k2, 33); - k2 *= c1; - h2 ^= k2; - - if (n >= 8) k1 ^= (bytes[position + 7] & 0xffL) << 56; - if (n >= 7) k1 ^= (bytes[position + 6] & 0xffL) << 48; - if (n >= 6) k1 ^= (bytes[position + 5] & 0xffL) << 40; - if (n >= 5) k1 ^= (bytes[position + 4] & 0xffL) << 32; - if (n >= 4) k1 ^= (bytes[position + 3] & 0xffL) << 24; - if (n >= 3) k1 ^= (bytes[position + 2] & 0xffL) << 16; - if (n >= 2) k1 ^= (bytes[position + 1] & 0xffL) << 8; - if (n >= 1) k1 ^= (bytes[position + 0] & 0xffL) << 0; - - k1 *= c1; - k1 = rotateLeft64(k1, 31); - k1 *= c2; - h1 ^= k1; - } - - // finalization - h1 ^= length; - h2 ^= length; - - h1 += h2; - h2 += h1; - - // h1 - h1 ^= h1 >>> 33; - h1 *= 0xff51afd7ed558ccdL; - h1 ^= h1 >>> 33; - h1 *= 0xc4ceb9fe1a85ec53L; - h1 ^= h1 >>> 33; - - // h2 - h2 ^= h2 >>> 33; - h2 *= 0xff51afd7ed558ccdL; - h2 ^= h2 >>> 33; - h2 *= 0xc4ceb9fe1a85ec53L; - h2 ^= h2 >>> 33; - - h1 += h2; - h2 += h1; - - h1 = Long.reverseBytes(h1); - h2 = Long.reverseBytes(h2); - - return new UInt128(h1, h2); - } - - - private static int rotateLeft32(int n, int numBits) { - assert numBits < 32; - return Integer.rotateLeft(n, numBits); - } - - private static long rotateLeft64(long n, int numBits) { - assert numBits < 64; - return Long.rotateLeft(n, numBits); - } - - private static final long getLittleEndianLong(byte[] bytes, int offset) { - return ((long) bytes[offset + 7] << 56) // no mask needed - | ((bytes[offset + 6] & 0xffL) << 48) - | ((bytes[offset + 5] & 0xffL) << 40) - | ((bytes[offset + 4] & 0xffL) << 32) - | ((bytes[offset + 3] & 0xffL) << 24) - | ((bytes[offset + 2] & 0xffL) << 16) - | ((bytes[offset + 1] & 0xffL) << 8) - | ((bytes[offset] & 0xffL)); - } - - private static int intAsLittleIndian(byte[] bytes, int i) { - return (bytes[i] & 0xff) | ((bytes[i + 1] & 0xff) << 8) | ((bytes[i + 2] & 0xff) << 16) | (bytes[i + 3] << 24); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MurmurHash3_32.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MurmurHash3_32.java deleted file mode 100644 index e92cb2e41187..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/MurmurHash3_32.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -/* - * The MurmurHash3 algorithm was created by Austin Appleby and placed in the public domain. - * This java port was authored by Yonik Seeley and also placed into the public domain. - * The author hereby disclaims copyright to this source code. - *

- * This produces exactly the same hash values as the final C++ - * version of MurmurHash3 and is thus suitable for producing the same hash values across - * platforms. - *

- * The 32 bit x86 version of this hash should be the fastest variant for relatively short keys like ids. - * See http://github.com/yonik/java_util for future updates to this file. - */ -public class MurmurHash3_32 { - /** - * Returns the MurmurHash3_x86_32 hash. - * - * @param data a byte array containing the data to be hashed - * @param len an integer indicating the length of data - * @param seed an integer to be used as hash seed - * @return the hash value - */ - public static int hash(byte[] data, int len, int seed) { - final int c1 = 0xcc9e2d51; - final int c2 = 0x1b873593; - - int h1 = seed; - int roundedEnd = (len & 0xfffffffc); // round down to 4 byte block - - for (int i = 0; i < roundedEnd; i += 4) { - // little endian load order - int k1 = (data[i] & 0xff) | ((data[i + 1] & 0xff) << 8) | ((data[i + 2] & 0xff) << 16) | (data[i + 3] << 24); - k1 *= c1; - k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); - k1 *= c2; - - h1 ^= k1; - h1 = (h1 << 13) | (h1 >>> 19); // ROTL32(h1,13); - h1 = h1 * 5 + 0xe6546b64; - } - - // tail - int k1 = 0; - - switch (len & 0x03) { - case 3: - k1 = (data[roundedEnd + 2] & 0xff) << 16; - // fallthrough - case 2: - k1 |= (data[roundedEnd + 1] & 0xff) << 8; - // fallthrough - case 1: - k1 |= (data[roundedEnd] & 0xff); - k1 *= c1; - k1 = (k1 << 15) | (k1 >>> 17); // ROTL32(k1,15); - k1 *= c2; - h1 ^= k1; - } - - // finalization - h1 ^= len; - - // fmix(h1); - h1 ^= h1 >>> 16; - h1 *= 0x85ebca6b; - h1 ^= h1 >>> 13; - h1 *= 0xc2b2ae35; - h1 ^= h1 >>> 16; - - return h1; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternalHelper.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternalHelper.java deleted file mode 100644 index 316f6e87dc35..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternalHelper.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import com.microsoft.azure.cosmosdb.CommonsBridgeInternal; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.PartitionKind; -import com.microsoft.azure.cosmosdb.internal.Bytes; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.List; - -public class PartitionKeyInternalHelper { - - public static final String MinimumInclusiveEffectivePartitionKey = PartitionKeyInternalHelper.toHexEncodedBinaryString(PartitionKeyInternal.EmptyPartitionKey.components); - public static final String MaximumExclusiveEffectivePartitionKey = PartitionKeyInternalHelper.toHexEncodedBinaryString(PartitionKeyInternal.InfinityPartitionKey.components); - - static final int MaxPartitionKeyBinarySize = - (1 /*type marker */ + - 9 /* hash value*/ + - 1 /* type marker*/ + StringPartitionKeyComponent.MAX_STRING_BYTES_TO_APPEND + - 1 /*trailing zero*/ - ) * 3; - private static final Int128 MaxHashV2Value = new Int128(new byte[] { - (byte) 0x3F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, - (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}); - - static byte[] uIntToBytes(UInt128 unit) { - ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES * 2); - buffer.putLong(unit.low); - buffer.putLong(unit.high); - return buffer.array(); - } - - static long asUnsignedLong(int x) { - return x & 0x00000000ffffffffL; - } - - static byte[] longToBytes(long x) { - ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); - buffer.putLong(x); - return buffer.array(); - } - - static String toHexEncodedBinaryString(IPartitionKeyComponent... components) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(MaxPartitionKeyBinarySize); - for (IPartitionKeyComponent component: components) { - component.WriteForBinaryEncoding(stream); - } - - return HexConvert.bytesToHex(stream.toByteArray()); - } - - static String toHexEncodedBinaryString(List components) { - ByteArrayOutputStream stream = new ByteArrayOutputStream(MaxPartitionKeyBinarySize); - for (IPartitionKeyComponent component: components) { - component.WriteForBinaryEncoding(stream); - } - - return HexConvert.bytesToHex(stream.toByteArray()); - } - - static public String getEffectivePartitionKeyForHashPartitioningV2(PartitionKeyInternal partitionKeyInternal) { - try(ByteArrayOutputStream byteArrayBuffer = new ByteArrayOutputStream()) { - for (int i = 0; i < partitionKeyInternal.components.size(); i++) { - partitionKeyInternal.components.get(i).WriteForHashingV2(byteArrayBuffer); - } - - byte[] bytes = byteArrayBuffer.toByteArray(); - UInt128 hashAsUnit128 = MurmurHash3_128.hash128(bytes); - - byte[] hash = uIntToBytes(hashAsUnit128); - Bytes.reverse(hash); - - // Reset 2 most significant bits, as max exclusive value is 'FF'. - // Plus one more just in case. - hash[0] &= 0x3F; - - return HexConvert.bytesToHex(hash); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - } - - static String getEffectivePartitionKeyForHashPartitioning(PartitionKeyInternal partitionKeyInternal) { - IPartitionKeyComponent[] truncatedComponents = new IPartitionKeyComponent[partitionKeyInternal.components.size()]; - - for (int i = 0; i < truncatedComponents.length; i++) { - truncatedComponents[i] = partitionKeyInternal.components.get(i).Truncate(); - } - - double hash; - try(ByteArrayOutputStream byteArrayBuffer = new ByteArrayOutputStream()) { - for (int i = 0; i < truncatedComponents.length; i++) { - truncatedComponents[i].WriteForHashing(byteArrayBuffer); - } - - byte[] bytes = byteArrayBuffer.toByteArray(); - int hashAsInt = MurmurHash3_32.hash(bytes, bytes.length, 0); - hash = (double) asUnsignedLong(hashAsInt); - } catch (IOException e) { - throw new IllegalArgumentException(e); - } - - IPartitionKeyComponent[] partitionKeyComponents = new IPartitionKeyComponent[partitionKeyInternal.components.size() + 1]; - partitionKeyComponents[0] = new NumberPartitionKeyComponent(hash); - for (int i = 0; i < truncatedComponents.length; i++) { - partitionKeyComponents[i + 1] = truncatedComponents[i]; - } - - return toHexEncodedBinaryString(partitionKeyComponents); - } - - public static String getEffectivePartitionKeyString(PartitionKeyInternal partitionKeyInternal, PartitionKeyDefinition partitionKeyDefinition) { - return getEffectivePartitionKeyString(partitionKeyInternal, partitionKeyDefinition, true); - } - - public static String getEffectivePartitionKeyString(PartitionKeyInternal partitionKeyInternal, PartitionKeyDefinition partitionKeyDefinition, boolean strict) { - if (partitionKeyInternal.equals(PartitionKeyInternal.EmptyPartitionKey)) { - return MinimumInclusiveEffectivePartitionKey; - } - - if (partitionKeyInternal.equals(PartitionKeyInternal.InfinityPartitionKey)) { - return MaximumExclusiveEffectivePartitionKey; - } - - if (partitionKeyInternal.components.size() < partitionKeyDefinition.getPaths().size()) { - throw new IllegalArgumentException(RMResources.TooFewPartitionKeyComponents); - } - - if (partitionKeyInternal.components.size() > partitionKeyDefinition.getPaths().size() && strict) { - throw new IllegalArgumentException(RMResources.TooManyPartitionKeyComponents); - } - - PartitionKind kind = partitionKeyDefinition.getKind(); - if (kind == null) { - kind = PartitionKind.Hash; - } - - switch (kind) { - case Hash: - if (CommonsBridgeInternal.isV2(partitionKeyDefinition)) { - // V2 - return getEffectivePartitionKeyForHashPartitioningV2(partitionKeyInternal); - } else { - // V1 - return getEffectivePartitionKeyForHashPartitioning(partitionKeyInternal); - } - - default: - return toHexEncodedBinaryString(partitionKeyInternal.components); - } - } - - static class HexConvert { - final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); - - public static String bytesToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; - } - return new String(hexChars); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/UInt128.java b/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/UInt128.java deleted file mode 100644 index 4241b78cd705..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/UInt128.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -class UInt128 { - long low; - long high; - - UInt128(long x, long y) { - this.low = x; - this.high = y; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/PartitionKeyHashingTests.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/PartitionKeyHashingTests.java deleted file mode 100644 index 72b83febf422..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/PartitionKeyHashingTests.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.microsoft.azure.cosmosdb; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import org.testng.annotations.Test; - -import com.fasterxml.jackson.databind.node.NullNode; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalHelper; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -public class PartitionKeyHashingTests { - - @Test(groups = "unit") - public void effectivePartitionKeyHashV1() { - HashMap keyToEffectivePartitionKeyString = new HashMap() {{ - put("", "05C1CF33970FF80800"); - put("partitionKey", "05C1E1B3D9CD2608716273756A756A706F4C667A00"); - put(new String(new char[1024]).replace("\0", "a"), "05C1EB5921F706086262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626262626200"); - put(null, "05C1ED45D7475601"); - put(NullNode.getInstance(), "05C1ED45D7475601"); - put(Undefined.Value(), "05C1D529E345DC00"); - put(true, "05C1D7C5A903D803"); - put(false, "05C1DB857D857C02"); - put(Byte.MIN_VALUE, "05C1D73349F54C053FA0"); - put(Byte.MAX_VALUE, "05C1DD539DDFCC05C05FE0"); - put(Long.MIN_VALUE, "05C1DB35F33D1C053C20"); - put(Long.MAX_VALUE, "05C1B799AB2DD005C3E0"); - put(Integer.MIN_VALUE, "05C1DFBF252BCC053E20"); - put(Integer.MAX_VALUE, "05C1E1F503DFB205C1DFFFFFFFFC"); - put(Double.MIN_VALUE, "05C1E5C91F4D3005800101010101010102"); - put(Double.MAX_VALUE, "05C1CBE367C53005FFEFFFFFFFFFFFFFFE"); - }}; - - for (Map.Entry entry : keyToEffectivePartitionKeyString.entrySet()) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - partitionKeyDef.setKind(PartitionKind.Hash); - partitionKeyDef.setPaths(Arrays.asList(new String[]{"\\id"})); - String actualEffectiveKeyString = PartitionKeyInternalHelper.getEffectivePartitionKeyString(new PartitionKey(entry.getKey()).getInternalPartitionKey(),partitionKeyDef, true); - assertThat(entry.getValue()).isEqualTo(actualEffectiveKeyString); - } - } - - @Test(groups = "unit") - public void effectivePartitionKeyHashV2() { - HashMap keyToEffectivePartitionKeyString = new HashMap() {{ - put("", "32E9366E637A71B4E710384B2F4970A0"); - put("partitionKey", "013AEFCF77FA271571CF665A58C933F1"); - put(new String(new char[1024]).replace("\0", "a"), "332BDF5512AE49615F32C7D98C2DB86C"); - put(null, "378867E4430E67857ACE5C908374FE16"); - put(NullNode.getInstance(), "378867E4430E67857ACE5C908374FE16"); - put(Undefined.Value(), "11622DAA78F835834610ABE56EFF5CB5"); - put(true, "0E711127C5B5A8E4726AC6DD306A3E59"); - put(false, "2FE1BE91E90A3439635E0E9E37361EF2"); - put(Byte.MIN_VALUE, "01DAEDABF913540367FE219B2AD06148"); - put(Byte.MAX_VALUE, "0C507ACAC853ECA7977BF4CEFB562A25"); - put(Long.MIN_VALUE, "23D5C6395512BDFEAFADAD15328AD2BB"); - put(Long.MAX_VALUE, "2EDB959178DFCCA18983F89384D1629B"); - put(Integer.MIN_VALUE, "0B1660D5233C3171725B30D4A5F4CC1F"); - put(Integer.MAX_VALUE, "2D9349D64712AEB5EB1406E2F0BE2725"); - put(Double.MIN_VALUE, "0E6CBA63A280927DE485DEF865800139"); - put(Double.MAX_VALUE, "31424D996457102634591FF245DBCC4D"); - }}; - - for (Map.Entry entry : keyToEffectivePartitionKeyString.entrySet()) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - partitionKeyDef.setKind(PartitionKind.Hash); - partitionKeyDef.setVersion(PartitionKeyDefinitionVersion.V2); - partitionKeyDef.setPaths(Arrays.asList(new String[]{"\\id"})); - String actualEffectiveKeyString = PartitionKeyInternalHelper.getEffectivePartitionKeyString(new PartitionKey(entry.getKey()).getInternalPartitionKey(),partitionKeyDef, true); - assertThat(entry.getValue()).isEqualTo(actualEffectiveKeyString); - } - } - - @Test(groups = "unit") - public void hashV2PartitionKeyDeserialization() { - String partitionKeyDefinitionStr = "{\"paths\":[\"/pk\"],\"kind\":\"Hash\",\"version\":2}"; - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(partitionKeyDefinitionStr); - assertThat(partitionKeyDef.getVersion()).isEqualTo(PartitionKeyDefinitionVersion.V2); - assertThat(partitionKeyDef.getKind()).isEqualTo(PartitionKind.Hash); - assertThat(partitionKeyDef.getPaths().toArray()[0]).isEqualTo("/pk"); - } - - @Test(groups = "unit") - public void hashV1PartitionKeyDeserialization() { - String partitionKeyDefinitionStr = "{\"paths\":[\"/pk\"],\"kind\":\"Hash\"}"; - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(partitionKeyDefinitionStr); - assertThat(partitionKeyDef.getVersion()).isNull(); - assertThat(partitionKeyDef.getKind()).isEqualTo(PartitionKind.Hash); - assertThat(partitionKeyDef.getPaths().toArray()[0]).isEqualTo("/pk"); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolverTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolverTest.java deleted file mode 100644 index 4c1fadafdeca..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressResolverTest.java +++ /dev/null @@ -1,1008 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.IServerIdentity; -import com.microsoft.azure.cosmosdb.internal.routing.InMemoryCollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalHelper; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.ICollectionRoutingMapCache; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import org.apache.commons.lang3.NotImplementedException; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.mutable.MutableObject; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Single; -import rx.functions.Func1; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.fail; - -/** - * Tests that partition manager correctly resolves addresses for requests and does appropriate number of cache refreshes. - */ -public class AddressResolverTest { - - private static final Logger logger = LoggerFactory.getLogger(AddressResolverTest.class); - private static final String DOCUMENT_TEST_URL = "dbs/IXYFAA==/colls/IXYFAOHEBPM=/docs/IXYFAOHEBPMBAAAAAAAAAA==/"; - private AddressResolver addressResolver; - private RxCollectionCache collectionCache; - private ICollectionRoutingMapCache collectionRoutingMapCache; - private IAddressCache fabricAddressCache; - - private int collectionCacheRefreshedCount; - private Map routingMapRefreshCount; - private Map addressesRefreshCount; - - @BeforeClass(groups = "unit") - public void setup() throws Exception { - this.addressResolver = new AddressResolver(); - this.collectionCache = Mockito.mock(RxCollectionCache.class); - this.collectionRoutingMapCache = Mockito.mock(ICollectionRoutingMapCache.class); - this.fabricAddressCache = Mockito.mock(IAddressCache.class); - this.addressResolver.initializeCaches(this.collectionCache, this.collectionRoutingMapCache, this.fabricAddressCache); - - this.collection1 = new DocumentCollection(); - this.collection1.setId("coll"); - this.collection1.setResourceId("rid1"); - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - partitionKeyDef.setPaths(ImmutableList.of("/field1")); - this.collection1.setPartitionKey(partitionKeyDef); - - this.collection2 = new DocumentCollection(); - this.collection2.setId("coll"); - this.collection2.setResourceId("rid2"); - new PartitionKeyDefinition(); - partitionKeyDef.setPaths(ImmutableList.of("/field1")); - this.collection2.setPartitionKey(partitionKeyDef); - - Func1>, Void> addPartitionKeyRangeFunc = listArg -> { - listArg.forEach(tuple -> ((ServiceIdentity) tuple.right).partitionKeyRangeIds.add(new PartitionKeyRangeIdentity(collection1.getResourceId(), tuple.left.getId()))); - return null; - }; - - List> rangesBeforeSplit1 = - new ArrayList<>(); - ServiceIdentity serverServiceIdentity = new ServiceIdentity("federation1", new URI("fabric://serverservice1"), false); - - rangesBeforeSplit1.add( - ImmutablePair.of(new PartitionKeyRange("0", PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey, - PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey), serverServiceIdentity)); - - addPartitionKeyRangeFunc.call(rangesBeforeSplit1); - - - this.routingMapCollection1BeforeSplit = - InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap( - rangesBeforeSplit1, - collection1.getResourceId()); - - List> rangesAfterSplit1 = - new ArrayList<>(); - ServiceIdentity serverServiceIdentity2 = new ServiceIdentity("federation1", new URI("fabric://serverservice2"), false); - ServiceIdentity serverServiceIdentity3 = new ServiceIdentity("federation1", new URI("fabric://serverservice3"), false); - - rangesAfterSplit1.add( - ImmutablePair.of( - new PartitionKeyRange("1", PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey, "5E", ImmutableList.of("0")), - serverServiceIdentity2)); - - rangesAfterSplit1.add( - ImmutablePair.of( - new PartitionKeyRange("2", "5E", PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey, ImmutableList.of("0")), - serverServiceIdentity3)); - - addPartitionKeyRangeFunc.call(rangesAfterSplit1); - - this.routingMapCollection1AfterSplit = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap(rangesAfterSplit1, collection1.getResourceId()); - - List> rangesBeforeSplit2 = - new ArrayList<>(); - ServiceIdentity serverServiceIdentity4 = new ServiceIdentity("federation1", new URI("fabric://serverservice4"), false); - - rangesBeforeSplit2.add( - ImmutablePair.of( - new PartitionKeyRange("0", PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey, PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey), - serverServiceIdentity4)); - - addPartitionKeyRangeFunc.call(rangesBeforeSplit2); - - - this.routingMapCollection2BeforeSplit = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap(rangesBeforeSplit2, collection2.getResourceId()); - - List> rangesAfterSplit2 = - new ArrayList<>(); - - ServiceIdentity serverServiceIdentity5 = new ServiceIdentity("federation1", new URI("fabric://serverservice5"), false); - ServiceIdentity serverServiceIdentity6 = new ServiceIdentity("federation1", new URI("fabric://serverservice6"), false); - rangesAfterSplit2.add( - ImmutablePair.of( - new PartitionKeyRange("1", PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey, "5E", ImmutableList.of("0")), - serverServiceIdentity5)); - - rangesAfterSplit2.add( - ImmutablePair.of( - new PartitionKeyRange("2", "5E", PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey, ImmutableList.of("0")), - serverServiceIdentity6)); - - - addPartitionKeyRangeFunc.call(rangesAfterSplit2); - - - this.routingMapCollection2AfterSplit = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap(rangesAfterSplit2, collection2.getResourceId()); - } - - private void TestCacheRefreshWhileRouteByPartitionKey( - DocumentCollection collectionBeforeRefresh, - DocumentCollection collectionAfterRefresh, - Map routingMapBeforeRefresh, - Map routingMapAfterRefresh, - Map addressesBeforeRefresh, - Map addressesAfterRefresh, - AddressInformation[] targetAddresses, - ServiceIdentity targetServiceIdentity, - PartitionKeyRange targetPartitionKeyRange, - boolean forceNameCacheRefresh, - boolean forceRoutingMapRefresh, - boolean forceAddressRefresh, - int collectionCacheRefreshed, - int routingMapCacheRefreshed, - int addressCacheRefreshed, - boolean nameBased) throws Exception { - - if (targetServiceIdentity != null && targetPartitionKeyRange != null) { - targetServiceIdentity.partitionKeyRangeIds.add(new PartitionKeyRangeIdentity(collectionAfterRefresh != null ? collectionAfterRefresh.getResourceId() : collectionBeforeRefresh.getResourceId(), targetPartitionKeyRange.getId())); - } - - this.initializeMocks( - collectionBeforeRefresh, - collectionAfterRefresh, - routingMapBeforeRefresh, - routingMapAfterRefresh, - addressesBeforeRefresh, - addressesAfterRefresh); - - RxDocumentServiceRequest request; - if (nameBased) { - request = RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.Document, - "dbs/db/colls/coll/docs/doc1", - new HashMap<>()); - } else { - request = RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.Document, - DOCUMENT_TEST_URL, - new HashMap<>()); - } - - request.forceNameCacheRefresh = forceNameCacheRefresh; - request.forcePartitionKeyRangeRefresh = forceRoutingMapRefresh; - request.getHeaders().put(HttpConstants.HttpHeaders.PARTITION_KEY, new PartitionKey("foo").toString()); - AddressInformation[] resolvedAddresses = null; - try { - resolvedAddresses = this.addressResolver.resolveAsync(request, forceAddressRefresh).toBlocking().value(); - } catch (RuntimeException e) { - throw (Exception) e.getCause(); - } finally { - assertThat(collectionCacheRefreshed).isEqualTo(collectionCacheRefreshedCount).describedAs("collection cache refresh count mismath"); - - assertThat(routingMapCacheRefreshed).isEqualTo(routingMapRefreshCount.values().stream().mapToInt(v -> v).sum()).describedAs("routing map cache refresh count mismath"); - assertThat(addressCacheRefreshed).isEqualTo(addressesRefreshCount.values().stream().mapToInt(v -> v).sum()).describedAs("address cache refresh count mismatch"); - assertThat(routingMapRefreshCount.entrySet().stream().filter(pair -> pair.getValue() > 1).count()).isEqualTo(0); - assertThat(addressesRefreshCount.entrySet().stream().filter(pair -> pair.getValue() > 1).count()).isEqualTo(0); - } - - assertThat(targetAddresses[0].getPhysicalUri()).isEqualTo(resolvedAddresses[0].getPhysicalUri()); - // Assert.AreEqual(targetServiceIdentity, request.requestContext.TargetIdentity); - assertThat(targetPartitionKeyRange.getId()).isEqualTo(request.requestContext.resolvedPartitionKeyRange.getId()); - } - - private void TestCacheRefreshWhileRouteByPartitionKeyRangeId( - DocumentCollection collectionBeforeRefresh, - DocumentCollection collectionAfterRefresh, - Map routingMapBeforeRefresh, - Map routingMapAfterRefresh, - Map addressesBeforeRefresh, - Map addressesAfterRefresh, - PartitionKeyRangeIdentity rangeIdentity, - AddressInformation[] targetAddresses, - ServiceIdentity targetServiceIdentity, - PartitionKeyRange targetPartitionKeyRange, - boolean forceNameCacheRefresh, - boolean forceRoutingMapRefresh, - boolean forceAddressRefresh, - int collectionCacheRefreshed, - int routingMapCacheRefreshed, - int addressCacheRefreshed, - boolean nameBased) throws Exception { - - if (targetServiceIdentity != null && targetPartitionKeyRange != null) { - targetServiceIdentity.partitionKeyRangeIds.add(new PartitionKeyRangeIdentity(collectionAfterRefresh != null ? collectionAfterRefresh.getResourceId() : collectionBeforeRefresh.getResourceId(), targetPartitionKeyRange.getId())); - } - - this.initializeMocks( - collectionBeforeRefresh, - collectionAfterRefresh, - routingMapBeforeRefresh, - routingMapAfterRefresh, - addressesBeforeRefresh, - addressesAfterRefresh); - - RxDocumentServiceRequest request; - if (nameBased) { - request = RxDocumentServiceRequest.createFromName( - OperationType.Read, - "dbs/db/colls/coll/docs/doc1", - ResourceType.Document); - } else { - request = RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.Document, - DOCUMENT_TEST_URL, - new HashMap<>()); - } - - request.forceNameCacheRefresh = forceNameCacheRefresh; - request.forcePartitionKeyRangeRefresh = forceRoutingMapRefresh; - request.routeTo(rangeIdentity); - AddressInformation[] resolvedAddresses; - try { - resolvedAddresses = this.addressResolver.resolveAsync(request, forceAddressRefresh).toBlocking().value(); - } catch (RuntimeException e) { - e.printStackTrace(); - throw (Exception) e.getCause(); - } finally { - assertThat(collectionCacheRefreshed).isEqualTo(collectionCacheRefreshedCount).describedAs("collection cache refresh count mismath"); - - assertThat(routingMapCacheRefreshed).isEqualTo(routingMapRefreshCount.values().stream().mapToInt(v -> v).sum()).describedAs("routing map cache refresh count mismath"); - assertThat(addressCacheRefreshed).isEqualTo(addressesRefreshCount.values().stream().mapToInt(v -> v).sum()).describedAs("address cache refresh count mismatch"); - - - assertThat(routingMapRefreshCount.entrySet().stream().filter(pair -> pair.getValue() > 1).count()).isEqualTo(0); - assertThat(addressesRefreshCount.entrySet().stream().filter(pair -> pair.getValue() > 1).count()).isEqualTo(0); - } - - assertThat(targetAddresses[0].getPhysicalUri()).isEqualTo(resolvedAddresses[0].getPhysicalUri()); - // Assert.AreEqual(targetServiceIdentity, request.requestContext.TargetIdentity); - assertThat(targetPartitionKeyRange.getId()).isEqualTo(request.requestContext.resolvedPartitionKeyRange.getId()); - } - - private void initializeMocks( - DocumentCollection collectionBeforeRefresh, - DocumentCollection collectionAfterRefresh, - Map routingMapBeforeRefresh, - Map routingMapAfterRefreshInitial, - Map addressesBeforeRefresh, - Map addressesAfterRefreshInitial) { - final Map routingMapAfterRefresh = ObjectUtils.defaultIfNull(routingMapAfterRefreshInitial, routingMapBeforeRefresh); - final Map addressesAfterRefresh = ObjectUtils.defaultIfNull(addressesAfterRefreshInitial, addressesBeforeRefresh); - - // Collection cache - MutableObject currentCollection = new MutableObject(collectionBeforeRefresh); - this.collectionCacheRefreshedCount = 0; - - Mockito.doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - RxDocumentServiceRequest request = invocationOnMock.getArgumentAt(0, RxDocumentServiceRequest.class); - if (request.forceNameCacheRefresh && collectionAfterRefresh != null) { - currentCollection.setValue(collectionAfterRefresh); - AddressResolverTest.this.collectionCacheRefreshedCount++; - request.forceNameCacheRefresh = false; - return Single.just(currentCollection.getValue()); - } - - if (request.forceNameCacheRefresh && collectionAfterRefresh == null) { - currentCollection.setValue(null); - AddressResolverTest.this.collectionCacheRefreshedCount++; - request.forceNameCacheRefresh = false; - return Single.error(new NotFoundException()); - } - - if (!request.forceNameCacheRefresh && currentCollection.getValue() == null) { - return Single.error(new NotFoundException()); - - } - - if (!request.forceNameCacheRefresh && currentCollection.getValue() != null) { - return Single.just(currentCollection.getValue()); - } - - return null; - } - }).when(this.collectionCache).resolveCollectionAsync(Mockito.any(RxDocumentServiceRequest.class)); - - // Routing map cache - Map currentRoutingMap = - new HashMap<>(routingMapBeforeRefresh); - this.routingMapRefreshCount = new HashMap<>(); - - Mockito.doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - String collectionRid = invocationOnMock.getArgumentAt(0, String.class); - CollectionRoutingMap previousValue = invocationOnMock.getArgumentAt(1, CollectionRoutingMap.class); - - return collectionRoutingMapCache.tryLookupAsync(collectionRid, previousValue, false, null); - } - }).when(this.collectionRoutingMapCache).tryLookupAsync(Mockito.anyString(), Mockito.any(CollectionRoutingMap.class), Mockito.anyMap()); - - // Refresh case - Mockito.doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - String collectionRid = invocationOnMock.getArgumentAt(0, String.class); - CollectionRoutingMap previousValue = invocationOnMock.getArgumentAt(1, CollectionRoutingMap.class); - - if (previousValue == null) { - return Single.just(currentRoutingMap.containsKey(collectionRid) ? currentRoutingMap.get(collectionRid) : null); - } - - if (previousValue != null && currentRoutingMap.containsKey(previousValue.getCollectionUniqueId()) && - currentRoutingMap.get(previousValue.getCollectionUniqueId()) == previousValue) { - - - if (previousValue != null && previousValue.getCollectionUniqueId() != collectionRid) { - throw new RuntimeException("InvalidOperation"); - } - - if (routingMapAfterRefresh.containsKey(collectionRid)) { - currentRoutingMap.put(collectionRid, routingMapAfterRefresh.get(collectionRid)); - } else { - currentRoutingMap.remove(collectionRid); - } - - if (!routingMapRefreshCount.containsKey(collectionRid)) { - routingMapRefreshCount.put(collectionRid, 1); - } else { - routingMapRefreshCount.put(collectionRid, routingMapRefreshCount.get(collectionRid) + 1); - } - - - return Single.just(currentRoutingMap.containsKey(collectionRid) ? currentRoutingMap.get(collectionRid) : null); - } - - return Single.error(new NotImplementedException("not mocked")); - } - }).when(this.collectionRoutingMapCache).tryLookupAsync(Mockito.anyString(), Mockito.any(CollectionRoutingMap.class), Mockito.anyBoolean(), Mockito.anyMap()); - - - // Fabric Address Cache - Map currentAddresses = - new HashMap<>(addressesBeforeRefresh); - this.addressesRefreshCount = new HashMap<>(); - - // No refresh case - Mockito.doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Exception { - RxDocumentServiceRequest request = invocationOnMock.getArgumentAt(0, RxDocumentServiceRequest.class); - PartitionKeyRangeIdentity pkri = invocationOnMock.getArgumentAt(1, PartitionKeyRangeIdentity.class); - Boolean forceRefresh = invocationOnMock.getArgumentAt(2, Boolean.class); - - if (!forceRefresh) { - return Single.just(currentAddresses.get(findMatchingServiceIdentity(currentAddresses, pkri))); - } else { - - ServiceIdentity si; - - if ((si = findMatchingServiceIdentity(addressesAfterRefresh, pkri)) != null) { - currentAddresses.put(si, addressesAfterRefresh.get(si)); - } else { - - si = findMatchingServiceIdentity(currentAddresses, pkri); - currentAddresses.remove(si); - } - - if (si == null) { - si = ServiceIdentity.dummyInstance; - } - - if (!addressesRefreshCount.containsKey(si)) { - addressesRefreshCount.put(si, 1); - } else { - addressesRefreshCount.put(si, addressesRefreshCount.get(si) + 1); - } - - - // TODO: what to return in this case if it is null!! - return Single.just(currentAddresses.containsKey(si) ? currentAddresses.get(si) : null); - } - } - // - }).when(fabricAddressCache).tryGetAddresses(Mockito.any(RxDocumentServiceRequest.class), Mockito.any(PartitionKeyRangeIdentity.class), Mockito.anyBoolean()); - } - - private static ServiceIdentity findMatchingServiceIdentity(Map map, PartitionKeyRangeIdentity pkri) { - for (ServiceIdentity si : map.keySet()) { - if (si.partitionKeyRangeIds.contains(pkri)) { - return si; - } - - } - return null; - } - - private final AddressInformation[] addresses1 = {new AddressInformation(true, true, "tcp://host/partition1", Protocol.Https)}; - private final AddressInformation[] addresses2 = {new AddressInformation(true, true, "tcp://host/partition2", Protocol.Https)}; - private final AddressInformation[] addresses3 = {new AddressInformation(true, true, "tcp://host/partition3", Protocol.Https)}; - - private DocumentCollection collection1; - private DocumentCollection collection2; - private CollectionRoutingMap routingMapCollection1BeforeSplit; - private CollectionRoutingMap routingMapCollection1AfterSplit; - private CollectionRoutingMap routingMapCollection2BeforeSplit; - private CollectionRoutingMap routingMapCollection2AfterSplit; - - @Test(groups = "unit") - public void testCacheRefreshesWhileRoutingByPartitionKey() throws Exception { - logger.info("All caches are up to date. Name Based"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1), - null, - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - getRangeAt(this.routingMapCollection1BeforeSplit, 0), - false, - false, - false, - 0, - 0, - 0, - true); - - logger.info("All caches are up to date. Rid Based"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1), - null, - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - getRangeAt(this.routingMapCollection1BeforeSplit, 0), - false, - false, - false, - 0, - 0, - 0, - true); - - logger.info("Address cache is stale. Force Refresh. Name Based"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses2), - this.addresses2, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - this.routingMapCollection1BeforeSplit.getOrderedPartitionKeyRanges().get(0), - false, - false, - true, - 0, - 0, - 1, - true); - - logger.info("Address cache is stale. Force Refresh. Rid Based"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses2), - this.addresses2, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - getRangeAt(this.routingMapCollection1BeforeSplit, 0), - false, - false, - true, - 0, - 0, - 1, - false); - - logger.info("Routing map cache is stale. Force Refresh. Name based"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1AfterSplit), - ImmutableMap.of( - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses2, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 1), this.addresses3), - null, - this.addresses2, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - true, - false, - 0, - 1, - 0, - true); - - logger.info("Routing map cache is stale. Force Refresh. Rid based"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1AfterSplit), - ImmutableMap.of( - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses2, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 1), this.addresses3), - null, - this.addresses2, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - true, - false, - 0, - 1, - 0, - false); - - logger.info("Name cache is stale. Force Refresh. Name based"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection2, - ImmutableMap.of(this.collection2.getResourceId(), this.routingMapCollection2BeforeSplit), - null, - ImmutableMap.of( - getServiceIdentityAt(this.routingMapCollection2BeforeSplit, 0), this.addresses1), - null, - this.addresses1, - getServiceIdentityAt(this.routingMapCollection2BeforeSplit, 0), - getRangeAt(this.routingMapCollection2BeforeSplit, 0), - true, - false, - false, - 1, - 0, - 0, - true); - - logger.info("Name cache is stale (collection deleted new one created same name). Routing Map Cache returns null"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection2, - ImmutableMap.of(this.collection2.getResourceId(), this.routingMapCollection2BeforeSplit), - null, - ImmutableMap.of( - getServiceIdentityAt(this.routingMapCollection2BeforeSplit, 0), this.addresses1), - null, - this.addresses1, - getServiceIdentityAt(this.routingMapCollection2BeforeSplit, 0), - getRangeAt(this.routingMapCollection2BeforeSplit, 0), - false, - false, - false, - 1, - 0, - 0, - true); - - logger.info("Routing map cache is stale (split happened). Address Cache returns null"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1AfterSplit), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - null, - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - false, - false, - 1, - 1, - 0, - true); - - - logger.info("Collection cache is stale (deleted created same name). Routing map cache is stale for new collection (split happened). Address Cache returns null"); - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - this.collection2, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit, - this.collection2.getResourceId(), this.routingMapCollection2BeforeSplit), - ImmutableMap.of(this.collection2.getResourceId(), this.routingMapCollection2AfterSplit), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection2AfterSplit, 0), this.addresses1), - null, - this.addresses1, - getServiceIdentityAt(this.routingMapCollection2AfterSplit, 0), - getRangeAt(this.routingMapCollection2AfterSplit, 0), - false, - false, - false, - 1, - 1, - 0, - true); - - logger.info("Collection cache is stale (collection deleted). Routing map cache is stale (collection deleted). Address Cache returns null"); - try { - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - null, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - ImmutableMap.of(), - ImmutableMap.of(), - null, - null, - null, - null, - false, - false, - false, - 1, - 0, - 0, - true); - - fail("Expected NotFoundException"); - } catch (NotFoundException e) { - } - - logger.info("Collection cache is stale (collection deleted). Routing map cache returns null."); - try { - this.TestCacheRefreshWhileRouteByPartitionKey( - this.collection1, - null, - ImmutableMap.of(), - null, - ImmutableMap.of(), - null, - null, - null, - null, - false, - false, - false, - 1, - 0, - 0, - true); - - fail("Expected NotFoundException"); - } catch (NotFoundException e) { - } - } - - private static PartitionKeyRange getRangeAt(CollectionRoutingMap routingMap, int index) { - return routingMap.getOrderedPartitionKeyRanges().get(index); - } - - private static ServiceIdentity getServiceIdentityAt(CollectionRoutingMap routingMap, int index) { - return (ServiceIdentity) routingMap.tryGetInfoByPartitionKeyRangeId(routingMap.getOrderedPartitionKeyRanges().get(index).getId()); - } - - @Test(groups = "unit") - public void testCacheRefreshesWhileRoutingByPartitionKeyRangeId() throws Exception { - logger.info("All caches are up to date. Name Based"); - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity(this.collection1.getResourceId(), "0"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - getRangeAt(this.routingMapCollection1BeforeSplit, 0), - false, - false, - false, - 0, - 0, - 0, - true); - - logger.info("All caches are up to date. Name Based. Non existent range with collection rid"); - try { - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity(this.collection1.getResourceId(), "1"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - getRangeAt(this.routingMapCollection1BeforeSplit, 0), - false, - false, - false, - 0, - 1, - 0, - true); - - fail("Should have gotten PartitionKeyRangeGoneException"); - } catch (PartitionKeyRangeGoneException e) { - } - - logger.info("All caches are up to date. Name Based. Non existent range withOUT collection rid"); - try { - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity("1"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - getRangeAt(this.routingMapCollection1BeforeSplit, 0), - false, - false, - false, - 1, - 1, - 0, - true); - - fail("Should have gotten PartitionKeyRangeGoneException"); - } catch (PartitionKeyRangeGoneException e) { - } - - logger.info("All caches are up to date. Name Based.Range doesn't exist in routing map because split happened."); - try { - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1AfterSplit), - null, - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity(collection1.getResourceId(), "0"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1BeforeSplit, 0), - getRangeAt(this.routingMapCollection1BeforeSplit, 0), - false, - false, - false, - 0, - 0, - 0, - true); - - fail("Should have gotten PartitionKeyRangeGoneException"); - } catch (PartitionKeyRangeGoneException e) { - } - - try { - logger.info("Name Based.Routing map cache is outdated because split happened. Address cache returns null."); - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1AfterSplit), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity(collection1.getResourceId(), "0"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - false, - false, - 0, - 1, - 0, - true); - - fail("Should have gotten PartitionKeyRangeGoneException"); - } catch (PartitionKeyRangeGoneException e) { - } - - logger.info("Name Based.Routing map cache is outdated because split happend."); - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - this.collection1, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1AfterSplit), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity(collection1.getResourceId(), "1"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - false, - false, - 0, - 1, - 0, - true); - - try { - logger.info("Collection cache is outdated. Routing map cache returns null. Collection is deleted. Range with collection rid."); - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - null, - ImmutableMap.of(), - ImmutableMap.of(), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity(collection1.getResourceId(), "0"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - false, - false, - 0, - 0, - 0, - true); - - fail("Should have gotten InvalidPartitionException"); - } catch (InvalidPartitionException e) { - } - - try { - logger.info("Collection cache is outdated. Routing map cache returns null. Collection is deleted. Range without collection rid"); - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - null, - ImmutableMap.of(), - ImmutableMap.of(), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity("0"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - false, - false, - 1, - 0, - 0, - true); - - fail("Should have gotten NotFoundException"); - } catch (NotFoundException e) { - } - - try { - logger.info("Collection cache is outdated. Routing map cache returns null. Collection is deleted. Range with collection rid. Rid based."); - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - null, - ImmutableMap.of(), - ImmutableMap.of(), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - null, - new PartitionKeyRangeIdentity(collection1.getResourceId(), "0"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - false, - false, - 0, - 0, - 0, - false); - - fail("Should have gotten NotFoundException"); - } catch (NotFoundException e) { - } - - try { - logger.info("Collection cache is outdated. Routing map cache is outdated. Address cache is outdated. ForceAddressRefresh. Range with collection rid. Name based."); - this.TestCacheRefreshWhileRouteByPartitionKeyRangeId( - this.collection1, - this.collection2, - ImmutableMap.of(this.collection1.getResourceId(), this.routingMapCollection1BeforeSplit), - ImmutableMap.of(this.collection2.getResourceId(), this.routingMapCollection2BeforeSplit), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), this.addresses1), - ImmutableMap.of(getServiceIdentityAt(this.routingMapCollection2AfterSplit, 0), this.addresses2), - new PartitionKeyRangeIdentity(collection1.getResourceId(), "0"), - this.addresses1, - getServiceIdentityAt(this.routingMapCollection1AfterSplit, 0), - getRangeAt(this.routingMapCollection1AfterSplit, 0), - false, - false, - true, - 0, - 1, - 1, - true); - - fail("Should have gotten InvalidPartitionException"); - } catch (InvalidPartitionException e) { - } - } - - static class ServiceIdentity implements IServerIdentity { - final boolean IsMasterService; - final URI ServiceName; - final String FederationId; - final Set partitionKeyRangeIds; - final static ServiceIdentity dummyInstance = new ServiceIdentity(null, null, true); - - public ServiceIdentity(String federationId, URI serviceName, boolean isMasterService, PartitionKeyRangeIdentity... partitionKeyRangeIdentities) { - this.FederationId = federationId; - this.ServiceName = serviceName; - this.IsMasterService = isMasterService; - this.partitionKeyRangeIds = new HashSet<>(Arrays.stream(partitionKeyRangeIdentities).collect(Collectors.toList())); - } - } -} - diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelectorTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelectorTest.java deleted file mode 100644 index 4755646d1896..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelectorTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.testng.annotations.Test; -import rx.Single; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -public class AddressSelectorTest { - - @Test(groups = "unit", expectedExceptions = GoneException.class) - public void getPrimaryUri_NoAddress() throws Exception { - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); - List replicaAddresses = new ArrayList<>(); - - AddressSelector.getPrimaryUri(request, replicaAddresses); - } - - @Test(groups = "unit", expectedExceptions = GoneException.class, expectedExceptionsMessageRegExp = - "The requested resource is no longer available at the server. Returned addresses are \\{https://cosmos1,https://cosmos2\\}") - public void getPrimaryUri_NoPrimaryAddress() throws Exception { - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); - - List replicaAddresses = new ArrayList<>(); - - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos1", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos2", Protocol.Https)); - - AddressSelector.getPrimaryUri(request, replicaAddresses); - } - - @Test(groups = "unit") - public void getPrimaryUri() throws Exception { - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); - - List replicaAddresses = new ArrayList<>(); - - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos1", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos2", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos3", Protocol.Https)); - - URI res = AddressSelector.getPrimaryUri(request, replicaAddresses); - - assertThat(res).isEqualTo(URI.create("https://cosmos2")); - } - - @Test(groups = "unit") - public void getPrimaryUri_WithRequestReplicaIndex() throws Exception { - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(1).when(request).getDefaultReplicaIndex(); - - List replicaAddresses = new ArrayList<>(); - - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos1", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos2", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos3", Protocol.Https)); - - URI res = AddressSelector.getPrimaryUri(request, replicaAddresses); - - assertThat(res).isEqualTo(URI.create("https://cosmos2")); - } - - @Test(groups = "unit") - public void resolvePrimaryUriAsync() { - IAddressResolver addressResolver = Mockito.mock(IAddressResolver.class); - AddressSelector selector = new AddressSelector(addressResolver, Protocol.Https); - - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); - - List replicaAddresses = new ArrayList<>(); - - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos4", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos5", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos1", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos2", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos3", Protocol.Https)); - - Mockito.doReturn(Single.just(replicaAddresses.toArray(new AddressInformation[0]))).when(addressResolver).resolveAsync(Mockito.any(RxDocumentServiceRequest.class), Matchers.eq(false)); - - URI res = selector.resolvePrimaryUriAsync(request, false).toBlocking().value(); - - assertThat(res).isEqualTo(URI.create("https://cosmos2")); - } - - @Test(groups = "unit") - public void resolveAllUriAsync() { - IAddressResolver addressResolver = Mockito.mock(IAddressResolver.class); - AddressSelector selector = new AddressSelector(addressResolver, Protocol.Https); - - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); - - List replicaAddresses = new ArrayList<>(); - - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos4", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos5", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos1", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos2", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos3", Protocol.Https)); - - Mockito.doReturn(Single.just(replicaAddresses.toArray(new AddressInformation[0]))).when(addressResolver).resolveAsync(Mockito.any(RxDocumentServiceRequest.class), Matchers.eq(false)); - - List res = selector.resolveAllUriAsync(request, true, false).toBlocking().value(); - - assertThat(res).isEqualTo(ImmutableList.of(URI.create("https://cosmos1"), URI.create("https://cosmos2"), URI.create("https://cosmos3"))); - } - - @Test(groups = "unit") - public void resolveAddressesAsync() { - IAddressResolver addressResolver = Mockito.mock(IAddressResolver.class); - AddressSelector selector = new AddressSelector(addressResolver, Protocol.Https); - - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); - - List replicaAddresses = new ArrayList<>(); - - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos4", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos5", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos1", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos2", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos3", Protocol.Https)); - - Mockito.doReturn(Single.just(replicaAddresses.toArray(new AddressInformation[0]))).when(addressResolver).resolveAsync(Mockito.any(RxDocumentServiceRequest.class), Matchers.eq(false)); - - List res = selector.resolveAddressesAsync(request, false).toBlocking().value(); - - assertThat(res).isEqualTo(replicaAddresses.stream().filter(a -> a.getProtocolName().equals(Protocol.Https.name())).collect(Collectors.toList())); - } - - @Test(groups = "unit") - public void resolveAllUriAsync_RNTBD() { - IAddressResolver addressResolver = Mockito.mock(IAddressResolver.class); - AddressSelector selector = new AddressSelector(addressResolver, Protocol.Tcp); - - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - Mockito.doReturn(null).when(request).getDefaultReplicaIndex(); - - List replicaAddresses = new ArrayList<>(); - - replicaAddresses.add(new AddressInformation(true, false, "rntbd://cosmos1", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, true, "rntbd://cosmos2", Protocol.Tcp)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos1", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, true, "https://cosmos2", Protocol.Https)); - replicaAddresses.add(new AddressInformation(true, false, "https://cosmos3", Protocol.Https)); - - Mockito.doReturn(Single.just(replicaAddresses.toArray(new AddressInformation[0]))).when(addressResolver).resolveAsync(Mockito.any(RxDocumentServiceRequest.class), Matchers.eq(false)); - - List res = selector.resolveAllUriAsync(request, true, false).toBlocking().value(); - - assertThat(res).isEqualTo(ImmutableList.of(URI.create("rntbd://cosmos1"), URI.create("rntbd://cosmos2"))); - } - -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelectorWrapper.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelectorWrapper.java deleted file mode 100644 index a968ffb24bc2..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressSelectorWrapper.java +++ /dev/null @@ -1,527 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.assertj.core.api.Condition; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import rx.Single; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Function; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; - -public class AddressSelectorWrapper { - - private static String resolveAllUriAsync = "resolveAllUriAsync"; - private static String resolvePrimaryUriAsync = "resolvePrimaryUriAsync"; - private static String resolveAddressesAsync = "resolveAddressesAsync"; - private final List invocationOnMockList; - - public final AddressSelector addressSelector; - - public static class InOrderVerificationBuilder { - private List> actions = new ArrayList<>(); - - public static InOrderVerificationBuilder create() { - return new InOrderVerificationBuilder(); - } - - public InOrderVerificationBuilder verify(InOrderVerification.Verifier v, int index) { - actions.add(verification -> { - verification.verify(v, index); - return null; - }); - return this; - } - - public InOrderVerificationBuilder verifyOnAll(InOrderVerification.Verifier v) { - actions.add(verification -> { - verification.verifyOnAll(v); - return null; - }); - return this; - } - - public InOrderVerificationBuilder verifyNext(InOrderVerification.Verifier v) { - actions.add(verification -> { - verification.verifyNext(v); - return null; - }); - return this; - } - - public InOrderVerificationBuilder verifyNumberOfInvocations(int expected) { - actions.add(verification -> { - verification.verifyNumberOfInvocations(expected); - return null; - }); - return this; - } - - public void execute(AddressSelectorWrapper addressSelectorWrapper) { - InOrderVerification v = new InOrderVerification(addressSelectorWrapper.invocationOnMockList); - for(Function action: actions) { - action.apply(v); - } - } - } - - public InOrderVerification getInOrderVerification() { - return new InOrderVerification(invocationOnMockList); - } - - public static class InOrderVerification { - private final List invocations; - private int internalIndex = 0; - - InOrderVerification(List invocationOnMockList) { - invocations = invocationOnMockList; - } - - public InOrderVerification verify(Verifier v, int index) { - v.verify(invocations.get(index)); - return this; - } - - public InOrderVerification verifyOnAll(Verifier v) { - for(InvocationOnMock i: invocations) { - v.verify(i); - } - return this; - } - - public InOrderVerification verifyNext(Verifier v) { - v.verify(invocations.get(internalIndex++)); - return this; - } - - public InOrderVerification verifyNumberOfInvocations(int expected) { - assertThat(invocations).hasSize(expected); - return this; - } - - interface Verifier { - - void verify(InvocationOnMock invocation); - - public static VerifierBuilder builder() { - return new VerifierBuilder(); - } - - public static class VerifierBuilder { - - public Verifier build() { - return new Verifier() { - @Override - public void verify(InvocationOnMock invocation) { - for(Verifier v: verifiers) { - v.verify(invocation); - } - } - }; - } - - List verifiers = new ArrayList<>(); - - VerifierBuilder add(Verifier verifier) { - verifiers.add(verifier); - return this; - } - - VerifierBuilder methodName(String methodName) { - add(new Verifier() { - @Override - public void verify(InvocationOnMock invocation) { - assertThat(invocation.getMethod().getName()).isEqualTo(methodName); - } - }); - return this; - } - - VerifierBuilder resolveAllUriAsync() { - methodName(resolveAllUriAsync); - return this; - } - - VerifierBuilder resolvePrimaryUriAsync() { - methodName(resolvePrimaryUriAsync); - return this; - } - - VerifierBuilder resolveAddressesAsync() { - methodName(resolveAddressesAsync); - return this; - } - - VerifierBuilder resolveAllUriAsync(Condition requestMatcher, Condition includePrimaryMatcher, Condition forceRefreshMatcher) { - methodName(resolveAllUriAsync); - add(new Verifier() { - @Override - public void verify(InvocationOnMock invocation) { - RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); - boolean includePrimary = invocation.getArgumentAt(1, Boolean.class); - boolean forceRefresh = invocation.getArgumentAt(2, Boolean.class); - - assertThat(request).is(requestMatcher); - - assertThat(includePrimary).is(includePrimaryMatcher); - assertThat(forceRefresh).is(forceRefreshMatcher); - } - }); - return this; - } - - VerifierBuilder resolveAllUriAsync_IncludePrimary(boolean primaryIncluded) { - methodName(resolveAllUriAsync); - - Condition alwaysTrue = new Condition(Predicates.alwaysTrue(), "no condition"); - Condition primaryIncludedCond = new Condition(Predicates.equalTo(primaryIncluded), String.format("%b (primaryIncluded)", primaryIncluded)); - - resolveAllUriAsync(alwaysTrue, primaryIncludedCond, alwaysTrue); - return this; - } - - VerifierBuilder resolveAllUriAsync_ForceRefresh(boolean forceRefresh) { - methodName(resolveAllUriAsync); - - Condition alwaysTrue = new Condition(Predicates.alwaysTrue(), "no condition"); - Condition forceRefreshCond = new Condition(Predicates.equalTo(forceRefresh), String.format("%b (forceRefresh)", forceRefresh)); - - resolveAllUriAsync(alwaysTrue, alwaysTrue, forceRefreshCond); - return this; - } - } - } - } - - public AddressSelectorWrapper(AddressSelector addressSelector, List invocationOnMockList) { - this.addressSelector = addressSelector; - this.invocationOnMockList = invocationOnMockList; - } - - public AddressSelectorWrapper verifyNumberOfForceCachRefresh(int expectedNumber) { - int count = 0; - for (InvocationOnMock invocationOnMock : invocationOnMockList) { - boolean forceRefresh; - if (invocationOnMock.getMethod().getName().endsWith("resolveAllUriAsync")) { - forceRefresh = invocationOnMock.getArgumentAt(2, Boolean.class); - } else { - forceRefresh = invocationOnMock.getArgumentAt(1, Boolean.class); - } - if (forceRefresh) { - count++; - } - } - assertThat(count).isEqualTo(expectedNumber); - return this; - } - - public AddressSelectorWrapper verifyNumberOfForceCacheRefreshGreaterThanOrEqualTo(int minimum) { - int count = 0; - for (InvocationOnMock invocationOnMock : invocationOnMockList) { - boolean forceRefresh; - if (invocationOnMock.getMethod().getName().endsWith("resolveAllUriAsync")) { - forceRefresh = invocationOnMock.getArgumentAt(2, Boolean.class); - } else { - forceRefresh = invocationOnMock.getArgumentAt(1, Boolean.class); - } - if (forceRefresh) { - count++; - } - } - assertThat(count).isGreaterThanOrEqualTo(minimum); - return this; - } - - public AddressSelectorWrapper validate() { - // for now do nothing; - return this; - } - - public AddressSelectorWrapper verifyVesolvePrimaryUriAsyncCount(int count) { - Mockito.verify(addressSelector, Mockito.times(count)).resolvePrimaryUriAsync(Mockito.any(), Mockito.anyBoolean()); - return this; - } - - public AddressSelectorWrapper verifyResolveAddressesAsync(int count) { - Mockito.verify(addressSelector, Mockito.times(count)).resolveAddressesAsync(Mockito.any(), Mockito.anyBoolean()); - return this; - } - - public AddressSelectorWrapper verifyResolveAllUriAsync(int count) { - Mockito.verify(addressSelector, Mockito.times(count)).resolveAllUriAsync(Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean()); - return this; - } - - public AddressSelectorWrapper verifyTotalInvocations(int count) { - assertThat(invocationOnMockList).hasSize(count); - return this; - } - - public static class Builder { - final Protocol protocol; - AddressSelector addressSelector; - List invocationOnMockList = Collections.synchronizedList(new ArrayList<>()); - - - public Builder(Protocol protocol) { - this.protocol = protocol; - } - - public static class PrimaryReplicaMoveBuilder extends Builder { - static PrimaryReplicaMoveBuilder create(Protocol protocol) { - return new PrimaryReplicaMoveBuilder(protocol); - } - - public PrimaryReplicaMoveBuilder(Protocol protocol) { - super(protocol); - addressSelector = Mockito.mock(AddressSelector.class); - } - - public PrimaryReplicaMoveBuilder withPrimaryReplicaMove(URI primaryURIBeforeForceRefresh, URI primaryURIAfterForceRefresh) { - AtomicBoolean refreshed = new AtomicBoolean(false); - Mockito.doAnswer((invocation) -> { - capture(invocation); - RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); - boolean forceRefresh = invocation.getArgumentAt(1, Boolean.class); - - if (forceRefresh || refreshed.get()) { - refreshed.set(true); - return Single.just(primaryURIAfterForceRefresh); - } - - return Single.just(primaryURIBeforeForceRefresh); - }).when(addressSelector).resolvePrimaryUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.anyBoolean()); - - Mockito.doAnswer((invocation -> { - capture(invocation); - return null; - })).when(addressSelector).resolveAllUriAsync(Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean()); - - Mockito.doAnswer((invocation -> { - capture(invocation); - return null; - })).when(addressSelector).resolveAddressesAsync(Mockito.any(), Mockito.anyBoolean()); - - return this; - } - - public AddressSelectorWrapper build() { - return new AddressSelectorWrapper(this.addressSelector, this.invocationOnMockList); - } - } - - public static class ReplicaMoveBuilder extends Builder { - - List> secondary = new ArrayList<>(); - Pair primary; - private Function partitionKeyRangeFunction; - - static ReplicaMoveBuilder create(Protocol protocol) { - return new ReplicaMoveBuilder(protocol); - } - - public ReplicaMoveBuilder(Protocol protocol) { - super(protocol); - addressSelector = Mockito.mock(AddressSelector.class); - } - - public ReplicaMoveBuilder withPrimaryMove(URI uriBeforeForceRefresh, URI uriAfterForceRefresh) { - withReplicaMove(uriBeforeForceRefresh, uriAfterForceRefresh, true); - return this; - } - - public ReplicaMoveBuilder withSecondaryMove(URI uriBeforeForceRefresh, URI uriAfterForceRefresh) { - withReplicaMove(uriBeforeForceRefresh, uriAfterForceRefresh, false); - return this; - } - - public ReplicaMoveBuilder newPartitionKeyRangeIdOnRefresh(Function partitionKeyRangeFunction) { - this.partitionKeyRangeFunction = partitionKeyRangeFunction; - return this; - } - - public ReplicaMoveBuilder withReplicaMove(URI uriBeforeForceRefresh, URI uriAfterForceRefresh, boolean isPrimary) { - if (isPrimary) { - primary = ImmutablePair.of(uriBeforeForceRefresh, uriAfterForceRefresh); - } else { - secondary.add(ImmutablePair.of(uriBeforeForceRefresh, uriAfterForceRefresh)); - } - return this; - } - - - public AddressSelectorWrapper build() { - AtomicBoolean refreshed = new AtomicBoolean(false); - Mockito.doAnswer((invocation) -> { - capture(invocation); - RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); - boolean forceRefresh = invocation.getArgumentAt(1, Boolean.class); - if (partitionKeyRangeFunction != null) { - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeFunction.apply(request); - } - if (forceRefresh || refreshed.get()) { - refreshed.set(true); - return Single.just(primary.getRight()); - } else { - return Single.just(primary.getLeft()); - } - - }).when(addressSelector).resolvePrimaryUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.anyBoolean()); - - Mockito.doAnswer((invocation -> { - capture(invocation); - RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); - boolean includePrimary = invocation.getArgumentAt(1, Boolean.class); - boolean forceRefresh = invocation.getArgumentAt(2, Boolean.class); - - ImmutableList.Builder b = ImmutableList.builder(); - - if (forceRefresh || refreshed.get()) { - if (partitionKeyRangeFunction != null) { - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeFunction.apply(request); - } - refreshed.set(true); - if (includePrimary) { - b.add(primary.getRight()); - } - b.addAll(secondary.stream().map(s -> s.getRight()).collect(Collectors.toList())); - return Single.just(b.build()); - } else { - // old - if (includePrimary) { - b.add(primary.getLeft()); - } - b.addAll(secondary.stream().map(s -> s.getLeft()).collect(Collectors.toList())); - return Single.just(b.build()); - } - - })).when(addressSelector).resolveAllUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.anyBoolean(), Mockito.anyBoolean()); - - Mockito.doAnswer((invocation -> { - capture(invocation); - RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); - boolean forceRefresh = invocation.getArgumentAt(1, Boolean.class); - - ImmutableList.Builder b = ImmutableList.builder(); - - if (forceRefresh || refreshed.get()) { - if (partitionKeyRangeFunction != null) { - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeFunction.apply(request); - } - - refreshed.set(true); - b.add(primary.getRight()); - b.addAll(secondary.stream().map(s -> s.getRight()).collect(Collectors.toList())); - return Single.just(b.build()); - } else { - // old - b.add(primary.getLeft()); - b.addAll(secondary.stream().map(s -> s.getLeft()).collect(Collectors.toList())); - return Single.just(b.build()); - } - })).when(addressSelector).resolveAddressesAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.anyBoolean()); - - return new AddressSelectorWrapper(addressSelector, invocationOnMockList); - } - } - - public static class Simple extends Builder { - private URI primaryAddress; - private List secondaryAddresses; - static Simple create() { - return new Simple(Protocol.Https); - } - - public Simple(Protocol protocol) { - super(protocol); - addressSelector = Mockito.mock(AddressSelector.class); - } - - public Simple withPrimary(URI primaryAddress) { - this.primaryAddress = primaryAddress; - return this; - } - - public Simple withSecondary(List secondaryAddresses) { - this.secondaryAddresses = secondaryAddresses; - return this; - } - - public AddressSelectorWrapper build() { - Mockito.doAnswer((invocation) -> { - capture(invocation); - return Single.just(primaryAddress); - }).when(addressSelector).resolvePrimaryUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.anyBoolean()); - - Mockito.doAnswer((invocation -> { - capture(invocation); - RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); - boolean includePrimary = invocation.getArgumentAt(1, Boolean.class); - boolean forceRefresh = invocation.getArgumentAt(2, Boolean.class); - - if (includePrimary) { - return Single.just(ImmutableList.builder().addAll(secondaryAddresses).add(primaryAddress).build()); - } else { - return Single.just(secondaryAddresses); - } - })).when(addressSelector).resolveAllUriAsync(Mockito.any(), Mockito.anyBoolean(), Mockito.anyBoolean()); - - Mockito.doAnswer((invocation -> { - capture(invocation); - return Single.just(ImmutableList.builder() - .addAll(secondaryAddresses.stream() - .map(uri -> toAddressInformation(uri, false, protocol)) - .collect(Collectors.toList())) - .add(toAddressInformation(primaryAddress, true, protocol)) - .build()); - })).when(addressSelector).resolveAddressesAsync(Mockito.any(), Mockito.anyBoolean()); - - - return new AddressSelectorWrapper(this.addressSelector, this.invocationOnMockList); - } - - private AddressInformation toAddressInformation(URI uri, boolean isPrimary, Protocol protocol) { - return new AddressInformation(true, isPrimary, uri.toString(), protocol); - } - } - - protected void capture(InvocationOnMock invocationOnMock) { - invocationOnMockList.add(invocationOnMock); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReaderTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReaderTest.java deleted file mode 100644 index 36c3795fe961..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReaderTest.java +++ /dev/null @@ -1,782 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.VectorSessionToken; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.mockito.Mockito; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.net.URI; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; -import static org.assertj.core.api.Assertions.assertThat; - -public class ConsistencyReaderTest { - private final Configs configs = new Configs(); - private static final int TIMEOUT = 30000; - @DataProvider(name = "deduceReadModeArgProvider") - public Object[][] deduceReadModeArgProvider() { - return new Object[][]{ - // account consistency, request consistency, expected readmode, expected consistency to use, whether use session - { ConsistencyLevel.Strong, null, ReadMode.Strong, ConsistencyLevel.Strong, false}, - { ConsistencyLevel.Strong, ConsistencyLevel.Eventual, ReadMode.Any, ConsistencyLevel.Eventual, false}, - { ConsistencyLevel.Strong, ConsistencyLevel.Session, ReadMode.Any, ConsistencyLevel.Session, true}, - { ConsistencyLevel.Session, ConsistencyLevel.Eventual, ReadMode.Any, ConsistencyLevel.Eventual, false}, - { ConsistencyLevel.Session, ConsistencyLevel.Session, ReadMode.Any, ConsistencyLevel.Session, true}, - { ConsistencyLevel.Session, ConsistencyLevel.Eventual, ReadMode.Any, ConsistencyLevel.Eventual, false}, - { ConsistencyLevel.Session, null, ReadMode.Any, ConsistencyLevel.Session, true}, - { ConsistencyLevel.Eventual, ConsistencyLevel.Eventual, ReadMode.Any, ConsistencyLevel.Eventual, false}, - { ConsistencyLevel.Eventual, null, ReadMode.Any, ConsistencyLevel.Eventual, false}, - }; - } - - @Test(groups = "unit", dataProvider = "deduceReadModeArgProvider") - public void deduceReadMode(ConsistencyLevel accountConsistencyLevel, ConsistencyLevel requestConsistency, ReadMode expectedReadMode, - ConsistencyLevel expectedConsistencyToUse, boolean expectedToUseSession) throws DocumentClientException { - AddressSelector addressSelector = Mockito.mock(AddressSelector.class); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - TransportClient transportClient = Mockito.mock(TransportClient.class); - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(accountConsistencyLevel); - IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReader consistencyReader = new ConsistencyReader(configs, - addressSelector, - sessionContainer, - transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authorizationTokenProvider); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - if (requestConsistency != null) { - request.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, requestConsistency.name()); - } - - ValueHolder consistencyLevel = ValueHolder.initialize(null); - ValueHolder useSession = ValueHolder.initialize(null); - - ReadMode readMode = consistencyReader.deduceReadMode(request, consistencyLevel, useSession); - - assertThat(readMode).isEqualTo(expectedReadMode); - assertThat(consistencyLevel.v).isEqualTo(expectedConsistencyToUse); - assertThat(useSession.v).isEqualTo(expectedToUseSession); - } - - @DataProvider(name = "getMaxReplicaSetSizeArgProvider") - public Object[][] getMaxReplicaSetSizeArgProvider() { - return new Object[][]{ - // system max replica count, system min replica count, user max replica count, user min replica, is reading from master operation - { 4, 3, 4, 3, false }, - { 4, 3, 4, 3, true }, - - { 4, 3, 3, 2, false }, - { 4, 3, 3, 2, true } - }; - } - - @Test(groups = "unit", dataProvider = "getMaxReplicaSetSizeArgProvider") - public void replicaSizes(int systemMaxReplicaCount, - int systemMinReplicaCount, - int userMaxReplicaCount, - int userMinReplicaCount, - boolean isReadingFromMasterOperation) { - AddressSelector addressSelector = Mockito.mock(AddressSelector.class); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - TransportClient transportClient = Mockito.mock(TransportClient.class); - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong, - systemMaxReplicaCount, - systemMinReplicaCount, - userMaxReplicaCount, - userMinReplicaCount); - IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReader consistencyReader = new ConsistencyReader(configs, - addressSelector, - sessionContainer, - transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authorizationTokenProvider); - - RxDocumentServiceRequest request; - if (isReadingFromMasterOperation) { - request = RxDocumentServiceRequest.createFromName( - OperationType.ReadFeed, "/dbs/db/colls/col", ResourceType.DocumentCollection); - } else { - request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - } - - assertThat(consistencyReader.getMaxReplicaSetSize(request)).isEqualTo(isReadingFromMasterOperation? systemMaxReplicaCount : userMaxReplicaCount); - assertThat(consistencyReader.getMinReplicaSetSize(request)).isEqualTo(isReadingFromMasterOperation? systemMinReplicaCount : userMinReplicaCount); - } - - @Test(groups = "unit") - public void readAny() { - List secondaries = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2"), URI.create("secondary3")); - URI primaryAddress = URI.create("primary"); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryAddress) - .withSecondary(secondaries) - .build(); - - StoreResponse primaryResponse = StoreResponseBuilder.create() - .withLSN(54) - .withLocalLSN(18) - .withRequestCharge(1.1) - .build(); - StoreResponse secondaryResponse1 = StoreResponseBuilder.create() - .withLSN(53) - .withLocalLSN(17) - .withRequestCharge(1.1) - .build(); - StoreResponse secondaryResponse2 = StoreResponseBuilder.create() - .withLSN(52) - .withLocalLSN(16) - .withRequestCharge(1.1) - .build(); - StoreResponse secondaryResponse3 = StoreResponseBuilder.create() - .withLSN(51) - .withLocalLSN(15) - .withRequestCharge(1.1) - .build(); - TransportClientWrapper transportClientWrapper = TransportClientWrapper.Builder.uriToResultBuilder() - .storeResponseOn(primaryAddress, OperationType.Read, ResourceType.Document, primaryResponse, true) - .storeResponseOn(secondaries.get(0), OperationType.Read, ResourceType.Document, secondaryResponse1, true) - .storeResponseOn(secondaries.get(1), OperationType.Read, ResourceType.Document, secondaryResponse2, true) - .storeResponseOn(secondaries.get(2), OperationType.Read, ResourceType.Document, secondaryResponse3, true) - .build(); - - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReaderUnderTest consistencyReader = new ConsistencyReaderUnderTest(addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authorizationTokenProvider); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - request.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Eventual.name()); - - TimeoutHelper timeout = Mockito.mock(TimeoutHelper.class); - boolean forceRefresh = false; - boolean isInRetry = false; - Single storeResponseSingle = consistencyReader.readAsync(request, timeout, isInRetry, forceRefresh); - - StoreResponseValidator validator = StoreResponseValidator.create() - .withBELSNGreaterThanOrEqualTo(51) - .withRequestCharge(1.1) - .in(primaryResponse, secondaryResponse1, secondaryResponse2, secondaryResponse3) - .build(); - validateSuccess(storeResponseSingle, validator); - - Mockito.verifyZeroInteractions(consistencyReader.getSpyQuorumReader()); - - - Mockito.verify(consistencyReader.getSpyStoreReader(), Mockito.times(1)) - .readMultipleReplicaAsync(Mockito.any(RxDocumentServiceRequest.class), - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyBoolean(), - Mockito.anyBoolean(), - Mockito.any(), - Mockito.anyBoolean(), - Mockito.anyBoolean()); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(1); - - addressSelectorWrapper.validate() - .verifyTotalInvocations(1) - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyResolveAllUriAsync(1); - } - - @Test(groups = "unit") - public void readSessionConsistency_SomeReplicasLagBehindAndReturningResponseWithLowerLSN_FindAnotherReplica() { - long slowReplicaLSN = 651176; - String partitionKeyRangeId = "1"; - long fasterReplicaLSN = 651177; - - List secondaries = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2"), URI.create("secondary3")); - URI primaryAddress = URI.create("primary"); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryAddress) - .withSecondary(secondaries) - .build(); - - StoreResponse primaryResponse = StoreResponseBuilder.create() - .withSessionToken(partitionKeyRangeId + ":-1#" + slowReplicaLSN) - .withLSN(slowReplicaLSN) - .withLocalLSN(slowReplicaLSN) - .withQuorumAckecdLsn(slowReplicaLSN) - .withQuorumAckecdLocalLsn(slowReplicaLSN) - .withGlobalCommittedLsn(-1) - .withItemLocalLSN(slowReplicaLSN) - .withRequestCharge(1.1) - .build(); - StoreResponse secondaryResponse1 = StoreResponseBuilder.create() - .withSessionToken(partitionKeyRangeId + ":-1#" + slowReplicaLSN) - .withLSN(slowReplicaLSN) - .withLocalLSN(slowReplicaLSN) - .withQuorumAckecdLsn(slowReplicaLSN) - .withQuorumAckecdLocalLsn(slowReplicaLSN) - .withGlobalCommittedLsn(-1) - .withItemLocalLSN(slowReplicaLSN) - .withRequestCharge(1.1) - .build(); - StoreResponse secondaryResponse2 = StoreResponseBuilder.create() - .withSessionToken(partitionKeyRangeId + ":-1#" + fasterReplicaLSN) - .withLSN(fasterReplicaLSN) - .withLocalLSN(fasterReplicaLSN) - .withQuorumAckecdLsn(fasterReplicaLSN) - .withQuorumAckecdLocalLsn(fasterReplicaLSN) - .withGlobalCommittedLsn(-1) - .withItemLocalLSN(fasterReplicaLSN) - .withRequestCharge(1.1) - .build(); - StoreResponse secondaryResponse3 = StoreResponseBuilder.create() - .withSessionToken(partitionKeyRangeId + ":-1#" + slowReplicaLSN) - .withLSN(slowReplicaLSN) - .withLocalLSN(slowReplicaLSN) - .withQuorumAckecdLsn(slowReplicaLSN) - .withQuorumAckecdLocalLsn(slowReplicaLSN) - .withGlobalCommittedLsn(-1) - .withItemLocalLSN(slowReplicaLSN) - .withRequestCharge(1.1) - .build(); - TransportClientWrapper transportClientWrapper = TransportClientWrapper.Builder.uriToResultBuilder() - .storeResponseOn(primaryAddress, OperationType.Read, ResourceType.Document, primaryResponse, true) - .storeResponseOn(secondaries.get(0), OperationType.Read, ResourceType.Document, secondaryResponse1, true) - .storeResponseOn(secondaries.get(1), OperationType.Read, ResourceType.Document, secondaryResponse2, true) - .storeResponseOn(secondaries.get(2), OperationType.Read, ResourceType.Document, secondaryResponse3, true) - .build(); - - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReaderUnderTest consistencyReader = new ConsistencyReaderUnderTest(addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authorizationTokenProvider); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - request.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - request.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - assertThat(VectorSessionToken.tryCreate("-1#" + fasterReplicaLSN , sessionToken)).isTrue(); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(request), Mockito.anyString()); - - - TimeoutHelper timeout = Mockito.mock(TimeoutHelper.class); - boolean forceRefresh = false; - boolean isInRetry = false; - Single storeResponseSingle = consistencyReader.readAsync(request, timeout, isInRetry, forceRefresh); - - StoreResponseValidator validator = StoreResponseValidator.create() - .withBELSN(fasterReplicaLSN) - .withRequestChargeGreaterThanOrEqualTo(1.1) - .in(primaryResponse, secondaryResponse1, secondaryResponse2, secondaryResponse3) - .build(); - validateSuccess(storeResponseSingle, validator); - - Mockito.verifyZeroInteractions(consistencyReader.getSpyQuorumReader()); - - - Mockito.verify(consistencyReader.getSpyStoreReader(), Mockito.times(1)) - .readMultipleReplicaAsync(Mockito.any(RxDocumentServiceRequest.class), - Mockito.anyBoolean(), - Mockito.anyInt(), - Mockito.anyBoolean(), - Mockito.anyBoolean(), - Mockito.any(), - Mockito.anyBoolean(), - Mockito.anyBoolean()); - - assertThat(transportClientWrapper.validate() - .getNumberOfInvocations()) - .isGreaterThanOrEqualTo(1) - .isLessThanOrEqualTo(4); - - addressSelectorWrapper.validate() - .verifyTotalInvocations(1) - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyResolveAllUriAsync(1); - } - - /** - * reading in session consistency, if the requested session token cannot be supported by some replicas - * tries others till we find a replica which can support the given session token - */ - @Test(groups = "unit") - public void sessionNotAvailableFromSomeReplicasThrowingNotFound_FindReplicaSatisfyingRequestedSession() { - long slowReplicaLSN = 651175; - long globalCommittedLsn = 651174; - - long fasterReplicaLSN = 651176; - String partitionKeyRangeId = "1"; - - NotFoundException foundException = new NotFoundException(); - foundException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + slowReplicaLSN); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LSN, Long.toString(slowReplicaLSN)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(slowReplicaLSN)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - - StoreResponse storeResponse = StoreResponseBuilder.create() - .withSessionToken(partitionKeyRangeId + ":-1#" + fasterReplicaLSN) - .withLSN(fasterReplicaLSN) - .withLocalLSN(fasterReplicaLSN) - .withQuorumAckecdLsn(fasterReplicaLSN) - .withQuorumAckecdLocalLsn(fasterReplicaLSN) - .withGlobalCommittedLsn(-1) - .withItemLocalLSN(fasterReplicaLSN) - .withRequestCharge(1.1) - .build(); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(foundException) // 1st replica read returns not found - .then(foundException) // 2nd replica read returns not found - .then(foundException) // 3rd replica read returns not found - .then(storeResponse) // 4th replica read returns storeResponse satisfying requested session token - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - Configs configs = new Configs(); - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong, - 4, - 3, - 4, - 3); - - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReader consistencyReader = new ConsistencyReader(configs, - addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authTokenProvider); - - - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - assertThat(VectorSessionToken.tryCreate("-1#" + fasterReplicaLSN , sessionToken)).isTrue(); - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Single storeResponseSingle = consistencyReader.readAsync(dsr, timeoutHelper, false, false); - - StoreResponseValidator validator = StoreResponseValidator.create().isSameAs(storeResponse).isSameAs(storeResponse).build(); - validateSuccess(storeResponseSingle, validator); - } - - /** - * Reading with session consistency, replicas have session token with higher than requested and return not found - */ - @Test(groups = "unit") - public void sessionRead_LegitimateNotFound() { - long lsn = 651175; - long globalCommittedLsn = 651174; - String partitionKeyRangeId = "73"; - - NotFoundException foundException = new NotFoundException(); - foundException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + lsn); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LSN, Long.toString(lsn)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(lsn)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(foundException) // 1st replica read returns not found lsn(response) >= lsn(request) - .then(foundException) // 2nd replica read returns not found lsn(response) >= lsn(request) - .then(foundException) // 3rd replica read returns not found lsn(response) >= lsn(request) - .then(foundException) // 4th replica read returns not found lsn(response) >= lsn(request) - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - assertThat(VectorSessionToken.tryCreate("-1#" + lsn , sessionToken)).isTrue(); - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Configs configs = new Configs(); - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong, - 4, - 3, - 4, - 3); - - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReader consistencyReader = new ConsistencyReader(configs, - addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authTokenProvider); - - Single storeResponseSingle = consistencyReader.readAsync(dsr, timeoutHelper, false, false); - - FailureValidator failureValidator = FailureValidator.builder().resourceNotFound().instanceOf(NotFoundException.class).unknownSubStatusCode().build(); - validateException(storeResponseSingle, failureValidator); - } - - /** - * reading in session consistency, no replica support requested lsn - */ - @Test(groups = "unit") - public void sessionRead_ReplicasDoNotHaveTheRequestedLSN() { - long lsn = 651175; - long globalCommittedLsn = 651174; - String partitionKeyRangeId = "73"; - NotFoundException foundException = new NotFoundException(); - foundException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + lsn); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LSN, Long.toString(651175)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(651175)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(foundException) // 1st replica read lsn lags behind the request lsn - .then(foundException) // 2nd replica read lsn lags behind the request lsn - .then(foundException) // 3rd replica read lsn lags behind the request lsn - .then(foundException) // 4th replica read lsn lags behind the request lsn - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - assertThat(VectorSessionToken.tryCreate("-1#" + (lsn + 1) , sessionToken)).isTrue(); - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Configs configs = new Configs(); - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong, - 4, - 3, - 4, - 3); - - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReader consistencyReader = new ConsistencyReader(configs, - addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authTokenProvider); - - Single storeResponseSingle = consistencyReader.readAsync(dsr, timeoutHelper, false, false); - - FailureValidator failureValidator = FailureValidator.builder().resourceNotFound().instanceOf(NotFoundException.class).subStatusCode(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE).build(); - validateException(storeResponseSingle, failureValidator); - } - - @Test(groups = "unit") - public void requestRateTooLarge_BubbleUp() { - long lsn = 651175; - long globalCommittedLsn = 651174; - String partitionKeyRangeId = "73"; - - RequestRateTooLargeException requestTooLargeException = new RequestRateTooLargeException(); - requestTooLargeException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + lsn); - requestTooLargeException.getResponseHeaders().put(WFConstants.BackendHeaders.LSN, Long.toString(651175)); - requestTooLargeException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(651175)); - requestTooLargeException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(requestTooLargeException) // 1st replica read result in throttling - .then(requestTooLargeException) // 2nd replica read result in throttling - .then(requestTooLargeException) // 3rd replica read result in throttling - .then(requestTooLargeException) // 4th replica read result in throttling - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - assertThat(VectorSessionToken.tryCreate("-1#" + lsn , sessionToken)).isTrue(); - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Configs configs = new Configs(); - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong, - 4, - 3, - 4, - 3); - - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ConsistencyReader consistencyReader = new ConsistencyReader(configs, - addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authTokenProvider); - - Single storeResponseSingle = consistencyReader.readAsync(dsr, timeoutHelper, false, false); - - - FailureValidator failureValidator = FailureValidator.builder().instanceOf(RequestRateTooLargeException.class).unknownSubStatusCode().build(); - validateException(storeResponseSingle, failureValidator); - } - - @DataProvider(name = "simpleReadStrongArgProvider") - public Object[][] simpleReadStrongArgProvider() { - return new Object[][]{ - { 1, ReadMode.Strong }, - { 2, ReadMode.Strong }, - { 3, ReadMode.Strong }, - }; - } - - @Test(groups = "unit", dataProvider = "simpleReadStrongArgProvider") - public void basicReadStrong_AllReplicasSameLSN(int replicaCountToRead, ReadMode readMode) { - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - URI primaryReplicaURI = URI.create("primary"); - ImmutableList secondaryReplicaURIs = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2"), URI.create("secondary3")); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryReplicaURI) - .withSecondary(secondaryReplicaURIs) - .build(); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = new DocumentServiceRequestContext(); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = Mockito.mock(PartitionKeyRange.class); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - BigDecimal requestChargePerRead = new BigDecimal(1.1); - - StoreResponse primaryResponse = StoreResponseBuilder.create() - .withLSN(51) - .withLocalLSN(18) - .withRequestCharge(requestChargePerRead.doubleValue()) - .build(); - StoreResponse secondaryResponse1 = StoreResponseBuilder.create() - .withLSN(51) - .withLocalLSN(18) - .withRequestCharge(requestChargePerRead.doubleValue()) - .build(); - StoreResponse secondaryResponse2 = StoreResponseBuilder.create() - .withLSN(51) - .withLocalLSN(18) - .withRequestCharge(requestChargePerRead.doubleValue()) - .build(); - StoreResponse secondaryResponse3 = StoreResponseBuilder.create() - .withLSN(51) - .withLocalLSN(18) - .withRequestCharge(requestChargePerRead.doubleValue()) - .build(); - - TransportClientWrapper transportClientWrapper = TransportClientWrapper.Builder.uriToResultBuilder() - .storeResponseOn(primaryReplicaURI, OperationType.Read, ResourceType.Document, primaryResponse, false) - .storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, secondaryResponse1, false) - .storeResponseOn(secondaryReplicaURIs.get(1), OperationType.Read, ResourceType.Document, secondaryResponse2, false) - .storeResponseOn(secondaryReplicaURIs.get(2), OperationType.Read, ResourceType.Document, secondaryResponse3, false) - .build(); - - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - GatewayServiceConfigurationReader serviceConfigurator = Mockito.mock(GatewayServiceConfigurationReader.class); - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - QuorumReader quorumReader = new QuorumReader(configs, transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, storeReader, serviceConfigurator, authTokenProvider); - - Single storeResponseSingle = quorumReader.readStrongAsync(request, replicaCountToRead, readMode); - - StoreResponseValidator validator = StoreResponseValidator.create() - .withBELSN(51) - .withRequestCharge(requestChargePerRead.multiply(BigDecimal.valueOf(replicaCountToRead)).setScale(2, RoundingMode.FLOOR).doubleValue()) - .build(); - validateSuccess(storeResponseSingle, validator); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(replicaCountToRead); - addressSelectorWrapper.validate() - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyTotalInvocations(1); - } - - // TODO: add more mocking tests for when one replica lags behind and we need to do barrier request. - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator, - long timeout) { - TestSubscriber> testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public static void validateSuccess(Single single, - StoreResponseValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single single, - StoreResponseValidator validator, - long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - - public static void validateException(Single single, - FailureValidator validator, - long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - public static void validateException(Single single, - FailureValidator validator) { - validateException(single, validator, TIMEOUT); - } - - private PartitionKeyRange partitionKeyRangeWithId(String id) { - PartitionKeyRange partitionKeyRange = Mockito.mock(PartitionKeyRange.class); - Mockito.doReturn(id).when(partitionKeyRange).getId(); - return partitionKeyRange; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReaderUnderTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReaderUnderTest.java deleted file mode 100644 index 4f35b9c0e973..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyReaderUnderTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import org.mockito.Mockito; - -public class ConsistencyReaderUnderTest extends ConsistencyReader { - private QuorumReader origQuorumReader; - private QuorumReader spyQuorumReader; - - private StoreReaderUnderTest origStoreReader; - private StoreReaderUnderTest spyStoreReader; - - public ConsistencyReaderUnderTest(AddressSelector addressSelector, - ISessionContainer sessionContainer, - TransportClient transportClient, - GatewayServiceConfigurationReader serviceConfigReader, - IAuthorizationTokenProvider authorizationTokenProvider) { - super(new Configs(), addressSelector, sessionContainer, transportClient, serviceConfigReader, authorizationTokenProvider); - - } - - public QuorumReader getOrigQuorumReader() { - return origQuorumReader; - } - - public QuorumReader getSpyQuorumReader() { - return spyQuorumReader; - } - - public StoreReaderUnderTest getOrigStoreReader() { - return origStoreReader; - } - - public StoreReaderUnderTest getSpyStoreReader() { - return spyStoreReader; - } - - @Override - QuorumReader createQuorumReader(TransportClient transportClient, - AddressSelector addressSelector, - StoreReader storeReader, - GatewayServiceConfigurationReader serviceConfigurationReader, - IAuthorizationTokenProvider authorizationTokenProvider) { - this.origQuorumReader = super.createQuorumReader(transportClient, - addressSelector, - storeReader, - serviceConfigurationReader, - authorizationTokenProvider); - this.spyQuorumReader = Mockito.spy(this.origQuorumReader); - return this.spyQuorumReader; - } - - @Override - StoreReader createStoreReader(TransportClient transportClient, - AddressSelector addressSelector, - ISessionContainer sessionContainer) { - this.origStoreReader = new StoreReaderUnderTest(transportClient, addressSelector, sessionContainer); - this.spyStoreReader = Mockito.spy(this.origStoreReader); - return this.spyStoreReader; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriterTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriterTest.java deleted file mode 100644 index 02f5b97aef37..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ConsistencyWriterTest.java +++ /dev/null @@ -1,297 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; -import rx.subjects.PublishSubject; - -import java.net.URI; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.TimeUnit; - -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.StatusCodes.GONE; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes.COMPLETING_PARTITION_MIGRATION; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes.COMPLETING_SPLIT; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE; -import static org.assertj.core.api.Assertions.assertThat; - -public class ConsistencyWriterTest { - - private AddressSelector addressSelector; - private ISessionContainer sessionContainer; - private TransportClient transportClient; - private GatewayServiceConfigurationReader serviceConfigReader; - private ConsistencyWriter consistencyWriter; - - @DataProvider(name = "exceptionArgProvider") - public Object[][] exceptionArgProvider() { - return new Object[][]{ - // exception to be thrown from transportClient, expected (exception type, status, subStatus) - { new PartitionKeyRangeGoneException(), PartitionKeyRangeGoneException.class, GONE, PARTITION_KEY_RANGE_GONE, }, - { new PartitionKeyRangeIsSplittingException() , PartitionKeyRangeIsSplittingException.class, GONE, COMPLETING_SPLIT, }, - { new PartitionIsMigratingException(), PartitionIsMigratingException.class, GONE, COMPLETING_PARTITION_MIGRATION, }, - }; - } - - @Test(groups = "unit", dataProvider = "exceptionArgProvider") - public void exception(Exception ex, Class klass, int expectedStatusCode, Integer expectedSubStatusCode) { - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(ex) - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - sessionContainer = Mockito.mock(ISessionContainer.class); - IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - serviceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - - consistencyWriter = new ConsistencyWriter( - addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - authorizationTokenProvider, - serviceConfigReader, - false); - - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = Mockito.mock(RxDocumentServiceRequest.class); - dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - - Single res = consistencyWriter.writeAsync(dsr, timeoutHelper, false); - - FailureValidator failureValidator = FailureValidator.builder() - .instanceOf(klass) - .statusCode(expectedStatusCode) - .subStatusCode(expectedSubStatusCode) - .build(); - - TestSubscriber subscriber = new TestSubscriber<>(); - res.subscribe(subscriber); - subscriber.awaitTerminalEvent(); - subscriber.assertNotCompleted(); - assertThat(subscriber.getOnErrorEvents()).hasSize(1); - failureValidator.validate(subscriber.getOnErrorEvents().get(0)); - } - - @Test(groups = "unit") - public void startBackgroundAddressRefresh() throws Exception { - initializeConsistencyWriter(false); - - CyclicBarrier b = new CyclicBarrier(2); - PublishSubject subject = PublishSubject.create(); - CountDownLatch c = new CountDownLatch(1); - - URI uri = URI.create("https://localhost:5050"); - - List invocationOnMocks = Collections.synchronizedList(new ArrayList<>()); - Mockito.doAnswer(new Answer() { - @Override - public Single answer(InvocationOnMock invocationOnMock) { - invocationOnMocks.add(invocationOnMock); - return subject.toSingle().doOnSuccess(x -> c.countDown()).doAfterTerminate(() -> { - new Thread() { - @Override - public void run() { - try { - b.await(); - } catch (Exception e) { - - } - } - }.start(); - }); - } - }).when(addressSelector).resolvePrimaryUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.anyBoolean()); - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - consistencyWriter.startBackgroundAddressRefresh(request); - - subject.onNext(uri); - subject.onCompleted(); - - TimeUnit.MILLISECONDS.sleep(1000); - assertThat(c.getCount()).isEqualTo(0); - assertThat(b.getNumberWaiting()).isEqualTo(1); - b.await(1000, TimeUnit.MILLISECONDS); - assertThat(invocationOnMocks).hasSize(1); - assertThat(invocationOnMocks.get(0).getArgumentAt(1, Boolean.class)).isTrue(); - } - - @Test(groups = "unit") - public void getLsnAndGlobalCommittedLsn() { - ImmutableList.Builder> builder = new ImmutableList.Builder<>(); - builder.add(new AbstractMap.SimpleEntry<>(WFConstants.BackendHeaders.LSN, "3")); - builder.add(new AbstractMap.SimpleEntry<>(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "2")); - ImmutableList> headers = builder.build(); - - StoreResponse sr = new StoreResponse(0, headers, (String) null); - Utils.ValueHolder lsn = Utils.ValueHolder.initialize(-2l); - Utils.ValueHolder globalCommittedLsn = Utils.ValueHolder.initialize(-2l); - ConsistencyWriter.getLsnAndGlobalCommittedLsn(sr, lsn, globalCommittedLsn); - assertThat(lsn.v).isEqualTo(3); - assertThat(globalCommittedLsn.v).isEqualTo(2); - } - - - @Test(groups = "unit") - public void timeout1() throws Exception { - initializeConsistencyWriter(false); - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - Mockito.doReturn(true).when(timeoutHelper).isElapsed(); - ConsistencyWriter spyConsistencyWriter = Mockito.spy(this.consistencyWriter); - TestSubscriber subscriber = new TestSubscriber(); - - spyConsistencyWriter.writeAsync(Mockito.mock(RxDocumentServiceRequest.class), timeoutHelper, false) - .toObservable() - .subscribe(subscriber); - - subscriber.awaitTerminalEvent(10, TimeUnit.MILLISECONDS); - subscriber.assertNoValues(); - - subscriber.assertError(RequestTimeoutException.class); - } - - @Test(groups = "unit") - public void timeout2() throws Exception { - initializeConsistencyWriter(false); - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - Mockito.doReturn(false).doReturn(true).when(timeoutHelper).isElapsed(); - ConsistencyWriter spyConsistencyWriter = Mockito.spy(this.consistencyWriter); - TestSubscriber subscriber = new TestSubscriber(); - - spyConsistencyWriter.writeAsync(Mockito.mock(RxDocumentServiceRequest.class), timeoutHelper, false) - .toObservable() - .subscribe(subscriber); - - subscriber.awaitTerminalEvent(10, TimeUnit.MILLISECONDS); - subscriber.assertError(RequestTimeoutException.class); - } - - @DataProvider(name = "globalStrongArgProvider") - public Object[][] globalStrongArgProvider() { - return new Object[][]{ - { - ConsistencyLevel.Session, - Mockito.mock(RxDocumentServiceRequest.class), - Mockito.mock(StoreResponse.class), - - false, - }, - { - ConsistencyLevel.Eventual, - Mockito.mock(RxDocumentServiceRequest.class), - Mockito.mock(StoreResponse.class), - - false, - }, - { - - ConsistencyLevel.Eventual, - Mockito.mock(RxDocumentServiceRequest.class), - StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, Integer.toString(5)) - .build(), - false, - }, - { - - ConsistencyLevel.Strong, - Mockito.mock(RxDocumentServiceRequest.class), - StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, Integer.toString(5)) - .build(), - true, - }, - { - - ConsistencyLevel.Strong, - Mockito.mock(RxDocumentServiceRequest.class), - StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, Integer.toString(0)) - .build(), - false, - } - }; - } - - @Test(groups = "unit", dataProvider = "globalStrongArgProvider") - public void isGlobalStrongRequest(ConsistencyLevel defaultConsistencyLevel, RxDocumentServiceRequest req, StoreResponse storeResponse, boolean isGlobalStrongExpected) { - initializeConsistencyWriter(false); - Mockito.doReturn(defaultConsistencyLevel).when(this.serviceConfigReader).getDefaultConsistencyLevel(); - - - assertThat(consistencyWriter.isGlobalStrongRequest(req, storeResponse)).isEqualTo(isGlobalStrongExpected); - } - - private void initializeConsistencyWriter(boolean useMultipleWriteLocation) { - addressSelector = Mockito.mock(AddressSelector.class); - sessionContainer = Mockito.mock(ISessionContainer.class); - transportClient = Mockito.mock(TransportClient.class); - IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - serviceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - - consistencyWriter = new ConsistencyWriter( - addressSelector, - sessionContainer, - transportClient, - authorizationTokenProvider, - serviceConfigReader, - useMultipleWriteLocation); - } - - // TODO: add more mocking unit tests for Global Strong (mocking unit tests) - // TODO: add more tests for Session behaviour (mocking unit tests) - // TODO: add more tests for error handling behaviour (mocking unit tests) - // TODO: add tests for replica catch up (request barrier while loop) (mocking unit tests) - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/320977 -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/EndpointMock.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/EndpointMock.java deleted file mode 100644 index d2d709b3bb18..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/EndpointMock.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.apache.commons.collections.map.HashedMap; - -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -abstract public class EndpointMock { - - TransportClientWrapper transportClientWrapper; - AddressSelectorWrapper addressSelectorWrapper; - - public EndpointMock(AddressSelectorWrapper addressSelectorWrapper, TransportClientWrapper transportClientWrapper) { - this.addressSelectorWrapper = addressSelectorWrapper; - this.transportClientWrapper = transportClientWrapper; - } - - public static class EndpointMockVerificationBuilder { - public static EndpointMockVerificationBuilder builder() { - return new EndpointMockVerificationBuilder(); - } - - private AddressSelectorWrapper.InOrderVerificationBuilder addressSelectorVerificationBuilder; - private TransportClientWrapper.TransportClientWrapperVerificationBuilder transportClientValidation; - - public EndpointMockVerificationBuilder withAddressSelectorValidation(AddressSelectorWrapper.InOrderVerificationBuilder addressSelectorBuilder) { - addressSelectorVerificationBuilder = addressSelectorBuilder; - return this; - } - - public EndpointMockVerificationBuilder withTransportClientValidation(TransportClientWrapper.TransportClientWrapperVerificationBuilder transportClientValidation) { - this.transportClientValidation = transportClientValidation; - return this; - } - - public void execute(EndpointMock endpointMock) { - this.addressSelectorVerificationBuilder.execute(endpointMock.addressSelectorWrapper); - this.transportClientValidation.execute(endpointMock.transportClientWrapper); - } - } - - - public void validate(EndpointMockVerificationBuilder verificationBuilder) { - this.addressSelectorWrapper.validate(); - this.transportClientWrapper.validate(); - if (verificationBuilder != null) { - verificationBuilder.execute(this); - } - } - - public static Builder.NoSecondaryReplica noSecondaryReplicaBuilder() { - return new Builder.NoSecondaryReplica(); - } - - abstract static class Builder { - - class ReplicasWithSameSpeed extends Builder { - - URI primary; - List secondaries = new ArrayList<>(); - StoreResponse headStoreResponse; - StoreResponse readStoreResponse; - - ReplicasWithSameSpeed addPrimary(URI replicaAddress) { - primary = replicaAddress; - return this; - } - - ReplicasWithSameSpeed addSecondary(URI replicaAddress) { - secondaries.add(replicaAddress); - return this; - } - - ReplicasWithSameSpeed storeResponseOnRead(StoreResponse storeResponse) { - this.readStoreResponse = storeResponse; - return this; - } - - ReplicasWithSameSpeed storeResponseOnHead(StoreResponse storeResponse) { - this.headStoreResponse = storeResponse; - return this; - } - - public EndpointMock build() { - TransportClientWrapper.Builder.ReplicaResponseBuilder transportClientWrapperBuilder = TransportClientWrapper.Builder.replicaResponseBuilder(); - - ImmutableList replicas = ImmutableList.builder().add(primary).addAll(secondaries).build(); - - for(URI replica: replicas) { - transportClientWrapperBuilder.addReplica(replica, (i, request) -> { - if (request.getOperationType() == OperationType.Head || request.getOperationType() == OperationType.HeadFeed) { - return headStoreResponse; - } else { - return readStoreResponse; - } - }); - } - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create().withPrimary(primary) - .withSecondary(secondaries).build(); - - return new EndpointMock(addressSelectorWrapper, transportClientWrapperBuilder.build()) {}; - } - } - - class QuorumNotMetSecondaryReplicasDisappear { - URI primary; - Map> disappearDictionary = new HashedMap(); - public QuorumNotMetSecondaryReplicasDisappear primaryReplica(URI primaryReplica) { - this.primary = primaryReplica; - return this; - } - - public QuorumNotMetSecondaryReplicasDisappear secondaryReplicasDisappearWhen(URI secondary, - Function2WithCheckedException disappearPredicate) { - disappearDictionary.put(secondary, disappearPredicate); - return this; - } - - public QuorumNotMetSecondaryReplicasDisappear secondaryReplicasDisappearAfter(URI secondary, int attempt) { - disappearDictionary.put(secondary, (i, r) -> i >= attempt); - return this; - } - } - - static public class NoSecondaryReplica extends Builder { - private long LOCAL_LSN = 19; - private long LSN = 52; - private URI defaultPrimaryURI = URI.create("primary"); - private URI primary = defaultPrimaryURI; - private StoreResponse defaultResponse = StoreResponseBuilder.create() - .withLSN(LSN) - .withLocalLSN(LOCAL_LSN) - .withHeader(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE, "1") - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LSN, Long.toString(LSN)) - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long.toString(LOCAL_LSN)) - .withRequestCharge(0) - .build(); - - private StoreResponse headStoreResponse = defaultResponse; - private StoreResponse readStoreResponse = defaultResponse; - private Function1WithCheckedException storeResponseFunc; - - public NoSecondaryReplica primaryReplica(URI primaryReplica) { - this.primary = primaryReplica; - return this; - } - - public NoSecondaryReplica response(StoreResponse storeResponse) { - this.readStoreResponse = storeResponse; - this.headStoreResponse = storeResponse; - return this; - } - - public NoSecondaryReplica response(Function1WithCheckedException storeResponseFunc) { - this.storeResponseFunc = storeResponseFunc; - return this; - } - - public EndpointMock build() { - - TransportClientWrapper.Builder.ReplicaResponseBuilder transportClientWrapperBuilder = TransportClientWrapper.Builder.replicaResponseBuilder(); - - ImmutableList replicas = ImmutableList.builder().add(primary).build(); - - for(URI replica: replicas) { - transportClientWrapperBuilder.addReplica(replica, (i, request) -> { - - if (storeResponseFunc != null) { - return storeResponseFunc.apply(request); - } - - if (request.getOperationType() == OperationType.Head || request.getOperationType() == OperationType.HeadFeed) { - return headStoreResponse; - } else { - return readStoreResponse; - } - }); - } - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create().withPrimary(primary) - .withSecondary(ImmutableList.of()).build(); - - return new EndpointMock(addressSelectorWrapper, transportClientWrapperBuilder.build()) {}; - } - } - - static public class NoSecondaryReplica_TwoSecondaryReplicasGoLiveAfterFirstHitOnPrimary extends Builder { - private long LOCAL_LSN = 19; - private long LSN = 52; - private URI primary = URI.create("primary"); - private ImmutableList secondaryReplicas = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2")); - private StoreResponse primaryDefaultResponse = StoreResponseBuilder.create() - .withLSN(LSN) - .withLocalLSN(LOCAL_LSN) - .withHeader(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE, "3") - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LSN, Long.toString(LSN)) - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long.toString(LOCAL_LSN)) - .withRequestCharge(0) - .build(); - - private StoreResponse secondaryDefaultResponse = StoreResponseBuilder.create() - .withLSN(LSN) - .withLocalLSN(LOCAL_LSN) - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LSN, Long.toString(LSN)) - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long.toString(LOCAL_LSN)) - .withRequestCharge(0) - .build(); - Map> secondaryResponseFunc = - new HashMap<>(); - - - public NoSecondaryReplica_TwoSecondaryReplicasGoLiveAfterFirstHitOnPrimary primaryReplica(URI primaryReplica) { - this.primary = primaryReplica; - return this; - } - - public NoSecondaryReplica_TwoSecondaryReplicasGoLiveAfterFirstHitOnPrimary responseFromSecondary( - URI replica, - Function1WithCheckedException func) { - secondaryResponseFunc.put(replica, func); - return this; - } - - public EndpointMock build() { - - TransportClientWrapper.Builder.ReplicaResponseBuilder transportClientWrapperBuilder = TransportClientWrapper.Builder.replicaResponseBuilder(); - - transportClientWrapperBuilder.addReplica(primary, (i, request) -> { - return primaryDefaultResponse; - }); - - transportClientWrapperBuilder.addReplica(secondaryReplicas.get(0), (i, request) -> { - return secondaryDefaultResponse; - }); - - transportClientWrapperBuilder.addReplica(secondaryReplicas.get(1), (i, request) -> { - return secondaryDefaultResponse; - }); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create().withPrimary(primary) - .withSecondary(ImmutableList.of()).build(); - - return new EndpointMock(addressSelectorWrapper, transportClientWrapperBuilder.build()){}; - } - } - - public abstract EndpointMock build() ; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ExceptionBuilder.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ExceptionBuilder.java deleted file mode 100644 index d73c90350fb1..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ExceptionBuilder.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; - -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -public class ExceptionBuilder { - private Integer status; - private List> headerEntries; - private String message; - - public static ExceptionBuilder create() { - return new ExceptionBuilder(); - } - - public ExceptionBuilder() { - headerEntries = new ArrayList<>(); - } - - public ExceptionBuilder withHeader(String key, String value) { - headerEntries.add(new AbstractMap.SimpleEntry(key, value)); - return this; - } - - public ExceptionBuilder withStatus(int status) { - this.status = status; - return this; - } - - public ExceptionBuilder withMessage(String message) { - this.message = message; - return this; - } - - public GoneException asGoneException() { - assert status == null; - GoneException dce = new GoneException(); - dce.getResponseHeaders().putAll(headerEntries.stream().collect(Collectors.toMap(i -> i.getKey(), i -> i.getValue()))); - return dce; - } - - public InvalidPartitionException asInvalidPartitionException() { - assert status == null; - InvalidPartitionException dce = new InvalidPartitionException(); - dce.getResponseHeaders().putAll(headerEntries.stream().collect(Collectors.toMap(i -> i.getKey(), i -> i.getValue()))); - return dce; - } - - public PartitionKeyRangeGoneException asPartitionKeyRangeGoneException() { - assert status == null; - PartitionKeyRangeGoneException dce = new PartitionKeyRangeGoneException(); - dce.getResponseHeaders().putAll(headerEntries.stream().collect(Collectors.toMap(i -> i.getKey(), i -> i.getValue()))); - return dce; - } - - - public PartitionKeyRangeIsSplittingException asPartitionKeyRangeIsSplittingException() { - assert status == null; - PartitionKeyRangeIsSplittingException dce = new PartitionKeyRangeIsSplittingException(); - dce.getResponseHeaders().putAll(headerEntries.stream().collect(Collectors.toMap(i -> i.getKey(), i -> i.getValue()))); - return dce; - } - - public PartitionIsMigratingException asPartitionIsMigratingException() { - assert status == null; - PartitionIsMigratingException dce = new PartitionIsMigratingException(); - dce.getResponseHeaders().putAll(headerEntries.stream().collect(Collectors.toMap(i -> i.getKey(), i -> i.getValue()))); - return dce; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Function1WithCheckedException.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Function1WithCheckedException.java deleted file mode 100644 index 3e55f35763fe..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Function1WithCheckedException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -@FunctionalInterface -public interface Function1WithCheckedException{ - - R apply(T t) throws Exception; - -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Function2WithCheckedException.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Function2WithCheckedException.java deleted file mode 100644 index 093ce601fcfe..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/Function2WithCheckedException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -@FunctionalInterface -public interface Function2WithCheckedException{ - R apply(T1 t1, T2 t2) throws Exception; - -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfiguratorReaderMock.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfiguratorReaderMock.java deleted file mode 100644 index 0b536d36c740..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfiguratorReaderMock.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.ReplicationPolicy; -import org.mockito.Mockito; -import rx.Single; - -public class GatewayServiceConfiguratorReaderMock { - - public GatewayServiceConfigurationReader gatewayServiceConfigurationReader; - - public static GatewayServiceConfiguratorReaderMock from(ConsistencyLevel accountConsistencyLevel) { - return new GatewayServiceConfiguratorReaderMock(new ReplicationPolicy("{}"), new ReplicationPolicy("{}"), accountConsistencyLevel); - } - - public static GatewayServiceConfiguratorReaderMock from(ConsistencyLevel accountConsistencyLevel, - int systemMaxReplicaCount, - int systemMinReplicaCount, - int userMaxReplicaCount, - int userMinReplicaCount) { - ReplicationPolicy userRP = Mockito.mock(ReplicationPolicy.class); - Mockito.doReturn(userMaxReplicaCount).when(userRP).getMaxReplicaSetSize(); - Mockito.doReturn(userMinReplicaCount).when(userRP).getMinReplicaSetSize(); - - ReplicationPolicy systemRP = Mockito.mock(ReplicationPolicy.class); - Mockito.doReturn(systemMaxReplicaCount).when(systemRP).getMaxReplicaSetSize(); - Mockito.doReturn(systemMinReplicaCount).when(systemRP).getMinReplicaSetSize(); - - return new GatewayServiceConfiguratorReaderMock(userRP, systemRP, accountConsistencyLevel); - } - - public static GatewayServiceConfiguratorReaderMock from(ConsistencyLevel accountConsistencyLevel, int maxReplicaSize, int minReplicaCase) { - ReplicationPolicy rp = Mockito.mock(ReplicationPolicy.class); - Mockito.doReturn(maxReplicaSize).when(rp).getMaxReplicaSetSize(); - Mockito.doReturn(minReplicaCase).when(rp).getMinReplicaSetSize(); - - return new GatewayServiceConfiguratorReaderMock(rp, rp, accountConsistencyLevel); - } - - - public GatewayServiceConfiguratorReaderMock(ReplicationPolicy userReplicationPolicy, - ReplicationPolicy systemReplicationPolicy, - ConsistencyLevel defaultConsistencyLevel) { - this.gatewayServiceConfigurationReader = Mockito.mock(GatewayServiceConfigurationReader.class); - - Mockito.doReturn(Single.just(Mockito.mock(DatabaseAccount.class))).when(this.gatewayServiceConfigurationReader).initializeReaderAsync(); - Mockito.doReturn(defaultConsistencyLevel).when(this.gatewayServiceConfigurationReader).getDefaultConsistencyLevel(); - Mockito.doReturn(systemReplicationPolicy).when(this.gatewayServiceConfigurationReader).getSystemReplicationPolicy(); - Mockito.doReturn(userReplicationPolicy).when(this.gatewayServiceConfigurationReader).getUserReplicationPolicy(); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneAndRetryWithRetryPolicyTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneAndRetryWithRetryPolicyTest.java deleted file mode 100644 index b9895fe301b7..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GoneAndRetryWithRetryPolicyTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.testng.annotations.Test; -import rx.Single; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This test file will cover various exception on GoneAndRetryWithRetryPolicy. - * - */ -public class GoneAndRetryWithRetryPolicyTest { - protected static final int TIMEOUT = 60000; - - /** - * Retry with GoneException , retried 4 times and verified the returned - * shouldRetryResult. ShouldRetryResult - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void shouldRetryWithGoneException() { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - GoneAndRetryWithRetryPolicy goneAndRetryWithRetryPolicy = new GoneAndRetryWithRetryPolicy(request, 30); - Single singleShouldRetry = goneAndRetryWithRetryPolicy - .shouldRetry(new GoneException()); - IRetryPolicy.ShouldRetryResult shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue0()).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue3()).isEqualTo(1); - assertThat(shouldRetryResult.backOffTime.getSeconds()).isEqualTo(0); - - singleShouldRetry = goneAndRetryWithRetryPolicy.shouldRetry(new GoneException()); - shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue0()).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue3()).isEqualTo(2); - assertThat(shouldRetryResult.backOffTime.getSeconds()).isEqualTo(1); - - singleShouldRetry = goneAndRetryWithRetryPolicy.shouldRetry(new GoneException()); - shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue0()).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue3()).isEqualTo(3); - assertThat(shouldRetryResult.backOffTime.getSeconds()).isEqualTo(2); - - singleShouldRetry = goneAndRetryWithRetryPolicy.shouldRetry(new GoneException()); - shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue0()).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue3()).isEqualTo(4); - assertThat(shouldRetryResult.backOffTime.getSeconds()).isEqualTo(4); - - } - - /** - * Retry with PartitionIsMigratingException - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void shouldRetryWithPartitionIsMigratingException() { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - GoneAndRetryWithRetryPolicy goneAndRetryWithRetryPolicy = new GoneAndRetryWithRetryPolicy(request, 30); - Single singleShouldRetry = goneAndRetryWithRetryPolicy - .shouldRetry(new PartitionIsMigratingException()); - IRetryPolicy.ShouldRetryResult shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(request.forceCollectionRoutingMapRefresh).isTrue(); - assertThat(shouldRetryResult.policyArg.getValue0()).isTrue(); - } - - /** - * Retry with InvalidPartitionException - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void shouldRetryWithInvalidPartitionException() { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - GoneAndRetryWithRetryPolicy goneAndRetryWithRetryPolicy = new GoneAndRetryWithRetryPolicy(request, 30); - Single singleShouldRetry = goneAndRetryWithRetryPolicy - .shouldRetry(new InvalidPartitionException()); - IRetryPolicy.ShouldRetryResult shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(request.requestContext.quorumSelectedLSN).isEqualTo(-1); - assertThat(request.requestContext.resolvedPartitionKeyRange).isNull(); - assertThat(request.requestContext.globalCommittedSelectedLSN).isEqualTo(-1); - assertThat(shouldRetryResult.policyArg.getValue0()).isFalse(); - - goneAndRetryWithRetryPolicy.shouldRetry(new InvalidPartitionException()); - // It will retry max till 3 attempts - shouldRetryResult = goneAndRetryWithRetryPolicy.shouldRetry(new InvalidPartitionException()).toBlocking() - .value(); - assertThat(shouldRetryResult.shouldRetry).isFalse(); - DocumentClientException clientException = (DocumentClientException) shouldRetryResult.exception; - assertThat(clientException.getStatusCode()).isEqualTo(HttpConstants.StatusCodes.SERVICE_UNAVAILABLE); - - } - - /** - * Retry with PartitionKeyRangeIsSplittingException - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void shouldRetryWithPartitionKeyRangeIsSplittingException() { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - GoneAndRetryWithRetryPolicy goneAndRetryWithRetryPolicy = new GoneAndRetryWithRetryPolicy(request, 30); - Single singleShouldRetry = goneAndRetryWithRetryPolicy - .shouldRetry(new PartitionKeyRangeIsSplittingException()); - IRetryPolicy.ShouldRetryResult shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(request.forcePartitionKeyRangeRefresh).isTrue(); - assertThat(request.requestContext.resolvedPartitionKeyRange).isNull(); - assertThat(request.requestContext.quorumSelectedLSN).isEqualTo(-1); - assertThat(shouldRetryResult.policyArg.getValue0()).isFalse(); - - } - - /** - * No retry on bad request exception - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void shouldRetryWithGenericException() { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - GoneAndRetryWithRetryPolicy goneAndRetryWithRetryPolicy = new GoneAndRetryWithRetryPolicy(request, 30); - Single singleShouldRetry = goneAndRetryWithRetryPolicy - .shouldRetry(new BadRequestException()); - IRetryPolicy.ShouldRetryResult shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isFalse(); - } - -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientMockWrapper.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientMockWrapper.java deleted file mode 100644 index f456424a0319..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpClientMockWrapper.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.ByteBufUtil; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import rx.Observable; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; - -public class HttpClientMockWrapper { - public static HttpClientBehaviourBuilder httpClientBehaviourBuilder() { - return new HttpClientBehaviourBuilder(); - } - - public static class HttpClientBehaviourBuilder { - private int status; - private String content; - private HttpHeaders httpHeaders = new DefaultHttpHeaders(); - private Exception networkFailure; - - public HttpClientBehaviourBuilder withNetworkFailure(Exception networkFailure) { - this.networkFailure = networkFailure; - return this; - } - - public HttpClientBehaviourBuilder withStatus(int status) { - this.status = status; - return this; - } - - public HttpClientBehaviourBuilder withHeaders(HttpHeaders httpHeaders) { - this.httpHeaders = httpHeaders; - return this; - } - - public HttpClientBehaviourBuilder withHeaders(String... pairs) { - if (pairs.length % 2 != 0) { - throw new IllegalArgumentException(); - } - - for(int i = 0; i < pairs.length/ 2; i++) { - this.httpHeaders.add(pairs[2*i], pairs[2*i +1]); - } - - return this; - } - - public HttpClientBehaviourBuilder withContent(String content) { - this.content = content; - return this; - } - - public HttpClientBehaviourBuilder withHeaderLSN(long lsn) { - this.httpHeaders.add(WFConstants.BackendHeaders.LSN, Long.toString(lsn)); - return this; - } - - public HttpClientBehaviourBuilder withHeaderPartitionKeyRangeId(String partitionKeyRangeId) { - this.httpHeaders.add(WFConstants.BackendHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId); - return this; - } - - public HttpClientBehaviourBuilder withHeaderSubStatusCode(int subStatusCode) { - this.httpHeaders.add(WFConstants.BackendHeaders.SUB_STATUS, Integer.toString(subStatusCode)); - return this; - } - - public HttpClientResponse asHttpClientResponse() { - if (this.networkFailure != null) { - return null; - } - - HttpClientResponse resp = Mockito.mock(HttpClientResponse.class); - Mockito.doReturn(HttpResponseStatus.valueOf(status)).when(resp).getStatus(); - Mockito.doReturn(Observable.just(ByteBufUtil.writeUtf8(ByteBufAllocator.DEFAULT, content))).when(resp).getContent(); - - DefaultHttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(status), httpHeaders); - - try { - Constructor constructor = HttpResponseHeaders.class.getDeclaredConstructor(HttpResponse.class); - constructor.setAccessible(true); - HttpResponseHeaders httpResponseHeaders = constructor.newInstance(httpResponse); - Mockito.doReturn(httpResponseHeaders).when(resp).getHeaders(); - - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException - | InvocationTargetException | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to instantiate class object.", e); - } - - return resp; - } - - public Exception asNetworkFailure() { - return this.networkFailure; - } - - @Override - public String toString() { - return "HttpClientBehaviourBuilder{" + - "status=" + status + - ", content='" + content + '\'' + - ", httpHeaders=" + httpHeaders + - ", networkFailure=" + networkFailure + - '}'; - } - } - - private final CompositeHttpClient httpClient; - private final List, RxClient.ServerInfo>> requests = Collections.synchronizedList(new ArrayList<>()); - - public HttpClientMockWrapper(long responseAfterMillis, HttpClientResponse httpClientResponse) { - this(responseAfterMillis, httpClientResponse, null); - } - - private static Observable> httpClientResponseOrException(HttpClientResponse httpClientResponse, Exception e) { - assert ((httpClientResponse != null && e == null) || (httpClientResponse == null && e != null)); - return httpClientResponse != null ? Observable.just(httpClientResponse) : Observable.error(e); - } - - public HttpClientMockWrapper(long responseAfterMillis, Exception e) { - this(responseAfterMillis, null, e); - } - - public HttpClientMockWrapper(HttpClientResponse httpClientResponse) { - this(0, httpClientResponse); - } - - private HttpClientMockWrapper(long responseAfterMillis, final HttpClientResponse httpClientResponse, final Exception e) { - httpClient = Mockito.mock(CompositeHttpClient.class); - assert httpClientResponse == null || e == null; - - Mockito.doAnswer(new Answer() { - @Override - public Observable> answer(InvocationOnMock invocationOnMock) throws Throwable { - RxClient.ServerInfo serverInfo = invocationOnMock.getArgumentAt(0, RxClient.ServerInfo.class); - HttpClientRequest req = invocationOnMock.getArgumentAt(1, HttpClientRequest.class); - - requests.add(new ImmutablePair<>(req, serverInfo)); - - if (responseAfterMillis <= 0) { - return httpClientResponseOrException(httpClientResponse, e); - } else { - return Observable.timer(responseAfterMillis, TimeUnit.MILLISECONDS).flatMap(t -> httpClientResponseOrException(httpClientResponse, e)); - } - } - }).when(httpClient).submit(Mockito.any(RxClient.ServerInfo.class), Mockito.any(HttpClientRequest.class)); - } - - public HttpClientMockWrapper(HttpClientBehaviourBuilder builder) { - this(0, builder.asHttpClientResponse(), builder.asNetworkFailure()); - } - - public HttpClientMockWrapper(Exception e) { - this(0, e); - } - - public CompositeHttpClient getClient() { - return httpClient; - } - - public List, RxClient.ServerInfo>> getCapturedInvocation() { - return requests; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpTransportClientTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpTransportClientTest.java deleted file mode 100644 index f4ca18efd052..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/HttpTransportClientTest.java +++ /dev/null @@ -1,641 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.buffer.ByteBuf; -import io.netty.channel.ConnectTimeoutException; -import io.netty.handler.codec.http.EmptyHttpHeaders; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.assertj.core.api.Assertions; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; - -import java.net.URI; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * Tests validating {@link HttpTransportClient} - */ -public class HttpTransportClientTest { - private final static Configs configs = new Configs(); - private final static int TIMEOUT = 1000; - - private final URI physicalAddress = URI.create( - "https://by4prdddc03-docdb-1.documents.azure.com:9056" + - "/apps/b76af614-5421-4318-4c9e-33056ff5a2bf/services/e7c8d429-c379-40c9-9486-65b89b70be2f" + - "/partitions/5f5b8766-3bdf-4713-b85a-a55ac2ccd62c/replicas/131828696163674404p/"); - - private final long lsn = 5; - private final String partitionKeyRangeId = "3"; - - @Test(groups = "unit") - public void getResourceFeedUri_Document() throws Exception { - RxDocumentServiceRequest req = RxDocumentServiceRequest.createFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Document); - URI res = HttpTransportClient.getResourceFeedUri(req.getResourceType(), physicalAddress, req); - assertThat(res.toString()).isEqualTo(physicalAddress.toString() + HttpUtils.urlEncode("dbs/db/colls/col/docs")); - } - - @Test(groups = "unit") - public void getResourceFeedUri_Attachment() throws Exception { - RxDocumentServiceRequest req = RxDocumentServiceRequest.createFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Attachment); - URI res = HttpTransportClient.getResourceFeedUri(req.getResourceType(), physicalAddress, req); - assertThat(res.toString()).isEqualTo(physicalAddress.toString() + HttpUtils.urlEncode("dbs/db/colls/col/attachments")); - } - - @Test(groups = "unit") - public void getResourceFeedUri_Collection() throws Exception { - RxDocumentServiceRequest req = RxDocumentServiceRequest.createFromName( - OperationType.Create, "dbs/db", ResourceType.DocumentCollection); - URI res = HttpTransportClient.getResourceFeedUri(req.getResourceType(), physicalAddress, req); - assertThat(res.toString()).isEqualTo(physicalAddress.toString() + HttpUtils.urlEncode("dbs/db/colls")); - } - - @Test(groups = "unit") - public void getResourceFeedUri_Conflict() throws Exception { - RxDocumentServiceRequest req = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/dbs/db/colls/col", ResourceType.Conflict); - URI res = HttpTransportClient.getResourceFeedUri(req.getResourceType(), physicalAddress, req); - assertThat(res.toString()).isEqualTo(physicalAddress.toString() + HttpUtils.urlEncode("dbs/db/colls/col/conflicts")); - } - - @Test(groups = "unit") - public void getResourceFeedUri_Database() throws Exception { - RxDocumentServiceRequest req = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/", ResourceType.Database); - URI res = HttpTransportClient.getResourceFeedUri(req.getResourceType(), physicalAddress, req); - assertThat(res.toString()).isEqualTo(physicalAddress.toString() + "dbs"); - } - - public static HttpTransportClient getHttpTransportClientUnderTest(int requestTimeout, - UserAgentContainer userAgent, - CompositeHttpClient httpClient) { - class HttpTransportClientUnderTest extends HttpTransportClient { - public HttpTransportClientUnderTest(int requestTimeout, UserAgentContainer userAgent) { - super(configs, requestTimeout, userAgent); - } - - @Override - CompositeHttpClient createHttpClient(int requestTimeout) { - return httpClient; - } - } - - return new HttpTransportClientUnderTest(requestTimeout, userAgent); - } - - @Test(groups = "unit") - public void validateDefaultHeaders() { - HttpClientResponse mockedResponse = new HttpClientMockWrapper.HttpClientBehaviourBuilder() - .withContent("").withStatus(200) - .withHeaders(EmptyHttpHeaders.INSTANCE) - .asHttpClientResponse(); - HttpClientMockWrapper httpClientMockWrapper = new HttpClientMockWrapper(mockedResponse); - - UserAgentContainer userAgentContainer = new UserAgentContainer(); - userAgentContainer.setSuffix("i am suffix"); - - HttpTransportClient transportClient = getHttpTransportClientUnderTest(100, - userAgentContainer, - httpClientMockWrapper.getClient()); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Document); - request.setContentBytes(new byte[0]); - - transportClient.invokeStoreAsync(physicalAddress, - new ResourceOperation(OperationType.Create, ResourceType.Document), - request).toBlocking().value(); - - assertThat(httpClientMockWrapper.getCapturedInvocation()).asList().hasSize(1); - ImmutablePair, RxClient.ServerInfo> httpClientInvocation = httpClientMockWrapper.getCapturedInvocation().get(0); - - assertThat(httpClientInvocation.left.getHeaders().get(HttpConstants.HttpHeaders.USER_AGENT)).endsWith("i am suffix"); - assertThat(httpClientInvocation.left.getHeaders().get(HttpConstants.HttpHeaders.CACHE_CONTROL)).isEqualTo("no-cache"); - assertThat(httpClientInvocation.left.getHeaders().get(HttpConstants.HttpHeaders.ACCEPT)).isEqualTo("application/json"); - assertThat(httpClientInvocation.left.getHeaders().get(HttpConstants.HttpHeaders.VERSION)).isEqualTo(HttpConstants.Versions.CURRENT_VERSION); - - } - - @DataProvider(name = "fromMockedHttpResponseToExpectedDocumentClientException") - public Object[][] fromMockedHttpResponseToExpectedDocumentClientException() { - return new Object[][]{ - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(401) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(UnauthorizedException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(403) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(ForbiddenException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(404) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(NotFoundException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(404) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId) - .withHeaders(HttpConstants.HttpHeaders.CONTENT_TYPE, "text/html"), - - FailureValidator.builder() - .instanceOf(GoneException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(400) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(BadRequestException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(405) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(MethodNotAllowedException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(409) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(ConflictException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(412) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(PreconditionFailedException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(412) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(PreconditionFailedException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(413) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(RequestEntityTooLargeException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(423) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(LockedException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(503) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(ServiceUnavailableException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(408) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(RequestTimeoutException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(449) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(RetryWithException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(429) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(RequestRateTooLargeException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(500) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId), - - FailureValidator.builder() - .instanceOf(InternalServerErrorException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(410) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId) - .withHeaderSubStatusCode(HttpConstants.SubStatusCodes.NAME_CACHE_IS_STALE), - - FailureValidator.builder() - .instanceOf(InvalidPartitionException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(410) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId) - .withHeaderSubStatusCode(HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE), - - FailureValidator.builder() - .instanceOf(PartitionKeyRangeGoneException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(410) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId) - .withHeaderSubStatusCode(HttpConstants.SubStatusCodes.COMPLETING_SPLIT), - - FailureValidator.builder() - .instanceOf(PartitionKeyRangeIsSplittingException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(410) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId) - .withHeaderSubStatusCode(HttpConstants.SubStatusCodes.COMPLETING_PARTITION_MIGRATION), - - FailureValidator.builder() - .instanceOf(PartitionIsMigratingException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - { - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withContent("").withStatus(410) - .withHeaderLSN(lsn) - .withHeaderPartitionKeyRangeId(partitionKeyRangeId) - .withHeaderSubStatusCode(0), - - FailureValidator.builder() - .instanceOf(GoneException.class) - .resourceAddress("dbs/db/colls/col") - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - }, - }; - } - - /** - * Validates the error handling behaviour of HttpTransportClient for https status codes >= 400 - * @param mockedResponseBuilder - * @param failureValidatorBuilder - */ - @Test(groups = "unit", dataProvider = "fromMockedHttpResponseToExpectedDocumentClientException") - public void failuresWithHttpStatusCodes(HttpClientMockWrapper.HttpClientBehaviourBuilder mockedResponseBuilder, - FailureValidator.Builder failureValidatorBuilder) { - HttpClientMockWrapper httpClientMockWrapper = new HttpClientMockWrapper(mockedResponseBuilder); - UserAgentContainer userAgentContainer = new UserAgentContainer(); - HttpTransportClient transportClient = getHttpTransportClientUnderTest( - 100, - userAgentContainer, - httpClientMockWrapper.getClient()); - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Document); - request.setContentBytes(new byte[0]); - - Single storeResp = transportClient.invokeStoreAsync( - physicalAddress, - new ResourceOperation(OperationType.Create, ResourceType.Document), - request); - - validateFailure(storeResp, failureValidatorBuilder.build()); - } - - @DataProvider(name = "fromMockedNetworkFailureToExpectedDocumentClientException") - public Object[][] fromMockedNetworkFailureToExpectedDocumentClientException() { - return new Object[][]{ - // create request, retriable network exception - { - createRequestFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Document), - - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withNetworkFailure(new UnknownHostException()), - - FailureValidator.builder() - .instanceOf(GoneException.class) - }, - - // create request, retriable network exception - { - createRequestFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Document), - - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withNetworkFailure(new UnknownHostException()), - - FailureValidator.builder() - .instanceOf(GoneException.class) - }, - - // create request, retriable network exception - { - createRequestFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Document), - - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withNetworkFailure(new ConnectTimeoutException()), - - FailureValidator.builder() - .instanceOf(GoneException.class) - }, - - // read request, retriable network exception - { - createRequestFromName( - OperationType.Read, "dbs/db/colls/col", ResourceType.Document), - - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withNetworkFailure(new ConnectTimeoutException()), - - FailureValidator.builder() - .instanceOf(GoneException.class) - }, - - // create request, non-retriable network exception - { - createRequestFromName( - OperationType.Create, "dbs/db/colls/col", ResourceType.Document), - - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withNetworkFailure(new RuntimeException()), - - FailureValidator.builder() - .instanceOf(ServiceUnavailableException.class) - }, - - // read request, non-retriable network exception - { - createRequestFromName( - OperationType.Read, "dbs/db/colls/col", ResourceType.Document), - - HttpClientMockWrapper. - httpClientBehaviourBuilder() - .withNetworkFailure(new RuntimeException()), - - FailureValidator.builder() - .instanceOf(GoneException.class) - }, - }; - } - - /** - * Validates the error handling behaviour of HttpTransportClient for network failures from which http status codes - * cannot be derived. For example Socket Connection failure. - * @param request - * @param mockedResponseBuilder - * @param failureValidatorBuilder - */ - @Test(groups = "unit", dataProvider = "fromMockedNetworkFailureToExpectedDocumentClientException") - public void networkFailures(RxDocumentServiceRequest request, - HttpClientMockWrapper.HttpClientBehaviourBuilder mockedResponseBuilder, - FailureValidator.Builder failureValidatorBuilder) { - HttpClientMockWrapper httpClientMockWrapper = new HttpClientMockWrapper(mockedResponseBuilder); - UserAgentContainer userAgentContainer = new UserAgentContainer(); - HttpTransportClient transportClient = getHttpTransportClientUnderTest( - 100, - userAgentContainer, - httpClientMockWrapper.getClient()); - - Single storeResp = transportClient.invokeStoreAsync( - physicalAddress, - new ResourceOperation(OperationType.Create, ResourceType.Document), - request); - - validateFailure(storeResp, failureValidatorBuilder.build()); - } - - private static RxDocumentServiceRequest createRequestFromName( - OperationType operationType, - String resourceFullName, - ResourceType resourceType) { - return createRequestFromName(operationType, resourceFullName, resourceType, new byte[0]); - } - - private static RxDocumentServiceRequest createRequestFromName( - OperationType operationType, - String resourceFullName, - ResourceType resourceType, - byte[] content) { - RxDocumentServiceRequest req = RxDocumentServiceRequest.create( - operationType, - resourceType, - resourceFullName, - new HashMap<>()); - - req.setContentBytes(content); - return req; - } - - public void validateSuccess(Single single, StoreResponseValidator validator) { - validateSuccess(single, validator, TIMEOUT); - } - - public static void validateSuccess(Single single, - StoreResponseValidator validator, long timeout) { - - TestSubscriber testSubscriber = new TestSubscriber<>(); - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public void validateFailure(Single single, - FailureValidator validator) { - validateFailure(single, validator, TIMEOUT); - } - - public static void validateFailure(Single single, - FailureValidator validator, long timeout) { - - TestSubscriber testSubscriber = new TestSubscriber<>(); - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MultiStoreResultValidator.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MultiStoreResultValidator.java deleted file mode 100644 index 3b948d992ba4..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MultiStoreResultValidator.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.base.Predicates; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import org.apache.commons.lang3.mutable.MutableObject; -import org.assertj.core.description.Description; -import org.assertj.core.description.TextDescription; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.BiFunction; -import java.util.function.Predicate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.fail; - -/** - * this is meant to be used when there reading multiple replicas for the same thing - */ -public interface MultiStoreResultValidator { - - static Builder create() { - return new Builder(); - } - - void validate(List storeResults); - - class Builder { - private List validators = new ArrayList<>(); - - public MultiStoreResultValidator build() { - return new MultiStoreResultValidator() { - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Override - public void validate(List storeResults) { - for (MultiStoreResultValidator validator : validators) { - validator.validate(storeResults); - } - } - }; - } - - public Builder validateEachWith(StoreResultValidator storeResultValidator) { - validators.add(new MultiStoreResultValidator() { - - @Override - public void validate(List storeResults) { - for(StoreResult srr: storeResults) { - storeResultValidator.validate(srr); - } - } - }); - return this; - } - - public Builder validateEachWith(StoreResponseValidator storeResponseValidator) { - validators.add(new MultiStoreResultValidator() { - - @Override - public void validate(List storeResults) { - for(StoreResult srr: storeResults) { - try { - storeResponseValidator.validate(srr.toResponse()); - } catch (DocumentClientException e) { - fail(e.getMessage()); - } - } - } - }); - return this; - } - - public Builder withMinimumLSN(long minimumLSN) { - this.validateEachWith(StoreResultValidator.create().withMinLSN(minimumLSN).build()); - return this; - } - - public Builder withAggregate(BiFunction aggregator, - T initialValue, - Predicate finalValuePredicate, - Description description) { - MutableObject total = new MutableObject<>(initialValue); - validators.add(new MultiStoreResultValidator() { - - @Override - public void validate(List storeResults) { - for(StoreResult srr: storeResults) { - total.setValue(aggregator.apply(srr, total.getValue())); - } - - assertThat(finalValuePredicate.test(total.getValue())) - .describedAs(Description.mostRelevantDescription(description, - String.format("actual value %s.", - total.getValue().toString()))) - .isTrue(); - } - }); - return this; - } - - public Builder withTotalRequestCharge(double totalExpectedRC) { - this.withAggregate((srr, v) -> srr.requestCharge + v.doubleValue(), - 0d, - Predicates.equalTo(totalExpectedRC), - new TextDescription("total request charge is expected to be %f", totalExpectedRC)); - return this; - } - - public Builder withNonZeroRequestCharge() { - - this.withAggregate((srr, v) -> srr.requestCharge + v.doubleValue(), - 0d, - aDouble -> aDouble > 0, - new TextDescription("total request charge expected to be greater than 0")); - return this; - } - - public Builder validateEachWith(FailureValidator failureValidator) { - validators.add(new MultiStoreResultValidator() { - - @Override - public void validate(List storeResults) { - for(StoreResult srr: storeResults) { - try { - failureValidator.validate(srr.getException()); - } catch (DocumentClientException e) { - fail(e.getMessage()); - } - } - } - }); - return this; - } - - public Builder noFailure() { - this.validateEachWith(StoreResultValidator.create().isValid().noException().build()); - return this; - } - - public Builder withSize(int expectedNumber) { - validators.add(new MultiStoreResultValidator() { - - @Override - public void validate(List storeResults) { - assertThat(storeResults).hasSize(expectedNumber); - } - }); - return this; - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MurmurHash3_32Test.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MurmurHash3_32Test.java deleted file mode 100644 index 0e8e01b2baa5..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/MurmurHash3_32Test.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.hash.HashFunction; -import com.google.common.hash.Hashing; -import com.microsoft.azure.cosmosdb.internal.routing.MurmurHash3_32; -import org.apache.commons.lang3.RandomUtils; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * validates {@link MurmurHash3_32} against Google's murmur3_32 implementation. - */ -public class MurmurHash3_32Test { - - private MurmurHash3_32 murmurHash3_32; - - @BeforeClass(groups = "unit") - public void setup() { - murmurHash3_32 = new MurmurHash3_32(); - } - - @Test(groups = "unit") - public void murmurHash3_32_EmptyByteArray() { - byte[] byteArray = new byte[0]; - int actualHash = murmurHash3_32.hash(byteArray, byteArray.length, 0); - - HashFunction googleMurmur3_32 = Hashing.murmur3_32(0); - int expectedHash = googleMurmur3_32.hashBytes(byteArray).asInt(); - - assertThat(actualHash).isEqualTo(expectedHash); - } - - @Test(groups = "unit") - public void murmurHash3_32_String() { - byte[] byteArray = new String("test").getBytes(Charset.forName("UTF-8")); - int actualHash = murmurHash3_32.hash(byteArray, byteArray.length, 0); - - HashFunction googleMurmur3_32 = Hashing.murmur3_32(0); - int expectedHash = googleMurmur3_32.hashBytes(byteArray).asInt(); - - assertThat(actualHash).isEqualTo(expectedHash); - } - - @Test(groups = "unit") - public void murmurHash3_32_NonLatin() throws UnsupportedEncodingException { - String nonLatin = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюя"; - for(int i = 0; i < nonLatin.length() + 1; i++) { - byte[] byteArray = nonLatin.substring(0, i).getBytes("UTF-8"); - int actualHash = murmurHash3_32.hash(byteArray, byteArray.length, 0); - - HashFunction googleMurmur3_32 = Hashing.murmur3_32(0); - int expectedHash = googleMurmur3_32.hashBytes(byteArray).asInt(); - - assertThat(actualHash).isEqualTo(expectedHash); - } - } - - @Test(groups = "unit") - public void murmurHash3_32_ZeroByteArray() { - byte[] byteArray = new byte[3]; - int actualHash = murmurHash3_32.hash(byteArray, byteArray.length, 0); - - HashFunction googleMurmur3_32 = Hashing.murmur3_32(0); - int expectedHash = googleMurmur3_32.hashBytes(byteArray).asInt(); - - assertThat(actualHash).isEqualTo(expectedHash); - } - - @Test(groups = "unit") - public void murmurHash3_32_RandomBytesOfAllSizes() { - for(int i = 0; i < 1000; i++) { - byte[] byteArray = randomBytes(i); - - int actualHash = murmurHash3_32.hash(byteArray, byteArray.length, 0); - - HashFunction googleMurmur3_32 = Hashing.murmur3_32(0); - int expectedHash = googleMurmur3_32.hashBytes(byteArray).asInt(); - - assertThat(actualHash).isEqualTo(expectedHash); - } - } - - private byte[] randomBytes(int count) { - return RandomUtils.nextBytes(count); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyInternalTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyInternalTest.java deleted file mode 100644 index 46d72c3e5b66..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyInternalTest.java +++ /dev/null @@ -1,473 +0,0 @@ -/* - * - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.microsoft.azure.cosmosdb.CommonsBridgeInternal; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.PartitionKind; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalHelper; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalUtils; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.functions.Func2; - -import java.util.ArrayList; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.fail; - -public class PartitionKeyInternalTest { - - /** - * Tests serialization of empty partition key. - */ - @Test(groups="unit") - public void emptyPartitionKey() { - String json = "[]"; - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(json); - assertThat(partitionKey).isEqualTo(PartitionKeyInternal.getEmpty()); - assertThat(partitionKey.toJson()).isEqualTo("[]"); - } - - /** - * Tests serialization of various types. - */ - @Test(groups="unit") - public void variousTypes() { - String json = "[\"aa\", null, true, false, {}, 5, 5.5]"; - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(json); - assertThat(partitionKey).isEqualTo( - PartitionKeyInternal.fromObjectArray( - Lists.newArrayList(new Object[]{"aa", null, true, false, Undefined.Value(), 5, 5.5}), true)); - - assertThat(partitionKey.toJson()).isEqualTo("[\"aa\",null,true,false,{},5.0,5.5]"); - } - - /** - * Tests deserialization of empty string - */ - @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) - public void deserializeEmptyString() { - PartitionKeyInternal.fromJsonString(""); - } - - /** - * Tests deserialization of null - */ - @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) - public void deserializeNull() { - PartitionKeyInternal.fromJsonString(null); - } - - /** - * Tests deserialization of invalid partition key - */ - @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) - public void invalidString() { - PartitionKeyInternal.fromJsonString("[aa]"); - } - - - /** - * Tests deserialization of invalid partition key - */ - @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) - public void invalidNumber() { - PartitionKeyInternal.fromJsonString("[1.a]"); - } - - /** - * Tests deserialization of invalid partition key - */ - @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) - public void missingBraces() { - PartitionKeyInternal.fromJsonString("[{]"); - } - - /** - * Missing Value - */ - @Test(groups = "unit") - public void missingValue() { - try { - PartitionKeyInternal.fromJsonString(""); - fail("should throw"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isEqualTo( - String.format( - RMResources.UnableToDeserializePartitionKeyValue, "")); - } - } - - /** - * Tests serialization of infinity value. - */ - @Test(groups = "unit") - public void maxValue() { - String json = "\"Infinity\""; - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(json); - assertThat(partitionKey).isEqualTo(PartitionKeyInternal.ExclusiveMaximum); - } - - /** - * Tests serialization of minimum value. - */ - @Test(groups = "unit") - public void minValue() { - String json = "[]"; - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(json); - assertThat(partitionKey).isEqualTo(PartitionKeyInternal.InclusiveMinimum); - } - - /** - * Tests serialization of undefined value. - */ - @Test(groups = "unit") - public void undefinedValue() { - String json = "[]"; - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(json); - assertThat(partitionKey).isEqualTo(PartitionKeyInternal.Empty); - } - - /** - * Tests JsonConvert.DefaultSettings that could cause indentation. - */ - @Test(groups="unit") - public void jsonConvertDefaultSettings() { - String json = "[123.0]"; - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(json); - assertThat(partitionKey.toJson()).isEqualTo(json); - } - - /** - * Tests unicode characters in partition key - */ - @Test(groups="unit") - public void unicodeCharacters() { - String json = "[\"电脑\"]"; - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(json); - assertThat(partitionKey.toJson()).isEqualTo("[\"\u7535\u8111\"]"); - } - - /** - * Tests partition key value comparisons. - */ - @Test(groups="unit") - public void comparison() { - verifyComparison("[]", "[]", 0); - verifyComparison("[]", "[{}]", -1); - verifyComparison("[]", "[false]", -1); - verifyComparison("[]", "[true]", -1); - verifyComparison("[]", "[null]", -1); - verifyComparison("[]", "[2]", -1); - verifyComparison("[]", "[\"aa\"]", -1); - verifyComparison("[]", "\"Infinity\"", -1); - - verifyComparison("[{}]", "[]", 1); - verifyComparison("[{}]", "[{}]", 0); - verifyComparison("[{}]", "[false]", -1); - verifyComparison("[{}]", "[true]", -1); - verifyComparison("[{}]", "[null]", -1); - verifyComparison("[{}]", "[2]", -1); - verifyComparison("[{}]", "[\"aa\"]", -1); - verifyComparison("[{}]", "\"Infinity\"", -1); - - verifyComparison("[false]", "[]", 1); - verifyComparison("[false]", "[{}]", 1); - verifyComparison("[false]", "[null]", 1); - verifyComparison("[false]", "[false]", 0); - verifyComparison("[false]", "[true]", -1); - verifyComparison("[false]", "[2]", -1); - verifyComparison("[false]", "[\"aa\"]", -1); - verifyComparison("[false]", "\"Infinity\"", -1); - - verifyComparison("[true]", "[]", 1); - verifyComparison("[true]", "[{}]", 1); - verifyComparison("[true]", "[null]", 1); - verifyComparison("[true]", "[false]", 1); - verifyComparison("[true]", "[true]", 0); - verifyComparison("[true]", "[2]", -1); - verifyComparison("[true]", "[\"aa\"]", -1); - verifyComparison("[true]", "\"Infinity\"", -1); - - verifyComparison("[null]", "[]", 1); - verifyComparison("[null]", "[{}]", 1); - verifyComparison("[null]", "[null]", 0); - verifyComparison("[null]", "[false]", -1); - verifyComparison("[null]", "[true]", -1); - verifyComparison("[null]", "[2]", -1); - verifyComparison("[null]", "[\"aa\"]", -1); - verifyComparison("[null]", "\"Infinity\"", -1); - - verifyComparison("[2]", "[]", 1); - verifyComparison("[2]", "[{}]", 1); - verifyComparison("[2]", "[null]", 1); - verifyComparison("[2]", "[false]", 1); - verifyComparison("[2]", "[true]", 1); - verifyComparison("[1]", "[2]", -1); - verifyComparison("[2]", "[2]", 0); - verifyComparison("[3]", "[2]", 1); - verifyComparison("[2.1234344]", "[2]", 1); - verifyComparison("[2]", "[\"aa\"]", -1); - verifyComparison("[2]", "\"Infinity\"", -1); - - verifyComparison("[\"aa\"]", "[]", 1); - verifyComparison("[\"aa\"]", "[{}]", 1); - verifyComparison("[\"aa\"]", "[null]", 1); - verifyComparison("[\"aa\"]", "[false]", 1); - verifyComparison("[\"aa\"]", "[true]", 1); - verifyComparison("[\"aa\"]", "[2]", 1); - verifyComparison("[\"\"]", "[\"aa\"]", -1); - verifyComparison("[\"aa\"]", "[\"aa\"]", 0); - verifyComparison("[\"b\"]", "[\"aa\"]", 1); - verifyComparison("[\"aa\"]", "\"Infinity\"", -1); - - verifyComparison("\"Infinity\"", "[]", 1); - verifyComparison("\"Infinity\"", "[{}]", 1); - verifyComparison("\"Infinity\"", "[null]", 1); - verifyComparison("\"Infinity\"", "[false]", 1); - verifyComparison("\"Infinity\"", "[true]", 1); - verifyComparison("\"Infinity\"", "[2]", 1); - verifyComparison("\"Infinity\"", "[\"aa\"]", 1); - verifyComparison("\"Infinity\"", "\"Infinity\"", 0); - } - - /** - * Tests that invalid partition key value will throw an exception. - */ - @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class) - public void invalidPartitionKeyValue() { - PartitionKeyInternal.fromObjectArray( - Lists.newArrayList(new Object[]{2, true, new StringBuilder()}), true); - } - - /** - * Tests {@link PartitionKeyInternal#contains(PartitionKeyInternal)} method. - */ - @Test(groups="unit") - public void contains() { - Func2 verifyContains = (parentPartitionKey, childPartitionKey) -> - PartitionKeyInternal.fromJsonString(parentPartitionKey) - .contains(PartitionKeyInternal.fromJsonString(childPartitionKey)); - - assertThat(verifyContains.call("[]", "[]")).isTrue(); - assertThat(verifyContains.call("[]", "[{}]")).isTrue(); - assertThat(verifyContains.call("[]", "[null]")).isTrue(); - assertThat(verifyContains.call("[]", "[true]")).isTrue(); - assertThat(verifyContains.call("[]", "[false]")).isTrue(); - assertThat(verifyContains.call("[]", "[2]")).isTrue(); - assertThat(verifyContains.call("[]", "[\"fdfd\"]")).isTrue(); - - assertThat(verifyContains.call("[2]", "[]")).isFalse(); - assertThat(verifyContains.call("[2]", "[2]")).isTrue(); - assertThat(verifyContains.call("[2]", "[2, \"USA\"]")).isTrue(); - assertThat(verifyContains.call("[1]", "[2, \"USA\"]")).isFalse(); - } - - @Test(groups="unit") - public void invalidPartitionKeyValueNonStrict() { - assertThat(PartitionKeyInternal.fromObjectArray(new Object[]{2, true, Undefined.Value()}, true)) - .isEqualTo( - PartitionKeyInternal.fromObjectArray(new Object[]{2, true, new StringBuilder()}, false)); - } - - /** - * Tests constructing effective partition key value. - */ - @Test(groups="unit") - public void hashEffectivePartitionKey() { - - assertThat(PartitionKeyInternalHelper.getEffectivePartitionKeyString(PartitionKeyInternal.InclusiveMinimum, new PartitionKeyDefinition())) - .isEqualTo(PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey); - - assertThat( - PartitionKeyInternalHelper.getEffectivePartitionKeyString(PartitionKeyInternal.ExclusiveMaximum, new PartitionKeyDefinition())) - .isEqualTo(PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey); - - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - partitionKeyDefinition.setPaths(Lists.newArrayList("/A", "/B", "/C", "/E", "/F", "/G")); - - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromObjectArray( - new Object[]{2, true, false, null, Undefined.Value(), "Привет!"}, true); - String effectivePartitionKey = PartitionKeyInternalHelper.getEffectivePartitionKeyString(partitionKey, partitionKeyDefinition); - - assertThat(effectivePartitionKey).isEqualTo("05C1D19581B37C05C0000302010008D1A0D281D1B9D1B3D1B6D2832200"); - } - - @DataProvider(name = "v2ParamProvider") - public Object[][] v2ParamProvider() { - return new Object[][] { - {"[5.0]", "19C08621B135968252FB34B4CF66F811"}, - { "[5.12312419050912359123]", "0EF2E2D82460884AF0F6440BE4F726A8"}, - {"[\"redmond\"]", "22E342F38A486A088463DFF7838A5963"}, - {"[true]", "0E711127C5B5A8E4726AC6DD306A3E59"}, - {"[false]", "2FE1BE91E90A3439635E0E9E37361EF2"}, - {"[]", ""}, - {"[null]", "378867E4430E67857ACE5C908374FE16"}, - {"[{}]", "11622DAA78F835834610ABE56EFF5CB5"}, - {"[5.0, \"redmond\", true, null]", "3032DECBE2AB1768D8E0AEDEA35881DF"}, - {"[\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"]", - "36375D21568760E891C9CB7002D5E059"}, - }; - } - - /** - * Tests binary encoding of partition key - */ - @Test(groups="unit", dataProvider = "v2ParamProvider") - public void partitionKeyBinaryEncodingV2(String partitionKeyRangeJson, String expectedHexEncoding) { - validateEffectivePartitionKeyV2(partitionKeyRangeJson, expectedHexEncoding); - } - - /** - * Tests that effective partition key produced by us and the backend is the same. - */ - @Test(groups="unit") - public void managedNativeCompatibility() { - PartitionKeyInternal partitionKey = - PartitionKeyInternal.fromJsonString("[\"по-русски\",null,true,false,{},5.5]"); - - PartitionKeyDefinition pkDefinition = new PartitionKeyDefinition(); - pkDefinition.setPaths(ImmutableList.of("/field1", "/field2", "/field3", "/field4", "/field5", "/field6")); - - String effectivePartitionKey = PartitionKeyInternalHelper.getEffectivePartitionKeyString(partitionKey, pkDefinition); - assertThat("05C1D39FA55F0408D1C0D1BF2ED281D284D282D282D1BBD1B9000103020005C016").isEqualTo(effectivePartitionKey); - - String latin = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"; - String nonLatin = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюяабвгдеёжзийклмнопрстуфхцчшщъыьэюя"; - - verifyEffectivePartitionKeyEncoding(latin, 99, "05C19B2DC38FC00862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F7071727374757600", false); - verifyEffectivePartitionKeyEncoding(latin, 99, "072D8FA3228DD2A6C0A7129C845700E6", true); - - verifyEffectivePartitionKeyEncoding(latin, 100, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 100, "023D5F0B62EBEF22A43564F267193B4D", true); - - verifyEffectivePartitionKeyEncoding(latin, 101, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 101, "357D83181DB32D35F58CDA3C9F2E0742", true); - - verifyEffectivePartitionKeyEncoding(latin, 102, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 102, "12B320F72959AB449FD8E090C6B23B88", true); - - verifyEffectivePartitionKeyEncoding(latin, 103, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 103, "25FD21A31C69A8C8AD994F7FAC2B2B9F", true); - - verifyEffectivePartitionKeyEncoding(latin, 104, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 104, "1DC6FB1CF6E1228C506AA6C8735023C4", true); - - verifyEffectivePartitionKeyEncoding(latin, 105, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 105, "308E1E7870956CE5D9BDAD01200E09BD", true); - - verifyEffectivePartitionKeyEncoding(latin, 106, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 106, "362E21ABDEA7179DBDF7BF549DD8303B", true); - - verifyEffectivePartitionKeyEncoding(latin, 107, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 107, "1EBE932ECEFA4F53CE339D31B6BF53FD", true); - - verifyEffectivePartitionKeyEncoding(latin, 108, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 108, "3BFA3A6E9CBABA0EF756AEDEC66B1B3C", true); - - verifyEffectivePartitionKeyEncoding(latin, 109, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 109, "2880BF78DE0CE2CD1B0120EDA22601C4", true); - - verifyEffectivePartitionKeyEncoding(latin, 110, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 110, "1F3577D1D9CA7FC56100AED11F4DC646", true); - - verifyEffectivePartitionKeyEncoding(latin, 111, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 111, "205A9EB61F3B063E61C6ED655C9220E6", true); - - verifyEffectivePartitionKeyEncoding(latin, 112, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 112, "1152A43F1A852AFDDD4518C9CDD48616", true); - - verifyEffectivePartitionKeyEncoding(latin, 113, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 113, "38E2EB2EF54012B5CA40CDA34F1C7736", true); - - verifyEffectivePartitionKeyEncoding(latin, 114, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 114, "19BCC416843B9085DBBC18E8C7C80D72", true); - - verifyEffectivePartitionKeyEncoding(latin, 115, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 115, "03F1BB89FD8E9747B047281E80FA2E84", true); - - verifyEffectivePartitionKeyEncoding(latin, 116, "05C1DD5D8149640862636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767778797A7B62636465666768696A6B6C6D6E6F707172737475767700", false); - verifyEffectivePartitionKeyEncoding(latin, 116, "2BA0757B833F3922A3CBBB6DDA3803B4", true); - - verifyEffectivePartitionKeyEncoding(nonLatin, 49, "05C1C1BD37FE08D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D281D282D283D284D285D286D287D288D289D28AD28BD28CD28DD28ED28FD290D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BF00", false); - verifyEffectivePartitionKeyEncoding(nonLatin, 49, "3742C1AF65AFA809282539F4BCDF2F6F", true); - - verifyEffectivePartitionKeyEncoding(nonLatin, 50, "05C1B339EF472008D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D281D282D283D284D285D286D287D288D289D28AD28BD28CD28DD28ED28FD290D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C000", false); - verifyEffectivePartitionKeyEncoding(nonLatin, 50, "399CF1F141E066E09CC7557EA7F0977A", true); - - verifyEffectivePartitionKeyEncoding(nonLatin, 51, "05C1EB1F29DBFA08D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D281D282D283D284D285D286D287D288D289D28AD28BD28CD28DD28ED28FD290D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D2", false); - verifyEffectivePartitionKeyEncoding(nonLatin, 51, "2D63C2F5FDAC6EFE5660CD509A723A90", true); - - verifyEffectivePartitionKeyEncoding(nonLatin, 99, "05C1E72F79C71608D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D281D282D283D284D285D286D287D288D289D28AD28BD28CD28DD28ED28FD290D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D2", false); - verifyEffectivePartitionKeyEncoding(nonLatin, 99, "1E9836D9BCB67FDB2B5C984BD40AFAF9", true); - - verifyEffectivePartitionKeyEncoding(nonLatin, 100, "05C1E3653D9F3E08D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D281D282D283D284D285D286D287D288D289D28AD28BD28CD28DD28ED28FD290D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D2", false); - verifyEffectivePartitionKeyEncoding(nonLatin, 100, "16102F19448867537E51BB4377962AF9", true); - - verifyEffectivePartitionKeyEncoding(nonLatin, 101, "05C1E3653D9F3E08D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D281D282D283D284D285D286D287D288D289D28AD28BD28CD28DD28ED28FD290D1B1D1B2D1B3D1B4D1B5D1B6D292D1B7D1B8D1B9D1BAD1BBD1BCD1BDD1BED1BFD1C0D2", false); - verifyEffectivePartitionKeyEncoding(nonLatin, 101, "0B6D25D07748AB9CA0F523D4BAD146C8", true); - } - - private static void validateEffectivePartitionKeyV2(String partitionKeyRangeJson, String expectedHexEncoding) { - PartitionKeyInternal partitionKey = PartitionKeyInternal.fromJsonString(partitionKeyRangeJson); - - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - partitionKeyDefinition.setKind(PartitionKind.Hash); - CommonsBridgeInternal.setV2(partitionKeyDefinition); - ArrayList paths = new ArrayList(); - for (int i = 0; i < partitionKey.getComponents().size(); i++) { - paths.add("/path" + i); - } - - if (paths.size() > 0) { - partitionKeyDefinition.setPaths(paths); - } - - String hexEncodedEffectivePartitionKey = PartitionKeyInternalHelper.getEffectivePartitionKeyString(partitionKey, partitionKeyDefinition); - assertThat(hexEncodedEffectivePartitionKey).isEqualTo(expectedHexEncoding); - } - - private void verifyComparison(String leftKey, String rightKey, int result) { - assertThat(PartitionKeyInternal.fromJsonString(leftKey). - compareTo(PartitionKeyInternal.fromJsonString(rightKey))).isEqualTo(result); - } - - private static void verifyEffectivePartitionKeyEncoding(String buffer, int length, String expectedValue, boolean v2) { - PartitionKeyDefinition pkDefinition = new PartitionKeyDefinition(); - pkDefinition.setPaths(ImmutableList.of("/field1")); - if (v2) { - CommonsBridgeInternal.setV2(pkDefinition); - } - - PartitionKeyInternal pk = PartitionKeyInternalUtils.createPartitionKeyInternal(buffer.substring(0, length)); - assertThat(PartitionKeyInternalHelper.getEffectivePartitionKeyString(pk, pkDefinition)).isEqualTo(expectedValue); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyTest.java deleted file mode 100644 index 31164b31156c..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionKeyTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalHelper; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.fail; - -public class PartitionKeyTest { - - @DataProvider(name = "paramProvider") - public Object[][] paramProvider() { - return new Object[][] { - { Undefined.Value(), "[{}]" }, - { null, "[null]"}, - { false, "[false]"}, - { true, "[true]"}, - { 123.456, "[123.456]"}, - { 5, "[5.0]"}, - { "PartitionKeyValue", "[\"PartitionKeyValue\"]"}, - }; - } - - /** - * Simple test for @{@link PartitionKey}. - */ - @Test(groups = "unit", dataProvider = "paramProvider") - public void partitionKey(Object partitionKey, String partitionKeyAsJson) { - assertThat(new PartitionKey(partitionKey).toString()).isEqualTo(partitionKeyAsJson); - } - - /** - * Test equals override for @{@link PartitionKey} - */ - @Test(groups = "unit", dataProvider = "paramProvider") - public void partitionKeyCompare(Object partitionKey, String partitionKeyAsJson) { - assertThat(new PartitionKey(partitionKey)).isEqualTo(PartitionKey.FromJsonString(partitionKeyAsJson)); - } - - /** - * too few partition key values. - */ - @Test(groups = "unit") - public void tooFewPartitionKeyComponents() { - PartitionKeyDefinition pkd = new PartitionKeyDefinition(); - pkd.setPaths(ImmutableList.of("/pk1", "/pk2")); - PartitionKey pk = PartitionKey.FromJsonString("[\"PartitionKeyValue\"]"); - - try { - PartitionKeyInternalHelper.getEffectivePartitionKeyString(pk.getInternalPartitionKey(), pkd); - fail("should throw"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isEqualTo(RMResources.TooFewPartitionKeyComponents); - } - } - - /** - * too many partition key values. - */ - @Test(groups = "unit") - public void tooManyPartitionKeyComponents() { - PartitionKeyDefinition pkd = new PartitionKeyDefinition(); - pkd.setPaths(ImmutableList.of("/pk1")); - PartitionKey pk = PartitionKey.FromJsonString("[true, false]"); - - try { - PartitionKeyInternalHelper.getEffectivePartitionKeyString(pk.getInternalPartitionKey(), pkd); - fail("should throw"); - } catch (IllegalArgumentException e) { - assertThat(e.getMessage()).isEqualTo(RMResources.TooManyPartitionKeyComponents); - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QuorumReaderTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QuorumReaderTest.java deleted file mode 100644 index cff71c20577a..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/QuorumReaderTest.java +++ /dev/null @@ -1,677 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.base.Stopwatch; -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.DocumentServiceRequestContextValidator; -import com.microsoft.azure.cosmosdb.rx.DocumentServiceRequestValidator; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.mockito.Mockito; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; - -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.net.URI; -import java.time.Duration; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; - -public class QuorumReaderTest { - private final Duration timeResolution = Duration.ofMillis(10); - private final Configs configs; - - public QuorumReaderTest() { - configs = new Configs(); - } - - @DataProvider(name = "simpleReadStrongArgProvider") - public Object[][] simpleReadStrongArgProvider() { - return new Object[][]{ - //int replicaCountToRead, ReadMode readMode, Long lsn, Long localLSN - { 1, ReadMode.Strong, 51l, 18l }, - { 2, ReadMode.Strong, 51l, 18l }, - { 3, ReadMode.Strong, 51l, 18l }, - - { 2, ReadMode.Any, 51l, 18l }, - { 1, ReadMode.Any, 51l, 18l }, - - { 2, ReadMode.Any, null, 18l }, - { 1, ReadMode.Any, null, 18l }, - }; - } - - private StoreResponse storeResponse(Long lsn, Long localLSN, Double rc) { - StoreResponseBuilder srb = StoreResponseBuilder.create(); - if (rc != null) { - srb.withRequestCharge(rc); - } - - if (lsn != null) { - srb.withLSN(lsn); - } - - if (localLSN != null) { - srb.withLocalLSN(localLSN); - } - - return srb.build(); - } - - @Test(groups = "unit", dataProvider = "simpleReadStrongArgProvider") - public void basicReadStrong_AllReplicasSameLSN(int replicaCountToRead, ReadMode readMode, Long lsn, Long localLSN) { - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - URI primaryReplicaURI = URI.create("primary"); - ImmutableList secondaryReplicaURIs = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2"), URI.create("secondary3")); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryReplicaURI) - .withSecondary(secondaryReplicaURIs) - .build(); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = new DocumentServiceRequestContext(); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = Mockito.mock(PartitionKeyRange.class); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - BigDecimal requestChargePerRead = new BigDecimal(1.1); - - StoreResponse primaryResponse = storeResponse(lsn, localLSN, requestChargePerRead.doubleValue()); - StoreResponse secondaryResponse1 = storeResponse(lsn, localLSN, requestChargePerRead.doubleValue()); - StoreResponse secondaryResponse2 = storeResponse(lsn, localLSN, requestChargePerRead.doubleValue()); - StoreResponse secondaryResponse3 = storeResponse(lsn, localLSN, requestChargePerRead.doubleValue()); - - TransportClientWrapper transportClientWrapper = TransportClientWrapper.Builder.uriToResultBuilder() - .storeResponseOn(primaryReplicaURI, OperationType.Read, ResourceType.Document, primaryResponse, false) - .storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, secondaryResponse1, false) - .storeResponseOn(secondaryReplicaURIs.get(1), OperationType.Read, ResourceType.Document, secondaryResponse2, false) - .storeResponseOn(secondaryReplicaURIs.get(2), OperationType.Read, ResourceType.Document, secondaryResponse3, false) - .build(); - - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - GatewayServiceConfigurationReader serviceConfigurator = Mockito.mock(GatewayServiceConfigurationReader.class); - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - QuorumReader quorumReader = new QuorumReader(configs, transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, storeReader, serviceConfigurator, authTokenProvider); - - Single storeResponseSingle = quorumReader.readStrongAsync(request, replicaCountToRead, readMode); - - StoreResponseValidator.Builder validatorBuilder = StoreResponseValidator.create() - .withBELocalLSN(localLSN) - .withRequestCharge(requestChargePerRead.multiply(BigDecimal.valueOf(replicaCountToRead)).setScale(2, RoundingMode.FLOOR).doubleValue()); - - if (lsn != null) { - validatorBuilder.withBELSN(lsn); - } - - validateSuccess(storeResponseSingle, validatorBuilder.build()); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(replicaCountToRead); - addressSelectorWrapper.validate() - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyTotalInvocations(1); - } - - @DataProvider(name = "readStrong_RequestBarrierArgProvider") - public Object[][] readStrong_RequestBarrierArgProvider() { - return new Object[][]{ - { 1 }, - { 2 }, - { configs.getMaxNumberOfReadBarrierReadRetries() - 1 }, - { configs.getMaxNumberOfReadBarrierReadRetries() }, - }; - } - - @Test(groups = "unit", dataProvider = "readStrong_RequestBarrierArgProvider") - public void readStrong_OnlySecondary_RequestBarrier_Success(int numberOfBarrierRequestTillCatchUp) { - // scenario: we get lsn l1, l2 where l1 > l2 - // we do barrier request and send it to all replicas till we have two replicas with at least l1 lsn - - ReadMode readMode = ReadMode.Strong; - int replicaCountToRead = 2; - - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - URI primaryReplicaURI = URI.create("primary"); - ImmutableList secondaryReplicaURIs = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2")); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryReplicaURI) - .withSecondary(secondaryReplicaURIs) - .build(); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = new DocumentServiceRequestContext(); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = Mockito.mock(PartitionKeyRange.class); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - BigDecimal requestChargePerRead = new BigDecimal(1.1); - BigDecimal requestChargePerHead = BigDecimal.ZERO; - - long expectedQuorumLsn = 53; - long expectedQuorumLocalLSN = 20; - - StoreResponse primaryResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 2) - .withLocalLSN(expectedQuorumLocalLSN - 2) - .withRequestCharge(requestChargePerRead) - .build(); - - TransportClientWrapper.Builder.UriToResultBuilder builder = TransportClientWrapper.Builder.uriToResultBuilder() - .storeResponseOn(primaryReplicaURI, OperationType.Read, ResourceType.Document, primaryResponse, false); - - // slow replica - StoreResponse readResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 1) - .withLocalLSN(expectedQuorumLocalLSN -1) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, readResponse, false); - - for(int i = 0; i < numberOfBarrierRequestTillCatchUp; i++) { - int lsnIncrement = (i == numberOfBarrierRequestTillCatchUp - 1) ? 1 : 0; - readResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 1 + lsnIncrement) - .withLocalLSN(expectedQuorumLocalLSN - 1 + lsnIncrement) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, readResponse, false); - - StoreResponse headResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 1 + lsnIncrement) - .withLocalLSN(expectedQuorumLocalLSN - 1 + lsnIncrement) - .withRequestCharge(requestChargePerHead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Head, ResourceType.DocumentCollection, headResponse, false); - } - - // faster replica - readResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn) - .withLocalLSN(expectedQuorumLocalLSN) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(1), OperationType.Read, ResourceType.Document, readResponse, false); - for(int i = 0; i < numberOfBarrierRequestTillCatchUp; i++) { - StoreResponse headResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn + 10 * (i + 1)) - .withLocalLSN(expectedQuorumLocalLSN + 10 * (i + 1)) - .withRequestCharge(requestChargePerHead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(1), OperationType.Head, ResourceType.DocumentCollection, headResponse, false); - } - - TransportClientWrapper transportClientWrapper = builder.build(); - - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - GatewayServiceConfigurationReader serviceConfigurator = Mockito.mock(GatewayServiceConfigurationReader.class); - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - QuorumReader quorumReader = new QuorumReader(configs, transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, storeReader, serviceConfigurator, authTokenProvider); - - int expectedNumberOfReads = 2; - int expectedNumberOfHeads = 2 * numberOfBarrierRequestTillCatchUp; - - double expectedRequestCharge = requestChargePerRead.multiply(BigDecimal.valueOf(expectedNumberOfReads)).add( - requestChargePerHead.multiply(BigDecimal.valueOf(expectedNumberOfHeads))).setScale(4, RoundingMode.FLOOR).doubleValue(); - - Stopwatch stopwatch = Stopwatch.createStarted(); - - Single storeResponseSingle = quorumReader.readStrongAsync(request, replicaCountToRead, readMode); - - StoreResponseValidator validator = StoreResponseValidator.create() - .withBELSN(expectedQuorumLsn) - .withRequestCharge(expectedRequestCharge) - .build(); - - validateSuccess(storeResponseSingle, validator); - - assertThat(stopwatch.elapsed().plus(timeResolution)).isGreaterThanOrEqualTo(Duration.ofMillis( - numberOfBarrierRequestTillCatchUp * configs.getDelayBetweenReadBarrierCallsInMs())); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(expectedNumberOfReads + expectedNumberOfHeads); - addressSelectorWrapper.validate() - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyTotalInvocations(1 + numberOfBarrierRequestTillCatchUp); - - AddressSelectorWrapper.InOrderVerification.Verifier addressSelectorVerifier = AddressSelectorWrapper.InOrderVerification.Verifier.builder() - .resolveAllUriAsync_IncludePrimary(false) - .resolveAllUriAsync_ForceRefresh(false) - .build(); - - addressSelectorWrapper.getInOrderVerification() - .verifyNumberOfInvocations(1 + numberOfBarrierRequestTillCatchUp) - .verifyOnAll(addressSelectorVerifier); - - DocumentServiceRequestValidator requestValidator = DocumentServiceRequestValidator.builder() - .add(DocumentServiceRequestContextValidator.builder() - .qurorumSelectedLSN(0l) - .globalCommittedSelectedLSN(0l) - .storeResponses(null) - .build()) - .build(); - requestValidator.validate(request); - } - - @DataProvider(name = "readStrong_SecondaryReadBarrierExhausted_ReadBarrierOnPrimary_SuccessArgProvider") - public Object[][] readStrong_SecondaryReadBarrierExhausted_ReadBarrierOnPrimary_SuccessArgProvider() { - return new Object[][]{ - { 1 }, - { 2 }, - { configs.getMaxNumberOfReadBarrierReadRetries() - 1 }, - { configs.getMaxNumberOfReadBarrierReadRetries() }, - }; - } - - @Test(groups = "unit", dataProvider = "readStrong_SecondaryReadBarrierExhausted_ReadBarrierOnPrimary_SuccessArgProvider") - public void readStrong_SecondaryReadBarrierExhausted_ReadBarrierOnPrimary_Success(int numberOfHeadBarriersWithPrimaryIncludedTillQuorumMet) { - // scenario: we exhaust all barrier request retries on secondaries - // after that we start barrier requests including the primary - - int numberOfBarrierRequestTillCatchUp = configs.getMaxNumberOfReadBarrierReadRetries() + numberOfHeadBarriersWithPrimaryIncludedTillQuorumMet; - - ReadMode readMode = ReadMode.Strong; - int replicaCountToRead = 2; - - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - URI primaryReplicaURI = URI.create("primary"); - ImmutableList secondaryReplicaURIs = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2")); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryReplicaURI) - .withSecondary(secondaryReplicaURIs) - .build(); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = new DocumentServiceRequestContext(); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = Mockito.mock(PartitionKeyRange.class); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - BigDecimal requestChargePerRead = new BigDecimal(1.1); - BigDecimal requestChargePerHead = BigDecimal.ZERO; - - TransportClientWrapper.Builder.UriToResultBuilder builder = TransportClientWrapper.Builder.uriToResultBuilder(); - - long expectedQuorumLsn = 53; - long expectedQuorumLocalLSN = 20; - - for(int i = 0; i < numberOfHeadBarriersWithPrimaryIncludedTillQuorumMet; i++) { - int lsnIncrement = (i == numberOfHeadBarriersWithPrimaryIncludedTillQuorumMet - 1) ? 1 : 0; - StoreResponse headResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 1 + lsnIncrement) - .withLocalLSN(expectedQuorumLocalLSN - 1 + lsnIncrement) - .withRequestCharge(requestChargePerHead) - .build(); - builder.storeResponseOn(primaryReplicaURI, OperationType.Head, ResourceType.DocumentCollection, headResponse, false); - } - - // slow replica - StoreResponse readResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 1) - .withLocalLSN(expectedQuorumLocalLSN - 1) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, readResponse, false); - - for(int i = 0; i < numberOfBarrierRequestTillCatchUp; i++) { - int lsnIncrement = (i == numberOfBarrierRequestTillCatchUp - 1) ? 1 : 0; - readResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 1 + lsnIncrement) - .withLocalLSN(expectedQuorumLocalLSN - 1 + lsnIncrement) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, readResponse, false); - - StoreResponse headResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn - 1 + lsnIncrement) - .withLocalLSN(expectedQuorumLocalLSN - 1 + lsnIncrement) - .withRequestCharge(requestChargePerHead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Head, ResourceType.DocumentCollection, headResponse, false); - } - - // faster replica - readResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn) - .withLocalLSN(expectedQuorumLocalLSN) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(1), OperationType.Read, ResourceType.Document, readResponse, false); - for(int i = 0; i < numberOfBarrierRequestTillCatchUp; i++) { - StoreResponse headResponse = StoreResponseBuilder.create() - .withLSN(expectedQuorumLsn + 10 * (i + 1)) - .withLocalLSN(expectedQuorumLocalLSN + 10 * (i + 1)) - .withRequestCharge(requestChargePerHead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(1), OperationType.Head, ResourceType.DocumentCollection, headResponse, false); - } - - TransportClientWrapper transportClientWrapper = builder.build(); - - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - GatewayServiceConfigurationReader serviceConfigurator = Mockito.mock(GatewayServiceConfigurationReader.class); - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - QuorumReader quorumReader = new QuorumReader(configs, transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, storeReader, serviceConfigurator, authTokenProvider); - - int beforeSecondariesRetriesExhausted_expectedNumberOfReads = 2; - int beforeSecondariesRetriesExhausted_expectedNumberOfHeads = 2 * configs.getMaxNumberOfReadBarrierReadRetries(); - - int numberOfHeadRetriesRequestWhenPrimaryIncluded = 3 * numberOfHeadBarriersWithPrimaryIncludedTillQuorumMet; - - double expectedRequestCharge = requestChargePerRead.multiply(BigDecimal.valueOf(beforeSecondariesRetriesExhausted_expectedNumberOfReads)) - .add(requestChargePerHead.multiply(BigDecimal.valueOf(beforeSecondariesRetriesExhausted_expectedNumberOfHeads))) - .setScale(4, RoundingMode.FLOOR).doubleValue(); - - Stopwatch stopwatch = Stopwatch.createStarted(); - - Single storeResponseSingle = quorumReader.readStrongAsync(request, replicaCountToRead, readMode); - - StoreResponseValidator validator = StoreResponseValidator.create() - .withBELSN(expectedQuorumLsn) - .withRequestCharge(expectedRequestCharge) - .build(); - - validateSuccess(storeResponseSingle, validator); - - assertThat(stopwatch.elapsed().plus(timeResolution)).isGreaterThanOrEqualTo(Duration.ofMillis( - numberOfBarrierRequestTillCatchUp * configs.getDelayBetweenReadBarrierCallsInMs())); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(beforeSecondariesRetriesExhausted_expectedNumberOfReads - + beforeSecondariesRetriesExhausted_expectedNumberOfHeads - + numberOfHeadRetriesRequestWhenPrimaryIncluded); - addressSelectorWrapper.validate() - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyTotalInvocations(1 + numberOfBarrierRequestTillCatchUp); - - AddressSelectorWrapper.InOrderVerification.Verifier primaryNotIncludedVerifier = AddressSelectorWrapper - .InOrderVerification.Verifier.builder() - .resolveAllUriAsync_IncludePrimary(false) - .resolveAllUriAsync_ForceRefresh(false) - .build(); - - AddressSelectorWrapper.InOrderVerification.Verifier primaryIncludedVerifier = AddressSelectorWrapper - .InOrderVerification.Verifier.builder() - .resolveAllUriAsync_IncludePrimary(true) - .resolveAllUriAsync_ForceRefresh(false) - .build(); - - int numberOfAddressResolutionWithoutPrimary = configs.getMaxNumberOfReadBarrierReadRetries()+ 1; - int numberOfAddressResolutionWithPrimary = 1; - - AddressSelectorWrapper.InOrderVerification ov = addressSelectorWrapper.getInOrderVerification(); - - for(int i = 0; i < numberOfAddressResolutionWithoutPrimary; i++) { - ov.verifyNext(primaryNotIncludedVerifier); - } - - for(int i = 0; i < numberOfAddressResolutionWithPrimary; i++) { - ov.verifyNext(primaryIncludedVerifier); - } - - DocumentServiceRequestValidator requestValidator = DocumentServiceRequestValidator.builder() - .add(DocumentServiceRequestContextValidator.builder() - .qurorumSelectedLSN(0l) - .globalCommittedSelectedLSN(0l) - .storeResponses(null) - .build()) - .build(); - requestValidator.validate(request); - } - - @Test(groups = "unit") - public void readStrong_QuorumNotSelected_ReadPrimary() { - // scenario: attempts to read from secondaries, - // only one secondary is available so ends in QuorumNotSelected State - // reads from Primary and succeeds - - ReadMode readMode = ReadMode.Strong; - int replicaCountToRead = 2; - - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - URI primaryReplicaURI = URI.create("primary"); - ImmutableList secondaryReplicaURIs = ImmutableList.of(URI.create("secondary1")); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryReplicaURI) - .withSecondary(secondaryReplicaURIs) - .build(); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = new DocumentServiceRequestContext(); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = Mockito.mock(PartitionKeyRange.class); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - BigDecimal requestChargePerRead = new BigDecimal(1.1); - BigDecimal requestChargePerHead = BigDecimal.ZERO; - - TransportClientWrapper.Builder.UriToResultBuilder builder = TransportClientWrapper.Builder.uriToResultBuilder(); - - long primaryLSN = 52; - long primaryLocalLSN = 19; - - StoreResponse headResponse = StoreResponseBuilder.create() - .withLSN(primaryLSN) - .withLocalLSN(primaryLocalLSN) - .withHeader(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE, "2") - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LSN, Long.toString(primaryLSN)) - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long.toString(primaryLocalLSN)) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(primaryReplicaURI, OperationType.Read, ResourceType.Document, headResponse, false); - - StoreResponse readResponse = StoreResponseBuilder.create() - .withLSN(primaryLSN) - .withLocalLSN(primaryLocalLSN) - .withRequestCharge(requestChargePerRead) - .build(); - builder.storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, readResponse, false); - - TransportClientWrapper transportClientWrapper = builder.build(); - - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - GatewayServiceConfigurationReader serviceConfigurator = Mockito.mock(GatewayServiceConfigurationReader.class); - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - QuorumReader quorumReader = new QuorumReader(configs, transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, storeReader, serviceConfigurator, authTokenProvider); - - double expectedRequestCharge = requestChargePerRead.multiply(BigDecimal.valueOf(1)) - .add(requestChargePerHead.multiply(BigDecimal.valueOf(0))) - .setScale(4, RoundingMode.FLOOR).doubleValue(); - - Single storeResponseSingle = quorumReader.readStrongAsync(request, replicaCountToRead, readMode); - - StoreResponseValidator validator = StoreResponseValidator.create() - .withBELSN(primaryLSN) - .withBELocalLSN(primaryLocalLSN) - .withRequestCharge(expectedRequestCharge) - .build(); - - validateSuccess(storeResponseSingle, validator); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(1); - - addressSelectorWrapper.validate() - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(1) - .verifyTotalInvocations(2); - - AddressSelectorWrapper.InOrderVerification.Verifier primaryNotIncludedVerifier = AddressSelectorWrapper - .InOrderVerification.Verifier.builder() - .resolveAllUriAsync_IncludePrimary(false) - .resolveAllUriAsync_ForceRefresh(false) - .build(); - - AddressSelectorWrapper.InOrderVerification.Verifier resolvePrimaryVerifier = AddressSelectorWrapper - .InOrderVerification.Verifier.builder() - .resolvePrimaryUriAsync() - .build(); - - AddressSelectorWrapper.InOrderVerification ov = addressSelectorWrapper.getInOrderVerification(); - ov.verifyNext(primaryNotIncludedVerifier); - ov.verifyNext(resolvePrimaryVerifier); - - DocumentServiceRequestValidator requestValidator = DocumentServiceRequestValidator.builder() - .add(DocumentServiceRequestContextValidator.builder() - .qurorumSelectedLSN(0l) - .globalCommittedSelectedLSN(0l) - .storeResponses(null) - .build()) - .build(); - requestValidator.validate(request); - } - - @DataProvider(name = "readPrimaryArgProvider") - public Object[][] readPrimaryArgProvider() { - return new Object[][]{ - // endpoint, verifier for endpoint expected result, verifying the StoreResponse returned - { - EndpointMock.noSecondaryReplicaBuilder() - .response(StoreResponseBuilder.create() - .withLSN(52) - .withLocalLSN(19) - .withHeader(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE, "1") - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LSN, "19") - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, "19") - .withRequestCharge(0) - .build()) - .build(), - - EndpointMock.EndpointMockVerificationBuilder.builder() - .withAddressSelectorValidation(AddressSelectorWrapper - .InOrderVerificationBuilder - .create() - .verifyNumberOfInvocations(2) - .verifyNext(AddressSelectorWrapper.InOrderVerification.Verifier.builder() - .resolveAllUriAsync_IncludePrimary(false) - .resolveAllUriAsync_ForceRefresh(false) - .build()) - .verifyNext(AddressSelectorWrapper.InOrderVerification.Verifier.builder() - .resolvePrimaryUriAsync() - .build())) - .withTransportClientValidation(TransportClientWrapper.TransportClientWrapperVerificationBuilder.create().verifyNumberOfInvocations(1)), - - StoreResponseValidator.create() - .withBELSN(52) - .build() - } - }; - } - - @Test(groups = "unit", dataProvider = "readPrimaryArgProvider") - public void readPrimary(EndpointMock endpointMock, - EndpointMock.EndpointMockVerificationBuilder verification, - StoreResponseValidator storeResponseValidator) { - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - GatewayServiceConfigurationReader serviceConfigurator = Mockito.mock(GatewayServiceConfigurationReader.class); - IAuthorizationTokenProvider authTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - - QuorumReader quorumReader = new QuorumReader(configs, endpointMock.transportClientWrapper.transportClient, - endpointMock.addressSelectorWrapper.addressSelector, - new StoreReader(endpointMock.transportClientWrapper.transportClient, - endpointMock.addressSelectorWrapper.addressSelector, - sessionContainer), - serviceConfigurator, - authTokenProvider); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = new DocumentServiceRequestContext(); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = Mockito.mock(PartitionKeyRange.class); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - int replicaCountToRead = 1; - ReadMode readMode = ReadMode.Strong; - Single storeResponseSingle = quorumReader.readStrongAsync(request, replicaCountToRead, readMode); - - validateSuccess(storeResponseSingle, storeResponseValidator); - endpointMock.validate(verification); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator, - long timeout) { - TestSubscriber> testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public static void validateSuccess(Single single, - StoreResponseValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single single, - StoreResponseValidator validator, - long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicaAddressFactory.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicaAddressFactory.java deleted file mode 100644 index 472f9e19eb7d..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicaAddressFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import org.apache.commons.lang3.RandomStringUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class ReplicaAddressFactory { - private static String TEMPLATE = "https://by4prdddc03-docdb-1.documents.azure.com:9056" + - "/apps/%s/services/e7c8d429-c379-40c9-9486-65b89b70be2f" + - "/partitions/%s/replicas/%s/"; - - public static String createPartitionPhysicalURI(String partitionId, boolean isPrimary) { - return String.format(TEMPLATE, UUID.randomUUID(), partitionId, RandomStringUtils.randomNumeric(18) + (isPrimary ? "p" : "s")); - } - - public static String createPrimaryPhysicalURI(String partitionId) { - return createPartitionPhysicalURI(partitionId, true); - } - - public static String createSecondaryPhysicalURI(String partitionId) { - return createPartitionPhysicalURI(partitionId, false); - } - - public static AddressInformation createAddressInformation(String partitionId, boolean isPrimary, Protocol protocol) { - String loc = createPartitionPhysicalURI(partitionId, isPrimary); - return new AddressInformation(true, isPrimary, loc, protocol); - } - - public static List createPartitionAddressInformation(String partitionId, - boolean includePrimary, - int numberOfAllReplicas, - Protocol protocol) { - List addressInformationList = new ArrayList<>(); - for (boolean isPrimary = includePrimary; numberOfAllReplicas > 0; numberOfAllReplicas--) { - addressInformationList.add(createAddressInformation(partitionId, isPrimary, protocol)); - isPrimary = false; - } - - return addressInformationList; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClientPartitionSplitTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClientPartitionSplitTest.java deleted file mode 100644 index dfc26fef75a4..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClientPartitionSplitTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.SessionContainer; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.assertj.core.api.Assertions; -import org.mockito.Mockito; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Single; -import rx.functions.Func1; -import rx.observers.TestSubscriber; - -import java.net.URI; -import java.util.List; -import java.util.concurrent.TimeUnit; - -public class ReplicatedResourceClientPartitionSplitTest { - protected static final int TIMEOUT = 120000; - - @DataProvider(name = "partitionIsSplittingArgProvider") - public Object[][] partitionIsSplittingArgProvider() { - return new Object[][]{ - // Consistency mode, number of partition splitting exception till split migration completes - { ConsistencyLevel.Eventual, 1}, - { ConsistencyLevel.Eventual, 2}, - { ConsistencyLevel.Eventual, Integer.MAX_VALUE }, // server side partition split operation never completes - }; - } - - @Test(groups = { "unit" }, dataProvider = "partitionIsSplittingArgProvider", timeOut = TIMEOUT) - public void partitionSplit_RefreshCache_Read(ConsistencyLevel consistencyLevel, int partitionIsSplitting) { - URI secondary1AddressBeforeMove = URI.create("secondary"); - URI secondary1AddressAfterMove = URI.create("secondaryNew"); - - URI primaryAddressBeforeMove = URI.create("primary"); - URI primaryAddressAfterMove = URI.create("primaryNew"); - - String partitionKeyRangeIdBeforeSplit = "1"; - String partitionKeyRangeIdAfterSplit = "2"; - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.ReplicaMoveBuilder.create(Protocol.Https) - .withPrimaryMove(primaryAddressBeforeMove, primaryAddressAfterMove) - .withSecondaryMove(secondary1AddressBeforeMove, secondary1AddressAfterMove) - .newPartitionKeyRangeIdOnRefresh(r -> partitionKeyRangeWithId(partitionKeyRangeIdAfterSplit)) - .build(); - - long lsn = 54; - long localLsn = 18; - - StoreResponse primaryResponse = StoreResponseBuilder.create() - .withLSN(lsn) - .withLocalLSN(localLsn) - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long.toString(localLsn)) - .withHeader(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE, partitionKeyRangeIdAfterSplit) - .withRequestCharge(1.1) - .build(); - StoreResponse secondaryResponse1 = StoreResponseBuilder.create() - .withLSN(lsn) - .withLocalLSN(localLsn) - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LOCAL_LSN, Long.toString(localLsn)) - .withHeader(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE, partitionKeyRangeIdAfterSplit) - .withRequestCharge(1.1) - .build(); - - TransportClientWrapper.Builder.UriToResultBuilder transportClientWrapperBuilder = TransportClientWrapper.Builder.uriToResultBuilder(); - - PartitionKeyRangeIsSplittingException splittingException = new PartitionKeyRangeIsSplittingException(); - if (partitionIsSplitting == Integer.MAX_VALUE) { - transportClientWrapperBuilder - .exceptionOn(primaryAddressBeforeMove, OperationType.Read, ResourceType.Document, splittingException, true) - .exceptionOn(secondary1AddressBeforeMove, OperationType.Read, ResourceType.Document, splittingException, true); - } else { - for (int i = 0; i < partitionIsSplitting; i++) { - transportClientWrapperBuilder - .exceptionOn(primaryAddressBeforeMove, OperationType.Read, ResourceType.Document, splittingException, false) - .exceptionOn(secondary1AddressBeforeMove, OperationType.Read, ResourceType.Document, splittingException, false); - } - } - - GoneException goneException = new GoneException(); - transportClientWrapperBuilder - .exceptionOn(primaryAddressBeforeMove, OperationType.Read, ResourceType.Document, goneException, true) - .exceptionOn(secondary1AddressBeforeMove, OperationType.Read, ResourceType.Document, goneException, true) - .storeResponseOn(primaryAddressAfterMove, OperationType.Read, ResourceType.Document, secondaryResponse1, true) - .storeResponseOn(secondary1AddressAfterMove, OperationType.Read, ResourceType.Document, primaryResponse, true); - - - TransportClientWrapper transportClientWrapper = transportClientWrapperBuilder.build(); - - GatewayServiceConfiguratorReaderMock gatewayServiceConfigurationReaderWrapper = GatewayServiceConfiguratorReaderMock.from(ConsistencyLevel.Strong, - 4, - 3, - 4, - 3); - - SessionContainer sessionContainer = new SessionContainer("test"); - - IAuthorizationTokenProvider authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - ReplicatedResourceClient resourceClient = new ReplicatedResourceClient(new Configs(), - addressSelectorWrapper.addressSelector, - sessionContainer, - transportClientWrapper.transportClient, - gatewayServiceConfigurationReaderWrapper.gatewayServiceConfigurationReader, - authorizationTokenProvider, - false, - false); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - request.requestContext = new DocumentServiceRequestContext(); - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeIdBeforeSplit); - request.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, consistencyLevel.name()); - - Func1> prepareRequestAsyncDelegate = null; - Single storeResponseObs = resourceClient.invokeAsync(request, prepareRequestAsyncDelegate); - - if (partitionIsSplitting < Integer.MAX_VALUE) { - - StoreResponseValidator validator = StoreResponseValidator.create() - .withBELSN(lsn) - .withRequestCharge(1.1) - .build(); - validateSuccess(storeResponseObs, validator); - - addressSelectorWrapper.verifyNumberOfForceCacheRefreshGreaterThanOrEqualTo(1); - } else { - FailureValidator validator = FailureValidator.builder().instanceOf(DocumentClientException.class) - .statusCode(503).build(); - validateFailure(storeResponseObs, validator, TIMEOUT); - } - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator) { - validateSuccess(single, validator, TIMEOUT); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator, long timeout) { - TestSubscriber> testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public static void validateSuccess(Single single, - StoreResponseValidator validator) { - validateSuccess(single, validator, TIMEOUT); - } - - public static void validateSuccess(Single single, - StoreResponseValidator validator, long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - - public static void validateFailure(Single single, FailureValidator validator, long timeout) { - - TestSubscriber testSubscriber = new TestSubscriber<>(); - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - private PartitionKeyRange partitionKeyRangeWithId(String id) { - PartitionKeyRange partitionKeyRange = Mockito.mock(PartitionKeyRange.class); - Mockito.doReturn(id).when(partitionKeyRange).getId(); - return partitionKeyRange; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClientTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClientTest.java deleted file mode 100644 index 55c8c4c6da04..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/ReplicatedResourceClientTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.assertj.core.api.Assertions; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; - -import java.util.concurrent.TimeUnit; - -public class ReplicatedResourceClientTest { - protected static final int TIMEOUT = 60000; - private IAddressResolver addressResolver; - private TransportClient transportClient; - private boolean enableReadRequestsFallback; - public boolean forceAddressRefresh; - private GatewayServiceConfigurationReader serviceConfigReader; - private IAuthorizationTokenProvider authorizationTokenProvider; - - @BeforeClass(groups = "unit") - public void setup() throws Exception { - addressResolver = Mockito.mock(IAddressResolver.class); - transportClient = Mockito.mock(TransportClient.class); - serviceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - } - - /** - * This test will verify that Gone exception will be retired - * fixed number of time before throwing error. - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void invokeAsyncWithGoneException() { - Configs configs = new Configs(); - ReplicatedResourceClient resourceClient = new ReplicatedResourceClient(configs, new AddressSelector(addressResolver, Protocol.Https), null, - transportClient, serviceConfigReader, authorizationTokenProvider, enableReadRequestsFallback, false); - FailureValidator validator = FailureValidator.builder().instanceOf(DocumentClientException.class).build(); - RxDocumentServiceRequest request = Mockito.spy(RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document)); - - Mockito.when(addressResolver.resolveAsync(Matchers.any(), Matchers.anyBoolean())) - .thenReturn(Single.error(new GoneException())); - Single response = resourceClient.invokeAsync(request, null); - - validateFailure(response, validator, TIMEOUT); - //method will fail 7 time (first try ,last try , and 5 retries within 30 sec(1,2,4,8,15 wait)) - Mockito.verify(addressResolver, Mockito.times(7)).resolveAsync(Matchers.any(), Matchers.anyBoolean()); - } - - public static void validateFailure(Single single, FailureValidator validator, long timeout) { - - TestSubscriber testSubscriber = new TestSubscriber<>(); - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RntbdTransportClientTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RntbdTransportClientTest.java deleted file mode 100644 index 0bdb62448466..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/RntbdTransportClientTest.java +++ /dev/null @@ -1,914 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableMap; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.BaseAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.internal.InternalServerErrorException; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.Paths; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdContext; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdContextNegotiator; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdContextRequest; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdEndpoint; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestArgs; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestEncoder; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestManager; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestRecord; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdRequestTimer; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdResponse; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdResponseDecoder; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.rntbd.RntbdUUID; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandler; -import io.netty.channel.embedded.EmbeddedChannel; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslContextBuilder; -import org.apache.commons.lang3.StringUtils; -import org.assertj.core.api.Assertions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Single; -import rx.Subscriber; -import rx.observers.TestSubscriber; - -import java.net.ConnectException; -import java.net.URI; -import java.time.Duration; -import java.util.Arrays; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.TimeUnit; -import java.util.stream.Stream; - -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.HttpHeaders; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.HttpMethods; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -public final class RntbdTransportClientTest { - - private static final Logger logger = LoggerFactory.getLogger(RntbdTransportClientTest.class); - private static final int lsn = 5; - private static final ByteBuf noContent = Unpooled.wrappedBuffer(new byte[0]); - private static final String partitionKeyRangeId = "3"; - private static final URI physicalAddress = URI.create("rntbd://host:10251/replica-path/"); - private static final Duration requestTimeout = Duration.ofSeconds(1000); - - @DataProvider(name = "fromMockedNetworkFailureToExpectedDocumentClientException") - public Object[][] fromMockedNetworkFailureToExpectedDocumentClientException() { - - return new Object[][] { - }; - } - - @DataProvider(name = "fromMockedRntbdResponseToExpectedDocumentClientException") - public Object[][] fromMockedRntbdResponseToExpectedDocumentClientException() { - - return new Object[][] { - { - // 1 BadRequestException - - FailureValidator.builder() - .instanceOf(BadRequestException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 400, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 2 UnauthorizedException - - FailureValidator.builder() - .instanceOf(UnauthorizedException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 401, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 3 ForbiddenException - - FailureValidator.builder() - .instanceOf(ForbiddenException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 403, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 4 NotFoundException - - FailureValidator.builder() - .instanceOf(NotFoundException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 404, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 5 MethodNotAllowedException - - FailureValidator.builder() - .instanceOf(MethodNotAllowedException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 405, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 6 RequestTimeoutException - - FailureValidator.builder() - .instanceOf(RequestTimeoutException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 408, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 7 ConflictException - - FailureValidator.builder() - .instanceOf(ConflictException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 409, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 8 InvalidPartitionException - - FailureValidator.builder() - .instanceOf(InvalidPartitionException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 410, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId, - HttpHeaders.SUB_STATUS, Integer.toString(SubStatusCodes.NAME_CACHE_IS_STALE) - ), - noContent) - }, - { - // 9 PartitionKeyRangeGoneException - - FailureValidator.builder() - .instanceOf(PartitionKeyRangeGoneException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 410, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId, - HttpHeaders.SUB_STATUS, Integer.toString(SubStatusCodes.PARTITION_KEY_RANGE_GONE) - ), - noContent) - }, - { - // 10 PartitionKeyRangeIsSplittingException - - FailureValidator.builder() - .instanceOf(PartitionKeyRangeIsSplittingException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 410, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId, - HttpHeaders.SUB_STATUS, Integer.toString(SubStatusCodes.COMPLETING_SPLIT) - ), - noContent) - }, - { - // 11 PartitionIsMigratingException - - FailureValidator.builder() - .instanceOf(PartitionIsMigratingException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 410, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId, - HttpHeaders.SUB_STATUS, Integer.toString(SubStatusCodes.COMPLETING_PARTITION_MIGRATION) - ), - noContent) - }, - { - // 12 GoneException - - FailureValidator.builder() - .instanceOf(GoneException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 410, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId, - HttpHeaders.SUB_STATUS, String.valueOf(SubStatusCodes.UNKNOWN)), - noContent) - }, - { - // 13 PreconditionFailedException - - FailureValidator.builder() - .instanceOf(PreconditionFailedException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 412, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 14 RequestEntityTooLargeException - - FailureValidator.builder() - .instanceOf(RequestEntityTooLargeException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 413, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 15 LockedException - - FailureValidator.builder() - .instanceOf(LockedException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 423, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 16 RequestRateTooLargeException - - FailureValidator.builder() - .instanceOf(RequestRateTooLargeException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 429, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 17 RetryWithException - - FailureValidator.builder() - .instanceOf(RetryWithException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 449, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 18 InternalServerErrorException - - FailureValidator.builder() - .instanceOf(InternalServerErrorException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 500, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - { - // 19 ServiceUnavailableException - - FailureValidator.builder() - .instanceOf(ServiceUnavailableException.class) - .lsn(lsn) - .partitionKeyRangeId(partitionKeyRangeId) - .resourceAddress(null), - RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - "/dbs/db/colls/col", - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - )), - new RntbdResponse( - RntbdUUID.EMPTY, - 503, - ImmutableMap.of( - HttpHeaders.LSN, Integer.toString(lsn), - HttpHeaders.PARTITION_KEY_RANGE_ID, partitionKeyRangeId - ), - noContent) - }, - }; - } - - /** - * Verifies that a request for a non-existent resource produces a {@link }GoneException} - */ - @Test(enabled = false, groups = "direct") - public void verifyGoneResponseMapsToGoneException() throws Exception { - - final RntbdTransportClient.Options options = new RntbdTransportClient.Options.Builder(requestTimeout).build(); - final SslContext sslContext = SslContextBuilder.forClient().build(); - - try (final RntbdTransportClient transportClient = new RntbdTransportClient(options, sslContext)) { - - final BaseAuthorizationTokenProvider authorizationTokenProvider = new BaseAuthorizationTokenProvider( - RntbdTestConfiguration.AccountKey - ); - - final URI physicalAddress = new URI("rntbd://" - + RntbdTestConfiguration.RntbdAuthority - + "/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/" - ); - - final ImmutableMap.Builder builder = ImmutableMap.builder(); - - builder.put(HttpHeaders.X_DATE, Utils.nowAsRFC1123()); - - final String token = authorizationTokenProvider.generateKeyAuthorizationSignature(HttpMethods.GET, - Paths.DATABASE_ACCOUNT_PATH_SEGMENT, - ResourceType.DatabaseAccount, - builder.build() - ); - - builder.put(HttpHeaders.AUTHORIZATION, token); - - final RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.DatabaseAccount, - Paths.DATABASE_ACCOUNT_PATH_SEGMENT, - builder.build() - ); - - final Single responseSingle = transportClient.invokeStoreAsync(physicalAddress, null, request); - - responseSingle.toObservable().toBlocking().subscribe(new Subscriber() { - @Override - public void onCompleted() { - } - - @Override - public void onError(final Throwable error) { - final String format = "Expected %s, not %s"; - assertTrue(error instanceof GoneException, String.format(format, GoneException.class, error.getClass())); - final Throwable cause = error.getCause(); - if (cause != null) { - // assumption: cosmos isn't listening on 10251 - assertTrue(cause instanceof ConnectException, String.format(format, ConnectException.class, error.getClass())); - } - } - - @Override - public void onNext(final StoreResponse response) { - fail(String.format("Expected GoneException, not a StoreResponse: %s", response)); - } - }); - - } catch (final Exception error) { - final String message = String.format("%s: %s", error.getClass(), error.getMessage()); - fail(message, error); - } - } - - /** - * Validates the error handling behavior of {@link RntbdTransportClient} for network failures - *

- * These are the exceptions that cannot be derived from server responses. They are mapped from Netty channel - * failures simulated by {@link FakeChannel}. - * - * @param builder A feature validator builder to confirm that response is correctly mapped to an exception - * @param request An RNTBD request instance - * @param exception An exception mapping - */ - @Test(enabled = false, groups = "unit", dataProvider = "fromMockedNetworkFailureToExpectedDocumentClientException") - public void verifyNetworkFailure( - final FailureValidator.Builder builder, - final RxDocumentServiceRequest request, - final DocumentClientException exception - ) { - // TODO: DANOBLE: Implement RntbdTransportClientTest.verifyNetworkFailure - // Links: - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/378750 - throw new UnsupportedOperationException("TODO: DANOBLE: Implement this test"); - } - - /** - * Validates the error handling behavior of the {@link RntbdTransportClient} for HTTP status codes >= 400 - * - * @param builder A feature validator builder to confirm that response is correctly mapped to an exception - * @param request An RNTBD request instance - * @param response The RNTBD response instance to be returned as a result of the request - */ - @Test(enabled = true, groups = "unit", dataProvider = "fromMockedRntbdResponseToExpectedDocumentClientException") - public void verifyRequestFailures( - final FailureValidator.Builder builder, - final RxDocumentServiceRequest request, - final RntbdResponse response - ) { - final UserAgentContainer userAgent = new UserAgentContainer(); - final Duration timeout = Duration.ofMillis(100); - - try (final RntbdTransportClient client = getRntbdTransportClientUnderTest(userAgent, timeout, response)) { - - final Single responseSingle; - - try { - responseSingle = client.invokeStoreAsync( - physicalAddress, new ResourceOperation(request.getOperationType(), request.getResourceType()), request - ); - } catch (final Exception error) { - throw new AssertionError(String.format("%s: %s", error.getClass(), error.getMessage())); - } - - this.validateFailure(responseSingle, builder.build()); - } - } - - private static RntbdTransportClient getRntbdTransportClientUnderTest( - final UserAgentContainer userAgent, - final Duration requestTimeout, - final RntbdResponse expected - ) { - - final RntbdTransportClient.Options options = new RntbdTransportClient.Options.Builder(requestTimeout) - .userAgent(userAgent) - .build(); - - final SslContext sslContext; - - try { - sslContext = SslContextBuilder.forClient().build(); - } catch (final Exception error) { - throw new AssertionError(String.format("%s: %s", error.getClass(), error.getMessage())); - } - - return new RntbdTransportClient(new FakeEndpoint.Provider(options, sslContext, expected)); - } - - private void validateFailure(final Single single, final FailureValidator validator) { - validateFailure(single, validator, requestTimeout.toMillis()); - } - - private static void validateFailure( - final Single single, final FailureValidator validator, final long timeout - ) { - - final TestSubscriber testSubscriber = new TestSubscriber<>(); - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - Assertions.assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - // region Types - - private static final class FakeChannel extends EmbeddedChannel { - - private static final ServerProperties serverProperties = new ServerProperties("agent", "3.0.0"); - private final BlockingQueue responses; - - FakeChannel(final BlockingQueue responses, final ChannelHandler... handlers) { - super(handlers); - this.responses = responses; - } - - @Override - protected void handleInboundMessage(final Object message) { - super.handleInboundMessage(message); - assertTrue(message instanceof ByteBuf); - } - - @Override - protected void handleOutboundMessage(final Object message) { - - assertTrue(message instanceof ByteBuf); - - final ByteBuf out = Unpooled.buffer(); - final ByteBuf in = (ByteBuf) message; - - // This is the end of the outbound pipeline and so we can do what we wish with the outbound message - - if (in.getUnsignedIntLE(4) == 0) { - - final RntbdContextRequest request = RntbdContextRequest.decode(in.copy()); - final RntbdContext rntbdContext = RntbdContext.from(request, serverProperties, HttpResponseStatus.OK); - - rntbdContext.encode(out); - - } else { - - final RntbdResponse rntbdResponse; - - try { - rntbdResponse = this.responses.take(); - } catch (final Exception error) { - throw new AssertionError(String.format("%s: %s", error.getClass(), error.getMessage())); - } - - rntbdResponse.encode(out); - out.setBytes(8, in.slice(8, 16)); // Overwrite activityId - } - - this.writeInbound(out); - } - } - - private static final class FakeEndpoint implements RntbdEndpoint { - - final RntbdRequestTimer requestTimer; - final FakeChannel fakeChannel; - final URI physicalAddress; - - private FakeEndpoint( - final Config config, final RntbdRequestTimer timer, final URI physicalAddress, - final RntbdResponse... expected - ) { - - final ArrayBlockingQueue responses = new ArrayBlockingQueue<>( - expected.length, true, Arrays.asList(expected) - ); - - RntbdRequestManager requestManager = new RntbdRequestManager(); - this.physicalAddress = physicalAddress; - this.requestTimer = timer; - - this.fakeChannel = new FakeChannel(responses, - new RntbdContextNegotiator(requestManager, config.getUserAgent()), - new RntbdRequestEncoder(), - new RntbdResponseDecoder(), - requestManager - ); - } - - @Override - public String getName() { - return "FakeEndpoint"; - } - - @Override - public void close() { - this.fakeChannel.close().syncUninterruptibly(); - } - - @Override - public RntbdRequestRecord request(final RntbdRequestArgs requestArgs) { - final RntbdRequestRecord requestRecord = new RntbdRequestRecord(requestArgs, this.requestTimer); - this.fakeChannel.writeOutbound(requestRecord); - return requestRecord; - } - - static class Provider implements RntbdEndpoint.Provider { - - final Config config; - final RntbdResponse expected; - final RntbdRequestTimer timer; - - Provider(RntbdTransportClient.Options options, SslContext sslContext, RntbdResponse expected) { - this.config = new Config(options, sslContext, LogLevel.WARN); - this.timer = new RntbdRequestTimer(config.getRequestTimeout()); - this.expected = expected; - } - - @Override - public void close() throws RuntimeException { - this.timer.close(); - } - - @Override - public Config config() { - return this.config; - } - - @Override - public int count() { - return 1; - } - - @Override - public RntbdEndpoint get(URI physicalAddress) { - return new FakeEndpoint(config, timer, physicalAddress, expected); - } - - @Override - public Stream list() { - return Stream.empty(); - } - } - } - - private static final class RntbdTestConfiguration { - - static String AccountHost = System.getProperty("ACCOUNT_HOST", - StringUtils.defaultString( - Strings.emptyToNull(System.getenv().get("ACCOUNT_HOST")), - "https://localhost:8081/" - ) - ); - - static String AccountKey = System.getProperty("ACCOUNT_KEY", - StringUtils.defaultString( - Strings.emptyToNull(System.getenv().get("ACCOUNT_KEY")), - "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" - ) - ); - - static String RntbdAuthority = System.getProperty("rntbd.authority", - StringUtils.defaultString( - Strings.emptyToNull(System.getenv().get("RNTBD_AUTHORITY")), - String.format("%s:10251", URI.create(AccountHost).getHost()) - ) - ); - - private RntbdTestConfiguration() { - } - } - - // endregion -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderDotNetTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderDotNetTest.java deleted file mode 100644 index 9b0d4bfa0b98..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderDotNetTest.java +++ /dev/null @@ -1,903 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.ReplicationPolicy; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.SessionContainer; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.AuthorizationTokenType; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.apache.commons.lang3.StringUtils; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; - -import java.net.URI; -import java.net.URISyntaxException; -import java.time.Duration; -import java.util.ArrayDeque; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Queue; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; - -public class StoreReaderDotNetTest { - private static final Logger logger = LoggerFactory.getLogger(StoreReaderDotNetTest.class); - @Test(groups = "unit") - public void addressCache() { - // create a real document service request - RxDocumentServiceRequest entity = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - - // setup mocks for address information - AddressInformation[] addressInformation = new AddressInformation[3]; - for (int i = 0; i < 3; i++) { - addressInformation[i] = new AddressInformation(true, true, "http://replica-" + i, Protocol.Https); - } - - IAddressResolver mockAddressCache = Mockito.mock(IAddressResolver.class); - - Mockito.doReturn(Single.just(addressInformation)) - .when(mockAddressCache) - .resolveAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.eq(false)); - - // validate that the mock works - AddressInformation[] addressInfo = mockAddressCache.resolveAsync(entity, false).toBlocking().value(); - assertThat(addressInfo[0]).isEqualTo(addressInformation[0]); - } - - /** - * Tests for TransportClient - */ - @Test(groups = "unit") - public void transportClient() { - // create a real document service request - RxDocumentServiceRequest entity = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - - // setup mocks for address information - AddressInformation[] addressInformation = new AddressInformation[3]; - - // construct URIs that look like the actual uri - // rntbd://yt1prdddc01-docdb-1.documents.azure.com:14003/apps/ce8ab332-f59e-4ce7-a68e-db7e7cfaa128/services/68cc0b50-04c6-4716-bc31-2dfefd29e3ee/partitions/5604283d-0907-4bf4-9357-4fa9e62de7b5/replicas/131170760736528207s/ - for (int i = 0; i < 3; i++) { - String physicalUri = - "rntbd://dummytenant.documents.azure.com:14003/apps/APPGUID/services/SERVICEGUID/partitions/PARTITIONGUID/replicas/" - + Integer.toString(i) + (i == 0 ? "p" : "s") + "/"; - addressInformation[i] = new AddressInformation(true, true, physicalUri, Protocol.Tcp); - - } - - // create objects for all the dependencies of the StoreReader - TransportClient mockTransportClient = Mockito.mock(TransportClient.class); - - // create mock store response object - StoreResponseBuilder srb = new StoreResponseBuilder(); - - - // set lsn and activityid on the store response. - srb.withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_1" ); - srb.withHeader(WFConstants.BackendHeaders.LSN, "50"); - - // setup mock transport client - Mockito.doReturn(Single.just(srb.build())) - .when(mockTransportClient) - .invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[0].getPhysicalUri())), - Mockito.any(RxDocumentServiceRequest.class)); - - - - // get response from mock object - StoreResponse response = mockTransportClient.invokeResourceOperationAsync(URI.create(addressInformation[0].getPhysicalUri()), entity).toBlocking().value(); - - // validate that the LSN matches - // validate that the ActivityId Matches - - StoreResponseValidator validator = StoreResponseValidator.create().withBELSN(50).withBEActivityId("ACTIVITYID1_1").build(); - validator.validate(response); - } - - private TransportClient getMockTransportClientDuringUpgrade(AddressInformation[] addressInformation) { - // create objects for all the dependencies of the StoreReader - TransportClient mockTransportClient = Mockito.mock(TransportClient.class); - - // create mock store response object - // set lsn and activityid on the store response. - StoreResponse mockStoreResponseFast = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "50") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_1") - .build(); - - StoreResponse mockStoreResponseSlow = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "30") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_1") - .build(); - - // setup mock transport client for the first replica - Mockito.doReturn(Single.just(mockStoreResponseFast)) - .when(mockTransportClient) - .invokeResourceOperationAsync(Mockito.eq(URI.create(addressInformation[0].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - - - // setup mock transport client with a sequence of outputs - Mockito.doReturn(Single.just(mockStoreResponseFast)) // initial read response - .doReturn(Single.just(mockStoreResponseFast)) // barrier retry, count 1 - .doReturn(Single.just(mockStoreResponseFast)) // barrier retry, count 2 - .doReturn(Single.error(new InvalidPartitionException())) // throw invalid partition exception to simulate collection recreate with same name - .doReturn(Single.just(mockStoreResponseFast)) // new read - .doReturn(Single.just(mockStoreResponseFast)) // subsequent barriers - .doReturn(Single.just(mockStoreResponseFast)) - .doReturn(Single.just(mockStoreResponseFast)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[1].getPhysicalUri())), - Mockito.any(RxDocumentServiceRequest.class)); - - // After this, the product code should reset target identity, and lsn response - Queue queueOfResponses = new ArrayDeque<>(); - - // let the first 10 responses be slow, and then fast - for (int i = 0; i < 20; i++) { - queueOfResponses.add(i <= 2 ? mockStoreResponseSlow : mockStoreResponseFast); - } - - // setup mock transport client with a sequence of outputs, for the second replica - // This replica behaves in the following manner: - // calling InvokeResourceOperationAsync - // 1st time: returns valid LSN - // 2nd time: returns InvalidPartitionException - // initial read response - - Mockito.doAnswer((params) -> Single.just(queueOfResponses.poll())) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[2].getPhysicalUri())), - Mockito.any(RxDocumentServiceRequest.class)); - - return mockTransportClient; - } - - private enum ReadQuorumResultKind { - QuorumMet, - QuorumSelected, - QuorumNotSelected - } - - private TransportClient getMockTransportClientForGlobalStrongReads(AddressInformation[] addressInformation, ReadQuorumResultKind result) { - // create objects for all the dependencies of the StoreReader - TransportClient mockTransportClient = Mockito.mock(TransportClient.class); - - // create mock store response object - - StoreResponse mockStoreResponse1 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "100") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "90") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_1") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse mockStoreResponse2 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "90") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "90") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_2") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - - StoreResponse mockStoreResponse3 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "92") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "90") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_3") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse mockStoreResponse4 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "100") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "92") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_3") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse mockStoreResponse5 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "100") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "100") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_3") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .withHeader(WFConstants.BackendHeaders.CURRENT_REPLICA_SET_SIZE, "1") - .withHeader(WFConstants.BackendHeaders.QUORUM_ACKED_LSN, "100") - .build(); - // set lsn and activityid on the store response. - - StoreResponse mockStoreResponseFast = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "50") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_1") - .build(); - - if(result == ReadQuorumResultKind.QuorumMet) { - // setup mock transport client for the first replica - Mockito.doReturn(Single.just(mockStoreResponse5)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[0].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - - Mockito.doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse5)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[1].getPhysicalUri())), - Mockito.any(RxDocumentServiceRequest.class)); - - Mockito.doReturn(Single.just(mockStoreResponse2)) - .doReturn(Single.just(mockStoreResponse2)) - .doReturn(Single.just(mockStoreResponse2)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse4)) - .doReturn(Single.just(mockStoreResponse5)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[2].getPhysicalUri())), - Mockito.any(RxDocumentServiceRequest.class)); - } - - if (result == ReadQuorumResultKind.QuorumSelected) { - // setup mock transport client for the first replica - Mockito.doReturn(Single.just(mockStoreResponse2)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[0].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - - // setup mock transport client with a sequence of outputs - Mockito.doReturn(Single.just(mockStoreResponse1)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[1].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - - - // setup mock transport client with a sequence of outputs - Mockito.doReturn(Single.just(mockStoreResponse2)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[2].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - } else if (result == ReadQuorumResultKind.QuorumNotSelected) { - // setup mock transport client for the first replica - - Mockito.doReturn(Single.just(mockStoreResponse5)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[0].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - - Mockito.doReturn(Single.just(mockStoreResponse5)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[1].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - - Mockito.doReturn(Single.error(new GoneException("test"))) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[2].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - } - - return mockTransportClient; - } - - private TransportClient getMockTransportClientForGlobalStrongWrites( - AddressInformation[] addressInformation, - int indexOfCaughtUpReplica, - boolean undershootGlobalCommittedLsnDuringBarrier, - boolean overshootLsnDuringBarrier, - boolean overshootGlobalCommittedLsnDuringBarrier) - { - TransportClient mockTransportClient = Mockito.mock(TransportClient.class); - - // create mock store response object - - // set lsn and activityid on the store response. - StoreResponse mockStoreResponse1 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "100") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_1") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "90") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse mockStoreResponse2 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "100") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_2") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "100") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse mockStoreResponse3 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "103") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_3") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "100") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse mockStoreResponse4 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "103") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_3") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "103") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse mockStoreResponse5 = StoreResponseBuilder.create() - .withHeader(WFConstants.BackendHeaders.LSN, "106") - .withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, "ACTIVITYID1_3") - .withHeader(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, "103") - .withHeader(WFConstants.BackendHeaders.NUMBER_OF_READ_REGIONS, "1") - .build(); - - StoreResponse finalResponse = null; - if (undershootGlobalCommittedLsnDuringBarrier) { - finalResponse = mockStoreResponse1; - } else { - if (overshootLsnDuringBarrier) { - if (overshootGlobalCommittedLsnDuringBarrier) { - finalResponse = mockStoreResponse5; - } else { - finalResponse = mockStoreResponse3; - } - } else { - if (overshootGlobalCommittedLsnDuringBarrier) { - finalResponse = mockStoreResponse4; - } else { - finalResponse = mockStoreResponse2; - } - } - } - - for (int i = 0; i < addressInformation.length; i++) { - if (i == indexOfCaughtUpReplica) { - Mockito.doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(finalResponse)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[i].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - - } else { - Mockito.doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .doReturn(Single.just(mockStoreResponse1)) - .when(mockTransportClient).invokeResourceOperationAsync( - Mockito.eq(URI.create(addressInformation[i].getPhysicalUri())), Mockito.any(RxDocumentServiceRequest.class)); - } - } - - return mockTransportClient; - } - - /** - * We are simulating upgrade scenario where one of the secondary replicas is down. - * And one of the other secondary replicas is an XP Primary (lagging behind). - * Dyanmic Quorum is in effect, so Write Quorum = 2 - * @return array of AddressInformation - */ - private AddressInformation[] getMockAddressInformationDuringUpgrade() { - // setup mocks for address information - AddressInformation[] addressInformation = new AddressInformation[3]; - - // construct URIs that look like the actual uri - // rntbd://yt1prdddc01-docdb-1.documents.azure.com:14003/apps/ce8ab332-f59e-4ce7-a68e-db7e7cfaa128/services/68cc0b50-04c6-4716-bc31-2dfefd29e3ee/partitions/5604283d-0907-4bf4-9357-4fa9e62de7b5/replicas/131170760736528207s/ - for (int i = 0; i <= 2; i++) { - String physicalUri = - "rntbd://dummytenant.documents.azure.com:14003/apps/APPGUID/services/SERVICEGUID/partitions/PARTITIONGUID/replicas/" - + Integer.toString(i) + (i == 0 ? "p" : "s") + "/"; - addressInformation[i] = new AddressInformation(true, i == 0 ? true : false, physicalUri, Protocol.Tcp); - } - - return addressInformation; - } - - /** - * Given an array of address information, gives mock address cache. - * @param addressInformation - * @return - */ - private IAddressResolver getMockAddressCache(AddressInformation[] addressInformation) - { - // Address Selector is an internal sealed class that can't be mocked, but its dependency - // AddressCache can be mocked. - IAddressResolver mockAddressCache = Mockito.mock(IAddressResolver.class); - - Mockito.doReturn(Single.just(addressInformation)).when(mockAddressCache) - .resolveAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.eq(false) /*forceRefresh*/); - - Mockito.doReturn(Single.just(new AddressInformation[0])).when(mockAddressCache) - .resolveAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.eq(true) /*forceRefresh*/); - - return mockAddressCache; - } - - /** - * Tests for {@link StoreReader} - */ - @Test(groups = "unit") - public void storeReaderBarrier() { - // create a real document service request - RxDocumentServiceRequest entity = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - - // set request charge tracker - this is referenced in store reader (ReadMultipleReplicaAsync) - DocumentServiceRequestContext requestContext = new DocumentServiceRequestContext(); - // requestContext.ClientRequestStatistics = new ClientSideRequestStatistics(); - requestContext.requestChargeTracker = new RequestChargeTracker(); - entity.requestContext = requestContext; - - // also setup timeout helper, used in store reader - // entity.requestContext.timeoutHelper = new TimeoutHelper(new TimeSpan(2, 2, 2)); - entity.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - - // when the store reader throws Invalid Partition exception, the higher layer should - // clear this target identity. - // entity.requestContext.TargetIdentity = new ServiceIdentity("dummyTargetIdentity1", new Uri("http://dummyTargetIdentity1"), false); - entity.requestContext.resolvedPartitionKeyRange = new PartitionKeyRange(); - - AddressInformation[] addressInformation = getMockAddressInformationDuringUpgrade(); - IAddressResolver mockAddressCache = getMockAddressCache(addressInformation); - - // validate that the mock works - AddressInformation[] addressInfo = mockAddressCache.resolveAsync(entity, false).toBlocking().value(); - - assertThat(addressInfo[0]).isEqualTo(addressInformation[0]); - - AddressSelector addressSelector = new AddressSelector(mockAddressCache, Protocol.Tcp); - URI primaryAddress = addressSelector.resolvePrimaryUriAsync(entity, false /*forceAddressRefresh*/).toBlocking().value(); - - // check if the address return from Address Selector matches the original address info - assertThat(primaryAddress.toString()).isEqualTo(addressInformation[0].getPhysicalUri()); - - // get mock transport client that returns a sequence of responses to simulate upgrade - TransportClient mockTransportClient = getMockTransportClientDuringUpgrade(addressInformation); - - // get response from mock object - StoreResponse response = mockTransportClient.invokeResourceOperationAsync(URI.create(addressInformation[0].getPhysicalUri()), entity).toBlocking().value(); - - // validate that the LSN matches - assertThat(response.getLSN()).isEqualTo(50); - - String activityId = response.getHeaderValue(WFConstants.BackendHeaders.ACTIVITY_ID); - - // validate that the ActivityId Matches - assertThat(activityId).isEqualTo("ACTIVITYID1_1"); - - // create a real session container - we don't need session for this test anyway - ISessionContainer sessionContainer = new SessionContainer(Strings.Emtpy); - - // create store reader with mock transport client, real address selector (that has mock address cache), and real session container - StoreReader storeReader = - new StoreReader(mockTransportClient, - addressSelector, - sessionContainer); - - // reads always go to read quorum (2) replicas - int replicaCountToRead = 2; - - List result = storeReader.readMultipleReplicaAsync( - entity, - false /*includePrimary*/, - replicaCountToRead, - true /*requiresValidLSN*/, - false /*useSessionToken*/, - ReadMode.Strong).toBlocking().value(); - - // make sure we got 2 responses from the store reader - assertThat(result).hasSize(2); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator, long timeout) { - TestSubscriber> testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public static void validateSuccess(Single single, - StoreResultValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single single, - StoreResultValidator validator, long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public static void validateException(Single single, - FailureValidator validator) { - validateException(single, validator, 10000); - } - - public static void validateException(Single single, - FailureValidator validator, long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - /** - * StoreClient uses ReplicatedResourceClient uses ConsistencyReader uses QuorumReader uses StoreReader uses TransportClient uses RntbdConnection - */ - @Test(groups = "unit", enabled = false) - public void storeClient() throws URISyntaxException { - // create a real document service request (with auth token level = god) - RxDocumentServiceRequest entity = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - entity.authorizationTokenType = AuthorizationTokenType.PrimaryMasterKey; - - // set request charge tracker - this is referenced in store reader (ReadMultipleReplicaAsync) - DocumentServiceRequestContext requestContext = new DocumentServiceRequestContext(); - requestContext.requestChargeTracker = new RequestChargeTracker(); - entity.requestContext = requestContext; - - // set a dummy resource id on the request. - entity.setResourceId("1-MxAPlgMgA="); - - // set consistency level on the request to Bounded Staleness - entity.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.BoundedStaleness.toString()); - - // also setup timeout helper, used in store reader - entity.requestContext.timeoutHelper = new TimeoutHelper(Duration.ofSeconds(2 * 60 * 60 + 2 * 60 + 2)); - - // when the store reader throws Invalid Partition exception, the higher layer should - entity.requestContext.resolvedPartitionKeyRange = new PartitionKeyRange(); - - AddressInformation[] addressInformations = getMockAddressInformationDuringUpgrade(); - IAddressResolver mockAddressCache = getMockAddressCache(addressInformations); - - // validate that the mock works - AddressInformation[] addressInfo = mockAddressCache.resolveAsync(entity, false).toBlocking().value(); - assertThat(addressInfo[0]).isEqualTo(addressInformations[0]); - - AddressSelector addressSelector = new AddressSelector(mockAddressCache, Protocol.Tcp); - URI primaryAddress = addressSelector.resolvePrimaryUriAsync(entity, false).toBlocking().value(); - - // check if the address return from Address Selector matches the original address info - assertThat(primaryAddress.toString()).isEqualTo(addressInformations[0].getPhysicalUri()); - - // get mock transport client that returns a sequence of responses to simulate upgrade - TransportClient mockTransportClient = getMockTransportClientDuringUpgrade(addressInformations); - - // get response from mock object - StoreResponse response = mockTransportClient.invokeResourceOperationAsync(new URI(addressInformations[0].getPhysicalUri()), entity).toBlocking().value(); - - // validate that the LSN matches - assertThat(response.getLSN()).isEqualTo(50); - - String activityId = response.getHeaderValue(WFConstants.BackendHeaders.ACTIVITY_ID); - // validate that the ActivityId Matches - assertThat(activityId).isEqualTo("ACTIVITYID1_1"); - - // create a real session container - we don't need session for this test anyway - SessionContainer sessionContainer = new SessionContainer(StringUtils.EMPTY); - - // create store reader with mock transport client, real address selector (that has mock address cache), and real session container - StoreReader storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer); - - IAuthorizationTokenProvider mockAuthorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - Mockito.when(mockAuthorizationTokenProvider.getUserAuthorizationToken(Matchers.anyString(), Matchers.any(), Matchers.anyString(), Matchers.anyMap(), - Matchers.any(), Matchers.anyMap())).thenReturn("dummyauthtoken"); - - // setup max replica set size on the config reader - ReplicationPolicy replicationPolicy = new ReplicationPolicy(); - GatewayServiceConfigurationReader mockServiceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - Mockito.when(mockServiceConfigReader.getUserReplicationPolicy()).thenReturn(replicationPolicy); - - try { - StoreClient storeClient = new StoreClient(new Configs(),mockAddressCache, sessionContainer, mockServiceConfigReader, mockAuthorizationTokenProvider, mockTransportClient, false); - - ServerStoreModel storeModel = new ServerStoreModel(storeClient); - Single result = storeModel.processMessage(entity).toSingle(); - result.toBlocking().value(); - - // if we have reached this point, there was a successful request. - // validate if the target identity has been cleared out. - // If the target identity is null and the request still succeeded, it means - // that the very first read succeeded without a barrier request. - assertThat(entity.requestContext.resolvedPartitionKeyRange).isNotNull(); - } catch (Exception e) { - assertThat(e instanceof ServiceUnavailableException - || e instanceof IllegalArgumentException - || e instanceof NullPointerException - || e instanceof NoSuchElementException).isTrue(); - } - } - - /** - * test consistency writer for global strong - */ - @Test(groups = "unit") - public void globalStrongConsistentWrite() { - // create a real document service request (with auth token level = god) - RxDocumentServiceRequest entity = RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document); - entity.authorizationTokenType = AuthorizationTokenType.PrimaryMasterKey; - - // set request charge tracker - this is referenced in store reader (ReadMultipleReplicaAsync) - DocumentServiceRequestContext requestContext = new DocumentServiceRequestContext(); - requestContext.requestChargeTracker = new RequestChargeTracker(); - entity.requestContext = requestContext; - - // set a dummy resource id on the request. - entity.setResourceId("1-MxAPlgMgA="); - - // set consistency level on the request to Bounded Staleness - entity.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Strong.toString()); - - // also setup timeout helper, used in store reader - entity.requestContext.timeoutHelper = new TimeoutHelper(Duration.ofSeconds(2 * 60 * 60 + 2 * 60 + 2)); - - // when the store reader throws Invalid Partition exception, the higher layer should - // clear this target identity. - entity.requestContext.resolvedPartitionKeyRange = new PartitionKeyRange(); - - AddressInformation[] addressInformations = getMockAddressInformationDuringUpgrade(); - IAddressResolver mockAddressCache = getMockAddressCache(addressInformations); - - // validate that the mock works - AddressInformation[] addressInfo = mockAddressCache.resolveAsync(entity, false).toBlocking().value(); - assertThat(addressInformations[0]).isEqualTo(addressInfo[0]); - - AddressSelector addressSelector = new AddressSelector(mockAddressCache, Protocol.Tcp); - URI primaryAddress = addressSelector.resolvePrimaryUriAsync(entity, false).toBlocking().value(); - - // check if the address return from Address Selector matches the original address info - assertThat(primaryAddress.toString()).isEqualTo(addressInformations[0].getPhysicalUri()); - - // create a real session container - we don't need session for this test anyway - SessionContainer sessionContainer = new SessionContainer(StringUtils.EMPTY); - GatewayServiceConfigurationReader serviceConfigurationReader = Mockito.mock(GatewayServiceConfigurationReader.class); - - IAuthorizationTokenProvider mockAuthorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - Mockito.when(mockAuthorizationTokenProvider.getUserAuthorizationToken(Matchers.anyString(),Matchers.any(), Matchers.anyString(), Matchers.anyMap(), - Matchers.any(), Matchers.anyMap())).thenReturn("dummyauthtoken"); - - for (int i = 0; i < addressInformations.length; i++) { - TransportClient mockTransportClient = getMockTransportClientForGlobalStrongWrites(addressInformations, i, false, false, false); - StoreReader storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer); - ConsistencyWriter consistencyWriter = new ConsistencyWriter(addressSelector, sessionContainer, mockTransportClient, mockAuthorizationTokenProvider, serviceConfigurationReader, false); - StoreResponse response = consistencyWriter.writeAsync(entity, new TimeoutHelper(Duration.ofSeconds(30)), false).toBlocking().value(); - assertThat(response.getLSN()).isEqualTo(100); - - //globalCommittedLsn never catches up in this case - mockTransportClient = getMockTransportClientForGlobalStrongWrites(addressInformations, i, true, false, false); - consistencyWriter = new ConsistencyWriter(addressSelector, sessionContainer, mockTransportClient, mockAuthorizationTokenProvider, serviceConfigurationReader, false); - try { - response = consistencyWriter.writeAsync(entity, new TimeoutHelper(Duration.ofSeconds(30)), false).toBlocking().value(); - // fail("it should throw exception"); - } catch (Exception e) { - } - - mockTransportClient = getMockTransportClientForGlobalStrongWrites(addressInformations, i, false, true, false); - storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer); - consistencyWriter = new ConsistencyWriter(addressSelector, sessionContainer, mockTransportClient, mockAuthorizationTokenProvider, serviceConfigurationReader, false); - response = consistencyWriter.writeAsync(entity, new TimeoutHelper(Duration.ofSeconds(30)), false).toBlocking().value(); - assertThat(response.getLSN()).isEqualTo(100); - - mockTransportClient = getMockTransportClientForGlobalStrongWrites(addressInformations, i, false, true, true); - storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer); - consistencyWriter = new ConsistencyWriter(addressSelector, sessionContainer, mockTransportClient, mockAuthorizationTokenProvider, serviceConfigurationReader, false); - response = consistencyWriter.writeAsync(entity, new TimeoutHelper(Duration.ofSeconds(30)), false).toBlocking().value(); - assertThat(response.getLSN()).isEqualTo(100); - - - mockTransportClient = getMockTransportClientForGlobalStrongWrites(addressInformations, i, false, false, true); - storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer); - consistencyWriter = new ConsistencyWriter(addressSelector, sessionContainer, mockTransportClient, mockAuthorizationTokenProvider, serviceConfigurationReader, false); - response = consistencyWriter.writeAsync(entity, new TimeoutHelper(Duration.ofSeconds(30)), false).toBlocking().value(); - assertThat(response.getLSN()).isEqualTo(100); - - } - } - - /** - * Mocking Consistency - */ - @Test(groups = "unit", priority = 1) - public void globalStrongConsistency() { - // create a real document service request (with auth token level = god) - RxDocumentServiceRequest entity = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document); - entity.authorizationTokenType = AuthorizationTokenType.PrimaryMasterKey; - - // set request charge tracker - this is referenced in store reader (ReadMultipleReplicaAsync) - DocumentServiceRequestContext requestContext = new DocumentServiceRequestContext(); - requestContext.requestChargeTracker = new RequestChargeTracker(); - entity.requestContext = requestContext; - - // set a dummy resource id on the request. - entity.setResourceId("1-MxAPlgMgA="); - - // set consistency level on the request to Bounded Staleness - entity.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.BoundedStaleness.toString()); - - // also setup timeout helper, used in store reader - entity.requestContext.timeoutHelper = new TimeoutHelper(Duration.ofSeconds(2 * 60 * 60 + 2 * 60 + 2)); - - // when the store reader throws Invalid Partition exception, the higher layer should - // clear this target identity. - entity.requestContext.resolvedPartitionKeyRange = new PartitionKeyRange(); - - AddressInformation[] addressInformations = getMockAddressInformationDuringUpgrade(); - IAddressResolver mockAddressCache = getMockAddressCache(addressInformations); - - // validate that the mock works - AddressInformation[] addressInfo = mockAddressCache.resolveAsync(entity, false).toBlocking().value(); - assertThat(addressInfo[0]).isEqualTo(addressInformations[0]); - - AddressSelector addressSelector = new AddressSelector(mockAddressCache, Protocol.Tcp); - URI primaryAddress = addressSelector.resolvePrimaryUriAsync(entity, false).toBlocking().value(); - - // check if the address return from Address Selector matches the original address info - assertThat(primaryAddress.toString()).isEqualTo(addressInformations[0].getPhysicalUri()); - - // Quorum Met scenario Start - { - // get mock transport client that returns a sequence of responses to simulate upgrade - TransportClient mockTransportClient = getMockTransportClientForGlobalStrongReads(addressInformations, ReadQuorumResultKind.QuorumMet); - - // create a real session container - we don't need session for this test anyway - SessionContainer sessionContainer = new SessionContainer(StringUtils.EMPTY); - - // create store reader with mock transport client, real address selector (that has mock address cache), and real session container - StoreReader storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer); - - IAuthorizationTokenProvider mockAuthorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - Mockito.when(mockAuthorizationTokenProvider.getUserAuthorizationToken(Matchers.anyString(), Matchers.any(), Matchers.anyString(), Matchers.anyMap(), - Matchers.any(), Matchers.anyMap())).thenReturn("dummyauthtoken"); - - // setup max replica set size on the config reader - ReplicationPolicy replicationPolicy = new ReplicationPolicy(); - GatewayServiceConfigurationReader mockServiceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - Mockito.when(mockServiceConfigReader.getUserReplicationPolicy()).thenReturn(replicationPolicy); - - QuorumReader reader = new QuorumReader(new Configs(),mockTransportClient, addressSelector, storeReader, mockServiceConfigReader, mockAuthorizationTokenProvider); - - entity.requestContext.originalRequestConsistencyLevel = ConsistencyLevel.Strong; - - StoreResponse result = reader.readStrongAsync(entity, 2, ReadMode.Strong).toBlocking().value(); - assertThat(result.getLSN()).isEqualTo(100); - - String globalCommitedLSN = result.getHeaderValue(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN); - - long nGlobalCommitedLSN = Long.parseLong(globalCommitedLSN); - assertThat(nGlobalCommitedLSN).isEqualTo(90); - } - - // Quorum Selected scenario - { - // get mock transport client that returns a sequence of responses to simulate upgrade - TransportClient mockTransportClient = getMockTransportClientForGlobalStrongReads(addressInformations, ReadQuorumResultKind.QuorumSelected); - - // create a real session container - we don't need session for this test anyway - SessionContainer sessionContainer = new SessionContainer(StringUtils.EMPTY); - - // create store reader with mock transport client, real address selector (that has mock address cache), and real session container - StoreReader storeReader = new StoreReader(mockTransportClient, addressSelector, sessionContainer); - - IAuthorizationTokenProvider mockAuthorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - Mockito.when(mockAuthorizationTokenProvider.getUserAuthorizationToken(Matchers.anyString(), Matchers.any(), Matchers.anyString(), Matchers.anyMap(), - Matchers.any(), Matchers.anyMap())).thenReturn("dummyauthtoken"); - - // setup max replica set size on the config reader - ReplicationPolicy replicationPolicy = new ReplicationPolicy(); - BridgeInternal.setMaxReplicaSetSize(replicationPolicy,4); - - GatewayServiceConfigurationReader mockServiceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - Mockito.when(mockServiceConfigReader.getUserReplicationPolicy()).thenReturn(replicationPolicy); - Mockito.when(mockServiceConfigReader.getDefaultConsistencyLevel()).thenReturn(ConsistencyLevel.Strong); - - QuorumReader reader = new QuorumReader(new Configs(), mockTransportClient, addressSelector, storeReader, mockServiceConfigReader, mockAuthorizationTokenProvider); - entity.requestContext.originalRequestConsistencyLevel = ConsistencyLevel.Strong; - entity.requestContext.quorumSelectedLSN = -1; - entity.requestContext.globalCommittedSelectedLSN = -1; - try { - StoreResponse result = reader.readStrongAsync(entity, 2, ReadMode.Strong).toBlocking().value(); - assertThat(false).isTrue(); - } catch (Exception ex) { - if (ex.getCause() instanceof GoneException) { - logger.info("Gone exception expected!"); - } - } - - assertThat(entity.requestContext.quorumSelectedLSN).isEqualTo(100); - assertThat(entity.requestContext.globalCommittedSelectedLSN).isEqualTo(100); - } - - // Quorum not met scenario - { - // get mock transport client that returns a sequence of responses to simulate upgrade - TransportClient mockTransportClient = getMockTransportClientForGlobalStrongReads(addressInformations, ReadQuorumResultKind.QuorumNotSelected); - - // create a real session container - we don't need session for this test anyway - SessionContainer sessionContainer = new SessionContainer(StringUtils.EMPTY); - - // create store reader with mock transport client, real address selector (that has mock address cache), and real session container - StoreReader storeReader = - new StoreReader(mockTransportClient, - addressSelector, - sessionContainer); - - IAuthorizationTokenProvider mockAuthorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - Mockito.when(mockAuthorizationTokenProvider.getUserAuthorizationToken(Matchers.anyString(), Matchers.any(), Matchers.anyString(), Matchers.anyMap(), - Matchers.any(), Matchers.anyMap())).thenReturn("dummyauthtoken"); - // setup max replica set size on the config reader - ReplicationPolicy replicationPolicy = new ReplicationPolicy(); - BridgeInternal.setMaxReplicaSetSize(replicationPolicy,4); - - GatewayServiceConfigurationReader mockServiceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - Mockito.when(mockServiceConfigReader.getUserReplicationPolicy()).thenReturn(replicationPolicy); - Mockito.when(mockServiceConfigReader.getDefaultConsistencyLevel()).thenReturn(ConsistencyLevel.Strong); - - QuorumReader reader = new QuorumReader(new Configs(), mockTransportClient, addressSelector, storeReader, mockServiceConfigReader, mockAuthorizationTokenProvider); - entity.requestContext.originalRequestConsistencyLevel = ConsistencyLevel.Strong; - entity.requestContext.performLocalRefreshOnGoneException = true; - - StoreResponse result = reader.readStrongAsync(entity, 2, ReadMode.Strong).toBlocking().value(); - assertThat(result.getLSN()).isEqualTo(100); - - String globalCommitedLSN; - globalCommitedLSN = result.getHeaderValue(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN); - long nGlobalCommitedLSN = Long.parseLong(globalCommitedLSN); - assertThat(nGlobalCommitedLSN).isEqualTo(90); - } - - } - - // TODO: more mocking unit tests for different scenarios in StoreReader - // TODO: more mocking tests on how session work for StoreReader -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderTest.java deleted file mode 100644 index 7ed77154118c..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderTest.java +++ /dev/null @@ -1,831 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.VectorSessionToken; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionIsMigratingException; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeIsSplittingException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.assertj.core.api.AssertionsForClassTypes; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; -import rx.subjects.PublishSubject; - -import java.net.URI; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.TimeUnit; - -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.StatusCodes.GONE; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes.COMPLETING_PARTITION_MIGRATION; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes.COMPLETING_SPLIT; -import static com.microsoft.azure.cosmosdb.internal.HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE; -import static org.assertj.core.api.Assertions.assertThat; - -public class StoreReaderTest { - private static final int TIMEOUT = 30000; - - - /** - * Tests for {@link StoreReader} - */ - @Test(groups = "unit") - public void startBackgroundAddressRefresh() throws Exception { - TransportClient transportClient = Mockito.mock(TransportClient.class); - AddressSelector addressSelector = Mockito.mock(AddressSelector.class); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - StoreReader storeReader = new StoreReader(transportClient, addressSelector, sessionContainer); - - CyclicBarrier b = new CyclicBarrier(2); - PublishSubject> subject = PublishSubject.create(); - CountDownLatch c = new CountDownLatch(1); - - List uris = ImmutableList.of(URI.create("https://localhost:5050"), URI.create("https://localhost:5051"), - URI.create("https://localhost:50502"), URI.create("https://localhost:5053")); - - Mockito.doAnswer(new Answer() { - @Override - public Single> answer(InvocationOnMock invocationOnMock) throws Throwable { - - return subject.toSingle().doOnSuccess(x -> c.countDown()).doAfterTerminate(() -> { - new Thread() { - @Override - public void run() { - try { - b.await(); - } catch (Exception e) { - - } - } - }.start(); - }); - } - }).when(addressSelector).resolveAllUriAsync(Mockito.any(RxDocumentServiceRequest.class), Mockito.eq(true), Mockito.eq(true)); - RxDocumentServiceRequest request = Mockito.mock(RxDocumentServiceRequest.class); - storeReader.startBackgroundAddressRefresh(request); - - subject.onNext(uris); - subject.onCompleted(); - - TimeUnit.MILLISECONDS.sleep(100); - AssertionsForClassTypes.assertThat(c.getCount()).isEqualTo(0); - AssertionsForClassTypes.assertThat(b.getNumberWaiting()).isEqualTo(1); - b.await(1000, TimeUnit.MILLISECONDS); - } - - @DataProvider(name = "verifyCanContinueOnExceptionArgProvider") - public Object[][] verifyCanContinueOnExceptionArgProvider() { - return new Object[][]{ - {new PartitionKeyRangeGoneException(), false,}, - {new PartitionKeyRangeIsSplittingException(), false,}, - {new PartitionKeyRangeGoneException(), false,}, - {new PartitionIsMigratingException(), false,}, - {new GoneException(), true,}, - {ExceptionBuilder.create().withHeader(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE, "").asGoneException(), true,}, - {ExceptionBuilder.create().withHeader(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE, "0").asGoneException(), true,}, - {ExceptionBuilder.create().withHeader(HttpConstants.HttpHeaders.REQUEST_VALIDATION_FAILURE, "1").asGoneException(), false,}, - }; - } - - @Test(groups = "unit", dataProvider = "verifyCanContinueOnExceptionArgProvider") - public void verifyCanContinueOnException(DocumentClientException dce, Boolean shouldVerify) { - DocumentClientException capturedFailure = null; - try { - StoreReader.verifyCanContinueOnException(dce); - } catch (DocumentClientException e) { - capturedFailure = e; - } - - if (shouldVerify) { - assertThat(capturedFailure).isNull(); - } else { - assertThat(capturedFailure).isEqualTo(dce); - } - } - - @DataProvider(name = "exceptionArgProvider") - public Object[][] exceptionArgProvider() { - return new Object[][]{ - // exception to be thrown from transportClient, expected (exception type, status, subStatus) - { new PartitionKeyRangeGoneException(), PartitionKeyRangeGoneException.class, GONE, PARTITION_KEY_RANGE_GONE, }, - { new PartitionKeyRangeIsSplittingException() , PartitionKeyRangeIsSplittingException.class, GONE, COMPLETING_SPLIT, }, - { new PartitionIsMigratingException(), PartitionIsMigratingException.class, GONE, COMPLETING_PARTITION_MIGRATION, }, - }; - } - - @Test(groups = "unit", dataProvider = "exceptionArgProvider") - public void exception(Exception ex, Class klass, int expectedStatusCode, Integer expectedSubStatusCode) { - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(ex) - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId("1"); - Single> res = storeReader.readMultipleReplicaAsync(dsr, true, 3, true, true, ReadMode.Strong); - - FailureValidator failureValidator = FailureValidator.builder() - .instanceOf(klass) - .statusCode(expectedStatusCode) - .subStatusCode(expectedSubStatusCode) - .build(); - - TestSubscriber> subscriber = new TestSubscriber<>(); - res.subscribe(subscriber); - subscriber.awaitTerminalEvent(); - subscriber.assertNotCompleted(); - assertThat(subscriber.getOnErrorEvents()).hasSize(1); - failureValidator.validate(subscriber.getOnErrorEvents().get(0)); - } - - /** - * reading in session consistency, if the requested session token cannot be supported by some replicas - * tries others till we find a replica which can support the given session token - */ - @Test(groups = "unit") - public void sessionNotAvailableFromSomeReplicas_FindReplicaSatisfyingRequestedSession() { - long slowReplicaLSN = 651175; - long globalCommittedLsn = 651174; - String partitionKeyRangeId = "73"; - NotFoundException foundException = new NotFoundException(); - foundException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + slowReplicaLSN); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LSN, Long.toString(slowReplicaLSN)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(slowReplicaLSN)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - - long fasterReplicaLSN = 651176; - - StoreResponse storeResponse = StoreResponseBuilder.create() - .withSessionToken(partitionKeyRangeId + ":-1#" + fasterReplicaLSN) - .withLSN(fasterReplicaLSN) - .withLocalLSN(fasterReplicaLSN) - .withQuorumAckecdLsn(fasterReplicaLSN) - .withQuorumAckecdLocalLsn(fasterReplicaLSN) - .withGlobalCommittedLsn(-1) - .withItemLocalLSN(fasterReplicaLSN) - .withRequestCharge(1.1) - .build(); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(foundException) // 1st replica read returns not found with lower lsn - .then(foundException) // 2nd replica read returns not found with lower lsn - .then(foundException) // 3rd replica read returns not found with lower lsn - .then(storeResponse) // 4th replica read returns storeResponse satisfying requested session token - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - dsr.requestContext.sessionToken = sessionToken.v; - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - assertThat(VectorSessionToken.tryCreate("-1#" + fasterReplicaLSN , sessionToken)).isTrue(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Single> readResult = storeReader.readMultipleReplicaAsync( - dsr, - /* includePrimary */ true, - /* replicaCountToRead */ 1, - /* requiresValidLSN */ true, - /* useSessionToken */ true, - /* readMode */ ReadMode.Any, - /* checkMinLsn */ true, - /* forceReadAll */ false); - - MultiStoreResultValidator validator = MultiStoreResultValidator.create() - .withSize(1) - .validateEachWith(StoreResultValidator.create() - .isValid() - .noException() - .withStoreResponse(StoreResponseValidator.create() - .isSameAs(storeResponse) - .build()) - .build()) - .build(); - validateSuccess(readResult, validator); - - addressSelectorWrapper.validate() - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyTotalInvocations(1); - } - - /** - * Reading with session consistency, replicas have session token with higher than requested and return not found - */ - @Test(groups = "unit") - public void sessionRead_LegitimateNotFound() { - long lsn = 651175; - long globalCommittedLsn = 651174; - String partitionKeyRangeId = "73"; - - NotFoundException foundException = new NotFoundException(); - foundException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + lsn); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LSN, Long.toString(lsn)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(lsn)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(foundException) // 1st replica read returns not found - .then(foundException) // 2nd replica read returns not found - .then(foundException) // 3rd replica read returns not found - .then(foundException) // 4th replica read returns not found - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - dsr.requestContext.sessionToken = sessionToken.v; - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - assertThat(VectorSessionToken.tryCreate("-1#" + (lsn - 1) , sessionToken)).isTrue(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Single> readResult = storeReader.readMultipleReplicaAsync( - dsr, - /* includePrimary */ true, - /* replicaCountToRead */ 1, - /* requiresValidLSN */ true, - /* useSessionToken */ true, - /* readMode */ ReadMode.Any, - /* checkMinLsn */ true, - /* forceReadAll */ false); - - MultiStoreResultValidator validator = MultiStoreResultValidator.create() - .withSize(1) - .validateEachWith(StoreResultValidator.create() - .isValid() - .withException(FailureValidator.builder().instanceOf(NotFoundException.class).build()) - .build()) - .build(); - validateSuccess(readResult, validator); - } - - /** - * reading in session consistency, none of the replicas can support the requested session token. - */ - @Test(groups = "unit") - public void sessionRead_ReplicasDoNotHaveTheRequestedLSN_NoResult() { - long lsn = 651175; - long globalCommittedLsn = 651174; - String partitionKeyRangeId = "73"; - - NotFoundException foundException = new NotFoundException(); - foundException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + lsn); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LSN, Long.toString(lsn)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(lsn)); - foundException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(foundException) // 1st replica read returns not found - .then(foundException) // 2nd replica read returns not found - .then(foundException) // 3rd replica read returns not found - .then(foundException) // 4th replica read returns not found - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - dsr.requestContext.sessionToken = sessionToken.v; - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId(partitionKeyRangeId); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - assertThat(VectorSessionToken.tryCreate("-1#" + (lsn + 1) , sessionToken)).isTrue(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Single> readResult = storeReader.readMultipleReplicaAsync( - dsr, - /* includePrimary */ true, - /* replicaCountToRead */ 1, - /* requiresValidLSN */ true, - /* useSessionToken */ true, - /* readMode */ ReadMode.Any, - /* checkMinLsn */ true, - /* forceReadAll */ false); - - MultiStoreResultValidator validator = MultiStoreResultValidator.create() - .withSize(0) - .build(); - validateSuccess(readResult, validator); - } - - @Test(groups = "unit") - public void requestRateTooLarge_BubbleUp() { - long lsn = 1045395; - long globalCommittedLsn = 1045395; - String partitionKeyRangeId = "257"; - - RequestRateTooLargeException requestRateTooLargeException = new RequestRateTooLargeException(); - requestRateTooLargeException.getResponseHeaders().put(HttpConstants.HttpHeaders.LSN, Long.toString(lsn)); - requestRateTooLargeException.getResponseHeaders().put(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, Long.toString(globalCommittedLsn)); - requestRateTooLargeException.getResponseHeaders().put(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(lsn)); - requestRateTooLargeException.getResponseHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":-1#" + lsn); - - TransportClientWrapper transportClientWrapper = new TransportClientWrapper.Builder.ReplicaResponseBuilder - .SequentialBuilder() - .then(requestRateTooLargeException) // 1st replica read returns 429 - .then(requestRateTooLargeException) // 2nd replica read returns 429 - .then(requestRateTooLargeException) // 3rd replica read returns 429 - .then(requestRateTooLargeException) // 4th replica read returns 429 - .build(); - - URI primaryUri = URI.create("primary"); - URI secondaryUri1 = URI.create("secondary1"); - URI secondaryUri2 = URI.create("secondary2"); - URI secondaryUri3 = URI.create("secondary3"); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryUri) - .withSecondary(ImmutableList.of(secondaryUri1, secondaryUri2, secondaryUri3)) - .build(); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - TimeoutHelper timeoutHelper = Mockito.mock(TimeoutHelper.class); - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, ConsistencyLevel.Session.name()); - dsr.requestContext = new DocumentServiceRequestContext(); - Utils.ValueHolder sessionToken = Utils.ValueHolder.initialize(null); - dsr.requestContext.sessionToken = sessionToken.v; - dsr.requestContext.timeoutHelper = timeoutHelper; - dsr.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId("1"); - dsr.requestContext.requestChargeTracker = new RequestChargeTracker(); - assertThat(VectorSessionToken.tryCreate("-1#" + (lsn - 1) , sessionToken)).isTrue(); - - Mockito.doReturn(sessionToken.v).when(sessionContainer).resolvePartitionLocalSessionToken(Mockito.eq(dsr), Mockito.anyString()); - - Single> readResult = storeReader.readMultipleReplicaAsync( - dsr, - /* includePrimary */ true, - /* replicaCountToRead */ 1, - /* requiresValidLSN */ true, - /* useSessionToken */ true, - /* readMode */ ReadMode.Any, - /* checkMinLsn */ true, - /* forceReadAll */ false); - - MultiStoreResultValidator validator = MultiStoreResultValidator.create() - .withSize(1) - .validateEachWith(FailureValidator.builder().instanceOf(RequestRateTooLargeException.class).build()) - .build(); - validateSuccess(readResult, validator); - } - - @Test(groups = "unit") - public void readPrimaryAsync() { - TransportClient transportClient = Mockito.mock(TransportClient.class); - AddressSelector addressSelector = Mockito.mock(AddressSelector.class); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - URI primaryURI = URI.create("primaryLoc"); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId("12"); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(Single.just(primaryURI)).when(addressSelector).resolvePrimaryUriAsync( - Mockito.eq(request) , Mockito.eq(false)); - - StoreResponse storeResponse = Mockito.mock(StoreResponse.class); - Mockito.doReturn(Single.just(storeResponse)).when(transportClient).invokeResourceOperationAsync(Mockito.eq(primaryURI), Mockito.eq(request)); - - StoreReader storeReader = new StoreReader(transportClient, addressSelector, sessionContainer); - - Single readResult = storeReader.readPrimaryAsync(request, true, true); - StoreResultValidator validator = StoreResultValidator.create() - .withStoreResponse(StoreResponseValidator.create().isSameAs(storeResponse).build()) - .build(); - validateSuccess(readResult, validator); - } - - @Test(groups = "unit") - public void readPrimaryAsync_GoneFromReplica() { - TransportClient transportClient = Mockito.mock(TransportClient.class); - AddressSelector addressSelector = Mockito.mock(AddressSelector.class); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - URI primaryURI = URI.create("primaryLoc"); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId("12"); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(Single.just(primaryURI)).when(addressSelector).resolvePrimaryUriAsync( - Mockito.eq(request) , Mockito.eq(false)); - - Mockito.doReturn(Single.error(ExceptionBuilder.create().asGoneException())).when(transportClient).invokeResourceOperationAsync(Mockito.eq(primaryURI), Mockito.eq(request)); - StoreReader storeReader = new StoreReader(transportClient, addressSelector, sessionContainer); - Single readResult = storeReader.readPrimaryAsync(request, true, true); - - FailureValidator validator = FailureValidator.builder().instanceOf(GoneException.class).build(); - validateException(readResult, validator); - } - - @Test(groups = "unit") - public void readPrimaryAsync_GoneExceptionOnTimeout() { - TransportClient transportClient = Mockito.mock(TransportClient.class); - AddressSelector addressSelector = Mockito.mock(AddressSelector.class); - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - - URI primaryURI = URI.create("primaryLoc"); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - Mockito.doReturn(true).when(request.requestContext.timeoutHelper).isElapsed(); - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId("12"); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - Mockito.doReturn(Single.just(primaryURI)).when(addressSelector).resolvePrimaryUriAsync( - Mockito.eq(request) , Mockito.eq(false)); - - StoreResponse storeResponse = Mockito.mock(StoreResponse.class); - Mockito.doReturn(Single.just(storeResponse)).when(transportClient).invokeResourceOperationAsync(Mockito.eq(primaryURI), Mockito.eq(request)); - - StoreReader storeReader = new StoreReader(transportClient, addressSelector, sessionContainer); - - Single readResult = storeReader.readPrimaryAsync(request, true, true); - FailureValidator validator = FailureValidator.builder().instanceOf(GoneException.class).build(); - validateException(readResult, validator); - } - - @DataProvider(name = "readPrimaryAsync_RetryOnGoneArgProvider") - public Object[][] readPrimaryAsync_RetryOnGoneArgProvider() { - return new Object[][]{ - // first exception from TransportClient, - // performLocalRefreshOnGoneException, - // retry with force refresh expected, - // validator for expected Exception from Single - // StoreResult has a successful StoreResponse - { - // partition moved, refresh replica address cache and retry - ExceptionBuilder.create().asGoneException(), true, true, null, true - }, - - { - // partition moved, refresh replica address cache is not requested, fail - ExceptionBuilder.create().asGoneException(), false, false, FailureValidator.builder().instanceOf(GoneException.class).build(), false - }, - - { - // invalid partition exception represents collection stale, cannot succeed, propagate failure - ExceptionBuilder.create().asInvalidPartitionException(), true, false, null, false - }, - - { - // cannot continue on partition key range gone, require address cache refresh - ExceptionBuilder.create().asPartitionKeyRangeGoneException(), true, false, - FailureValidator.builder().instanceOf(PartitionKeyRangeGoneException.class).build(), true - }, - - { - // cannot continue on partition split, require address cache refresh - ExceptionBuilder.create().asPartitionKeyRangeIsSplittingException(), true, false, - FailureValidator.builder().instanceOf(PartitionKeyRangeIsSplittingException.class).build(), true - }, - - { - // cannot continue on partition split, require address cache refresh - ExceptionBuilder.create().asPartitionIsMigratingException(), true, false, - FailureValidator.builder().instanceOf(PartitionIsMigratingException.class).build(), true - }, - }; - } - - @Test(groups = "unit", dataProvider = "readPrimaryAsync_RetryOnGoneArgProvider") - public void readPrimaryAsync_RetryOnPrimaryReplicaMove(Exception firstExceptionFromTransport, - boolean performLocalRefreshOnGoneException, - boolean retryWithForceRefreshExpected, - FailureValidator failureFromSingle, - boolean expectedStoreResponseInStoredReadResult) { - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - StoreResponse response = StoreResponseBuilder.create().build(); - - TransportClientWrapper transportClientWrapper = TransportClientWrapper.Builder.sequentialBuilder() - .then(firstExceptionFromTransport) - .then(response) - .build(); - - URI primaryURIPriorToRefresh = URI.create("stale"); - URI primaryURIAfterRefresh = URI.create("new"); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext.performLocalRefreshOnGoneException = performLocalRefreshOnGoneException; - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId("12"); - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.PrimaryReplicaMoveBuilder.create(Protocol.Https) - .withPrimaryReplicaMove(primaryURIPriorToRefresh, primaryURIAfterRefresh).build(); - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - Single readResult = storeReader.readPrimaryAsync(request, true, true); - - if (failureFromSingle == null) { - StoreResultValidator validator; - if (expectedStoreResponseInStoredReadResult) { - validator = StoreResultValidator.create().withStoreResponse(StoreResponseValidator.create().isSameAs(response).build()).build(); - } else { - validator = StoreResultValidator.create().withException(FailureValidator.builder().sameAs(firstExceptionFromTransport).build()).build(); - } - - validateSuccess(readResult, validator); - } else { - validateException(readResult, failureFromSingle); - } - - int numberOfAttempts = 1 + (retryWithForceRefreshExpected ? 1: 0); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(numberOfAttempts); - - addressSelectorWrapper.validate() - .verifyResolveAddressesAsync(0) - .verifyResolveAllUriAsync(0) - .verifyVesolvePrimaryUriAsyncCount(numberOfAttempts) - .verifyNumberOfForceCachRefresh(retryWithForceRefreshExpected ? 1: 0); - } - - @DataProvider(name = "readMultipleReplicasAsyncArgProvider") - public Object[][] readMultipleReplicasAsyncArgProvider() { - return new Object[][]{ - // boolean includePrimary, int replicaCountToRead, ReadMode.Strong - { false, 3, ReadMode.Strong }, - { true, 3, ReadMode.Strong }, - { false, 3, ReadMode.Any }, - { true, 3, ReadMode.Any }, - { true, 2, ReadMode.Any }, - { false, 2, ReadMode.Any }, - { true, 1, ReadMode.Any }, - { false, 1, ReadMode.Any }, - }; - } - - @Test(groups = "unit", dataProvider = "readMultipleReplicasAsyncArgProvider") - public void readMultipleReplicasAsync(boolean includePrimary, int replicaCountToRead, ReadMode readMode) { - // This adds basic tests for StoreReader.readMultipleReplicasAsync(.) without failure - // TODO: add some tests for readMultipleReplicasAsync which mock behaviour of failure of reading from a replica - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - URI primaryReplicaURI = URI.create("primary"); - ImmutableList secondaryReplicaURIs = ImmutableList.of(URI.create("secondary1"), URI.create("secondary2"), URI.create("secondary3")); - AddressSelectorWrapper addressSelectorWrapper = AddressSelectorWrapper.Builder.Simple.create() - .withPrimary(primaryReplicaURI) - .withSecondary(secondaryReplicaURIs) - .build(); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - - request.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - request.requestContext.timeoutHelper = Mockito.mock(TimeoutHelper.class); - request.requestContext.resolvedPartitionKeyRange = partitionKeyRangeWithId("12"); - - request.requestContext.requestChargeTracker = new RequestChargeTracker(); - - double requestChargePerRead = 1.1; - - StoreResponse primaryResponse = StoreResponseBuilder.create() - .withLSN(51) - .withLocalLSN(18) - .withRequestCharge(requestChargePerRead) - .build(); - StoreResponse secondaryResponse1 = StoreResponseBuilder.create() - .withLSN(50) - .withLocalLSN(17) - .withRequestCharge(requestChargePerRead) - .build(); - StoreResponse secondaryResponse2 = StoreResponseBuilder.create() - .withLSN(49) - .withLocalLSN(16) - .withRequestCharge(requestChargePerRead) - .build(); - StoreResponse secondaryResponse3 = StoreResponseBuilder.create() - .withLSN(48) - .withLocalLSN(15) - .withRequestCharge(requestChargePerRead) - .build(); - - List responseList = ImmutableList.of(primaryResponse, secondaryResponse1, secondaryResponse2, secondaryResponse3); - - TransportClientWrapper transportClientWrapper = TransportClientWrapper.Builder.uriToResultBuilder() - .storeResponseOn(primaryReplicaURI, OperationType.Read, ResourceType.Document, primaryResponse, false) - .storeResponseOn(secondaryReplicaURIs.get(0), OperationType.Read, ResourceType.Document, secondaryResponse1, false) - .storeResponseOn(secondaryReplicaURIs.get(1), OperationType.Read, ResourceType.Document, secondaryResponse2, false) - .storeResponseOn(secondaryReplicaURIs.get(2), OperationType.Read, ResourceType.Document, secondaryResponse3, false) - .build(); - - StoreReader storeReader = new StoreReader(transportClientWrapper.transportClient, addressSelectorWrapper.addressSelector, sessionContainer); - - Single> readResult = storeReader.readMultipleReplicaAsync(request, includePrimary, replicaCountToRead, true, true, readMode); - - long expectedMinLsn = - responseList - .stream() - .filter(sr -> (sr != primaryResponse || includePrimary)) - .mapToLong(sr -> - { - String value = (ReadMode.Strong == readMode)? - sr.getHeaderValue(WFConstants.BackendHeaders.LSN) : - sr.getHeaderValue(WFConstants.BackendHeaders.LOCAL_LSN); - return Long.parseLong(value); - }) - .min().orElse(-1); - - - MultiStoreResultValidator validator = MultiStoreResultValidator.create() - .withSize(replicaCountToRead) - .withMinimumLSN(expectedMinLsn) - .noFailure() - .withTotalRequestCharge(requestChargePerRead * replicaCountToRead) - .build(); - validateSuccess(readResult, validator); - - transportClientWrapper.validate() - .verifyNumberOfInvocations(replicaCountToRead); - addressSelectorWrapper.validate() - .verifyNumberOfForceCachRefresh(0) - .verifyVesolvePrimaryUriAsyncCount(0) - .verifyTotalInvocations(1); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single> single, - MultiStoreResultValidator validator, long timeout) { - TestSubscriber> testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public static void validateSuccess(Single single, - StoreResultValidator validator) { - validateSuccess(single, validator, 10000); - } - - public static void validateSuccess(Single single, - StoreResultValidator validator, long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public static void validateException(Single single, - FailureValidator validator, long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - public static void validateException(Single single, - FailureValidator validator) { - validateException(single, validator, TIMEOUT); - } - - private PartitionKeyRange partitionKeyRangeWithId(String id) { - PartitionKeyRange partitionKeyRange = Mockito.mock(PartitionKeyRange.class); - Mockito.doReturn(id).when(partitionKeyRange).getId(); - return partitionKeyRange; - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderUnderTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderUnderTest.java deleted file mode 100644 index f2953ac71c4e..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreReaderUnderTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.apache.commons.lang3.tuple.Pair; -import rx.Single; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class StoreReaderUnderTest extends StoreReader { - - public List>> invocations = Collections.synchronizedList(new ArrayList<>()); - - public StoreReaderUnderTest(TransportClient transportClient, AddressSelector addressSelector, ISessionContainer sessionContainer) { - super(transportClient, addressSelector, sessionContainer); - } - - @Override - public Single> readMultipleReplicaAsync(RxDocumentServiceRequest entity, boolean includePrimary, int replicaCountToRead, boolean requiresValidLsn, boolean useSessionToken, ReadMode readMode) { - Method method = new Object(){}.getClass().getEnclosingMethod(); - ImmutableList list = ImmutableList.of(entity, includePrimary, replicaCountToRead, requiresValidLsn, useSessionToken, readMode); - invocations.add(Pair.of(method, list)); - - return super.readMultipleReplicaAsync(entity, includePrimary, replicaCountToRead, requiresValidLsn, useSessionToken, readMode); - } - - @Override - public Single> readMultipleReplicaAsync(RxDocumentServiceRequest entity, boolean includePrimary, int replicaCountToRead, boolean requiresValidLsn, boolean useSessionToken, ReadMode readMode, boolean checkMinLSN, boolean forceReadAll) { - Method method = new Object(){}.getClass().getEnclosingMethod(); - ImmutableList list = ImmutableList.of(entity, includePrimary, replicaCountToRead, requiresValidLsn, useSessionToken, readMode, checkMinLSN, forceReadAll); - invocations.add(Pair.of(method, list)); - return super.readMultipleReplicaAsync(entity, includePrimary, replicaCountToRead, requiresValidLsn, useSessionToken, readMode, checkMinLSN, forceReadAll); - } - - @Override - public Single readPrimaryAsync(RxDocumentServiceRequest entity, boolean requiresValidLsn, boolean useSessionToken) { - Method method = new Object(){}.getClass().getEnclosingMethod(); - ImmutableList list = ImmutableList.of(entity, requiresValidLsn, useSessionToken); - invocations.add(Pair.of(method, list)); - return super.readPrimaryAsync(entity, requiresValidLsn, useSessionToken); - } - -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseValidator.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseValidator.java deleted file mode 100644 index 708d2a36b9a3..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResponseValidator.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import org.assertj.core.api.Condition; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public interface StoreResponseValidator { - - void validate(StoreResponse storeResponse); - - public static Builder create() { - return new Builder(); - } - - public class Builder { - private List validators = new ArrayList<>(); - - public StoreResponseValidator build() { - return new StoreResponseValidator() { - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Override - public void validate(StoreResponse resp) { - for (StoreResponseValidator validator : validators) { - validator.validate(resp); - } - } - }; - } - public Builder hasHeader(String headerKey) { - - validators.add(new StoreResponseValidator() { - @Override - public void validate(StoreResponse resp) { - assertThat(Arrays.asList(resp.getResponseHeaderNames())).asList().contains(headerKey); - } - }); - return this; - } - public Builder withHeader(String headerKey, String headerValue) { - - validators.add(new StoreResponseValidator() { - @Override - public void validate(StoreResponse resp) { - assertThat(Arrays.asList(resp.getResponseHeaderNames())).asList().contains(headerKey); - int index = Arrays.asList(resp.getResponseHeaderNames()).indexOf(headerKey); - assertThat(resp.getResponseHeaderValues()[index]).isEqualTo(headerValue); - } - }); - return this; - } - - public Builder withHeaderValueCondition(String headerKey, Condition condition) { - - validators.add(new StoreResponseValidator() { - @Override - public void validate(StoreResponse resp) { - assertThat(Arrays.asList(resp.getResponseHeaderNames())).asList().contains(headerKey); - int index = Arrays.asList(resp.getResponseHeaderNames()).indexOf(headerKey); - String value = resp.getResponseHeaderValues()[index]; - condition.matches(value); - } - }); - return this; - } - - public Builder isSameAs(StoreResponse storeResponse) { - - validators.add(new StoreResponseValidator() { - @Override - public void validate(StoreResponse resp) { - assertThat(resp).isSameAs(storeResponse); - } - }); - return this; - } - - public Builder withContent(String content) { - - validators.add(new StoreResponseValidator() { - @Override - public void validate(StoreResponse resp) { - assertThat(content).isEqualTo(resp.getResponseBody()); - } - }); - return this; - } - - public Builder withStatus(int status) { - - validators.add(new StoreResponseValidator() { - @Override - public void validate(StoreResponse resp) { - assertThat(status == resp.getStatus()).isTrue(); - } - }); - return this; - } - - public Builder in(StoreResponse... storeResponse) { - - validators.add(new StoreResponseValidator() { - @Override - public void validate(StoreResponse resp) { - assertThat(resp).isIn((Object[]) storeResponse); - } - }); - return this; - } - - public Builder withBEActivityId(String activityId) { - withHeader(WFConstants.BackendHeaders.ACTIVITY_ID, activityId); - return this; - } - - public Builder withRequestCharge(double value) { - withHeader(HttpConstants.HttpHeaders.REQUEST_CHARGE, Double.toString(value)); - return this; - } - - public Builder withRequestChargeGreaterThanOrEqualTo(double value) { - withHeaderValueCondition(HttpConstants.HttpHeaders.REQUEST_CHARGE, new Condition<>(s -> { - try { - double parsed = Double.parseDouble(s); - return parsed >= value; - } catch (Exception e) { - return false; - } - }, "request charge should be greater than or equal to " + value)); - return this; - } - - public Builder withRequestChargeLessThanOrEqualTo(double value) { - withHeaderValueCondition(HttpConstants.HttpHeaders.REQUEST_CHARGE, new Condition<>(s -> { - try { - double parsed = Double.parseDouble(s); - return parsed <= value; - } catch (Exception e) { - return false; - } - }, "request charge should be greater than or equal to " + value)); - return this; - } - - - public Builder withBELSN(long lsn) { - withHeader(WFConstants.BackendHeaders.LSN, Long.toString(lsn)); - return this; - } - - public Builder withBELocalLSN(long lsn) { - withHeader(WFConstants.BackendHeaders.LOCAL_LSN, Long.toString(lsn)); - return this; - } - - public Builder withBELSNGreaterThanOrEqualTo(long minLSN) { - Condition condition = new Condition<>(value -> { - try { - Long valueAsLong = Long.parseLong(value); - return valueAsLong > minLSN; - } catch (Exception e) { - return false; - } - }, "min lsn"); - withHeaderValueCondition(WFConstants.BackendHeaders.LSN, condition); - return this; - } - - public Builder withBEGlobalLSNGreaterThanOrEqualTo(long minLSN) { - Condition condition = new Condition<>(value -> { - try { - Long valueAsLong = Long.parseLong(value); - return valueAsLong > minLSN; - } catch (Exception e) { - return false; - } - }, "min global lsn"); - withHeaderValueCondition(WFConstants.BackendHeaders.GLOBAL_COMMITTED_LSN, condition); - return this; - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResultValidator.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResultValidator.java deleted file mode 100644 index a526001f84dd..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/StoreResultValidator.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.fail; - - -public interface StoreResultValidator { - - static Builder create() { - return new Builder(); - } - - void validate(StoreResult storeResult); - - class Builder { - private List validators = new ArrayList<>(); - - public StoreResultValidator build() { - return new StoreResultValidator() { - - @SuppressWarnings({"rawtypes", "unchecked"}) - @Override - public void validate(StoreResult storeResult) { - for (StoreResultValidator validator : validators) { - validator.validate(storeResult); - } - } - }; - } - - public Builder withStoreResponse(StoreResponseValidator storeResponseValidator) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - try { - storeResponseValidator.validate(storeResult.toResponse()); - }catch (DocumentClientException e) { - fail(e.getMessage()); - } - } - }); - return this; - } - - public Builder withException(FailureValidator failureValidator) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - try { - failureValidator.validate(storeResult.getException()); - }catch (DocumentClientException e) { - fail(e.getMessage()); - } - } - }); - return this; - } - - public Builder withLSN(long lsn) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult.lsn).isEqualTo(lsn); - } - }); - return this; - } - - public Builder withMinLSN(long minLSN) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult.lsn).isGreaterThanOrEqualTo(minLSN); - } - }); - return this; - } - - public Builder withGlobalCommitedLSN(long globalLsn) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult.globalCommittedLSN).isEqualTo(globalLsn); - } - }); - return this; - } - - public Builder withQuorumAckedLsn(long quorumAckedLsn) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult.quorumAckedLSN).isEqualTo(quorumAckedLsn); - } - }); - return this; - } - - public Builder noException() { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult).hasFieldOrPropertyWithValue("exception", null); - assertThat(storeResult.isGoneException).isFalse(); - } - }); - return this; - } - - public Builder isValid() { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult.isValid).isTrue(); - } - }); - return this; - } - - public Builder withReplicaSize(int count) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult.currentReplicaSetSize).isEqualTo(count); - } - }); - return this; - } - - public Builder withStorePhysicalURI(URI expectedURi) { - validators.add(new StoreResultValidator() { - - @Override - public void validate(StoreResult storeResult) { - assertThat(storeResult.storePhysicalAddress).isEqualTo(expectedURi); - } - }); - return this; - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TimeoutHelperTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TimeoutHelperTest.java deleted file mode 100644 index 4f0b3105087b..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TimeoutHelperTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import org.testng.annotations.Test; - -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TimeoutHelperTest { - - @Test(groups = "unit") - public void isElapsed() throws InterruptedException { - Duration duration1 = Duration.ofMillis(100); - TimeoutHelper timeoutHelper1 = new TimeoutHelper(duration1); - assertThat(timeoutHelper1.isElapsed()).isFalse(); - - Duration duration2 = Duration.ofMillis(100); - TimeoutHelper timeoutHelper2 = new TimeoutHelper(duration2); - Thread.sleep(100); - assertThat(timeoutHelper2.isElapsed()).isTrue(); - } - - @Test(groups = "unit") - public void getRemainingTime() throws InterruptedException { - for (int i = 1; i <= 5; i++) { - Duration duration = Duration.ofMillis(100); - TimeoutHelper timeoutHelper = new TimeoutHelper(duration); - Thread.sleep((10*i)); - Duration remainingTime1 = timeoutHelper.getRemainingTime(); - //Giving 5 ms extra buffer in case thread sleep complete early - assertThat(remainingTime1.toMillis()).isLessThanOrEqualTo(100-10*i+5); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportClientWrapper.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportClientWrapper.java deleted file mode 100644 index c92b6204b3ec..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/TransportClientWrapper.java +++ /dev/null @@ -1,330 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.apache.commons.lang3.tuple.Pair; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TransportClientWrapper { - private static Logger logger = LoggerFactory.getLogger(TransportClientWrapper.class); - public final TransportClient transportClient; - private final AtomicBoolean valid; - private final AtomicInteger cnt; - private final List> requests; - - TransportClientWrapper(TransportClient transportClient, AtomicInteger cnt, AtomicBoolean valid, List> requests) { - this.transportClient = transportClient; - this.valid = valid; - this.cnt = cnt; - this.requests = requests; - } - - public static class TransportClientWrapperVerificationBuilder { - private List> actions = new ArrayList<>(); - - public static TransportClientWrapperVerificationBuilder create() { - return new TransportClientWrapperVerificationBuilder(); - } - - public TransportClientWrapperVerificationBuilder verifyNumberOfInvocations(int count) { - actions.add(transportClientWrapper -> { - assertThat(transportClientWrapper.getNumberOfInvocations()).isEqualTo(count); - return null; - }); - return this; - } - - public void execute(TransportClientWrapper transportClientWrapper) { - for(Function action: actions) { - action.apply(transportClientWrapper); - } - } - } - - public TransportClientWrapper verifyNumberOfInvocations(int count) { - assertThat(cnt.get()).isEqualTo(count); - return this; - } - - public List> getCapturedArgs() { - return requests; - } - - public int getNumberOfInvocations() { - return cnt.get(); - } - - public TransportClientWrapper validate() { - assertThat(valid).isTrue(); - return this; - } - - public interface Builder { - - static void capture(List> capturedRequests, InvocationOnMock invocation) { - URI physicalUri = invocation.getArgumentAt(0, URI.class); - RxDocumentServiceRequest request = invocation.getArgumentAt(1, RxDocumentServiceRequest.class); - logger.debug("URI: {}, request {}", physicalUri, request); - capturedRequests.add(Pair.of(physicalUri, request)); - } - - TransportClientWrapper build(); - - public static ReplicaResponseBuilder replicaResponseBuilder() { - return new ReplicaResponseBuilder(); - } - - class ReplicaResponseBuilder implements Builder { - Map responseFunctionDictionary = new HashMap<>(); - - public ReplicaResponseBuilder addReplica(URI replicaURI, - Function2WithCheckedException invocationNumberToStoreResponse) { - - responseFunctionDictionary.put(replicaURI, invocationNumberToStoreResponse); - return this; - } - - public TransportClientWrapper build() { - - Map replicaResponseCounterDict = new HashMap<>(); - - AtomicInteger i = new AtomicInteger(0); - AtomicBoolean valid = new AtomicBoolean(true); - List> capturedArgs = Collections.synchronizedList(new ArrayList<>()); - - TransportClient transportClient = Mockito.mock(TransportClient.class); - Mockito.doAnswer(invocation -> { - i.incrementAndGet(); - URI physicalUri = invocation.getArgumentAt(0, URI.class); - RxDocumentServiceRequest request = invocation.getArgumentAt(1, RxDocumentServiceRequest.class); - Function2WithCheckedException function = responseFunctionDictionary.get(physicalUri); - if (function == null) { - valid.set(false); - return Single.error(new IllegalStateException("no registered function for replica " + physicalUri)); - } - int current; - synchronized (transportClient) { - capture(capturedArgs, invocation); - - AtomicInteger cnt = replicaResponseCounterDict.get(physicalUri); - if (cnt == null) { - cnt = new AtomicInteger(0); - replicaResponseCounterDict.put(physicalUri, cnt); - } - - current = cnt.getAndIncrement(); - } - - try { - return Single.just(function.apply(current, request)); - } catch (Exception e) { - return Single.error(e); - } - - }).when(transportClient).invokeResourceOperationAsync(Mockito.any(URI.class), Mockito.any(RxDocumentServiceRequest.class)); - - return new TransportClientWrapper(transportClient, i, valid, capturedArgs); - } - } - - - static SequentialBuilder sequentialBuilder() { - return new SequentialBuilder(); - } - - class SequentialBuilder implements Builder { - private List list = new ArrayList<>(); - - public SequentialBuilder then(StoreResponse response) { - list.add(response); - return this; - } - - public SequentialBuilder then(Exception exception) { - list.add(exception); - return this; - } - - public TransportClientWrapper build() { - AtomicInteger i = new AtomicInteger(0); - AtomicBoolean valid = new AtomicBoolean(true); - List> capturedArgs = Collections.synchronizedList(new ArrayList<>()); - - TransportClient transportClient = Mockito.mock(TransportClient.class); - Mockito.doAnswer(invocation -> { - capture(capturedArgs, invocation); - - int current = i.getAndIncrement(); - if (current >= list.size()) { - valid.set(false); - return Single.error(new IllegalStateException()); - } - Object obj = list.get(current); - StoreResponse response = Utils.as(obj, StoreResponse.class); - if (response != null) { - return Single.just(response); - } else { - return Single.error((Exception) obj); - } - - }).when(transportClient).invokeResourceOperationAsync(Mockito.any(URI.class), Mockito.any(RxDocumentServiceRequest.class)); - - return new TransportClientWrapper(transportClient, i, valid, capturedArgs); - } - } - - static UriToResultBuilder uriToResultBuilder() { - return new UriToResultBuilder(); - } - - class UriToResultBuilder implements Builder { - private static class Result { - StoreResponse storeResponse; - Exception exception; - boolean stickyResult; - - public Result(StoreResponse storeResponse, Exception exception, boolean stickyResult) { - this.storeResponse = storeResponse; - this.exception = exception; - this.stickyResult = stickyResult; - } - } - - private static class Tuple { - URI replicaURI; - OperationType operationType; - ResourceType resourceType; - - public Tuple(URI replicaURI, OperationType operationType, ResourceType resourceType) { - this.replicaURI = replicaURI; - this.operationType = operationType; - this.resourceType = resourceType; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Tuple tuple = (Tuple) o; - return Objects.equals(replicaURI, tuple.replicaURI) && - operationType == tuple.operationType && - resourceType == tuple.resourceType; - } - - @Override - public int hashCode() { - return Objects.hash(replicaURI, operationType, resourceType); - } - - @Override - public String toString() { - return "Tuple{" + - "replicaURI=" + replicaURI + - ", operationType=" + operationType + - ", resourceType=" + resourceType + - '}'; - } - } - private Map> uriToResult = new HashMap<>(); - - - private UriToResultBuilder resultOn(URI replicaURI, OperationType operationType, ResourceType resourceType, StoreResponse rsp, Exception ex, boolean stickyResult) { - Tuple key = new Tuple(replicaURI, operationType, resourceType); - List list = uriToResult.get(key); - if (list == null) { - list = new ArrayList<>(); - uriToResult.put(key, list); - } - list.add(new Result(rsp, ex, stickyResult)); - return this; - } - - public UriToResultBuilder storeResponseOn(URI replicaURI, OperationType operationType, ResourceType resourceType, StoreResponse response, boolean stickyResult) { - resultOn(replicaURI, operationType, resourceType, response, null, stickyResult); - return this; - } - - public UriToResultBuilder exceptionOn(URI replicaURI, OperationType operationType, ResourceType resourceType, Exception exception, boolean stickyResult) { - resultOn(replicaURI, operationType, resourceType, null, exception, stickyResult); - return this; - } - - public TransportClientWrapper build() { - AtomicBoolean valid = new AtomicBoolean(true); - AtomicInteger cnt = new AtomicInteger(0); - List> capturedArgs = Collections.synchronizedList(new ArrayList<>()); - TransportClient transportClient = Mockito.mock(TransportClient.class); - Mockito.doAnswer(invocation -> { - cnt.getAndIncrement(); - URI physicalUri = invocation.getArgumentAt(0, URI.class); - RxDocumentServiceRequest request = invocation.getArgumentAt(1, RxDocumentServiceRequest.class); - capture(capturedArgs, invocation); - - Tuple tuple = new Tuple(physicalUri, request.getOperationType(), request.getResourceType()); - List list = uriToResult.get(tuple); - if (list == null || list.isEmpty()) { - // unknown - valid.set(false); - return Single.error(new IllegalStateException(tuple.toString())); - } - - Result result = list.get(0); - - if (!result.stickyResult) { - list.remove(0); - } - if (result.storeResponse != null) { - return Single.just(result.storeResponse); - } else { - return Single.error(result.exception); - } - - }).when(transportClient).invokeResourceOperationAsync(Mockito.any(URI.class), Mockito.any(RxDocumentServiceRequest.class)); - - return new TransportClientWrapper(transportClient, cnt, valid, capturedArgs); - } - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WebExceptionUtilityTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WebExceptionUtilityTest.java deleted file mode 100644 index 8d80eece8e9f..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WebExceptionUtilityTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import io.netty.channel.ChannelException; -import io.netty.channel.ConnectTimeoutException; -import io.netty.handler.timeout.ReadTimeoutException; -import io.reactivex.netty.client.PoolExhaustedException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.SSLPeerUnverifiedException; -import java.net.ConnectException; -import java.net.NoRouteToHostException; -import java.net.SocketTimeoutException; -import java.net.UnknownHostException; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -/** - * validation tests for {@link WebExceptionUtility} - */ -public class WebExceptionUtilityTest { - - @DataProvider(name = "exceptionToIsRetriable") - public Object[][] exceptionToIsRetriable() { - return new Object[][]{ - // exception, is retriable - { - new RuntimeException(), false - }, - { - new ConnectException(), true - }, - { - new ConnectTimeoutException(), true - }, - { - new UnknownHostException(), true - }, - { - ReadTimeoutException.INSTANCE, false - }, - { - new SSLHandshakeException("dummy"), true - }, - { - new NoRouteToHostException(), true, - }, - { - new SSLPeerUnverifiedException("dummy"), true - }, - { - new SocketTimeoutException(), false - }, - { - new PoolExhaustedException(), true - } - }; - } - - @Test(groups = "unit", dataProvider = "exceptionToIsRetriable") - public void isWebExceptionRetriable(Exception e, boolean isRetriable) { - boolean actualRes = WebExceptionUtility.isWebExceptionRetriable(e); - if (isRetriable) { - assertThat(actualRes).describedAs(e.toString()).isTrue(); - } else { - assertThat(actualRes).describedAs(e.toString()).isFalse(); - } - } - - @DataProvider(name = "networkFailure") - public Object[][] networkFailure() { - return new Object[][]{ - // exception, is retriable - { - new RuntimeException(), false - }, - { - new ConnectException(), true - }, - { - new ConnectTimeoutException(), true - }, - { - new UnknownHostException(), true - }, - { - ReadTimeoutException.INSTANCE, true - }, - { - new SSLHandshakeException("dummy"), true - }, - { - new NoRouteToHostException(), true, - }, - { - new SSLPeerUnverifiedException("dummy"), true - }, - { - new SocketTimeoutException(), true - }, - { - new ChannelException(), true - } - }; - } - - @Test(groups = "unit", dataProvider = "networkFailure") - public void isNetworkFailure(Exception e, boolean isNetworkFailure) { - boolean actualRes = WebExceptionUtility.isNetworkFailure(e); - if (isNetworkFailure) { - assertThat(actualRes).describedAs(e.toString()).isTrue(); - } else { - assertThat(actualRes).describedAs(e.toString()).isFalse(); - } - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternalUtils.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternalUtils.java deleted file mode 100644 index b4e9875f6cf8..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/PartitionKeyInternalUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import com.google.common.collect.ImmutableList; - -public class PartitionKeyInternalUtils { - - public static PartitionKeyInternal createPartitionKeyInternal(String str) { - return new PartitionKeyInternal(ImmutableList.of( - new StringPartitionKeyComponent(str))); - - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryUtilsTest.java b/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryUtilsTest.java deleted file mode 100644 index 606380453aba..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryUtilsTest.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.internal.Quadruple; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GoneException; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponseBuilder; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponseValidator; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RetryUtils; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicy.ShouldRetryResult; - -import rx.Single; -import rx.functions.Func1; -import rx.observers.TestSubscriber; - -public class RetryUtilsTest { - IRetryPolicy retryPolicy; - Func1, Single> callbackMethod; - Func1, Single> inBackoffAlternateCallbackMethod; - private static final Duration minBackoffForInBackoffCallback = Duration.ofMillis(10); - private static final int TIMEOUT = 30000; - private static final Duration BACK_OFF_DURATION = Duration.ofMillis(20); - private StoreResponse storeResponse; - - @BeforeClass(groups = { "unit" }) - public void beforeClass() throws Exception { - retryPolicy = Mockito.mock(IRetryPolicy.class); - callbackMethod = Mockito.mock(Func1.class); - inBackoffAlternateCallbackMethod = Mockito.mock(Func1.class); - storeResponse = getStoreResponse(); - } - - /** - * This method will make sure we are throwing original exception in case of - * ShouldRetryResult.noRetry() instead of Single.error(null). - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void toRetryWithAlternateFuncWithNoRetry() { - Func1> onErrorFunc = RetryUtils.toRetryWithAlternateFunc(callbackMethod, - retryPolicy, inBackoffAlternateCallbackMethod, minBackoffForInBackoffCallback); - Mockito.when(retryPolicy.shouldRetry(Matchers.any())).thenReturn(Single.just(ShouldRetryResult.noRetry())); - Single response = onErrorFunc.call(new GoneException()); - validateFailure(response, TIMEOUT, GoneException.class); - } - - /** - * This method will test retries on callbackMethod, eventually returning success - * response after some failures and making sure it failed for at least specific - * number before passing. - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void toRetryWithAlternateFuncTestingMethodOne() { - Func1> onErrorFunc = RetryUtils.toRetryWithAlternateFunc(callbackMethod, - retryPolicy, null, minBackoffForInBackoffCallback); - - toggleMockFuncBtwFailureSuccess(callbackMethod); - Mockito.when(retryPolicy.shouldRetry(Matchers.any())) - .thenReturn(Single.just(ShouldRetryResult.retryAfter(BACK_OFF_DURATION))); - Single response = onErrorFunc.call(new GoneException()); - StoreResponseValidator validator = StoreResponseValidator.create().withStatus(storeResponse.getStatus()) - .withContent(storeResponse.getResponseBody()).build(); - validateSuccess(response, validator, TIMEOUT); - Mockito.verify(callbackMethod, Mockito.times(4)).call(Matchers.any()); - } - - /** - * This method will test retries on inBackoffAlternateCallbackMethod, eventually - * returning success response after some failures and making sure it failed for - * at least specific number before passing. - */ - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void toRetryWithAlternateFuncTestingMethodTwo() { - Func1> onErrorFunc = RetryUtils.toRetryWithAlternateFunc(callbackMethod, - retryPolicy, inBackoffAlternateCallbackMethod, minBackoffForInBackoffCallback); - Mockito.when(callbackMethod.call(Matchers.any())).thenReturn(Single.error(new GoneException())); - toggleMockFuncBtwFailureSuccess(inBackoffAlternateCallbackMethod); - Mockito.when(retryPolicy.shouldRetry(Matchers.any())) - .thenReturn(Single.just(ShouldRetryResult.retryAfter(BACK_OFF_DURATION))); - Single response = onErrorFunc.call(new GoneException()); - StoreResponseValidator validator = StoreResponseValidator.create().withStatus(storeResponse.getStatus()) - .withContent(storeResponse.getResponseBody()).build(); - validateSuccess(response, validator, TIMEOUT); - Mockito.verify(inBackoffAlternateCallbackMethod, Mockito.times(4)).call(Matchers.any()); - } - - private void validateFailure(Single single, long timeout, Class class1) { - - TestSubscriber testSubscriber = new TestSubscriber<>(); - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - if (!(testSubscriber.getOnErrorEvents().get(0).getClass().equals(class1))) { - fail("Not expecting " + testSubscriber.getOnErrorEvents().get(0)); - } - } - - private void validateSuccess(Single single, StoreResponseValidator validator, long timeout) { - - TestSubscriber testSubscriber = new TestSubscriber<>(); - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - assertThat(testSubscriber.getOnNextEvents()).hasSize(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - private void toggleMockFuncBtwFailureSuccess( - Func1, Single> method) { - Mockito.when(method.call(Matchers.any())).thenAnswer(new Answer>() { - - private int count = 0; - - @Override - public Single answer(InvocationOnMock invocation) throws Throwable { - if (count++ < 3) { - return Single.error(new GoneException()); - } - return Single.just(storeResponse); - } - }); - } - - private StoreResponse getStoreResponse() { - StoreResponseBuilder storeResponseBuilder = new StoreResponseBuilder().withContent("Test content") - .withStatus(200); - return storeResponseBuilder.build(); - } -} diff --git a/cosmosdb/data-plane/direct-impl/src/test/resources/log4j.properties b/cosmosdb/data-plane/direct-impl/src/test/resources/log4j.properties deleted file mode 100644 index 00b89ecf16b7..000000000000 --- a/cosmosdb/data-plane/direct-impl/src/test/resources/log4j.properties +++ /dev/null @@ -1,16 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -# Set HTTP components' logger to INFO - -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -log4j.category.com.microsoft.azure.cosmosdb=INFO -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p %c - %m%n diff --git a/cosmosdb/data-plane/examples/pom.xml b/cosmosdb/data-plane/examples/pom.xml deleted file mode 100644 index 52ef7db4eeda..000000000000 --- a/cosmosdb/data-plane/examples/pom.xml +++ /dev/null @@ -1,154 +0,0 @@ - - - - 4.0.0 - - com.microsoft.azure - azure-cosmosdb-parent - 2.4.5 - - - azure-cosmosdb-examples - Async SDK for SQL API of Azure Cosmos DB Service - Examples - Examples for Async SDK for SQL API of Azure Cosmos DB Service - - - UTF-8 - 1.7.6 - 1.2.17 - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 - - com.microsoft.azure.cosmosdb.benchmark.Main - - - - maven-assembly-plugin - 2.2 - - - jar-with-dependencies - - - - com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples.Main - - - - - - make-assembly - package - - single - - - - - - - - - com.microsoft.azure - azure-cosmosdb - - - com.microsoft.azure - azure-cosmosdb-commons-test-utils - - - com.google.guava - guava - ${guava.version} - - - io.reactivex - rxjava-guava - 1.0.3 - test - - - org.testng - testng - ${testng.version} - test - - - org.mockito - mockito-core - ${mockito.version} - test - - - org.hamcrest - hamcrest-all - 1.3 - test - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - - - log4j - log4j - ${log4j.version} - - - diff --git a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/ConfigurationManager.java b/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/ConfigurationManager.java deleted file mode 100644 index a09f58c3da25..000000000000 --- a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/ConfigurationManager.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples.multimaster; - -import java.util.Properties; - -public class ConfigurationManager { - public static Properties getAppSettings() { - return System.getProperties(); - } -} diff --git a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/Helpers.java b/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/Helpers.java deleted file mode 100644 index 389faee55a6e..000000000000 --- a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/Helpers.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples.multimaster; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import rx.Observable; -import rx.Single; - -public class Helpers { - - static public String createDocumentCollectionUri(String databaseName, String collectionName) { - return String.format("/dbs/%s/colls/%s", databaseName, collectionName); - } - - static public String createDatabaseUri(String databaseName) { - return String.format("/dbs/%s", databaseName); - } - - static public Single createDatabaseIfNotExists(AsyncDocumentClient client, String databaseName) { - - return client.readDatabase("/dbs/" + databaseName, null) - .onErrorResumeNext( - e -> { - if (e instanceof DocumentClientException) { - DocumentClientException dce = (DocumentClientException) e; - if (dce.getStatusCode() == 404) { - // if doesn't exist create it - - Database d = new Database(); - d.setId(databaseName); - - return client.createDatabase(d, null); - } - } - - return Observable.error(e); - } - ).map(ResourceResponse::getResource).toSingle(); - } - - static public Single createCollectionIfNotExists(AsyncDocumentClient client, String databaseName, String collectionName) { - return client.readCollection(createDocumentCollectionUri(databaseName, collectionName), null) - .onErrorResumeNext( - e -> { - if (e instanceof DocumentClientException) { - DocumentClientException dce = (DocumentClientException) e; - if (dce.getStatusCode() == 404) { - // if doesn't exist create it - - DocumentCollection collection = new DocumentCollection(); - collection.setId(collectionName); - - return client.createCollection(createDatabaseUri(databaseName), collection, null); - } - } - - return Observable.error(e); - } - ).map(ResourceResponse::getResource).toSingle(); - } - - static public Single createCollectionIfNotExists(AsyncDocumentClient client, String databaseName, DocumentCollection collection) { - return client.readCollection(createDocumentCollectionUri(databaseName, collection.getId()), null) - .onErrorResumeNext( - e -> { - if (e instanceof DocumentClientException) { - DocumentClientException dce = (DocumentClientException) e; - if (dce.getStatusCode() == 404) { - // if doesn't exist create it - - return client.createCollection(createDatabaseUri(databaseName), collection, null); - } - } - - return Observable.error(e); - } - ).map(ResourceResponse::getResource).toSingle(); - } -} diff --git a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/ConflictWorker.java b/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/ConflictWorker.java deleted file mode 100644 index 6f6f4548f7f0..000000000000 --- a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/ConflictWorker.java +++ /dev/null @@ -1,877 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples; - -import com.microsoft.azure.cosmosdb.AccessCondition; -import com.microsoft.azure.cosmosdb.AccessConditionType; -import com.microsoft.azure.cosmosdb.Conflict; -import com.microsoft.azure.cosmosdb.ConflictResolutionMode; -import com.microsoft.azure.cosmosdb.ConflictResolutionPolicy; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.examples.multimaster.Helpers; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Scheduler; -import rx.schedulers.Schedulers; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -public class ConflictWorker { - private static Logger logger = LoggerFactory.getLogger(ConflictWorker.class); - - private final Scheduler schedulerForBlockingWork; - private final List clients; - private final String basicCollectionUri; - private final String manualCollectionUri; - private final String lwwCollectionUri; - private final String udpCollectionUri; - private final String databaseName; - private final String basicCollectionName; - private final String manualCollectionName; - private final String lwwCollectionName; - private final String udpCollectionName; - private final ExecutorService executor; - - public ConflictWorker(String databaseName, String basicCollectionName, String manualCollectionName, String lwwCollectionName, String udpCollectionName) { - this.clients = new ArrayList<>(); - this.basicCollectionUri = Helpers.createDocumentCollectionUri(databaseName, basicCollectionName); - this.manualCollectionUri = Helpers.createDocumentCollectionUri(databaseName, manualCollectionName); - this.lwwCollectionUri = Helpers.createDocumentCollectionUri(databaseName, lwwCollectionName); - this.udpCollectionUri = Helpers.createDocumentCollectionUri(databaseName, udpCollectionName); - - this.databaseName = databaseName; - this.basicCollectionName = basicCollectionName; - this.manualCollectionName = manualCollectionName; - this.lwwCollectionName = lwwCollectionName; - this.udpCollectionName = udpCollectionName; - - this.executor = Executors.newFixedThreadPool(100); - this.schedulerForBlockingWork = Schedulers.from(executor); - } - - public void addClient(AsyncDocumentClient client) { - this.clients.add(client); - } - - private DocumentCollection createCollectionIfNotExists(AsyncDocumentClient createClient, String databaseName, DocumentCollection collection) { - return Helpers.createCollectionIfNotExists(createClient, this.databaseName, collection) - .subscribeOn(schedulerForBlockingWork).toBlocking().value(); - } - - private DocumentCollection createCollectionIfNotExists(AsyncDocumentClient createClient, String databaseName, String collectionName) { - - return Helpers.createCollectionIfNotExists(createClient, this.databaseName, this.basicCollectionName) - .subscribeOn(schedulerForBlockingWork).toBlocking().value(); - } - - private DocumentCollection getCollectionDefForManual(String id) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(id); - ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy(); - collection.setConflictResolutionPolicy(policy); - return collection; - } - - private DocumentCollection getCollectionDefForLastWinWrites(String id, String conflictResolutionPath) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(id); - ConflictResolutionPolicy policy = ConflictResolutionPolicy.createLastWriterWinsPolicy(conflictResolutionPath); - collection.setConflictResolutionPolicy(policy); - return collection; - } - - private DocumentCollection getCollectionDefForCustom(String id, String storedProc) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(id); - ConflictResolutionPolicy policy = ConflictResolutionPolicy.createCustomPolicy(storedProc); - collection.setConflictResolutionPolicy(policy); - return collection; - } - - public void initialize() throws Exception { - AsyncDocumentClient createClient = this.clients.get(0); - - Helpers.createDatabaseIfNotExists(createClient, this.databaseName).subscribeOn(schedulerForBlockingWork).toBlocking().value(); - - DocumentCollection basic = createCollectionIfNotExists(createClient, this.databaseName, this.basicCollectionName); - - DocumentCollection manualCollection = createCollectionIfNotExists(createClient, - Helpers.createDatabaseUri(this.databaseName), getCollectionDefForManual(this.manualCollectionName)); - - DocumentCollection lwwCollection = createCollectionIfNotExists(createClient, - Helpers.createDatabaseUri(this.databaseName), getCollectionDefForLastWinWrites(this.lwwCollectionName, "/regionId")); - - DocumentCollection udpCollection = createCollectionIfNotExists(createClient, - Helpers.createDatabaseUri(this.databaseName), getCollectionDefForCustom(this.udpCollectionName, - String.format("dbs/%s/colls/%s/sprocs/%s", this.databaseName, this.udpCollectionName, "resolver"))); - - StoredProcedure lwwSproc = new StoredProcedure(); - lwwSproc.setId("resolver"); - lwwSproc.setBody(IOUtils.toString( - getClass().getClassLoader().getResourceAsStream("resolver-storedproc.txt"), "UTF-8")); - - lwwSproc = - getResource(createClient.upsertStoredProcedure( - Helpers.createDocumentCollectionUri(this.databaseName, this.udpCollectionName), lwwSproc, null)); - - } - - private T getResource(Observable> obs) { - return obs.subscribeOn(schedulerForBlockingWork).toBlocking().single().getResource(); - } - - public void runManualConflict() throws Exception { - logger.info("\r\nInsert Conflict\r\n"); - this.runInsertConflictOnManual(); - - logger.info("\r\nUpdate Conflict\r\n"); - this.runUpdateConflictOnManual(); - - logger.info("\r\nDelete Conflict\r\n"); - this.runDeleteConflictOnManual(); - } - - public void runLWWConflict() throws Exception { - logger.info("\r\nInsert Conflict\r\n"); - this.runInsertConflictOnLWW(); - - logger.info("\r\nUpdate Conflict\r\n"); - this.runUpdateConflictOnLWW(); - - logger.info("\r\nDelete Conflict\r\n"); - this.runDeleteConflictOnLWW(); - } - - public void runUDPConflict() throws Exception { - logger.info("\r\nInsert Conflict\r\n"); - this.runInsertConflictOnUdp(); - - logger.info("\r\nUpdate Conflict\r\n"); - this.runUpdateConflictOnUdp(); - - logger.info("\r\nDelete Conflict\r\n"); - this.runDeleteConflictOnUdp(); - } - - public void runInsertConflictOnManual() throws Exception { - do { - logger.info("1) Performing conflicting insert across {} regions on {}", this.clients.size(), this.manualCollectionName); - - ArrayList> insertTask = new ArrayList>(); - - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - insertTask.add(this.tryInsertDocument(client, this.manualCollectionUri, conflictDocument, index++)); - } - - List conflictDocuments = Observable.merge(insertTask).toList().subscribeOn(schedulerForBlockingWork).toBlocking().single(); - - if (conflictDocuments.size() == this.clients.size()) { - logger.info("2) Caused {} insert conflicts, verifying conflict resolution", conflictDocuments.size()); - - for (Document conflictingInsert : conflictDocuments) { - this.validateManualConflict(this.clients, conflictingInsert); - } - break; - } else { - logger.info("Retrying insert to induce conflicts"); - } - } while (true); - } - - public void runUpdateConflictOnManual() throws Exception { - do { - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - - conflictDocument = this.tryInsertDocument(clients.get(0), this.manualCollectionUri, conflictDocument, 0) - .firstOrDefault(null).toBlocking().first(); - - TimeUnit.SECONDS.sleep(1);//1 Second for write to sync. - - - logger.info("1) Performing conflicting update across 3 regions on {}", this.manualCollectionName); - - ArrayList> updateTask = new ArrayList>(); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - updateTask.add(this.tryUpdateDocument(client, this.manualCollectionUri, conflictDocument, index++)); - } - - List conflictDocuments = Observable.merge(updateTask).toList().toBlocking().single(); - - if (conflictDocuments.size() > 1) { - logger.info("2) Caused {} updated conflicts, verifying conflict resolution", conflictDocuments.size()); - - for (Document conflictingUpdate : conflictDocuments) { - this.validateManualConflict(this.clients, conflictingUpdate); - } - break; - } else { - logger.info("Retrying update to induce conflicts"); - } - } while (true); - } - - public void runDeleteConflictOnManual() throws Exception { - do { - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - conflictDocument = this.tryInsertDocument(clients.get(0), this.manualCollectionUri, conflictDocument, 0) - .firstOrDefault(null).toBlocking().first(); - - TimeUnit.SECONDS.sleep(10);//1 Second for write to sync. - - logger.info("1) Performing conflicting delete across 3 regions on {}", this.manualCollectionName); - - ArrayList> deleteTask = new ArrayList>(); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - deleteTask.add(this.tryDeleteDocument(client, this.manualCollectionUri, conflictDocument, index++)); - } - - List conflictDocuments = Observable.merge(deleteTask).toList() - .subscribeOn(schedulerForBlockingWork) - .toBlocking().single(); - - if (conflictDocuments.size() > 1) { - logger.info("2) Caused {} delete conflicts, verifying conflict resolution", conflictDocuments.size()); - - for (Document conflictingDelete : conflictDocuments) { - this.validateManualConflict(this.clients, conflictingDelete); - } - - break; - } else { - logger.info("Retrying update to induce conflicts"); - } - } while (true); - } - - public void runInsertConflictOnLWW() throws Exception { - do { - logger.info("Performing conflicting insert across 3 regions"); - - ArrayList> insertTask = new ArrayList>(); - - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - insertTask.add(this.tryInsertDocument(client, this.lwwCollectionUri, conflictDocument, index++)); - } - - List conflictDocuments = Observable.merge(insertTask).toList().toBlocking().single(); - - - if (conflictDocuments.size() > 1) { - logger.info("Inserted {} conflicts, verifying conflict resolution", conflictDocuments.size()); - - this.validateLWW(this.clients, conflictDocuments); - - break; - } else { - logger.info("Retrying insert to induce conflicts"); - } - } while (true); - } - - public void runUpdateConflictOnLWW() throws Exception { - do { - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - conflictDocument = this.tryInsertDocument(clients.get(0), this.lwwCollectionUri, conflictDocument, 0) - .firstOrDefault(null).toBlocking().first(); - - - TimeUnit.SECONDS.sleep(1); //1 Second for write to sync. - - logger.info("1) Performing conflicting update across {} regions on {}", this.clients.size(), this.lwwCollectionUri); - - ArrayList> insertTask = new ArrayList>(); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - insertTask.add(this.tryUpdateDocument(client, this.lwwCollectionUri, conflictDocument, index++)); - } - - List conflictDocuments = Observable.merge(insertTask).toList().toBlocking().single(); - - - if (conflictDocuments.size() > 1) { - logger.info("2) Caused {} update conflicts, verifying conflict resolution", conflictDocuments.size()); - - this.validateLWW(this.clients, conflictDocuments); - - break; - } else { - logger.info("Retrying insert to induce conflicts"); - } - } while (true); - } - - public void runDeleteConflictOnLWW() throws Exception { - do { - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - conflictDocument = this.tryInsertDocument(clients.get(0), this.lwwCollectionUri, conflictDocument, 0) - .firstOrDefault(null).toBlocking().first(); - - - TimeUnit.SECONDS.sleep(1); //1 Second for write to sync. - - logger.info("1) Performing conflicting delete across {} regions on {}", this.clients.size(), this.lwwCollectionUri); - - ArrayList> insertTask = new ArrayList>(); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - if (index % 2 == 1) { - //We delete from region 1, even though region 2 always win. - insertTask.add(this.tryDeleteDocument(client, this.lwwCollectionUri, conflictDocument, index++)); - } else { - insertTask.add(this.tryUpdateDocument(client, this.lwwCollectionUri, conflictDocument, index++)); - } - } - - List conflictDocuments = Observable.merge(insertTask).toList().toBlocking().single(); - - if (conflictDocuments.size() > 1) { - logger.info("Inserted {} conflicts, verifying conflict resolution", conflictDocuments.size()); - - //Delete should always win. irrespective of LWW. - this.validateLWW(this.clients, conflictDocuments, true); - break; - } else { - logger.info("Retrying update/delete to induce conflicts"); - } - } while (true); - } - - public void runInsertConflictOnUdp() throws Exception { - do { - logger.info("1) Performing conflicting insert across 3 regions on {}", this.udpCollectionName); - - ArrayList> insertTask = new ArrayList>(); - - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - insertTask.add(this.tryInsertDocument(client, this.udpCollectionUri, conflictDocument, index++)); - } - - List conflictDocuments = Observable.merge(insertTask).toList().toBlocking().single(); - - - if (conflictDocuments.size() > 1) { - logger.info("2) Caused {} insert conflicts, verifying conflict resolution", conflictDocuments.size()); - - this.validateUDPAsync(this.clients, conflictDocuments); - - break; - } else { - logger.info("Retrying insert to induce conflicts"); - } - } while (true); - } - - public void runUpdateConflictOnUdp() throws Exception { - do { - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - conflictDocument = this.tryInsertDocument(clients.get(0), this.udpCollectionUri, conflictDocument, 0) - .firstOrDefault(null).toBlocking().first(); - - TimeUnit.SECONDS.sleep(1); //1 Second for write to sync. - - logger.info("1) Performing conflicting update across 3 regions on {}", this.udpCollectionUri); - - ArrayList> updateTask = new ArrayList>(); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - updateTask.add(this.tryUpdateDocument(client, this.udpCollectionUri, conflictDocument, index++)); - } - - List conflictDocuments = Observable.merge(updateTask).toList().toBlocking().single(); - - - if (conflictDocuments.size() > 1) { - logger.info("2) Caused {} update conflicts, verifying conflict resolution", conflictDocuments.size()); - - this.validateUDPAsync(this.clients, conflictDocuments); - - break; - } else { - logger.info("Retrying update to induce conflicts"); - } - } while (true); - } - - public void runDeleteConflictOnUdp() throws Exception { - do { - Document conflictDocument = new Document(); - conflictDocument.setId(UUID.randomUUID().toString()); - - conflictDocument = this.tryInsertDocument(clients.get(0), this.udpCollectionUri, conflictDocument, 0) - .firstOrDefault(null).toBlocking().first(); - - TimeUnit.SECONDS.sleep(1); //1 Second for write to sync. - - logger.info("1) Performing conflicting update/delete across 3 regions on {}", this.udpCollectionUri); - - ArrayList> deleteTask = new ArrayList>(); - - int index = 0; - for (AsyncDocumentClient client : this.clients) { - if (index % 2 == 1) { - //We delete from region 1, even though region 2 always win. - deleteTask.add(this.tryDeleteDocument(client, this.udpCollectionUri, conflictDocument, index++)); - } else { - deleteTask.add(this.tryUpdateDocument(client, this.udpCollectionUri, conflictDocument, index++)); - } - } - - List conflictDocuments = Observable.merge(deleteTask).toList().toBlocking().single(); - - if (conflictDocuments.size() > 1) { - logger.info("2) Caused {} delete conflicts, verifying conflict resolution", conflictDocuments.size()); - - //Delete should always win. irrespective of LWW. - this.validateUDPAsync(this.clients, conflictDocuments, true); - break; - } else { - logger.info("Retrying update/delete to induce conflicts"); - } - } while (true); - } - - private Observable tryInsertDocument(AsyncDocumentClient client, String collectionUri, Document document, int index) { - - logger.debug("region: {}", client.getWriteEndpoint()); - document.set("regionId", index); - document.set("regionEndpoint", client.getReadEndpoint()); - return client.createDocument(collectionUri, document, null, false) - .onErrorResumeNext(e -> { - if (hasDocumentClientException(e, 409)) { - return Observable.empty(); - } else { - return Observable.error(e); - } - }).map(ResourceResponse::getResource); - } - - private boolean hasDocumentClientException(Throwable e, int statusCode) { - if (e instanceof DocumentClientException) { - DocumentClientException dce = (DocumentClientException) e; - return dce.getStatusCode() == statusCode; - } - - return false; - } - - private boolean hasDocumentClientExceptionCause(Throwable e) { - while (e != null) { - if (e instanceof DocumentClientException) { - return true; - } - - e = e.getCause(); - } - return false; - } - - private boolean hasDocumentClientExceptionCause(Throwable e, int statusCode) { - while (e != null) { - if (e instanceof DocumentClientException) { - DocumentClientException dce = (DocumentClientException) e; - return dce.getStatusCode() == statusCode; - } - - e = e.getCause(); - } - - return false; - } - - private Observable tryUpdateDocument(AsyncDocumentClient client, String collectionUri, Document document, int index) { - document.set("regionId", index); - document.set("regionEndpoint", client.getReadEndpoint()); - - RequestOptions options = new RequestOptions(); - options.setAccessCondition(new AccessCondition()); - options.getAccessCondition().setType(AccessConditionType.IfMatch); - options.getAccessCondition().setCondition(document.getETag()); - - - return client.replaceDocument(document.getSelfLink(), document, null).onErrorResumeNext(e -> { - - // pre condition failed - if (hasDocumentClientException(e, 412)) { - //Lost synchronously or not document yet. No conflict is induced. - return Observable.empty(); - - } - return Observable.error(e); - }).map(ResourceResponse::getResource); - } - - private Observable tryDeleteDocument(AsyncDocumentClient client, String collectionUri, Document document, int index) { - document.set("regionId", index); - document.set("regionEndpoint", client.getReadEndpoint()); - - RequestOptions options = new RequestOptions(); - options.setAccessCondition(new AccessCondition()); - options.getAccessCondition().setType(AccessConditionType.IfMatch); - options.getAccessCondition().setCondition(document.getETag()); - - - return client.deleteDocument(document.getSelfLink(), options).onErrorResumeNext(e -> { - - // pre condition failed - if (hasDocumentClientException(e, 412)) { - //Lost synchronously. No conflict is induced. - return Observable.empty(); - - } - return Observable.error(e); - }).map(rr -> document); - } - - private void validateManualConflict(List clients, Document conflictDocument) throws Exception { - boolean conflictExists = false; - for (AsyncDocumentClient client : clients) { - conflictExists = this.validateManualConflict(client, conflictDocument); - } - - if (conflictExists) { - this.deleteConflict(conflictDocument); - } - } - - private boolean isDelete(Conflict conflict) { - return StringUtils.equalsIgnoreCase(conflict.getOperationKind(), "delete"); - } - - - private boolean equals(String a, String b) { - return StringUtils.equals(a, b); - } - - private boolean validateManualConflict(AsyncDocumentClient client, Document conflictDocument) throws Exception { - while (true) { - FeedResponse response = client.readConflicts(this.manualCollectionUri, null) - .first().toBlocking().single(); - - for (Conflict conflict : response.getResults()) { - if (!isDelete(conflict)) { - Document conflictDocumentContent = conflict.getResource(Document.class); - if (equals(conflictDocument.getId(), conflictDocumentContent.getId())) { - if (equals(conflictDocument.getResourceId(), conflictDocumentContent.getResourceId()) && - equals(conflictDocument.getETag(), conflictDocumentContent.getETag())) { - logger.info("Document from Region {} lost conflict @ {}", - conflictDocument.getId(), - conflictDocument.getInt("regionId"), - client.getReadEndpoint()); - return true; - } else { - try { - //Checking whether this is the winner. - Document winnerDocument = client.readDocument(conflictDocument.getSelfLink(), null) - .toBlocking().single().getResource(); - logger.info("Document from region {} won the conflict @ {}", - conflictDocument.getInt("regionId"), - client.getReadEndpoint()); - return false; - } - catch (Exception exception) { - if (hasDocumentClientException(exception, 404)) { - throw exception; - } else { - logger.info( - "Document from region {} not found @ {}", - conflictDocument.getInt("regionId"), - client.getReadEndpoint()); - } - } - } - } - } else { - if (equals(conflict.getSourceResourceId(), conflictDocument.getResourceId())) { - logger.info("Delete conflict found @ {}", - client.getReadEndpoint()); - return false; - } - } - } - - logger.error("Document {} is not found in conflict feed @ {}, retrying", - conflictDocument.getId(), - client.getReadEndpoint()); - - TimeUnit.MILLISECONDS.sleep(500); - } - } - - private void deleteConflict(Document conflictDocument) { - AsyncDocumentClient delClient = clients.get(0); - - FeedResponse conflicts = delClient.readConflicts(this.manualCollectionUri, null).first().toBlocking().single(); - - for (Conflict conflict : conflicts.getResults()) { - if (!isDelete(conflict)) { - Document conflictContent = conflict.getResource(Document.class); - if (equals(conflictContent.getResourceId(), conflictDocument.getResourceId()) - && equals(conflictContent.getETag(), conflictDocument.getETag())) { - logger.info("Deleting manual conflict {} from region {}", - conflict.getSourceResourceId(), - conflictContent.getInt("regionId")); - delClient.deleteConflict(conflict.getSelfLink(), null) - .toBlocking().single(); - - } - } else if (equals(conflict.getSourceResourceId(), conflictDocument.getResourceId())) { - logger.info("Deleting manual conflict {} from region {}", - conflict.getSourceResourceId(), - conflictDocument.getInt("regionId")); - delClient.deleteConflict(conflict.getSelfLink(), null) - .toBlocking().single(); - } - } - } - - private void validateLWW(List clients, List conflictDocument) throws Exception { - validateLWW(clients, conflictDocument, false); - } - - - private void validateLWW(List clients, List conflictDocument, boolean hasDeleteConflict) throws Exception { - for (AsyncDocumentClient client : clients) { - this.validateLWW(client, conflictDocument, hasDeleteConflict); - } - } - - private void validateLWW(AsyncDocumentClient client, List conflictDocument, boolean hasDeleteConflict) throws Exception { - FeedResponse response = client.readConflicts(this.lwwCollectionUri, null) - .first().toBlocking().single(); - - if (response.getResults().size() != 0) { - logger.error("Found {} conflicts in the lww collection", response.getResults().size()); - return; - } - - if (hasDeleteConflict) { - do { - try { - client.readDocument(conflictDocument.get(0).getSelfLink(), null).toBlocking().single(); - - logger.error("Delete conflict for document {} didnt win @ {}", - conflictDocument.get(0).getId(), - client.getReadEndpoint()); - - TimeUnit.MILLISECONDS.sleep(500); - } catch (Exception exception) { - if (!hasDocumentClientExceptionCause(exception)) { - throw exception; - } - - // NotFound - if (hasDocumentClientExceptionCause(exception, 404)) { - - logger.info("Delete conflict won @ {}", client.getReadEndpoint()); - return; - } else { - logger.error("Delete conflict for document {} didnt win @ {}", - conflictDocument.get(0).getId(), - client.getReadEndpoint()); - - TimeUnit.MILLISECONDS.sleep(500); - } - } - } while (true); - } - - Document winnerDocument = null; - - for (Document document : conflictDocument) { - if (winnerDocument == null || - winnerDocument.getInt("regionId") <= document.getInt("regionId")) { - winnerDocument = document; - } - } - - logger.info("Document from region {} should be the winner", - winnerDocument.getInt("regionId")); - - while (true) { - try { - Document existingDocument = client.readDocument(winnerDocument.getSelfLink(), null) - .toBlocking().single().getResource(); - - if (existingDocument.getInt("regionId") == winnerDocument.getInt("regionId")) { - logger.info("Winner document from region {} found at {}", - existingDocument.getInt("regionId"), - client.getReadEndpoint()); - break; - } else { - logger.error("Winning document version from region {} is not found @ {}, retrying...", - winnerDocument.getInt("regionId"), - client.getWriteEndpoint()); - TimeUnit.MILLISECONDS.sleep(500); - } - } catch (Exception e) { - logger.error("Winner document from region {} is not found @ {}, retrying...", - winnerDocument.getInt("regionId"), - client.getWriteEndpoint()); - TimeUnit.MILLISECONDS.sleep(500); - } - } - } - - private void validateUDPAsync(List clients, List conflictDocument) throws Exception { - validateUDPAsync(clients, conflictDocument, false); - } - - private void validateUDPAsync(List clients, List conflictDocument, boolean hasDeleteConflict) throws Exception { - for (AsyncDocumentClient client : clients) { - this.validateUDPAsync(client, conflictDocument, hasDeleteConflict); - } - } - - private String documentNameLink(String collectionId, String documentId) { - return String.format("dbs/%s/colls/%s/docs/%s", databaseName, collectionId, documentId); - } - - private void validateUDPAsync(AsyncDocumentClient client, List conflictDocument, boolean hasDeleteConflict) throws Exception { - FeedResponse response = client.readConflicts(this.udpCollectionUri, null).first().toBlocking().single(); - - if (response.getResults().size() != 0) { - logger.error("Found {} conflicts in the udp collection", response.getResults().size()); - return; - } - - if (hasDeleteConflict) { - do { - try { - client.readDocument( - documentNameLink(udpCollectionName, conflictDocument.get(0).getId()), null) - .toBlocking().single(); - - logger.error("Delete conflict for document {} didnt win @ {}", - conflictDocument.get(0).getId(), - client.getReadEndpoint()); - - TimeUnit.MILLISECONDS.sleep(500); - - } catch (Exception exception) { - if (hasDocumentClientExceptionCause(exception, 404)) { - logger.info("Delete conflict won @ {}", client.getReadEndpoint()); - return; - } else { - logger.error("Delete conflict for document {} didnt win @ {}", - conflictDocument.get(0).getId(), - client.getReadEndpoint()); - - TimeUnit.MILLISECONDS.sleep(500); - } - } - } while (true); - } - - Document winnerDocument = null; - - for (Document document : conflictDocument) { - if (winnerDocument == null || - winnerDocument.getInt("regionId") <= document.getInt("regionId")) { - winnerDocument = document; - } - } - - logger.info("Document from region {} should be the winner", - winnerDocument.getInt("regionId")); - - while (true) { - try { - - Document existingDocument = client.readDocument( - documentNameLink(udpCollectionName, winnerDocument.getId()), null) - .toBlocking().single().getResource(); - - if (existingDocument.getInt("regionId") == winnerDocument.getInt( - ("regionId"))) { - logger.info("Winner document from region {} found at {}", - existingDocument.getInt("regionId"), - client.getReadEndpoint()); - break; - } else { - logger.error("Winning document version from region {} is not found @ {}, retrying...", - winnerDocument.getInt("regionId"), - client.getWriteEndpoint()); - TimeUnit.MILLISECONDS.sleep(500); - } - } catch (Exception e) { - logger.error("Winner document from region {} is not found @ {}, retrying...", - winnerDocument.getInt("regionId"), - client.getWriteEndpoint()); - TimeUnit.MILLISECONDS.sleep(500); - } - } - } - - public void shutdown() { - this.executor.shutdown(); - for(AsyncDocumentClient client: clients) { - client.close(); - } - } -} diff --git a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/Main.java b/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/Main.java deleted file mode 100644 index 58f1864a54d3..000000000000 --- a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/Main.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples; - -import com.microsoft.azure.cosmosdb.rx.examples.multimaster.ConfigurationManager; -import org.apache.commons.io.IOUtils; - -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - - -public class Main { - public static void main(String[] args) throws Exception { - - if (args.length != 1) { - help(); - System.exit(1); - } - - try (InputStream inputStream = new FileInputStream(args[0])) { - ConfigurationManager.getAppSettings().load(inputStream); - System.out.println("Using file " + args[0] + " for the setting."); - } - - Main.runScenarios(); - } - - private static void runScenarios() throws Exception { - MultiMasterScenario scenario = new MultiMasterScenario(); - scenario.initialize(); - - scenario.runBasic(); - - scenario.runManualConflict(); - scenario.runLWW(); - scenario.runUDP(); - - System.out.println("Finished"); - - //shutting down the active the resources - scenario.shutdown(); - } - - private static void help() throws IOException { - System.out.println("Provide the path to setting file in the following format: "); - try (InputStream inputStream = - Main.class.getClassLoader() - .getResourceAsStream("multi-master-sample-config.properties")) { - - IOUtils.copy(inputStream, System.out); - - System.out.println(); - } catch (Exception e) { - throw e; - } - } -} diff --git a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/MultiMasterScenario.java b/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/MultiMasterScenario.java deleted file mode 100644 index 5c127de357fc..000000000000 --- a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/MultiMasterScenario.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples; - -import com.google.common.base.Preconditions; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.examples.multimaster.ConfigurationManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Completable; - -import javax.net.ssl.SSLException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class MultiMasterScenario { - - private final static Logger logger = LoggerFactory.getLogger(MultiMasterScenario.class); - - final private String accountEndpoint; - final private String accountKey; - final private List workers; - final private ConflictWorker conflictWorker; - - public MultiMasterScenario() { - this.accountEndpoint = ConfigurationManager.getAppSettings().getProperty("endpoint"); - this.accountKey = ConfigurationManager.getAppSettings().getProperty("key"); - - String databaseName = ConfigurationManager.getAppSettings().getProperty("databaseName"); - String manualCollectionName = ConfigurationManager.getAppSettings().getProperty("manualCollectionName"); - String lwwCollectionName = ConfigurationManager.getAppSettings().getProperty("lwwCollectionName"); - String udpCollectionName = ConfigurationManager.getAppSettings().getProperty("udpCollectionName"); - String basicCollectionName = ConfigurationManager.getAppSettings().getProperty("basicCollectionName"); - String regionsAsString = ConfigurationManager.getAppSettings().getProperty("regions"); - Preconditions.checkNotNull(regionsAsString, "regions is required"); - String[] regions = regionsAsString.split(";"); - Preconditions.checkArgument(regions.length > 0, "at least one region is required"); - Preconditions.checkNotNull(accountEndpoint, "accountEndpoint is required"); - Preconditions.checkNotNull(accountKey, "accountKey is required"); - Preconditions.checkNotNull(databaseName, "databaseName is required"); - Preconditions.checkNotNull(manualCollectionName, "manualCollectionName is required"); - Preconditions.checkNotNull(lwwCollectionName, "lwwCollectionName is required"); - Preconditions.checkNotNull(udpCollectionName, "udpCollectionName is required"); - Preconditions.checkNotNull(basicCollectionName, "basicCollectionName is required"); - - this.workers = new ArrayList<>(); - this.conflictWorker = new ConflictWorker(databaseName, basicCollectionName, manualCollectionName, lwwCollectionName, udpCollectionName); - - for (String region : regions) { - ConnectionPolicy policy = new ConnectionPolicy(); - policy.setUsingMultipleWriteLocations(true); - policy.setPreferredLocations(Collections.singletonList(region)); - - AsyncDocumentClient client = - new AsyncDocumentClient.Builder() - .withMasterKeyOrResourceToken(this.accountKey) - .withServiceEndpoint(this.accountEndpoint) - .withConsistencyLevel(ConsistencyLevel.Eventual) - .withConnectionPolicy(policy).build(); - - - workers.add(new Worker(client, databaseName, basicCollectionName)); - - conflictWorker.addClient(client); - } - } - - public void initialize() throws Exception { - this.conflictWorker.initialize(); - logger.info("Initialized collections."); - } - - public void runBasic() throws Exception { - logger.info("\n####################################################"); - logger.info("Basic Active-Active"); - logger.info("####################################################"); - - logger.info("1) Starting insert loops across multiple regions ..."); - - List basicTask = new ArrayList(); - - int documentsToInsertPerWorker = 100; - - for (Worker worker : this.workers) { - basicTask.add(worker.runLoopAsync(documentsToInsertPerWorker)); - } - - Completable.merge(basicTask).await(); - - basicTask.clear(); - - logger.info("2) Reading from every region ..."); - - int expectedDocuments = this.workers.size() * documentsToInsertPerWorker; - for (Worker worker : this.workers) { - basicTask.add(worker.readAllAsync(expectedDocuments)); - } - - Completable.merge(basicTask).await(); - - basicTask.clear(); - - logger.info("3) Deleting all the documents ..."); - - this.workers.get(0).deleteAll(); - - logger.info("####################################################"); - } - - public void runManualConflict() throws Exception { - logger.info("\n####################################################"); - logger.info("Manual Conflict Resolution"); - logger.info("####################################################"); - - this.conflictWorker.runManualConflict(); - logger.info("####################################################"); - } - - public void runLWW() throws Exception { - logger.info("\n####################################################"); - logger.info("LWW Conflict Resolution"); - logger.info("####################################################"); - - this.conflictWorker.runLWWConflict(); - logger.info("####################################################"); - } - - public void runUDP() throws Exception { - logger.info("\n####################################################"); - logger.info("UDP Conflict Resolution"); - logger.info("####################################################"); - - this.conflictWorker.runUDPConflict(); - logger.info("####################################################"); - } - - public void shutdown() { - conflictWorker.shutdown(); - for(Worker worker: this.workers) { - worker.shutdown(); - } - } -} diff --git a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/Worker.java b/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/Worker.java deleted file mode 100644 index 90a5ab77aaff..000000000000 --- a/cosmosdb/data-plane/examples/src/main/java/com/microsoft/azure/cosmosdb/rx/examples/multimaster/samples/Worker.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples; - - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.rx.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Completable; -import rx.Scheduler; -import rx.schedulers.Schedulers; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -public class Worker { - private final static Logger logger = LoggerFactory.getLogger(Worker.class); - - private final AsyncDocumentClient client; - private final String documentCollectionUri; - - // scheduler for blocking work - private final Scheduler schedulerForBlockingWork; - private final ExecutorService executor; - - public Worker(AsyncDocumentClient client, String databaseName, String collectionName) { - this.client = client; - this.documentCollectionUri = String.format("/dbs/%s/colls/%s", databaseName, collectionName); - this.executor = Executors.newSingleThreadExecutor(); - this.schedulerForBlockingWork = Schedulers.from(executor); - } - - public Completable runLoopAsync(int documentsToInsert) { - return Completable.defer(() -> { - - int iterationCount = 0; - - List latency = new ArrayList<>(); - while (iterationCount++ < documentsToInsert) { - long startTick = System.currentTimeMillis(); - - Document d = new Document(); - d.setId(UUID.randomUUID().toString()); - - this.client.createDocument(this.documentCollectionUri, d, null, false) - .subscribeOn(schedulerForBlockingWork).toBlocking().single(); - - long endTick = System.currentTimeMillis(); - - latency.add(endTick - startTick); - } - - Collections.sort(latency); - int p50Index = (latency.size() / 2); - - logger.info("Inserted {} documents at {} with p50 {} ms", - documentsToInsert, - this.client.getWriteEndpoint(), - latency.get(p50Index)); - - return Completable.complete(); - - }); - - } - - - public Completable readAllAsync(int expectedNumberOfDocuments) { - - return Completable.defer(() -> { - - while (true) { - int totalItemRead = 0; - FeedResponse response = null; - do { - - FeedOptions options = new FeedOptions(); - options.setRequestContinuation(response != null ? response.getResponseContinuation() : null); - - response = this.client.readDocuments(this.documentCollectionUri, options).first() - .subscribeOn(schedulerForBlockingWork).toBlocking().single(); - - totalItemRead += response.getResults().size(); - } while (response.getResponseContinuation() != null); - - if (totalItemRead < expectedNumberOfDocuments) { - logger.info("Total item read {} from {} is less than {}, retrying reads", - totalItemRead, - this.client.getReadEndpoint(), - expectedNumberOfDocuments); - - try { - TimeUnit.SECONDS.sleep(1); - } catch (InterruptedException e) { - logger.info("interrupted"); - break; - } - continue; - } else { - logger.info("Read {} items from {}", totalItemRead, this.client.getReadEndpoint()); - break; - } - } - - return Completable.complete(); - }); - } - - void deleteAll() { - List documents = new ArrayList<>(); - FeedResponse response = null; - do { - - FeedOptions options = new FeedOptions(); - options.setRequestContinuation(response != null ? response.getResponseContinuation() : null); - - response = this.client.readDocuments(this.documentCollectionUri, options).first() - .subscribeOn(schedulerForBlockingWork).toBlocking().single(); - - documents.addAll(response.getResults()); - } while (response.getResponseContinuation() != null); - - for (Document document : documents) { - try { - this.client.deleteDocument(document.getSelfLink(), null) - .subscribeOn(schedulerForBlockingWork).toBlocking().single(); - } catch (RuntimeException exEx) { - DocumentClientException dce = getDocumentClientExceptionCause(exEx); - - if (dce.getStatusCode() != 404) { - logger.info("Error occurred while deleting {} from {}", dce, client.getWriteEndpoint()); - } - } - } - - logger.info("Deleted all documents from region {}", this.client.getWriteEndpoint()); - } - - private DocumentClientException getDocumentClientExceptionCause(Throwable e) { - while (e != null) { - - if (e instanceof DocumentClientException) { - return (DocumentClientException) e; - } - - e = e.getCause(); - } - - return null; - } - - public void shutdown() { - executor.shutdown(); - client.close(); - } -} diff --git a/cosmosdb/data-plane/examples/src/main/resources/log4j.properties b/cosmosdb/data-plane/examples/src/main/resources/log4j.properties deleted file mode 100644 index 00b7fefa6413..000000000000 --- a/cosmosdb/data-plane/examples/src/main/resources/log4j.properties +++ /dev/null @@ -1,23 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=WARN, A1 - -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -log4j.category.com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples.ConflictWorker=INFO -log4j.category.com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples.Main=INFO -log4j.category.com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples.Worker=INFO -log4j.category.com.microsoft.azure.cosmosdb.rx.examples.multimaster.samples.MultiMasterScenario=INFO -log4j.category.com.microsoft.azure.cosmosdb.rx.examples.multimaster.ConfigurationManager=INFO -log4j.category.com.microsoft.azure.cosmosdb.rx.examples.multimaster.Helpers=INFO - -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -#log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p - %m%n - -log4j.appender.A1.layout.ConversionPattern=%m%n - diff --git a/cosmosdb/data-plane/examples/src/main/resources/multi-master-sample-config.properties b/cosmosdb/data-plane/examples/src/main/resources/multi-master-sample-config.properties deleted file mode 100644 index 42c20302edc1..000000000000 --- a/cosmosdb/data-plane/examples/src/main/resources/multi-master-sample-config.properties +++ /dev/null @@ -1,8 +0,0 @@ -endpoint= -key= -regions=North Central US;North Europe;Southeast Asia -databaseName=multiMasterDemoDB -manualCollectionName=myManualCollection -lwwCollectionName=myLwwCollection -udpCollectionName=myUdpCollection -basicCollectionName=myBasicCollection \ No newline at end of file diff --git a/cosmosdb/data-plane/examples/src/main/resources/resolver-storedproc.txt b/cosmosdb/data-plane/examples/src/main/resources/resolver-storedproc.txt deleted file mode 100644 index e856721a979a..000000000000 --- a/cosmosdb/data-plane/examples/src/main/resources/resolver-storedproc.txt +++ /dev/null @@ -1,45 +0,0 @@ -function resolver(incomingRecord, existingRecord, isTombstone, conflictingRecords) { - var collection = getContext().getCollection(); - if (!incomingRecord) { - if (existingRecord) { - collection.deleteDocument(existingRecord._self, {}, function(err, responseOptions) { - if (err) throw err; - }); - } - } else if (isTombstone) { - // delete always wins. - } else { - var documentToUse = incomingRecord; - if (existingRecord) { - if (documentToUse.regionId < existingRecord.regionId) { - documentToUse = existingRecord; - } - } - var i; - for (i = 0; i < conflictingRecords.length; i++) { - if (documentToUse.regionId < conflictingRecords[i].regionId) { - documentToUse = conflictingRecords[i]; - } - } - tryDelete(conflictingRecords, incomingRecord, existingRecord, documentToUse); - } - function tryDelete(documents, incoming, existing, documentToInsert) { - if (documents.length > 0) { - collection.deleteDocument(documents[0]._self, {}, function(err, responseOptions) { - if (err) throw err; - documents.shift(); - tryDelete(documents, incoming, existing, documentToInsert); - }); - } else if (existing) { - collection.replaceDocument(existing._self, documentToInsert, - function(err, documentCreated) { - if (err) throw err; - }); - } else { - collection.createDocument(collection.getSelfLink(), documentToInsert, - function(err, documentCreated) { - if (err) throw err; - }); - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/CollectionCRUDAsyncAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/CollectionCRUDAsyncAPITest.java deleted file mode 100644 index e9d0c4d33604..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/CollectionCRUDAsyncAPITest.java +++ /dev/null @@ -1,410 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.google.common.util.concurrent.ListenableFuture; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; -import rx.Observable; -import rx.functions.Action1; -import rx.observable.ListenableFutureObservable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; - -/** - * This integration test class demonstrates how to use Async API to create, - * delete, replace, and update Document Collections. - *

- * NOTE: you can use rxJava based async api with java8 lambda expression. Use of - * rxJava based async APIs with java8 lambda expressions is much prettier. - *

- * You can also use the async API without java8 lambda expression support. - *

- * For example - *

    - *
  • {@link #createCollection_MultiPartition_Async()} demonstrates how to use async api - * with java8 lambda expression. - * - *
  • {@link #createCollection_Async_withoutLambda()} demonstrates how to - * do the same thing without lambda expression. - *
- *

- * Also if you need to work with Future or ListenableFuture it is possible to - * transform an observable to ListenableFuture. Please see - * {@link #transformObservableToGoogleGuavaListenableFuture()} - *

- * To Modify the Collection's throughput after it has been created, you need to - * update the corresponding Offer. Please see - * {@see com.microsoft.azure.cosmosdb.rx.examples.OfferCRUDAsyncAPITest#testUpdateOffer()} - */ -public class CollectionCRUDAsyncAPITest { - private final static int TIMEOUT = 120000; - private static Database createdDatabase; - private static AsyncDocumentClient asyncClient; - private DocumentCollection collectionDefinition; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - createdDatabase = Utils.createDatabaseForTest(asyncClient); - } - - @BeforeMethod(groups = "samples", timeOut = TIMEOUT) - public void before() { - collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(asyncClient, createdDatabase); - Utils.safeClose(asyncClient); - } - - /** - * Create a document collection using async api. - * If you want a single partition collection with 10,000 RU/s throughput, - * the only way to do so is to create a single partition collection with lower - * throughput (400) and then increase the throughput. - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createCollection_SinglePartition_Async() throws Exception { - RequestOptions singlePartitionRequestOptions = new RequestOptions(); - singlePartitionRequestOptions.setOfferThroughput(400); - Observable> createCollectionObservable = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, singlePartitionRequestOptions); - - final CountDownLatch countDownLatch = new CountDownLatch(1); - - createCollectionObservable.single() // We know there is only single result - .subscribe(collectionResourceResponse -> { - System.out.println(collectionResourceResponse.getActivityId()); - countDownLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while creating the collection: actual cause: " + error.getMessage()); - countDownLatch.countDown(); - }); - - // Wait till collection creation completes - countDownLatch.await(); - } - - /** - * Create a document collection using async api. - * This test uses java8 lambda expression. - * See testCreateCollection_Async_withoutLambda for usage without lambda - * expressions. - * Set the throughput to be > 10,000 RU/s - * to create a multi partition collection. - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createCollection_MultiPartition_Async() throws Exception { - RequestOptions multiPartitionRequestOptions = new RequestOptions(); - multiPartitionRequestOptions.setOfferThroughput(20000); - - Observable> createCollectionObservable = asyncClient.createCollection( - getDatabaseLink(), getMultiPartitionCollectionDefinition(), multiPartitionRequestOptions); - - final CountDownLatch countDownLatch = new CountDownLatch(1); - - createCollectionObservable.single() // We know there is only single result - .subscribe(collectionResourceResponse -> { - System.out.println(collectionResourceResponse.getActivityId()); - countDownLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while creating the collection: actual cause: " + error.getMessage()); - countDownLatch.countDown(); - }); - - // Wait till collection creation completes - countDownLatch.await(); - } - - /** - * Create a document Collection using async api, without java8 lambda expressions - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createCollection_Async_withoutLambda() throws Exception { - Observable> createCollectionObservable = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, null); - - final CountDownLatch countDownLatch = new CountDownLatch(1); - Action1> onCollectionCreationAction = new Action1>() { - - @Override - public void call(ResourceResponse resourceResponse) { - // Collection is created - System.out.println(resourceResponse.getActivityId()); - countDownLatch.countDown(); - } - }; - - Action1 onError = new Action1() { - @Override - public void call(Throwable error) { - System.err.println( - "an error occurred while creating the collection: actual cause: " + error.getMessage()); - countDownLatch.countDown(); - } - }; - - createCollectionObservable.single() // We know there is only a single event - .subscribe(onCollectionCreationAction, onError); - - // Wait till collection creation completes - countDownLatch.await(); - } - - /** - * Create a collection in a blocking manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createCollection_toBlocking() { - Observable> createCollectionObservable = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, null); - - // toBlocking() converts the observable to a blocking observable. - // single() gets the only result. - createCollectionObservable.toBlocking().single(); - } - - /** - * Attempt to create a Collection which already exists - * - First create a Collection - * - Using the async api generate an async collection creation observable - * - Converts the Observable to blocking using Observable.toBlocking() api - * - Catch already exist failure (409) - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createCollection_toBlocking_CollectionAlreadyExists_Fails() { - asyncClient.createCollection(getDatabaseLink(), collectionDefinition, null).toBlocking().single(); - - // Create the collection for test. - Observable> collectionForTestObservable = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, null); - - try { - collectionForTestObservable.toBlocking() // Blocks - .single(); // Gets the single result - assertThat("Should not reach here", false); - } catch (Exception e) { - assertThat("Collection already exists.", ((DocumentClientException) e.getCause()).getStatusCode(), - equalTo(409)); - } - } - - /** - * You can convert an Observable to a ListenableFuture. - * ListenableFuture (part of google guava library) is a popular extension - * of Java's Future which allows registering listener callbacks: - * https://github.com/google/guava/wiki/ListenableFutureExplained - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void transformObservableToGoogleGuavaListenableFuture() throws Exception { - Observable> createCollectionObservable = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, null); - ListenableFuture> future = ListenableFutureObservable - .to(createCollectionObservable); - - ResourceResponse rrd = future.get(); - - assertThat(rrd.getRequestCharge(), greaterThan((double) 0)); - System.out.println(rrd.getRequestCharge()); - } - - /** - * Read a Collection in an Async manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createAndReadCollection() throws Exception { - // Create a Collection - DocumentCollection documentCollection = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, null).toBlocking().single() - .getResource(); - - // Read the created collection using async api - Observable> readCollectionObservable = asyncClient - .readCollection(getCollectionLink(documentCollection), null); - - final CountDownLatch countDownLatch = new CountDownLatch(1); - - readCollectionObservable.single() // We know there is only single result - .subscribe(collectionResourceResponse -> { - System.out.println(collectionResourceResponse.getActivityId()); - countDownLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while reading the collection: actual cause: " + error.getMessage()); - countDownLatch.countDown(); - }); - - // Wait till read collection completes - countDownLatch.await(); - } - - /** - * Delete a Collection in an Async manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createAndDeleteCollection() throws Exception { - // Create a Collection - DocumentCollection documentCollection = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, null).toBlocking().single() - .getResource(); - - // Delete the created collection using async api - Observable> deleteCollectionObservable = asyncClient - .deleteCollection(getCollectionLink(documentCollection), null); - - final CountDownLatch countDownLatch = new CountDownLatch(1); - - deleteCollectionObservable.single() // We know there is only single result - .subscribe(collectionResourceResponse -> { - System.out.println(collectionResourceResponse.getActivityId()); - countDownLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while deleting the collection: actual cause: " + error.getMessage()); - countDownLatch.countDown(); - }); - - // Wait till collection deletion completes - countDownLatch.await(); - } - - /** - * Query a Collection in an Async manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void collectionCreateAndQuery() throws Exception { - // Create a Collection - DocumentCollection collection = asyncClient - .createCollection(getDatabaseLink(), collectionDefinition, null).toBlocking().single() - .getResource(); - - // Query the created collection using async api - Observable> queryCollectionObservable = asyncClient.queryCollections( - getDatabaseLink(), String.format("SELECT * FROM r where r.id = '%s'", collection.getId()), - null); - - final CountDownLatch countDownLatch = new CountDownLatch(1); - - queryCollectionObservable.toList().subscribe(collectionFeedResponseList -> { - // toList() should return a list of size 1 - assertThat(collectionFeedResponseList.size(), equalTo(1)); - - // First element of the list should have only 1 result - FeedResponse collectionFeedResponse = collectionFeedResponseList.get(0); - assertThat(collectionFeedResponse.getResults().size(), equalTo(1)); - - // This collection should have the same id as the one we created - DocumentCollection foundCollection = collectionFeedResponse.getResults().get(0); - assertThat(foundCollection.getId(), equalTo(collection.getId())); - - System.out.println(collectionFeedResponse.getActivityId()); - countDownLatch.countDown(); - }, error -> { - System.err.println("an error occurred while querying the collection: actual cause: " + error.getMessage()); - countDownLatch.countDown(); - }); - - // Wait till collection query completes - countDownLatch.await(); - } - - private String getDatabaseLink() { - return "dbs/" + createdDatabase.getId(); - } - - private String getCollectionLink(DocumentCollection collection) { - return "dbs/" + createdDatabase.getId() + "/colls/" + collection.getId(); - } - - private DocumentCollection getMultiPartitionCollectionDefinition() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Set the partitionKeyDefinition for a partitioned collection. - // Here, we are setting the partitionKey of the Collection to be /city - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - List paths = new ArrayList<>(); - paths.add("/city"); - partitionKeyDefinition.setPaths(paths); - collectionDefinition.setPartitionKey(partitionKeyDefinition); - - // Set indexing policy to be range range for string and number - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection includedPaths = new ArrayList<>(); - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath("/*"); - Collection indexes = new ArrayList<>(); - Index stringIndex = Index.Range(DataType.String); - stringIndex.set("precision", -1); - indexes.add(stringIndex); - - Index numberIndex = Index.Range(DataType.Number); - numberIndex.set("precision", -1); - indexes.add(numberIndex); - includedPath.setIndexes(indexes); - includedPaths.add(includedPath); - indexingPolicy.setIncludedPaths(includedPaths); - collectionDefinition.setIndexingPolicy(indexingPolicy); - - return collectionDefinition; - } -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/ConflictAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/ConflictAPITest.java deleted file mode 100644 index 8aad1f45b8e9..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/ConflictAPITest.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.google.common.util.concurrent.ListenableFuture; -import com.microsoft.azure.cosmosdb.Conflict; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Observable; -import rx.observable.ListenableFutureObservable; - -import java.util.Iterator; -import java.util.List; -import java.util.UUID; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.notNullValue; - -/** - * This integration test class demonstrates how to use Async API for - * Conflicts. - *

- * Also if you need to work with Future or ListenableFuture it is possible to - * transform an observable to ListenableFuture. Please see - * {@link #transformObservableToGoogleGuavaListenableFuture()} - */ -public class ConflictAPITest { - private final static int TIMEOUT = 60000; - - private AsyncDocumentClient client; - private DocumentCollection createdCollection; - private Database createdDatabase; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - client = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Create database - createdDatabase = Utils.createDatabaseForTest(client); - - // Create collection - createdCollection = client - .createCollection("/dbs/" + createdDatabase.getId(), collectionDefinition, null) - .toBlocking().single().getResource(); - - int numberOfDocuments = 20; - // Add documents - for (int i = 0; i < numberOfDocuments; i++) { - Document doc = new Document(String.format("{ 'id': 'loc%d', 'counter': %d}", i, i)); - client.createDocument(getCollectionLink(), doc, null, true).toBlocking().single(); - } - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(client, createdDatabase); - Utils.safeClose(client); - } - - /** - * Read conflicts - * Converts the conflict read feed observable to blocking observable and - * uses that to find all conflicts - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void readConflicts_toBlocking_toIterator() { - // read all conflicts - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable> conflictReadFeedObservable = client - .readConflicts(getCollectionLink(), options); - - // Covert the observable to a blocking observable, then convert the blocking - // observable to an iterator - Iterator> it = conflictReadFeedObservable.toBlocking().getIterator(); - - int expectedNumberOfConflicts = 0; - - int numberOfResults = 0; - while (it.hasNext()) { - FeedResponse page = it.next(); - System.out.println("items: " + page.getResults()); - String pageSizeAsString = page.getResponseHeaders().get(HttpConstants.HttpHeaders.ITEM_COUNT); - assertThat("header item count must be present", pageSizeAsString, notNullValue()); - int pageSize = Integer.valueOf(pageSizeAsString); - assertThat("Result size must match header item count", page.getResults(), hasSize(pageSize)); - numberOfResults += pageSize; - } - assertThat("number of total results", numberOfResults, equalTo(expectedNumberOfConflicts)); - } - - /** - * You can convert an Observable to a ListenableFuture. - * ListenableFuture (part of google guava library) is a popular extension - * of Java's Future which allows registering listener callbacks: - * https://github.com/google/guava/wiki/ListenableFutureExplained - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void transformObservableToGoogleGuavaListenableFuture() throws Exception { - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable> conflictReadFeedObservable = client - .readConflicts(getCollectionLink(), options); - - // Convert to observable of list of pages - Observable>> allPagesObservable = conflictReadFeedObservable.toList(); - - // Convert the observable of list of pages to a Future - ListenableFuture>> future = ListenableFutureObservable.to(allPagesObservable); - - List> pageList = future.get(); - - int totalNumberOfRetrievedConflicts = 0; - for (FeedResponse page : pageList) { - totalNumberOfRetrievedConflicts += page.getResults().size(); - } - assertThat(0, equalTo(totalNumberOfRetrievedConflicts)); - } - - private String getCollectionLink() { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(); - } -} - diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DatabaseCRUDAsyncAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DatabaseCRUDAsyncAPITest.java deleted file mode 100644 index 1f2fdfde4b64..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DatabaseCRUDAsyncAPITest.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.google.common.util.concurrent.ListenableFuture; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Observable; -import rx.functions.Action1; -import rx.observable.ListenableFutureObservable; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; - -/** - * This integration test class demonstrates how to use Async API to create, - * delete, replace, and update Databases. - *

- * NOTE: you can use rxJava based async api with java8 lambda expression. Use of - * rxJava based async APIs with java8 lambda expressions is much prettier. - *

- * You can also use the async API without java8 lambda expression support. - *

- * For example - *

    - *
  • {@link #createDatabase_Async()} demonstrates how to use async api - * with java8 lambda expression. - * - *
  • {@link #createDatabase_Async_withoutLambda()} demonstrates how to - * do the same thing without lambda expression. - *
- *

- * Also if you need to work with Future or ListenableFuture it is possible to - * transform an observable to ListenableFuture. Please see - * {@link #transformObservableToGoogleGuavaListenableFuture()} - */ -public class DatabaseCRUDAsyncAPITest { - private final static int TIMEOUT = 60000; - private final List databaseIds = new ArrayList<>(); - - private AsyncDocumentClient asyncClient; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - } - - private Database getDatabaseDefinition() { - Database databaseDefinition = new Database(); - databaseDefinition.setId(Utils.generateDatabaseId()); - - databaseIds.add(databaseDefinition.getId()); - - return databaseDefinition; - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - for (String id : databaseIds) { - Utils.safeClean(asyncClient, id); - } - Utils.safeClose(asyncClient); - } - - /** - * Create a database using async api. - * This test uses java8 lambda expression. - * See testCreateDatabase_Async_withoutLambda for usage without lambda. - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDatabase_Async() throws Exception { - Observable> createDatabaseObservable = asyncClient.createDatabase(getDatabaseDefinition(), - null); - - final CountDownLatch completionLatch = new CountDownLatch(1); - - createDatabaseObservable.single() // We know there is only single result - .subscribe(databaseResourceResponse -> { - System.out.println(databaseResourceResponse.getActivityId()); - completionLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while creating the database: actual cause: " + error.getMessage()); - completionLatch.countDown(); - }); - - // Wait till database creation completes - completionLatch.await(); - } - - /** - * Create a database using async api, without java8 lambda expressions - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDatabase_Async_withoutLambda() throws Exception { - Observable> createDatabaseObservable = asyncClient.createDatabase(getDatabaseDefinition(), - null); - - final CountDownLatch completionLatch = new CountDownLatch(1); - Action1> onDatabaseCreationAction = new Action1>() { - - @Override - public void call(ResourceResponse resourceResponse) { - // Database is created - System.out.println(resourceResponse.getActivityId()); - completionLatch.countDown(); - } - }; - - Action1 onError = new Action1() { - @Override - public void call(Throwable error) { - System.err - .println("an error occurred while creating the database: actual cause: " + error.getMessage()); - completionLatch.countDown(); - } - }; - - createDatabaseObservable.single() // We know there is only a single event - .subscribe(onDatabaseCreationAction, onError); - - // Wait till database creation completes - completionLatch.await(); - } - - /** - * Create a database in a blocking manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDatabase_toBlocking() { - Observable> createDatabaseObservable = asyncClient.createDatabase(getDatabaseDefinition(), - null); - - // toBlocking() converts to a blocking observable. - // single() gets the only result. - createDatabaseObservable.toBlocking().single(); - } - - /** - * Attempt to create a database which already exists - * - First create a database - * - Using the async api generate an async database creation observable - * - Converts the Observable to blocking using Observable.toBlocking() api - * - Catch already exist failure (409) - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDatabase_toBlocking_DatabaseAlreadyExists_Fails() { - Database databaseDefinition = getDatabaseDefinition(); - asyncClient.createDatabase(databaseDefinition, null).toBlocking().single(); - - // Create the database for test. - Observable> databaseForTestObservable = asyncClient - .createDatabase(databaseDefinition, null); - - try { - databaseForTestObservable.toBlocking() // Blocks - .single(); // Gets the single result - assertThat("Should not reach here", false); - } catch (Exception e) { - assertThat("Database already exists.", ((DocumentClientException) e.getCause()).getStatusCode(), - equalTo(409)); - } - } - - /** - * You can convert an Observable to a ListenableFuture. - * ListenableFuture (part of google guava library) is a popular extension - * of Java's Future which allows registering listener callbacks: - * https://github.com/google/guava/wiki/ListenableFutureExplained - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void transformObservableToGoogleGuavaListenableFuture() throws Exception { - Observable> createDatabaseObservable = asyncClient.createDatabase(getDatabaseDefinition(), - null); - ListenableFuture> future = ListenableFutureObservable.to(createDatabaseObservable); - - ResourceResponse rrd = future.get(); - - assertThat(rrd.getRequestCharge(), greaterThan((double) 0)); - System.out.print(rrd.getRequestCharge()); - } - - /** - * Read a Database in an Async manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createAndReadDatabase() throws Exception { - // Create a database - Database database = asyncClient.createDatabase(getDatabaseDefinition(), null).toBlocking().single().getResource(); - - // Read the created database using async api - Observable> readDatabaseObservable = asyncClient.readDatabase("dbs/" + database.getId(), - null); - - final CountDownLatch completionLatch = new CountDownLatch(1); - - readDatabaseObservable.single() // We know there is only single result - .subscribe(databaseResourceResponse -> { - System.out.println(databaseResourceResponse.getActivityId()); - completionLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while reading the database: actual cause: " + error.getMessage()); - completionLatch.countDown(); - }); - - // Wait till read database completes - completionLatch.await(); - } - - /** - * Delete a Database in an Async manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createAndDeleteDatabase() throws Exception { - // Create a database - Database database = asyncClient.createDatabase(getDatabaseDefinition(), null).toBlocking().single().getResource(); - - // Delete the created database using async api - Observable> deleteDatabaseObservable = asyncClient - .deleteDatabase("dbs/" + database.getId(), null); - - final CountDownLatch completionLatch = new CountDownLatch(1); - - deleteDatabaseObservable.single() // We know there is only single result - .subscribe(databaseResourceResponse -> { - System.out.println(databaseResourceResponse.getActivityId()); - completionLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while deleting the database: actual cause: " + error.getMessage()); - completionLatch.countDown(); - }); - - // Wait till database deletion completes - completionLatch.await(); - } - - /** - * Query a Database in an Async manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void databaseCreateAndQuery() throws Exception { - // Create a database - Database databaseDefinition = getDatabaseDefinition(); - asyncClient.createDatabase(databaseDefinition, null).toBlocking().single().getResource(); - - // Query the created database using async api - Observable> queryDatabaseObservable = asyncClient - .queryDatabases(String.format("SELECT * FROM r where r.id = '%s'", databaseDefinition.getId()), null); - - final CountDownLatch completionLatch = new CountDownLatch(1); - - queryDatabaseObservable.toList().subscribe(databaseFeedResponseList -> { - // toList() should return a list of size 1 - assertThat(databaseFeedResponseList.size(), equalTo(1)); - - // First element of the list should have only 1 result - FeedResponse databaseFeedResponse = databaseFeedResponseList.get(0); - assertThat(databaseFeedResponse.getResults().size(), equalTo(1)); - - // This database should have the same id as the one we created - Database foundDatabase = databaseFeedResponse.getResults().get(0); - assertThat(foundDatabase.getId(), equalTo(databaseDefinition.getId())); - - System.out.println(databaseFeedResponse.getActivityId()); - completionLatch.countDown(); - }, error -> { - System.err.println("an error occurred while querying the database: actual cause: " + error.getMessage()); - completionLatch.countDown(); - }); - - // Wait till database query completes - completionLatch.await(); - } -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DocumentCRUDAsyncAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DocumentCRUDAsyncAPITest.java deleted file mode 100644 index a9df3991e84c..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DocumentCRUDAsyncAPITest.java +++ /dev/null @@ -1,540 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.util.concurrent.ListenableFuture; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.apache.commons.lang3.RandomUtils; -import org.assertj.core.api.Assertions; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Observable; -import rx.functions.Action1; -import rx.observable.ListenableFutureObservable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; - -/** - * This integration test class demonstrates how to use Async API to create, - * delete, replace, and upsert Documents. If you are interested in examples for - * querying for documents please see {@link DocumentQueryAsyncAPITest} - *

- * NOTE: you can use rxJava based async api with java8 lambda expression. Use - * of rxJava based async APIs with java8 lambda expressions is much prettier. - *

- * You can also use the async API without java8 lambda expression. - *

- * For example - *

    - *
  • {@link #createDocument_Async()} demonstrates how to use async api - * with java8 lambda expression. - * - *
  • {@link #createDocument_Async_withoutLambda()} demonstrates how to do - * the same thing without lambda expression. - *
- *

- * Also if you need to work with Future or ListenableFuture it is possible to - * transform an observable to ListenableFuture. Please see - * {@link #transformObservableToGoogleGuavaListenableFuture()} - */ -public class DocumentCRUDAsyncAPITest { - private final static String PARTITION_KEY_PATH = "/mypk"; - private final static int TIMEOUT = 60000; - private AsyncDocumentClient asyncClient; - private Database createdDatabase; - private DocumentCollection createdCollection; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - // Sets up the requirements for each test - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - ArrayList partitionKeyPaths = new ArrayList(); - partitionKeyPaths.add(PARTITION_KEY_PATH); - partitionKeyDefinition.setPaths(partitionKeyPaths); - collectionDefinition.setPartitionKey(partitionKeyDefinition); - - // Create database - createdDatabase = Utils.createDatabaseForTest(asyncClient); - - // Create collection - createdCollection = asyncClient - .createCollection("dbs/" + createdDatabase.getId(), collectionDefinition, null) - .toBlocking().single().getResource(); - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(asyncClient, createdDatabase); - Utils.safeClose(asyncClient); - } - - /** - * Create a document using java8 lambda expressions - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDocument_Async() throws Exception { - Document doc = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), 1)); - Observable> createDocumentObservable = asyncClient - .createDocument(getCollectionLink(), doc, null, true); - - final CountDownLatch completionLatch = new CountDownLatch(1); - - // Subscribe to Document resource response emitted by the observable - createDocumentObservable.single() // We know there will be one response - .subscribe(documentResourceResponse -> { - System.out.println(documentResourceResponse.getActivityId()); - completionLatch.countDown(); - }, error -> { - System.err.println( - "an error occurred while creating the document: actual cause: " + error.getMessage()); - completionLatch.countDown(); - }); - - // Wait till document creation completes - completionLatch.await(); - } - - /** - * Create a document without java8 lambda expressions - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDocument_Async_withoutLambda() throws Exception { - Document doc = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), 1)); - Observable> createDocumentObservable = asyncClient - .createDocument(getCollectionLink(), doc, null, true); - - final CountDownLatch completionLatch = new CountDownLatch(1); - - Action1> onNext = new Action1>() { - - @Override - public void call(ResourceResponse documentResourceResponse) { - System.out.println(documentResourceResponse.getActivityId()); - completionLatch.countDown(); - } - }; - - Action1 onError = new Action1() { - - public void call(Throwable error) { - System.err - .println("an error occurred while creating the document: actual cause: " + error.getMessage()); - completionLatch.countDown(); - } - }; - - // Subscribe to Document resource response emitted by the observable - createDocumentObservable.single() // We know there will be one response - .subscribe(onNext, onError); - - // Wait till document creation completes - completionLatch.await(); - } - - /** - * Create a document in a blocking manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDocument_toBlocking() { - Document doc = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), 1)); - Observable> createDocumentObservable = asyncClient - .createDocument(getCollectionLink(), doc, null, true); - - // toBlocking() converts to a blocking observable. - // single() gets the only result. - createDocumentObservable.toBlocking().single(); - } - - /** - * Create a document with a programmatically set definition, in an Async manner - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDocumentWithProgrammableDocumentDefinition() throws Exception { - Document documentDefinition = new Document(); - documentDefinition.setId("test-document"); - documentDefinition.set("counter", 1); - - // Create a document - Document createdDocument = asyncClient - .createDocument(getCollectionLink(), documentDefinition, null, false).toBlocking().single() - .getResource(); - - // Read the created document - Observable> readDocumentObservable = asyncClient - .readDocument(getDocumentLink(createdDocument), null); - - final CountDownLatch completionLatch = new CountDownLatch(1); - - readDocumentObservable.subscribe(documentResourceResponse -> { - Document readDocument = documentResourceResponse.getResource(); - - // The read document must be the same as the written document - assertThat(readDocument.getId(), equalTo("test-document")); - assertThat(readDocument.getInt("counter"), equalTo(1)); - System.out.println(documentResourceResponse.getActivityId()); - completionLatch.countDown(); - }, error -> { - System.err.println("an error occured while creating the document: actual cause: " + error.getMessage()); - completionLatch.countDown(); - }); - - completionLatch.await(); - } - - /** - * Create 10 documents and sum up all the documents creation request charges - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void documentCreation_SumUpRequestCharge() throws Exception { - // Create 10 documents - List>> listOfCreateDocumentObservables = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - Document doc = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), i)); - - Observable> createDocumentObservable = asyncClient - .createDocument(getCollectionLink(), doc, null, false); - listOfCreateDocumentObservables.add(createDocumentObservable); - } - - // Merge all document creation observables into one observable - Observable> mergedObservable = Observable.merge(listOfCreateDocumentObservables); - - // Create a new observable emitting the total charge of creating all 10 - // documents. - Observable totalChargeObservable = mergedObservable - .map(ResourceResponse::getRequestCharge) - // Map to request charge - .reduce((totalCharge, charge) -> totalCharge + charge); - // Sum up all the charges - - final CountDownLatch completionLatch = new CountDownLatch(1); - - // Subscribe to the total request charge observable - totalChargeObservable.subscribe(totalCharge -> { - // Print the total charge - System.out.println(totalCharge); - completionLatch.countDown(); - }, e -> completionLatch.countDown() - ); - - completionLatch.await(); - } - - /** - * Attempt to create a document which already exists - * - First create a document - * - Using the async api generate an async document creation observable - * - Converts the Observable to blocking using Observable.toBlocking() api - * - Catch already exist failure (409) - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDocument_toBlocking_DocumentAlreadyExists_Fails() { - Document doc = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), 1)); - asyncClient.createDocument(getCollectionLink(), doc, null, false).toBlocking().single(); - - // Create the document - Observable> createDocumentObservable = asyncClient - .createDocument(getCollectionLink(), doc, null, false); - - try { - createDocumentObservable.toBlocking() // Converts the observable to a blocking observable - .single(); // Gets the single result - Assert.fail("Document Already Exists. Document Creation must fail"); - } catch (Exception e) { - assertThat("Document already exists.", ((DocumentClientException) e.getCause()).getStatusCode(), - equalTo(409)); - } - } - - /** - * Attempt to create a document which already exists - * - First create a document - * - Using the async api generate an async document creation observable - * - Converts the Observable to blocking using Observable.toBlocking() api - * - Catch already exist failure (409) - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void createDocument_Async_DocumentAlreadyExists_Fails() throws Exception { - Document doc = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), 1)); - asyncClient.createDocument(getCollectionLink(), doc, null, false).toBlocking().single(); - - // Create the document - Observable> createDocumentObservable = asyncClient - .createDocument(getCollectionLink(), doc, null, false); - - List errorList = Collections.synchronizedList(new ArrayList<>()); - - createDocumentObservable.subscribe(resourceResponse -> { - }, error -> { - errorList.add(error); - System.err.println("failed to create a document due to: " + error.getMessage()); - }); - - Thread.sleep(2000); - assertThat(errorList, hasSize(1)); - assertThat(errorList.get(0), is(instanceOf(DocumentClientException.class))); - assertThat(((DocumentClientException) errorList.get(0)).getStatusCode(), equalTo(409)); - } - - /** - * Replace a document - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void documentReplace_Async() throws Exception { - // Create a document - Document createdDocument = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), 1)); - createdDocument = asyncClient.createDocument(getCollectionLink(), createdDocument, null, false).toBlocking() - .single().getResource(); - - // Try to replace the existing document - Document replacingDocument = new Document( - String.format("{ 'id': 'doc%s', 'counter': '%d', 'new-prop' : '2'}", createdDocument.getId(), 1)); - Observable> replaceDocumentObservable = asyncClient - .replaceDocument(getDocumentLink(createdDocument), replacingDocument, null); - - List> capturedResponse = Collections - .synchronizedList(new ArrayList<>()); - - replaceDocumentObservable.subscribe(resourceResponse -> { - capturedResponse.add(resourceResponse); - }); - - Thread.sleep(2000); - - assertThat(capturedResponse, hasSize(1)); - assertThat(capturedResponse.get(0).getResource().get("new-prop"), equalTo("2")); - } - - /** - * Upsert a document - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void documentUpsert_Async() throws Exception { - // Create a document - Document doc = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d'}", UUID.randomUUID().toString(), 1)); - asyncClient.createDocument(getCollectionLink(), doc, null, false).toBlocking().single(); - - // Upsert the existing document - Document upsertingDocument = new Document( - String.format("{ 'id': 'doc%s', 'counter': '%d', 'new-prop' : '2'}", doc.getId(), 1)); - Observable> upsertDocumentObservable = asyncClient - .upsertDocument(getCollectionLink(), upsertingDocument, null, false); - - List> capturedResponse = Collections - .synchronizedList(new ArrayList<>()); - - upsertDocumentObservable.subscribe(resourceResponse -> { - capturedResponse.add(resourceResponse); - }); - - Thread.sleep(4000); - - assertThat(capturedResponse, hasSize(1)); - assertThat(capturedResponse.get(0).getResource().get("new-prop"), equalTo("2")); - } - - /** - * Delete a document - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void documentDelete_Async() throws Exception { - // Create a document - Document createdDocument = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d', 'mypk' : '%s'}", UUID.randomUUID().toString(), 1, UUID.randomUUID().toString())); - createdDocument = asyncClient.createDocument(getCollectionLink(), createdDocument, null, false).toBlocking() - .single().getResource(); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(createdDocument.getString("mypk"))); - - // Delete the existing document - Observable> deleteDocumentObservable = asyncClient - .deleteDocument(getDocumentLink(createdDocument), options); - - List> capturedResponse = Collections - .synchronizedList(new ArrayList<>()); - - deleteDocumentObservable.subscribe(resourceResponse -> { - capturedResponse.add(resourceResponse); - }); - - Thread.sleep(2000); - - assertThat(capturedResponse, hasSize(1)); - - // Assert document is deleted - FeedOptions queryOptions = new FeedOptions(); - queryOptions.setEnableCrossPartitionQuery(true); - List listOfDocuments = asyncClient - .queryDocuments(getCollectionLink(), String.format("SELECT * FROM r where r.id = '%s'", createdDocument.getId()), queryOptions) - .map(FeedResponse::getResults) // Map page to its list of documents - .concatMap(Observable::from) // Flatten the observable - .toList() // Transform to a observable - .toBlocking() // Block - .single(); // Gets the List - - // Assert that there is no document found - assertThat(listOfDocuments, hasSize(0)); - } - - /** - * Read a document - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void documentRead_Async() throws Exception { - // Create a document - Document createdDocument = new Document(String.format("{ 'id': 'doc%s', 'counter': '%d', 'mypk' : '%s'}", UUID.randomUUID().toString(), 1, UUID.randomUUID().toString())); - createdDocument = asyncClient.createDocument(getCollectionLink(), createdDocument, null, false).toBlocking() - .single().getResource(); - - // Read the document - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(createdDocument.getString("mypk"))); - Observable> readDocumentObservable = asyncClient - .readDocument(getDocumentLink(createdDocument), options); - - List> capturedResponse = Collections - .synchronizedList(new ArrayList<>()); - - readDocumentObservable.subscribe(resourceResponse -> { - capturedResponse.add(resourceResponse); - }); - - Thread.sleep(2000); - - // Assert document is retrieved - assertThat(capturedResponse, hasSize(1)); - } - - private static class TestObject { - @JsonProperty("mypk") - private String mypk; - - @JsonProperty("id") - private String id; - - @JsonProperty("prop") - private String prop; - } - - @Test(groups = {"samples"}, timeOut = TIMEOUT) - public void customSerialization() throws Exception { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true); - - TestObject testObject = new TestObject(); - testObject.id = UUID.randomUUID().toString(); - testObject.mypk = UUID.randomUUID().toString(); - testObject.prop = UUID.randomUUID().toString(); - String itemAsJsonString = mapper.writeValueAsString(testObject); - Document doc = new Document(itemAsJsonString); - - Document createdDocument = asyncClient - .createDocument(getCollectionLink(), doc, null, false) - .toBlocking() - .single() - .getResource(); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(testObject.mypk)); - - Document readDocument = asyncClient - .readDocument(createdDocument.getSelfLink(), options) - .toBlocking() - .single() - .getResource(); - - TestObject readObject = mapper.readValue(readDocument.toJson(), TestObject.class); - assertThat(readObject.prop, equalTo(testObject.prop)); - } - - /** - * You can convert an Observable to a ListenableFuture. - * ListenableFuture (part of google guava library) is a popular extension - * of Java's Future which allows registering listener callbacks: - * https://github.com/google/guava/wiki/ListenableFutureExplained - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void transformObservableToGoogleGuavaListenableFuture() throws Exception { - Document doc = new Document(String.format("{ 'id': 'doc%d', 'counter': '%d'}", RandomUtils.nextInt(), 1)); - Observable> createDocumentObservable = asyncClient - .createDocument(getCollectionLink(), doc, null, false); - ListenableFuture> listenableFuture = ListenableFutureObservable - .to(createDocumentObservable); - - ResourceResponse rrd = listenableFuture.get(); - - assertThat(rrd.getRequestCharge(), greaterThan((double) 0)); - System.out.print(rrd.getRequestCharge()); - } - - private String getCollectionLink() { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(); - } - - private String getDocumentLink(Document createdDocument) { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId() + "/docs/" + createdDocument.getId(); - } -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DocumentQueryAsyncAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DocumentQueryAsyncAPITest.java deleted file mode 100644 index 35d652c3efdf..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/DocumentQueryAsyncAPITest.java +++ /dev/null @@ -1,491 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.google.common.util.concurrent.ListenableFuture; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.SqlParameterCollection; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.apache.commons.lang3.RandomStringUtils; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Observable; -import rx.Subscriber; -import rx.functions.Action1; -import rx.functions.Func1; -import rx.observable.ListenableFutureObservable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.notNullValue; - -/** - * This integration test class demonstrates how to use Async API to query for - * Documents. - *

- * NOTE: you can use rxJava based async api with java8 lambda expression. Use - * of rxJava based async APIs with java8 lambda expressions is much prettier. - *

- * You can also use the async API without java8 lambda expression. - *

- * For example - *

    - *
  • {@link #queryDocuments_Async()} demonstrates how to use async api - * with java8 lambda expression. - * - *
  • {@link #queryDocuments_Async_withoutLambda()} demonstrates how to do - * the same thing without lambda expression. - *
- *

- * Also if you need to work with Future or ListenableFuture it is possible to - * transform an observable to ListenableFuture. Please see - * {@link #transformObservableToGoogleGuavaListenableFuture()} - */ -public class DocumentQueryAsyncAPITest { - private final static int TIMEOUT = 60000; - private AsyncDocumentClient asyncClient; - private DocumentCollection createdCollection; - private Database createdDatabase; - private int numberOfDocuments; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Create database - - createdDatabase = Utils.createDatabaseForTest(asyncClient); - - // Create collection - createdCollection = asyncClient - .createCollection("dbs/" + createdDatabase.getId(), collectionDefinition, null) - .toBlocking().single().getResource(); - - numberOfDocuments = 20; - // Add documents - for (int i = 0; i < numberOfDocuments; i++) { - Document doc = new Document(String.format("{ 'id': 'loc%d', 'counter': %d}", i, i)); - asyncClient.createDocument(getCollectionLink(), doc, null, true).toBlocking().single(); - } - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(asyncClient, createdDatabase); - Utils.safeClose(asyncClient); - } - - /** - * Query for documents using java8 lambda expressions - * Creates a document query observable and verifies the async behavior - * of document query observable - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void queryDocuments_Async() throws Exception { - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable> documentQueryObservable = asyncClient - .queryDocuments(getCollectionLink(), "SELECT * FROM root", options); - - final CountDownLatch mainThreadBarrier = new CountDownLatch(1); - - final CountDownLatch resultsCountDown = new CountDownLatch(numberOfDocuments); - - // forEach(.) is an alias for subscribe(.) - documentQueryObservable.forEach(page -> { - try { - // Waits on the barrier - mainThreadBarrier.await(); - } catch (InterruptedException e) { - } - - for (@SuppressWarnings("unused") - Document d : page.getResults()) { - resultsCountDown.countDown(); - } - }); - - // The following code will run concurrently - System.out.println("action is subscribed to the observable"); - - // Release main thread barrier - System.out.println("after main thread barrier is released, subscribed observable action can continue"); - mainThreadBarrier.countDown(); - - System.out.println("waiting for all the results using result count down latch"); - - resultsCountDown.await(); - } - - /** - * Query for documents, without using java8 lambda expressions - * Creates a document query observable and verifies the async behavior - * of document query observable - * NOTE: does the same thing as testQueryDocuments_Async without java8 lambda - * expression - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void queryDocuments_Async_withoutLambda() throws Exception { - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable> documentQueryObservable = asyncClient - .queryDocuments(getCollectionLink(), "SELECT * FROM root", options); - - final CountDownLatch mainThreadBarrier = new CountDownLatch(1); - - final CountDownLatch resultsCountDown = new CountDownLatch(numberOfDocuments); - - Action1> actionPerPage = new Action1>() { - - @SuppressWarnings("unused") - @Override - public void call(FeedResponse t) { - - try { - // waits on the barrier - mainThreadBarrier.await(); - } catch (InterruptedException e) { - } - - for (Document d : t.getResults()) { - resultsCountDown.countDown(); - } - } - }; - - // forEach(.) is an alias for subscribe(.) - documentQueryObservable.forEach(actionPerPage); - // The following code will run concurrently - - System.out.println("action is subscribed to the observable"); - - // Release main thread barrier - System.out.println("after main thread barrier is released, subscribed observable action can continue"); - mainThreadBarrier.countDown(); - - System.out.println("waiting for all the results using result count down latch"); - - resultsCountDown.await(); - } - - /** - * Queries for documents and sum up the total request charge - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void queryDocuments_findTotalRequestCharge() throws Exception { - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable totalChargeObservable = asyncClient - .queryDocuments(getCollectionLink(), "SELECT * FROM root", options) - .map(FeedResponse::getRequestCharge) // Map the page to its request charge - .reduce((totalCharge, charge) -> totalCharge + charge); // Sum up all the request charges - - final CountDownLatch successfulCompletionLatch = new CountDownLatch(1); - - // subscribe(.) is the same as forEach(.) - totalChargeObservable.subscribe(totalCharge -> { - System.out.println(totalCharge); - successfulCompletionLatch.countDown(); - }); - - successfulCompletionLatch.await(); - } - - /** - * Subscriber unsubscribes after first page - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void queryDocuments_unsubscribeAfterFirstPage() throws Exception { - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable> requestChargeObservable = asyncClient - .queryDocuments(getCollectionLink(), "SELECT * FROM root", options); - - AtomicInteger onNextCounter = new AtomicInteger(); - AtomicInteger onCompletedCounter = new AtomicInteger(); - AtomicInteger onErrorCounter = new AtomicInteger(); - - // Subscribe to the pages of Documents emitted by the observable - requestChargeObservable.subscribe(new Subscriber>() { - - @Override - public void onCompleted() { - onCompletedCounter.incrementAndGet(); - } - - @Override - public void onError(Throwable e) { - onErrorCounter.incrementAndGet(); - } - - @Override - public void onNext(FeedResponse page) { - onNextCounter.incrementAndGet(); - unsubscribe(); - } - }); - - Thread.sleep(4000); - - // After subscriber unsubscribes, it doesn't receive any more pages. - assertThat(onNextCounter.get(), equalTo(1)); - assertThat(onCompletedCounter.get(), equalTo(0)); - assertThat(onErrorCounter.get(), equalTo(0)); - } - - /** - * Queries for documents and filter out the fetched results - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void queryDocuments_filterFetchedResults() throws Exception { - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Func1 isPrimeNumber = new Func1() { - - @Override - public Boolean call(Document doc) { - int n = doc.getInt("counter"); - if (n <= 1) - return false; - for (int i = 2; 2 * i < n; i++) { - if (n % i == 0) - return false; - } - return true; - } - }; - - List resultList = Collections.synchronizedList(new ArrayList()); - - asyncClient.queryDocuments(getCollectionLink(), "SELECT * FROM root", options) - .map(FeedResponse::getResults) // Map the page to the list of documents - .concatMap(Observable::from) // Flatten the observable> to observable - .filter(isPrimeNumber) // Filter documents using isPrimeNumber predicate - .subscribe(doc -> resultList.add(doc)); // Collect the results - - Thread.sleep(4000); - - int expectedNumberOfPrimes = 0; - // Find all the documents with prime number counter - for (int i = 0; i < numberOfDocuments; i++) { - boolean isPrime = true; - if (i <= 1) - isPrime = false; - for (int j = 2; 2 * j < i; j++) { - if (i % j == 0) { - isPrime = false; - break; - } - } - - if (isPrime) { - expectedNumberOfPrimes++; - } - } - - // Assert that we only collected what's expected - assertThat(resultList, hasSize(expectedNumberOfPrimes)); - } - - /** - * Queries for documents - * Converts the document query observable to blocking observable and - * uses that to find all documents - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void queryDocuments_toBlocking_toIterator() { - // Query for documents - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable> documentQueryObservable = asyncClient - .queryDocuments(getCollectionLink(), "SELECT * FROM root", options); - - // Covert the observable to a blocking observable, then convert the blocking - // observable to an iterator - Iterator> it = documentQueryObservable.toBlocking().getIterator(); - - int pageCounter = 0; - int numberOfResults = 0; - while (it.hasNext()) { - FeedResponse page = it.next(); - pageCounter++; - - String pageSizeAsString = page.getResponseHeaders().get(HttpConstants.HttpHeaders.ITEM_COUNT); - assertThat("header item count must be present", pageSizeAsString, notNullValue()); - int pageSize = Integer.valueOf(pageSizeAsString); - assertThat("Result size must match header item count", page.getResults(), hasSize(pageSize)); - numberOfResults += pageSize; - } - assertThat("number of total results", numberOfResults, equalTo(numberOfDocuments)); - assertThat("number of result pages", pageCounter, - equalTo((numberOfDocuments + requestPageSize - 1) / requestPageSize)); - } - - /** - * Queries for documents using an Orderby query. - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void qrderBy_Async() throws Exception { - // Create a partitioned collection - String collectionId = UUID.randomUUID().toString(); - DocumentCollection multiPartitionCollection = createMultiPartitionCollection("dbs/" + createdDatabase.getId(), - collectionId, "/key"); - - // Insert documents - int totalNumberOfDocumentsInMultiPartitionCollection = 10; - for (int i = 0; i < totalNumberOfDocumentsInMultiPartitionCollection; i++) { - - Document doc = new Document(String.format("{\"id\":\"documentId%d\",\"key\":\"%s\",\"prop\":%d}", i, - RandomStringUtils.randomAlphabetic(2), i)); - asyncClient.createDocument("dbs/" + createdDatabase.getId() + "/colls/" + multiPartitionCollection.getId(), - doc, null, true).toBlocking().single(); - } - - // Query for the documents order by the prop field - SqlQuerySpec query = new SqlQuerySpec("SELECT r.id FROM r ORDER BY r.prop", new SqlParameterCollection()); - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(5); - - // Max degree of parallelism determines the number of partitions that - // the SDK establishes simultaneous connections to. - options.setMaxDegreeOfParallelism(2); - - // Get the observable order by query documents - Observable> documentQueryObservable = asyncClient.queryDocuments( - "dbs/" + createdDatabase.getId() + "/colls/" + multiPartitionCollection.getId(), query, options); - - List resultList = Collections.synchronizedList(new ArrayList<>()); - - documentQueryObservable.map(FeedResponse::getResults) - // Map the logical page to the list of documents in the page - .concatMap(Observable::from) // Flatten the list of documents - .map(doc -> doc.getId()) // Map to the document Id - .forEach(docId -> resultList.add(docId)); // Add each document Id to the resultList - - Thread.sleep(4000); - - // Assert we found all the results - assertThat(resultList, hasSize(totalNumberOfDocumentsInMultiPartitionCollection)); - for (int i = 0; i < totalNumberOfDocumentsInMultiPartitionCollection; i++) { - String docId = resultList.get(i); - // Assert that the order of the documents are valid - assertThat(docId, equalTo("documentId" + i)); - } - } - - /** - * You can convert an Observable to a ListenableFuture. - * ListenableFuture (part of google guava library) is a popular extension - * of Java's Future which allows registering listener callbacks: - * https://github.com/google/guava/wiki/ListenableFutureExplained - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void transformObservableToGoogleGuavaListenableFuture() throws Exception { - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable> documentQueryObservable = asyncClient - .queryDocuments(getCollectionLink(), "SELECT * FROM root", options); - - // Convert to observable of list of pages - Observable>> allPagesObservable = documentQueryObservable.toList(); - - // Convert the observable of list of pages to a Future - ListenableFuture>> future = ListenableFutureObservable.to(allPagesObservable); - - List> pageList = future.get(); - - int totalNumberOfRetrievedDocuments = 0; - for (FeedResponse page : pageList) { - totalNumberOfRetrievedDocuments += page.getResults().size(); - } - assertThat(numberOfDocuments, equalTo(totalNumberOfRetrievedDocuments)); - } - - private String getCollectionLink() { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(); - } - - private DocumentCollection createMultiPartitionCollection(String databaseLink, String collectionId, - String partitionKeyPath) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add(partitionKeyPath); - partitionKeyDef.setPaths(paths); - - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(10100); - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(collectionId); - collectionDefinition.setPartitionKey(partitionKeyDef); - DocumentCollection createdCollection = asyncClient.createCollection(databaseLink, collectionDefinition, options) - .toBlocking().single().getResource(); - - return createdCollection; - } -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/InMemoryGroupbyTest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/InMemoryGroupbyTest.java deleted file mode 100644 index baeac40b2a02..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/InMemoryGroupbyTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.SqlParameter; -import com.microsoft.azure.cosmosdb.SqlParameterCollection; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Observable; -import rx.observables.GroupedObservable; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.UUID; - -public class InMemoryGroupbyTest { - private final static int TIMEOUT = 60000; - - private static AsyncDocumentClient asyncClient; - private static Database createdDatabase; - private static DocumentCollection createdCollection; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public static void setUp() throws Exception { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - // Create database - createdDatabase = Utils.createDatabaseForTest(asyncClient); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Create collection - createdCollection = asyncClient - .createCollection("dbs/" + createdDatabase.getId(), collectionDefinition, null) - .toBlocking().single().getResource(); - - int numberOfPayers = 10; - int numberOfDocumentsPerPayer = 10; - - for (int i = 0; i < numberOfPayers; i++) { - - for (int j = 0; j < numberOfDocumentsPerPayer; j++) { - - LocalDateTime currentTime = LocalDateTime.now(); - - Document doc = new Document(String.format("{ " - + "'id' : '%s'," - + "'site_id': 'ABC', " - + "'payer_id': %d, " - + " 'created_time' : %d " - + "}", UUID.randomUUID().toString(), i, currentTime.getSecond())); - asyncClient.createDocument(getCollectionLink(), doc, null, true).toBlocking().single(); - - Thread.sleep(100); - } - } - System.out.println("finished inserting documents"); - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public static void shutdown() { - Utils.safeClean(asyncClient, createdDatabase); - asyncClient.close(); - } - - /** - * Queries Documents and performs Group by operation after fetching the Documents. - * If you want to understand the steps in more details see {@link #groupByInMemory_MoreDetail()} - * @throws Exception - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void groupByInMemory() { - // If you want to understand the steps in more details see groupByInMemoryMoreDetail() - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - Observable documentsObservable = asyncClient - .queryDocuments(getCollectionLink(), - new SqlQuerySpec("SELECT * FROM root r WHERE r.site_id=@site_id", - new SqlParameterCollection(new SqlParameter("@site_id", "ABC"))), - options) - .flatMap(page -> Observable.from(page.getResults())); - - final LocalDateTime now = LocalDateTime.now(); - - List> resultsGroupedAsLists = documentsObservable - .filter(doc -> Math.abs(now.getSecond() - doc.getInt("created_time")) <= 90) - .groupBy(doc -> doc.getInt("payer_id")).flatMap(grouped -> grouped.toList()) - .toList() - .toBlocking() - .single(); - - for(List resultsForEachPayer :resultsGroupedAsLists) { - System.out.println("documents with payer_id : " + resultsForEachPayer.get(0).getInt("payer_id") + " are " + resultsForEachPayer); - } - } - - /** - * This does the same thing as {@link #groupByInMemory_MoreDetail()} but with pedagogical details - * @throws Exception - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void groupByInMemory_MoreDetail() { - - int requestPageSize = 3; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(requestPageSize); - - - Observable documentsObservable = asyncClient - .queryDocuments(getCollectionLink(), - new SqlQuerySpec("SELECT * FROM root r WHERE r.site_id=@site_id", - new SqlParameterCollection(new SqlParameter("@site_id", "ABC"))), - options) - .flatMap(page -> Observable.from(page.getResults())); - - final LocalDateTime now = LocalDateTime.now(); - - Observable> groupedByPayerIdObservable = documentsObservable - .filter(doc -> Math.abs(now.getSecond() - doc.getInt("created_time")) <= 90) - .groupBy(doc -> doc.getInt("payer_id")); - - Observable> docsGroupedAsList = groupedByPayerIdObservable.flatMap(grouped -> { - Observable> list = grouped.toList(); - return list; - }); - - List> resultsGroupedAsLists = docsGroupedAsList.toList().toBlocking().single(); - - for(List resultsForEachPayer : resultsGroupedAsLists) { - System.out.println("documents with payer_id : " + resultsForEachPayer.get(0).getInt("payer_id") + " are " + resultsForEachPayer); - } - } - - private static String getCollectionLink() { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(); - } -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/OfferCRUDAsyncAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/OfferCRUDAsyncAPITest.java deleted file mode 100644 index f64d4ec20fc3..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/OfferCRUDAsyncAPITest.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2017 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; - -/** - * This integration test class demonstrates how to use Async API to query and - * replace an Offer. - */ -public class OfferCRUDAsyncAPITest { - private final static int TIMEOUT = 60000; - private Database createdDatabase; - private AsyncDocumentClient asyncClient; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - // Create database - createdDatabase = Utils.createDatabaseForTest(asyncClient); - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(asyncClient, createdDatabase); - Utils.safeClose(asyncClient); - } - - /** - * Query for all the offers existing in the database account. - * Replace the required offer so that it has a higher throughput. - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void updateOffer() throws Exception { - - int initialThroughput = 10200; - int newThroughput = 10300; - - // Set the throughput to be 10,200 - RequestOptions multiPartitionRequestOptions = new RequestOptions(); - multiPartitionRequestOptions.setOfferThroughput(initialThroughput); - - // Create the collection - DocumentCollection createdCollection = asyncClient.createCollection("dbs/" + createdDatabase.getId(), - getMultiPartitionCollectionDefinition(), multiPartitionRequestOptions).toBlocking().single() - .getResource(); - - final CountDownLatch successfulCompletionLatch = new CountDownLatch(1); - - // Find offer associated with this collection - asyncClient.queryOffers( - String.format("SELECT * FROM r where r.offerResourceId = '%s'", createdCollection.getResourceId()), - null).flatMap(offerFeedResponse -> { - List offerList = offerFeedResponse.getResults(); - // Number of offers returned should be 1 - assertThat(offerList.size(), equalTo(1)); - - // This offer must correspond to the collection we created - Offer offer = offerList.get(0); - int currentThroughput = offer.getThroughput(); - assertThat(offer.getString("offerResourceId"), equalTo(createdCollection.getResourceId())); - assertThat(currentThroughput, equalTo(initialThroughput)); - System.out.println("initial throughput: " + currentThroughput); - - // Update the offer's throughput - offer.setThroughput(newThroughput); - - // Replace the offer - return asyncClient.replaceOffer(offer); - }).subscribe(offerResourceResponse -> { - Offer offer = offerResourceResponse.getResource(); - int currentThroughput = offer.getThroughput(); - - // The current throughput of the offer must be equal to the new throughput value - assertThat(offer.getString("offerResourceId"), equalTo(createdCollection.getResourceId())); - assertThat(currentThroughput, equalTo(newThroughput)); - - System.out.println("updated throughput: " + currentThroughput); - successfulCompletionLatch.countDown(); - }, error -> { - System.err - .println("an error occurred while updating the offer: actual cause: " + error.getMessage()); - }); - - successfulCompletionLatch.await(); - } - - private DocumentCollection getMultiPartitionCollectionDefinition() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Set the partitionKeyDefinition for a partitioned collection - // Here, we are setting the partitionKey of the Collection to be /city - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - List paths = new ArrayList<>(); - paths.add("/city"); - partitionKeyDefinition.setPaths(paths); - collectionDefinition.setPartitionKey(partitionKeyDefinition); - - // Set indexing policy to be range range for string and number - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection includedPaths = new ArrayList<>(); - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath("/*"); - Collection indexes = new ArrayList<>(); - Index stringIndex = Index.Range(DataType.String); - stringIndex.set("precision", -1); - indexes.add(stringIndex); - - Index numberIndex = Index.Range(DataType.Number); - numberIndex.set("precision", -1); - indexes.add(numberIndex); - includedPath.setIndexes(indexes); - includedPaths.add(includedPath); - indexingPolicy.setIncludedPaths(includedPaths); - collectionDefinition.setIndexingPolicy(indexingPolicy); - - return collectionDefinition; - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/StoredProcedureAsyncAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/StoredProcedureAsyncAPITest.java deleted file mode 100644 index aa06bf501397..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/StoredProcedureAsyncAPITest.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2017 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; - -import javax.net.ssl.SSLException; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.core.Is.is; - -/** - * This integration test class demonstrates how to use Async API to create - * and execute Stored Procedures. - */ -public class StoredProcedureAsyncAPITest { - private final static int TIMEOUT = 60000; - - private Database createdDatabase; - private DocumentCollection createdCollection; - private AsyncDocumentClient asyncClient; - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - createdDatabase = Utils.createDatabaseForTest(asyncClient); - - createdCollection = asyncClient - .createCollection("dbs/" + createdDatabase.getId(), getMultiPartitionCollectionDefinition(), null) - .toBlocking().single().getResource(); - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(asyncClient, createdDatabase); - Utils.safeClose(asyncClient); - } - - /** - * Execute Stored Procedure and retrieve the Script Log - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void scriptConsoleLogEnabled() throws Exception { - // Create a stored procedure - StoredProcedure storedProcedure = new StoredProcedure( - "{" + - " 'id':'storedProcedureSample'," + - " 'body':" + - " 'function() {" + - " var mytext = \"x\";" + - " var myval = 1;" + - " try {" + - " console.log(\"The value of %s is %s.\", mytext, myval);" + - " getContext().getResponse().setBody(\"Success!\");" + - " }" + - " catch(err) {" + - " getContext().getResponse().setBody(\"inline err: [\" + err.number + \"] \" + err);" + - " }" + - " }'" + - "}"); - - storedProcedure = asyncClient.createStoredProcedure(getCollectionLink(), storedProcedure, null) - .toBlocking().single().getResource(); - - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setScriptLoggingEnabled(true); - requestOptions.setPartitionKey(new PartitionKey("Seattle")); - - final CountDownLatch successfulCompletionLatch = new CountDownLatch(1); - - // Execute the stored procedure - asyncClient.executeStoredProcedure(getSprocLink(storedProcedure), requestOptions, new Object[]{}) - .subscribe(storedProcedureResponse -> { - String logResult = "The value of x is 1."; - try { - assertThat(URLDecoder.decode(storedProcedureResponse.getScriptLog(), "UTF-8"), is(logResult)); - assertThat(URLDecoder.decode(storedProcedureResponse.getResponseHeaders() - .get(HttpConstants.HttpHeaders.SCRIPT_LOG_RESULTS), "UTF-8"), is(logResult)); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - successfulCompletionLatch.countDown(); - System.out.println(storedProcedureResponse.getActivityId()); - }, error -> { - System.err.println("an error occurred while executing the stored procedure: actual cause: " - + error.getMessage()); - }); - - successfulCompletionLatch.await(); - } - - /** - * Execute Stored Procedure that takes arguments - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void executeStoredProcWithArgs() throws Exception { - // Create stored procedure - StoredProcedure storedProcedure = new StoredProcedure( - "{" + - " 'id': 'multiplySample'," + - " 'body':" + - " 'function (value, num) {" + - " getContext().getResponse().setBody(" + - " \"2*\" + value + \" is \" + num * 2 );" + - " }'" + - "}"); - - storedProcedure = asyncClient.createStoredProcedure(getCollectionLink(), storedProcedure, null) - .toBlocking().single().getResource(); - - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey("Seattle")); - - final CountDownLatch successfulCompletionLatch = new CountDownLatch(1); - - // Execute the stored procedure - Object[] storedProcedureArgs = new Object[]{"a", 123}; - asyncClient.executeStoredProcedure(getSprocLink(storedProcedure), requestOptions, storedProcedureArgs) - .subscribe(storedProcedureResponse -> { - String storedProcResultAsString = storedProcedureResponse.getResponseAsString(); - assertThat(storedProcResultAsString, equalTo("\"2*a is 246\"")); - successfulCompletionLatch.countDown(); - System.out.println(storedProcedureResponse.getActivityId()); - }, error -> { - System.err.println("an error occurred while executing the stored procedure: actual cause: " - + error.getMessage()); - }); - - successfulCompletionLatch.await(); - } - - /** - * Execute Stored Procedure that takes arguments, passing a Pojo object - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void executeStoredProcWithPojoArgs() throws Exception { - // create stored procedure - StoredProcedure storedProcedure = new StoredProcedure( - "{" + - " 'id': 'storedProcedurePojoSample'," + - " 'body':" + - " 'function (value) {" + - " getContext().getResponse().setBody(" + - " \"a is \" + value.temp);" + - " }'" + - "}"); - - storedProcedure = asyncClient.createStoredProcedure(getCollectionLink(), storedProcedure, null) - .toBlocking().single().getResource(); - - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey("Seattle")); - - final CountDownLatch successfulCompletionLatch = new CountDownLatch(1); - - // POJO - class SamplePojo { - public String temp = "my temp value"; - } - SamplePojo samplePojo = new SamplePojo(); - - // Execute the stored procedure - Object[] storedProcedureArgs = new Object[]{samplePojo}; - asyncClient.executeStoredProcedure(getSprocLink(storedProcedure), requestOptions, storedProcedureArgs) - .subscribe(storedProcedureResponse -> { - String storedProcResultAsString = storedProcedureResponse.getResponseAsString(); - assertThat(storedProcResultAsString, equalTo("\"a is my temp value\"")); - successfulCompletionLatch.countDown(); - System.out.println(storedProcedureResponse.getActivityId()); - }, error -> { - System.err.println("an error occurred while executing the stored procedure: actual cause: " - + error.getMessage()); - }); - - successfulCompletionLatch.await(); - } - - private static DocumentCollection getMultiPartitionCollectionDefinition() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Set the partitionKeyDefinition for a partitioned collection - // Here, we are setting the partitionKey of the Collection to be /city - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - List paths = new ArrayList(); - paths.add("/city"); - partitionKeyDefinition.setPaths(paths); - collectionDefinition.setPartitionKey(partitionKeyDefinition); - - // Set indexing policy to be range range for string and number - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection includedPaths = new ArrayList(); - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath("/*"); - Collection indexes = new ArrayList(); - Index stringIndex = Index.Range(DataType.String); - stringIndex.set("precision", -1); - indexes.add(stringIndex); - - Index numberIndex = Index.Range(DataType.Number); - numberIndex.set("precision", -1); - indexes.add(numberIndex); - includedPath.setIndexes(indexes); - includedPaths.add(includedPath); - indexingPolicy.setIncludedPaths(includedPaths); - collectionDefinition.setIndexingPolicy(indexingPolicy); - - return collectionDefinition; - } - - private String getCollectionLink() { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(); - } - - private String getSprocLink(StoredProcedure sproc) { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId() + "/sprocs/" + sproc.getId(); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/TestConfigurations.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/TestConfigurations.java deleted file mode 100644 index f48ee5da652c..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/TestConfigurations.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import org.apache.commons.lang3.StringUtils; - -import com.google.common.base.Strings; - -/** - * Contains the configurations for tests. - *

- * For running tests, you can pass a customized endpoint configuration in one of the following - * ways: - *

    - *
  • -DACCOUNT_KEY="[your-key]" -ACCOUNT_HOST="[your-endpoint]" as JVM - * command-line option.
  • - *
  • You can set ACCOUNT_KEY and ACCOUNT_HOST as environment variables.
  • - *
- *

- * If none of the above is set, emulator endpoint will be used. - */ -public final class TestConfigurations { - // Replace MASTER_KEY and HOST with values from your Azure Cosmos DB account. - // The default values are credentials of the local emulator, which are not used in any production environment. - // - public static String MASTER_KEY = - System.getProperty("ACCOUNT_KEY", - StringUtils.defaultString(Strings.emptyToNull( - System.getenv().get("ACCOUNT_KEY")), - "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==")); - - public static String HOST = - System.getProperty("ACCOUNT_HOST", - StringUtils.defaultString(Strings.emptyToNull( - System.getenv().get("ACCOUNT_HOST")), - "https://localhost:443/")); -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/TokenResolverTest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/TokenResolverTest.java deleted file mode 100644 index c33f14fdc2b3..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/TokenResolverTest.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.google.common.collect.ImmutableMap; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.CosmosResourceType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.PermissionMode; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.TokenResolver; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Observable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.core.IsInstanceOf.instanceOf; - -public class TokenResolverTest { - private final static int TIMEOUT = 60000; - private final static String USER_ID = "userId"; - private AsyncDocumentClient asyncClient; - private Database createdDatabase; - private DocumentCollection createdCollection; - private Map userToReadOnlyResourceTokenMap = new HashMap<>(); - private Map documentToReadUserMap = new HashMap<>(); - - private Map documentToReadWriteUserMap = new HashMap<>(); - private Map userToReadWriteResourceTokenMap = new HashMap<>(); - - - /** - * This Example walks you through how to use a token resolver to - * control authorization and access to Cosmos DB resources. - */ - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - // Sets up the requirements for each test - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClient = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Create database - createdDatabase = Utils.createDatabaseForTest(asyncClient); - - // Create collection - createdCollection = asyncClient - .createCollection("dbs/" + createdDatabase.getId(), collectionDefinition, null) - .toBlocking().single().getResource(); - - for (int i = 0; i < 10; i++) { - // Create a document - Document documentDefinition = new Document(); - documentDefinition.setId(UUID.randomUUID().toString()); - Document createdDocument = asyncClient.createDocument(createdCollection.getSelfLink(), documentDefinition, null, true).toBlocking().first().getResource(); - - // Create a User who is meant to only read this document - User readUserDefinition = new User(); - readUserDefinition.setId(UUID.randomUUID().toString()); - User createdReadUser = asyncClient.createUser(createdDatabase.getSelfLink(), readUserDefinition, null).toBlocking().first().getResource(); - - // Create a read only permission for the above document - Permission readOnlyPermissionDefinition = new Permission(); - readOnlyPermissionDefinition.setId(UUID.randomUUID().toString()); - readOnlyPermissionDefinition.setResourceLink(createdDocument.getSelfLink()); - readOnlyPermissionDefinition.setPermissionMode(PermissionMode.Read); - - // Assign the permission to the above user - Permission readOnlyCreatedPermission = asyncClient.createPermission(createdReadUser.getSelfLink(), readOnlyPermissionDefinition, null).toBlocking().first().getResource(); - userToReadOnlyResourceTokenMap.put(createdReadUser.getId(), readOnlyCreatedPermission.getToken()); - - documentToReadUserMap.put(createdDocument.getSelfLink(), createdReadUser.getId()); - - // Create a User who can both read and write this document - User readWriteUserDefinition = new User(); - readWriteUserDefinition.setId(UUID.randomUUID().toString()); - User createdReadWriteUser = asyncClient.createUser(createdDatabase.getSelfLink(), readWriteUserDefinition, null).toBlocking().first().getResource(); - - // Create a read/write permission for the above document - Permission readWritePermissionDefinition = new Permission(); - readWritePermissionDefinition.setId(UUID.randomUUID().toString()); - readWritePermissionDefinition.setResourceLink(createdDocument.getSelfLink()); - readWritePermissionDefinition.setPermissionMode(PermissionMode.All); - - // Assign the permission to the above user - Permission readWriteCreatedPermission = asyncClient.createPermission(createdReadWriteUser.getSelfLink(), readWritePermissionDefinition, null).toBlocking().first().getResource(); - userToReadWriteResourceTokenMap.put(createdReadWriteUser.getId(), readWriteCreatedPermission.getToken()); - - documentToReadWriteUserMap.put(createdDocument.getSelfLink(), createdReadWriteUser.getId()); - } - } - - /** - * Read a document with a user having read permission - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void readDocumentThroughTokenResolver() throws Exception { - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getTokenResolverForRead()) - .build(); - List> capturedResponse = Collections - .synchronizedList(new ArrayList<>()); - for (String documentLink : documentToReadUserMap.keySet()) { - - // Each document has one User who can only read it. Pass that User Id in the properties. - // The token resolver will resolve the token for that User based on 'userId'. - ImmutableMap properties = ImmutableMap. builder() - .put(USER_ID, documentToReadUserMap.get(documentLink)) - .build(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setProperties(properties); - Observable> readDocumentObservable = asyncClientWithTokenResolver - .readDocument(documentLink, requestOptions); - readDocumentObservable.subscribe(resourceResponse -> { - capturedResponse.add(resourceResponse); - }); - } - Thread.sleep(2000); - System.out.println("capturedResponse.size() = " + capturedResponse.size()); - assertThat(capturedResponse, hasSize(10)); - } finally { - Utils.safeClose(asyncClientWithTokenResolver); - } - } - - /** - * Delete a document with a user having all permission - */ - @Test(groups = "samples", timeOut = TIMEOUT, dependsOnMethods = {"readDocumentThroughTokenResolver"}) - public void deleteDocumentThroughTokenResolver() throws Exception { - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getTokenResolverForReadWrite()) - .build(); - List> capturedResponse = Collections - .synchronizedList(new ArrayList<>()); - for (String documentLink : documentToReadWriteUserMap.keySet()) { - - // Each document has one User who can read and write it. Pass that User Id in the properties. - // The token resolver will resolve the token for that User based on 'userId'. - ImmutableMap properties = ImmutableMap. builder() - .put(USER_ID, documentToReadWriteUserMap.get(documentLink)) - .build(); - - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setProperties(properties); - Observable> readDocumentObservable = asyncClientWithTokenResolver - .deleteDocument(documentLink, requestOptions); - readDocumentObservable.subscribe(resourceResponse -> { - capturedResponse.add(resourceResponse); - }); - } - Thread.sleep(2000); - assertThat(capturedResponse, hasSize(10)); - } finally { - Utils.safeClose(asyncClientWithTokenResolver); - } - } - - /** - * Block list an user and throw error from token resolver - */ - @Test(groups = "samples", timeOut = TIMEOUT) - public void blockListUserThroughTokenResolver() throws Exception { - String blockListedUserId = "block listed user"; - String errorMessage = "block listed user! access denied!"; - - AsyncDocumentClient asyncClientWithTokenResolver = null; - - try { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getTokenResolverWithBlockList(blockListedUserId, errorMessage)) - .build(); - - // Read a document using a block listed user, passing the 'userId' in the properties. - // Token resolver will throw RuntimeException. - RequestOptions options = new RequestOptions(); - ImmutableMap properties = ImmutableMap. builder() - .put(USER_ID, blockListedUserId) - .build(); - - options.setProperties(properties); - Observable> readObservable = asyncClientWithTokenResolver.readCollection(createdCollection.getSelfLink(), options); - List capturedErrors = Collections - .synchronizedList(new ArrayList<>()); - readObservable.subscribe(response -> {}, throwable -> capturedErrors.add(throwable)); - Thread.sleep(2000); - assertThat(capturedErrors, hasSize(1)); - assertThat(capturedErrors.get(0), instanceOf(RuntimeException.class)); - assertThat(capturedErrors.get(0).getMessage(), equalTo(errorMessage)); - - // Read a document using a valid user, passing the 'userId' in the properties. - // Token resolver will pass on the correct token for authentication. - String validUserId = userToReadWriteResourceTokenMap.keySet().iterator().next(); - System.out.println(validUserId); - properties = ImmutableMap. builder() - .put(USER_ID, validUserId) - .build(); - options.setProperties(properties); - readObservable = asyncClientWithTokenResolver.readCollection(createdCollection.getSelfLink(), options); - List capturedResponse = Collections - .synchronizedList(new ArrayList<>()); - readObservable.subscribe(resourceResponse -> capturedResponse.add(resourceResponse.getResource()), error -> error.printStackTrace()); - Thread.sleep(2000); - assertThat(capturedErrors, hasSize(1)); - assertThat(capturedResponse.get(0).getId(), equalTo(createdCollection.getId())); - } finally { - Utils.safeClose(asyncClientWithTokenResolver); - } - } - - /** - * For Reading DatabaseAccount on client initialization, use any User's token. - * For subsequent Reads, get the correct read only token based on 'userId'. - */ - private TokenResolver getTokenResolverForRead() { - return (String requestVerb, String resourceIdOrFullName, CosmosResourceType resourceType, Map properties) -> { - if (resourceType.equals(CosmosResourceType.System)) { - //Choose any token it should have the read access on database account - for (String token : userToReadOnlyResourceTokenMap.values()) { - return token; - } - } else { - return userToReadOnlyResourceTokenMap.get(properties.get(USER_ID)); - } - return null; - }; - } - - /** - * For Reading DatabaseAccount on client initialization, use any User's token. - * For subsequent Reads/Writes, get the correct read/write token based on 'userId'. - */ - private TokenResolver getTokenResolverForReadWrite() { - return (String requestVerb, String resourceIdOrFullName, CosmosResourceType resourceType, Map properties) -> { - if (resourceType.equals(CosmosResourceType.System)) { - //Choose any token it should have the read access on database account - for (String token : userToReadWriteResourceTokenMap.values()) { - return token; - } - } else { - return userToReadWriteResourceTokenMap.get(properties.get(USER_ID)); - } - return null; - }; - } - - /** - * For Reading DatabaseAccount on client initialization, use any User's token. - * For subsequent Reads, get the correct read/write token based on 'userId', - * only if user is not block listed. In this scenario, the block listed user id - * is compared to the current user's id, passed into the properties for the request. - */ - private TokenResolver getTokenResolverWithBlockList(String blockListedUserId, String errorMessage) { - return (String requestVerb, String resourceIdOrFullName, CosmosResourceType resourceType, Map properties) -> { - if (resourceType == CosmosResourceType.System) { - return userToReadWriteResourceTokenMap.values().iterator().next(); - } else if (!properties.get(USER_ID).toString().equals(blockListedUserId)) { - return userToReadWriteResourceTokenMap.get(properties.get(USER_ID)); - } else { - throw new RuntimeException(errorMessage); - } - }; - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(asyncClient, createdDatabase); - Utils.safeClose(asyncClient); - } -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/UniqueIndexAsyncAPITest.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/UniqueIndexAsyncAPITest.java deleted file mode 100644 index e253729f1ee4..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/UniqueIndexAsyncAPITest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.UniqueKey; -import com.microsoft.azure.cosmosdb.UniqueKeyPolicy; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Observable; -import rx.observers.TestSubscriber; - -import java.util.Collections; -import java.util.UUID; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasSize; - -public class UniqueIndexAsyncAPITest { - private final static int TIMEOUT = 60000; - - private AsyncDocumentClient client; - private Database createdDatabase; - - @Test(groups = "samples", timeOut = TIMEOUT) - public void uniqueIndex() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy(); - UniqueKey uniqueKey = new UniqueKey(); - uniqueKey.setPaths(ImmutableList.of("/name", "/field")); - uniqueKeyPolicy.setUniqueKeys(Collections.singleton(uniqueKey)); - collectionDefinition.setUniqueKeyPolicy(uniqueKeyPolicy); - - DocumentCollection collection = client.createCollection(getDatabaseLink(), collectionDefinition, null).toBlocking().single().getResource(); - - Document doc1 = new Document("{ 'name':'Alan Turning', 'field': 'Mathematics', 'other' : 'Logic' }"); - Document doc2 = new Document("{ 'name':'Al-Khwarizmi', 'field': 'Mathematics' , 'other' : 'Algebra '}"); - Document doc3 = new Document("{ 'name':'Alan Turning', 'field': 'Mathematics', 'other' : 'CS' }"); - - client.createDocument(getCollectionLink(collection), doc1, null, false).toBlocking().single().getResource(); - client.createDocument(getCollectionLink(collection), doc2, null, false).toBlocking().single().getResource(); - - // doc1 got inserted with the same values for 'name' and 'field' - // so inserting a new one with the same values will violate unique index constraint. - Observable> docCreation = - client.createDocument(getCollectionLink(collection), doc3, null, false); - - TestSubscriber> subscriber = new TestSubscriber<>(); - docCreation.subscribe(subscriber); - - subscriber.awaitTerminalEvent(); - subscriber.assertError(DocumentClientException.class); - assertThat(subscriber.getOnErrorEvents(), hasSize(1)); - - // error code for failure is conflict - assertThat(((DocumentClientException) subscriber.getOnErrorEvents().get(0)).getStatusCode(), equalTo(409)); - } - - @BeforeClass(groups = "samples", timeOut = TIMEOUT) - public void setUp() { - // Sets up the requirements for each test - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - client = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - // Create database - createdDatabase = Utils.createDatabaseForTest(client); - } - - @AfterClass(groups = "samples", timeOut = TIMEOUT) - public void shutdown() { - Utils.safeClean(client, createdDatabase); - Utils.safeClose(client); - } - - private String getCollectionLink(DocumentCollection collection) { - return "dbs/" + createdDatabase.getId() + "/colls/" + collection.getId(); - } - - private String getDatabaseLink() { - return "dbs/" + createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/Utils.java b/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/Utils.java deleted file mode 100644 index 5e498bcc2e2a..000000000000 --- a/cosmosdb/data-plane/examples/src/test/java/com/microsoft/azure/cosmosdb/rx/examples/Utils.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.examples; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.RetryOptions; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import org.testng.annotations.AfterSuite; -import rx.Observable; - -public class Utils { - - @AfterSuite(groups = "samples") - public void cleanupStaleDatabase() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - RetryOptions options = new RetryOptions(); - connectionPolicy.setRetryOptions(options); - AsyncDocumentClient client = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - safeCleanDatabases(client); - client.close(); - } - - public static String getCollectionLink(Database db, DocumentCollection collection) { - return "dbs/" + db.getId() + "/colls/" + collection; - } - - public static Database createDatabaseForTest(AsyncDocumentClient client) { - return DatabaseForTest.create(DatabaseManagerImpl.getInstance(client)).createdDatabase; - } - - private static void safeCleanDatabases(AsyncDocumentClient client) { - if (client != null) { - DatabaseForTest.cleanupStaleTestDatabases(DatabaseManagerImpl.getInstance(client)); - } - } - - public static void safeClean(AsyncDocumentClient client, Database database) { - if (database != null) { - safeClean(client, database.getId()); - } - } - - public static void safeClean(AsyncDocumentClient client, String databaseId) { - if (client != null) { - if (databaseId != null) { - try { - client.deleteDatabase("/dbs/" + databaseId, null).toBlocking().single(); - } catch (Exception e) { - } - } - } - } - - public static String generateDatabaseId() { - return DatabaseForTest.generateId(); - } - - public static void safeClose(AsyncDocumentClient client) { - if (client != null) { - client.close(); - } - } - - private static class DatabaseManagerImpl implements DatabaseForTest.DatabaseManager { - public static DatabaseManagerImpl getInstance(AsyncDocumentClient client) { - return new DatabaseManagerImpl(client); - } - - private final AsyncDocumentClient client; - - private DatabaseManagerImpl(AsyncDocumentClient client) { - this.client = client; - } - - @Override - public Observable> queryDatabases(SqlQuerySpec query) { - return client.queryDatabases(query, null); - } - - @Override - public Observable> createDatabase(Database databaseDefinition) { - return client.createDatabase(databaseDefinition, null); - } - - @Override - public Observable> deleteDatabase(String id) { - - return client.deleteDatabase("dbs/" + id, null); - } - } -} diff --git a/cosmosdb/data-plane/examples/src/test/resources/log4j.properties b/cosmosdb/data-plane/examples/src/test/resources/log4j.properties deleted file mode 100644 index b7947ea7907d..000000000000 --- a/cosmosdb/data-plane/examples/src/test/resources/log4j.properties +++ /dev/null @@ -1,13 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p %c - %m%n diff --git a/cosmosdb/data-plane/faq/README.md b/cosmosdb/data-plane/faq/README.md deleted file mode 100644 index 8fa637f1570d..000000000000 --- a/cosmosdb/data-plane/faq/README.md +++ /dev/null @@ -1,9 +0,0 @@ - -### FAQ - -#### I am getting this error: - -- ``Request Rate too Large`` Request too large is an error from service indicating that you temporarily went beyond the provisioned throughput. You should retry after the provided -``DocumentClientException#getRetryAfterInMilliseconds()``. - -- ``CollectionPoolExhausted`` this is a SDK side error indicating that the SDK's connection pool is saturated. Consider to retry later, increase the connection pool size or use a semaphore to throttle your workload. diff --git a/cosmosdb/data-plane/gateway/pom.xml b/cosmosdb/data-plane/gateway/pom.xml deleted file mode 100644 index a51483cb36f6..000000000000 --- a/cosmosdb/data-plane/gateway/pom.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - 4.0.0 - - com.microsoft.azure - azure-cosmosdb-parent - 2.4.5 - - azure-cosmosdb-gateway - Common Gateway Components for Async SDK for SQL API of Azure Cosmos DB Service - Common Gateway Components for Async SDK for SQL API of Azure Cosmos DB Service - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.22.0 - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - org.apache.maven.plugins - maven-jxr-plugin - 2.1 - - - - - - com.microsoft.azure - azure-cosmosdb-commons - - - com.microsoft.azure - azure-cosmosdb-commons-test-utils - test - - - org.testng - testng - ${testng.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.mockito - mockito-all - ${mockito.version} - test - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - test - - - log4j - log4j - ${log4j.version} - test - - - com.google.guava - guava - ${guava.version} - test - - - diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccountManagerInternal.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccountManagerInternal.java deleted file mode 100644 index 670153b18672..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/DatabaseAccountManagerInternal.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb; - -import rx.Observable; - -import java.net.URI; - -public interface DatabaseAccountManagerInternal { - - /** - * Gets database account information. - * - * @param endpoint the endpoint from which gets the database account - * @return the database account. - */ - Observable getDatabaseAccountFromEndpoint(URI endpoint); - - /** - * Gets the connection policy - * - * @return connection policy - */ - ConnectionPolicy getConnectionPolicy(); - - /** - * Gets the service endpoint - * - * @return service endpoint - */ - URI getServiceEndpoint(); - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/ISessionContainer.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/ISessionContainer.java deleted file mode 100644 index 24abe4825075..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/ISessionContainer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import java.util.Map; - -public interface ISessionContainer { - /** - * Returns a serialized map of partitionKeyRangeId to session token. If a entity is name based then the method extracts name from - * ResourceAddress and use it to identify collection otherwise it uses ResourceId. Returns empty string if collection is unknown - * @param entity {@link RxDocumentServiceRequest entity} - * @return serialzed map of partitionKeyRangeId to session token or empty string is collection is unknown - */ - String resolveGlobalSessionToken(RxDocumentServiceRequest entity); - - /** - * Returns a session token identified by partitionKeyRangeId(*) from a collection identified either by ResourceAddress - * (in case of name based entity) or either by ResourceId. - * - * If partitionKeyRangeId is not in the collection's partitionKeyRangeId token map then method - * iterates through request.RequestContext.ResolvedPartitionKeyRange.Parents starting from tail and - * returns a corresponding token if there is a match. - * @param entity {@link RxDocumentServiceRequest} - * @param partitionKeyRangeId partitionKeyRangeId - * @return Returns a session token identified by partitionKeyRangeId(*) from a collection identified either by ResourceAddress - * (in case of name based entity) or either by ResourceId. - */ - ISessionToken resolvePartitionLocalSessionToken(RxDocumentServiceRequest entity, String partitionKeyRangeId); - - /** - * Atomically: removes partitionKeyRangeId token map associated with resourceId, - * maps resourceId to collectionFullName and removes its map as well - * @param resourceId resourceId - */ - void clearTokenByResourceId(String resourceId); - - /** - * Atomically: removes partitionKeyRangeId token map associated with collectionFullName, maps collectionFullName to resourceId and - * removes its map as well. - * @param collectionFullName collectionFullName - */ - void clearTokenByCollectionFullName(String collectionFullName); - - /** - * Infers collectionFullName using responseHeaders[HttpConstants.HttpHeaders.OwnerFullName] or request.ResourceAddress, - * infers resourceId using responseHeaders[HttpConstants.HttpHeaders.OwnerId] or request.ResourceId, - * and adds responseHeaders[HttpConstants.HttpHeaders.SessionToken] session token to the (collectionFullName, resourceId)'s - * partitionKeyRangeId token map. - * - * NB: Silently does nothing for master queries, or when it's impossible to infer collectionRid and collectionFullName - * from the request, or then SessionToken is missing in responseHeader. - * - * @param request {@link RxDocumentServiceRequest} - * @param responseHeaders responseHeaders - */ - void setSessionToken(RxDocumentServiceRequest request, Map responseHeaders); - - /** - * Adds responseHeaders[HttpConstants.HttpHeaders.SessionToken] session token to the (collectionFullName, collectionRid)'s partitionKeyRangeId token map. - * @param collectionRid collectionRid - * @param collectionFullName collectionFullName - * @param responseHeaders responseHeaders - */ - void setSessionToken(String collectionRid, String collectionFullName, Map responseHeaders); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/AuthorizationTokenProvider.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/AuthorizationTokenProvider.java deleted file mode 100644 index 3aaa9f60dbc5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/AuthorizationTokenProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.util.Map; - -/** - * Represents types that can provide functionality to generate authorization token for the Azure Cosmos DB database - * service. - */ -public interface AuthorizationTokenProvider { - String generateKeyAuthorizationSignature(String verb, - String resourceIdOrFullName, - ResourceType resourceType, - Map headers); - - String getAuthorizationTokenUsingResourceTokens(Map resourceTokens, - String path, - String resourceId); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/BaseAuthorizationTokenProvider.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/BaseAuthorizationTokenProvider.java deleted file mode 100644 index f04df192d7f4..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/BaseAuthorizationTokenProvider.java +++ /dev/null @@ -1,373 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import java.net.URI; -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.util.Collections; -import java.util.HashSet; -import java.util.Locale; -import java.util.Map; - -import javax.crypto.Mac; -import javax.crypto.SecretKey; -import javax.crypto.spec.SecretKeySpec; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; - -/** - * This class is used internally by both client (for generating the auth header with master/system key) and by the Gateway when - * verifying the auth header in the Azure Cosmos DB database service. - */ -public class BaseAuthorizationTokenProvider implements AuthorizationTokenProvider { - - private static final String AUTH_PREFIX = "type=master&ver=1.0&sig="; - private final String masterKey; - private final Mac macInstance; - - public BaseAuthorizationTokenProvider(String masterKey) { - this.masterKey = masterKey; - byte[] masterKeyDecodedBytes = Utils.Base64Decoder.decode(this.masterKey.getBytes()); - SecretKey signingKey = new SecretKeySpec(masterKeyDecodedBytes, "HMACSHA256"); - try { - this.macInstance = Mac.getInstance("HMACSHA256"); - this.macInstance.init(signingKey); - } catch (NoSuchAlgorithmException | InvalidKeyException e) { - throw new IllegalStateException(e); - } - } - - private static String getResourceSegment(ResourceType resourceType) { - switch (resourceType) { - case Attachment: - return Paths.ATTACHMENTS_PATH_SEGMENT; - case Database: - return Paths.DATABASES_PATH_SEGMENT; - case Conflict: - return Paths.CONFLICTS_PATH_SEGMENT; - case Document: - return Paths.DOCUMENTS_PATH_SEGMENT; - case DocumentCollection: - return Paths.COLLECTIONS_PATH_SEGMENT; - case Offer: - return Paths.OFFERS_PATH_SEGMENT; - case Permission: - return Paths.PERMISSIONS_PATH_SEGMENT; - case StoredProcedure: - return Paths.STORED_PROCEDURES_PATH_SEGMENT; - case Trigger: - return Paths.TRIGGERS_PATH_SEGMENT; - case UserDefinedFunction: - return Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT; - case User: - return Paths.USERS_PATH_SEGMENT; - case PartitionKeyRange: - return Paths.PARTITION_KEY_RANGES_PATH_SEGMENT; - case Media: - return Paths.MEDIA_PATH_SEGMENT; - case DatabaseAccount: - return ""; - default: - return null; - } - } - - /** - * This API is a helper method to create auth header based on client request using masterkey. - * - * @param verb the verb. - * @param resourceIdOrFullName the resource id or full name - * @param resourceType the resource type. - * @param headers the request headers. - * @return the key authorization signature. - */ - public String generateKeyAuthorizationSignature(String verb, - String resourceIdOrFullName, - ResourceType resourceType, - Map headers) { - return this.generateKeyAuthorizationSignature(verb, resourceIdOrFullName, - BaseAuthorizationTokenProvider.getResourceSegment(resourceType).toLowerCase(), headers); - } - - /** - * This API is a helper method to create auth header based on client request using masterkey. - * - * @param verb the verb - * @param resourceIdOrFullName the resource id or full name - * @param resourceSegment the resource segment - * @param headers the request headers - * @return the key authorization signature - */ - public String generateKeyAuthorizationSignature(String verb, - String resourceIdOrFullName, - String resourceSegment, - Map headers) { - if (verb == null || verb.isEmpty()) { - throw new IllegalArgumentException("verb"); - } - - if (resourceIdOrFullName == null) { - resourceIdOrFullName = ""; - } - - if (resourceSegment == null) { - throw new IllegalArgumentException("resourceSegment"); - } - - if (headers == null) { - throw new IllegalArgumentException("headers"); - } - - if (this.masterKey == null || this.masterKey.isEmpty()) { - throw new IllegalArgumentException("masterKey"); - } - - if(!PathsHelper.isNameBased(resourceIdOrFullName)) { - resourceIdOrFullName = resourceIdOrFullName.toLowerCase(Locale.ROOT); - } - - // Skipping lower casing of resourceId since it may now contain "ID" of the resource as part of the FullName - StringBuilder body = new StringBuilder(); - body.append(verb.toLowerCase()) - .append('\n') - .append(resourceSegment) - .append('\n') - .append(resourceIdOrFullName) - .append('\n'); - - if (headers.containsKey(HttpConstants.HttpHeaders.X_DATE)) { - body.append(headers.get(HttpConstants.HttpHeaders.X_DATE).toLowerCase()); - } - - body.append('\n'); - - if (headers.containsKey(HttpConstants.HttpHeaders.HTTP_DATE)) { - body.append(headers.get(HttpConstants.HttpHeaders.HTTP_DATE).toLowerCase()); - } - - body.append('\n'); - - Mac mac = null; - try { - mac = (Mac) this.macInstance.clone(); - } catch (CloneNotSupportedException e) { - throw new IllegalStateException(e); - } - - byte[] digest = mac.doFinal(body.toString().getBytes()); - - String auth = Utils.encodeBase64String(digest); - - return AUTH_PREFIX + auth; - } - - /** - * This API is a helper method to create auth header based on client request using resourceTokens. - * - * @param resourceTokens the resource tokens. - * @param path the path. - * @param resourceId the resource id. - * @return the authorization token. - */ - public String getAuthorizationTokenUsingResourceTokens(Map resourceTokens, - String path, - String resourceId) { - if (resourceTokens == null) { - throw new IllegalArgumentException("resourceTokens"); - } - - String resourceToken = null; - if (resourceTokens.containsKey(resourceId) && resourceTokens.get(resourceId) != null) { - resourceToken = resourceTokens.get(resourceId); - } else if (StringUtils.isEmpty(path) || StringUtils.isEmpty(resourceId)) { - if (resourceTokens.size() > 0) { - resourceToken = resourceTokens.values().iterator().next(); - } - } else { - // Get the last resource id from the path and use that to find the corresponding token. - String[] pathParts = StringUtils.split(path, "/"); - String[] resourceTypes = {"dbs", "colls", "docs", "sprocs", "udfs", "triggers", "users", "permissions", - "attachments", "media", "conflicts"}; - HashSet resourceTypesSet = new HashSet(); - Collections.addAll(resourceTypesSet, resourceTypes); - - for (int i = pathParts.length - 1; i >= 0; --i) { - - if (!resourceTypesSet.contains(pathParts[i]) && resourceTokens.containsKey(pathParts[i])) { - resourceToken = resourceTokens.get(pathParts[i]); - } - } - } - - return resourceToken; - } - public String generateKeyAuthorizationSignature(String verb, URI uri, Map headers) { - if (StringUtils.isEmpty(verb)) { - throw new IllegalArgumentException(String.format(RMResources.StringArgumentNullOrEmpty, "verb")); - } - - if (uri == null) { - throw new IllegalArgumentException("uri"); - } - - if (headers == null) { - throw new IllegalArgumentException("headers"); - } - PathInfo pathInfo = new PathInfo(false, StringUtils.EMPTY, StringUtils.EMPTY, false); - getResourceTypeAndIdOrFullName(uri, pathInfo); - return generateKeyAuthorizationSignatureNew(verb, pathInfo.resourceIdOrFullName, pathInfo.resourcePath, - headers); - } - - public String generateKeyAuthorizationSignatureNew(String verb, String resourceIdValue, String resourceType, - Map headers) { - if (StringUtils.isEmpty(verb)) { - throw new IllegalArgumentException(String.format(RMResources.StringArgumentNullOrEmpty, "verb")); - } - - if (resourceType == null) { - throw new IllegalArgumentException(String.format(RMResources.StringArgumentNullOrEmpty, "resourceType")); // can be empty - } - - if (headers == null) { - throw new IllegalArgumentException("headers"); - } - // Order of the values included in the message payload is a protocol that - // clients/BE need to follow exactly. - // More headers can be added in the future. - // If any of the value is optional, it should still have the placeholder value - // of "" - // OperationType -> ResourceType -> ResourceId/OwnerId -> XDate -> Date - String verbInput = verb; - String resourceIdInput = resourceIdValue; - String resourceTypeInput = resourceType; - - String authResourceId = getAuthorizationResourceIdOrFullName(resourceTypeInput, resourceIdInput); - String payLoad = generateMessagePayload(verbInput, authResourceId, resourceTypeInput, headers); - Mac mac = null; - try { - mac = (Mac) this.macInstance.clone(); - } catch (CloneNotSupportedException e) { - throw new IllegalStateException(e); - } - byte[] digest = mac.doFinal(payLoad.getBytes()); - String authorizationToken = Utils.encodeBase64String(digest); - String authtoken = AUTH_PREFIX + authorizationToken; - return HttpUtils.urlEncode(authtoken); - } - - private String generateMessagePayload(String verb, String resourceId, String resourceType, - Map headers) { - String xDate = headers.get(HttpConstants.HttpHeaders.X_DATE); - String date = headers.get(HttpConstants.HttpHeaders.HTTP_DATE); - // At-least one of date header should present - // https://docs.microsoft.com/en-us/rest/api/documentdb/access-control-on-documentdb-resources - if (StringUtils.isEmpty(xDate) && (StringUtils.isEmpty(date) || StringUtils.isWhitespace(date))) { - headers.put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); - xDate = Utils.nowAsRFC1123(); - } - - // for name based, it is case sensitive, we won't use the lower case - if (!PathsHelper.isNameBased(resourceId)) { - resourceId = resourceId.toLowerCase(); - } - - StringBuilder payload = new StringBuilder(); - payload.append(verb.toLowerCase()) - .append('\n') - .append(resourceType.toLowerCase()) - .append('\n') - .append(resourceId) - .append('\n') - .append(xDate.toLowerCase()) - .append('\n') - .append(StringUtils.isEmpty(xDate) ? date.toLowerCase() : "") - .append('\n'); - - return payload.toString(); - } - - private String getAuthorizationResourceIdOrFullName(String resourceType, String resourceIdOrFullName) { - if (StringUtils.isEmpty(resourceType) || StringUtils.isEmpty(resourceIdOrFullName)) { - return resourceIdOrFullName; - } - if (PathsHelper.isNameBased(resourceIdOrFullName)) { - // resource fullname is always end with name (not type segment like docs/colls). - return resourceIdOrFullName; - } - - if (resourceType.equalsIgnoreCase(Paths.OFFERS_PATH_SEGMENT) - || resourceType.equalsIgnoreCase(Paths.PARTITIONS_PATH_SEGMENT) - || resourceType.equalsIgnoreCase(Paths.TOPOLOGY_PATH_SEGMENT) - || resourceType.equalsIgnoreCase(Paths.RID_RANGE_PATH_SEGMENT)) { - return resourceIdOrFullName; - } - - ResourceId parsedRId = ResourceId.parse(resourceIdOrFullName); - if (resourceType.equalsIgnoreCase(Paths.DATABASES_PATH_SEGMENT)) { - return parsedRId.getDatabaseId().toString(); - } else if (resourceType.equalsIgnoreCase(Paths.USERS_PATH_SEGMENT)) { - return parsedRId.getUserId().toString(); - } else if (resourceType.equalsIgnoreCase(Paths.COLLECTIONS_PATH_SEGMENT)) { - return parsedRId.getDocumentCollectionId().toString(); - } else if (resourceType.equalsIgnoreCase(Paths.DOCUMENTS_PATH_SEGMENT)) { - return parsedRId.getDocumentId().toString(); - } else { - // leaf node - return resourceIdOrFullName; - } - } - - private void getResourceTypeAndIdOrFullName(URI uri, PathInfo pathInfo) { - if (uri == null) { - throw new IllegalArgumentException("uri"); - } - - pathInfo.resourcePath = StringUtils.EMPTY; - pathInfo.resourceIdOrFullName = StringUtils.EMPTY; - - String[] segments = StringUtils.split(uri.toString(), Constants.Properties.PATH_SEPARATOR); - if (segments == null || segments.length < 1) { - throw new IllegalArgumentException(RMResources.InvalidUrl); - } - // Authorization code is fine with Uri not having resource id and path. - // We will just return empty in that case - String pathAndQuery = StringUtils.EMPTY ; - if(StringUtils.isNotEmpty(uri.getPath())) { - pathAndQuery+= uri.getPath(); - } - if(StringUtils.isNotEmpty(uri.getQuery())) { - pathAndQuery+="?"; - pathAndQuery+= uri.getQuery(); - } - if (!PathsHelper.tryParsePathSegments(pathAndQuery, pathInfo, null)) { - pathInfo.resourcePath = StringUtils.EMPTY; - pathInfo.resourceIdOrFullName = StringUtils.EMPTY; - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/BaseDatabaseAccountConfigurationProvider.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/BaseDatabaseAccountConfigurationProvider.java deleted file mode 100644 index a9faa3657514..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/BaseDatabaseAccountConfigurationProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DatabaseAccount; - -/** - * Used internally to provides functionality to work with database account configuration in the Azure Cosmos DB database service. - */ -public class BaseDatabaseAccountConfigurationProvider implements DatabaseAccountConfigurationProvider { - private ConsistencyLevel desiredConsistencyLevel; - private DatabaseAccount databaseAccount; - - public BaseDatabaseAccountConfigurationProvider(DatabaseAccount databaseAccount, ConsistencyLevel desiredConsistencyLevel) { - this.databaseAccount = databaseAccount; - this.desiredConsistencyLevel = desiredConsistencyLevel; - } - - public ConsistencyLevel getStoreConsistencyPolicy() { - ConsistencyLevel databaseAccountConsistency = this.databaseAccount.getConsistencyPolicy().getDefaultConsistencyLevel(); - if (this.desiredConsistencyLevel == null) { - return databaseAccountConsistency; - } else if (!Utils.isValidConsistency(databaseAccountConsistency, this.desiredConsistencyLevel)) { - throw new IllegalArgumentException(String.format( - "ConsistencyLevel %1s specified in the request is invalid when service is configured with consistency level %2s. Ensure the request consistency level is not stronger than the service consistency level.", - this.desiredConsistencyLevel.toString(), - databaseAccountConsistency.toString())); - } else { - return this.desiredConsistencyLevel; - } - } - - public int getMaxReplicaSetSize() { - return this.databaseAccount.getReplicationPolicy().getMaxReplicaSetSize(); - } - - @Override - public String getQueryEngineConfiguration() { - return databaseAccount.get("queryEngineConfiguration").toString(); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/DatabaseAccountConfigurationProvider.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/DatabaseAccountConfigurationProvider.java deleted file mode 100644 index 15ef723956d9..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/DatabaseAccountConfigurationProvider.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; - -/** - * Defines an interface to work with database account configuration in the Azure Cosmos DB database service. - */ -public interface DatabaseAccountConfigurationProvider { - ConsistencyLevel getStoreConsistencyPolicy(); - - int getMaxReplicaSetSize(); - - String getQueryEngineConfiguration(); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/RetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/RetryPolicy.java deleted file mode 100644 index 9b1b5eec6312..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/RetryPolicy.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; - -/** - * Used internally to define the interface for retry policy in the Azure Cosmos DB database service Java SDK. - */ -public interface RetryPolicy { - boolean shouldRetry(DocumentClientException exception) ; - - long getRetryAfterInMilliseconds(); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/SessionContainer.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/SessionContainer.java deleted file mode 100644 index 58e4ff4f65f1..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/SessionContainer.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.rx.internal.ReplicatedResourceClientUtils; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -/** - * Used internally to cache the collections' session tokens in the Azure Cosmos DB database service. - */ -public final class SessionContainer implements ISessionContainer { - private final Logger logger = LoggerFactory.getLogger(SessionContainer.class); - - /** - * Session token cache that maps collection ResourceID to session tokens - */ - private final ConcurrentHashMap> collectionResourceIdToSessionTokens = new ConcurrentHashMap<>(); - /** - * Collection ResourceID cache that maps collection name to collection ResourceID - * When collection name is provided instead of self-link, this is used in combination with - * collectionResourceIdToSessionTokens to retrieve the session token for the collection by name - */ - private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock(); - private final ReentrantReadWriteLock.ReadLock readLock = readWriteLock.readLock(); - private final ReentrantReadWriteLock.WriteLock writeLock = readWriteLock.writeLock(); - - private final ConcurrentHashMap collectionNameToCollectionResourceId = new ConcurrentHashMap<>(); - private final ConcurrentHashMap collectionResourceIdToCollectionName = new ConcurrentHashMap<>(); - private final String hostName; - - public SessionContainer(final String hostName) { - this.hostName = hostName; - } - - public String getHostName() { - return this.hostName; - } - - public String getSessionToken(String collectionLink) { - - PathInfo pathInfo = new PathInfo(false, null, null, false); - ConcurrentHashMap partitionKeyRangeIdToTokenMap = null; - if (PathsHelper.tryParsePathSegments(collectionLink, pathInfo, null)) { - Long UniqueDocumentCollectionId = null; - if (pathInfo.isNameBased) { - String collectionName = PathsHelper.getCollectionPath(pathInfo.resourceIdOrFullName); - UniqueDocumentCollectionId = this.collectionNameToCollectionResourceId.get(collectionName); - } else { - ResourceId resourceId = ResourceId.parse(pathInfo.resourceIdOrFullName); - if (resourceId.getDocumentCollection() != 0) { - UniqueDocumentCollectionId = resourceId.getUniqueDocumentCollectionId(); - } - } - - if (UniqueDocumentCollectionId != null) { - partitionKeyRangeIdToTokenMap = this.collectionResourceIdToSessionTokens.get(UniqueDocumentCollectionId); - } - } - - if (partitionKeyRangeIdToTokenMap == null) { - return StringUtils.EMPTY; - } - - return SessionContainer.getCombinedSessionToken(partitionKeyRangeIdToTokenMap); - } - - private ConcurrentHashMap getPartitionKeyRangeIdToTokenMap(RxDocumentServiceRequest request) { - return getPartitionKeyRangeIdToTokenMap(request.getIsNameBased(), request.getResourceId(), request.getResourceAddress()); - } - - private ConcurrentHashMap getPartitionKeyRangeIdToTokenMap(boolean isNameBased, String rId, String resourceAddress) { - ConcurrentHashMap rangeIdToTokenMap = null; - if (!isNameBased) { - if (!StringUtils.isEmpty(rId)) { - ResourceId resourceId = ResourceId.parse(rId); - if (resourceId.getDocumentCollection() != 0) { - rangeIdToTokenMap = - this.collectionResourceIdToSessionTokens.get(resourceId.getUniqueDocumentCollectionId()); - } - } - } else { - String collectionName = Utils.getCollectionName(resourceAddress); - if (!StringUtils.isEmpty(collectionName) && this.collectionNameToCollectionResourceId.containsKey(collectionName)) { - rangeIdToTokenMap = this.collectionResourceIdToSessionTokens.get( - this.collectionNameToCollectionResourceId.get(collectionName)); - } - } - return rangeIdToTokenMap; - } - - - public String resolveGlobalSessionToken(RxDocumentServiceRequest request) { - ConcurrentHashMap partitionKeyRangeIdToTokenMap = this.getPartitionKeyRangeIdToTokenMap(request); - if (partitionKeyRangeIdToTokenMap != null) { - return SessionContainer.getCombinedSessionToken(partitionKeyRangeIdToTokenMap); - } - - return StringUtils.EMPTY; - } - - @Override - public ISessionToken resolvePartitionLocalSessionToken(RxDocumentServiceRequest request, String partitionKeyRangeId) { - return SessionTokenHelper.resolvePartitionLocalSessionToken(request, - partitionKeyRangeId, - this.getPartitionKeyRangeIdToTokenMap(request)); - } - - @Override - public void clearTokenByCollectionFullName(String collectionFullName) { - if (!Strings.isNullOrEmpty(collectionFullName)) { - String collectionName = PathsHelper.getCollectionPath(collectionFullName); - this.writeLock.lock(); - try { - if (this.collectionNameToCollectionResourceId.containsKey(collectionName)) { - Long rid = this.collectionNameToCollectionResourceId.get(collectionName); - this.collectionResourceIdToSessionTokens.remove(rid); - this.collectionResourceIdToCollectionName.remove(rid); - this.collectionNameToCollectionResourceId.remove(collectionName); - } - } finally { - this.writeLock.unlock(); - } - } - } - - @Override - public void clearTokenByResourceId(String resourceId) { - if (!StringUtils.isEmpty(resourceId)) { - ResourceId resource = ResourceId.parse(resourceId); - if (resource.getDocumentCollection() != 0) { - Long rid = resource.getUniqueDocumentCollectionId(); - this.writeLock.lock(); - try { - if (this.collectionResourceIdToCollectionName.containsKey(rid)) { - String collectionName = this.collectionResourceIdToCollectionName.get(rid); - this.collectionResourceIdToSessionTokens.remove(rid); - this.collectionResourceIdToCollectionName.remove(rid); - this.collectionNameToCollectionResourceId.remove(collectionName); - } - } finally { - this.writeLock.unlock(); - } - } - } - } - - @Override - public void setSessionToken(RxDocumentServiceRequest request, Map responseHeaders) { - String token = responseHeaders.get(HttpConstants.HttpHeaders.SESSION_TOKEN); - - if (!Strings.isNullOrEmpty(token)) { - ValueHolder resourceId = ValueHolder.initialize(null); - ValueHolder collectionName = ValueHolder.initialize(null); - - if (shouldUpdateSessionToken(request, responseHeaders, resourceId, collectionName)) { - this.setSessionToken(resourceId.v, collectionName.v, token); - } - } - } - - @Override - public void setSessionToken(String collectionRid, String collectionFullName, Map responseHeaders) { - ResourceId resourceId = ResourceId.parse(collectionRid); - String collectionName = PathsHelper.getCollectionPath(collectionFullName); - String token = responseHeaders.get(HttpConstants.HttpHeaders.SESSION_TOKEN); - if (!Strings.isNullOrEmpty(token)) { - this.setSessionToken(resourceId, collectionName, token); - } - } - - private void setSessionToken(ResourceId resourceId, String collectionName, String token) { - String partitionKeyRangeId; - ISessionToken parsedSessionToken; - - String[] tokenParts = StringUtils.split(token, ':'); - partitionKeyRangeId = tokenParts[0]; - parsedSessionToken = SessionTokenHelper.parse(tokenParts[1]); - - logger.trace("Update Session token {} {} {}", resourceId.getUniqueDocumentCollectionId(), collectionName, parsedSessionToken); - - boolean isKnownCollection; - - this.readLock.lock(); - try { - isKnownCollection = this.collectionNameToCollectionResourceId.containsKey(collectionName) && - this.collectionResourceIdToCollectionName.containsKey(resourceId.getUniqueDocumentCollectionId()) && - this.collectionNameToCollectionResourceId.get(collectionName) == resourceId.getUniqueDocumentCollectionId() && - this.collectionResourceIdToCollectionName.get(resourceId.getUniqueDocumentCollectionId()).equals(collectionName); - if (isKnownCollection) { - this.addSessionToken(resourceId, partitionKeyRangeId, parsedSessionToken); - } - } finally { - this.readLock.unlock(); - } - - if (!isKnownCollection) { - this.writeLock.lock(); - try { - if (collectionName != null && resourceId.getUniqueDocumentCollectionId() != 0) { - this.collectionNameToCollectionResourceId.compute(collectionName, (k, v) -> resourceId.getUniqueDocumentCollectionId()); - this.collectionResourceIdToCollectionName.compute(resourceId.getUniqueDocumentCollectionId(), (k, v) -> collectionName); - } - addSessionToken(resourceId, partitionKeyRangeId, parsedSessionToken); - } finally { - this.writeLock.unlock(); - } - } - } - - private void addSessionToken(ResourceId resourceId, String partitionKeyRangeId, ISessionToken parsedSessionToken) { - this.collectionResourceIdToSessionTokens.compute( - resourceId.getUniqueDocumentCollectionId(), (k, existingTokens) -> { - if (existingTokens == null) { - ConcurrentHashMap tokens = new ConcurrentHashMap<>(); - tokens.put(partitionKeyRangeId, parsedSessionToken); - return tokens; - } - - existingTokens.merge(partitionKeyRangeId, parsedSessionToken, (existingSessionTokens, newSessionToken) -> { - try { - if (existingSessionTokens == null) { - return newSessionToken; - } - - return existingSessionTokens.merge(newSessionToken); - } catch (DocumentClientException e) { - throw new IllegalStateException(e); - } - }); - - return existingTokens; - } - ); - } - - private static String getCombinedSessionToken(ConcurrentHashMap tokens) { - StringBuilder result = new StringBuilder(); - if (tokens != null) { - for (Iterator> iterator = tokens.entrySet().iterator(); iterator.hasNext(); ) { - Entry entry = iterator.next(); - result = result.append(entry.getKey()).append(":").append(entry.getValue().convertToString()); - if (iterator.hasNext()) { - result = result.append(","); - } - } - } - - return result.toString(); - } - - private static boolean shouldUpdateSessionToken( - RxDocumentServiceRequest request, - Map responseHeaders, - ValueHolder resourceId, - ValueHolder collectionName) { - resourceId.v = null; - String ownerFullName = responseHeaders.get(HttpConstants.HttpHeaders.OWNER_FULL_NAME); - if (Strings.isNullOrEmpty(ownerFullName)) ownerFullName = request.getResourceAddress(); - - collectionName.v = PathsHelper.getCollectionPath(ownerFullName); - String resourceIdString; - - if (!request.getIsNameBased()) { - resourceIdString = request.getResourceId(); - } else { - resourceIdString = responseHeaders.get(HttpConstants.HttpHeaders.OWNER_ID); - if (Strings.isNullOrEmpty(resourceIdString)) resourceIdString = request.getResourceId(); - } - - if (!Strings.isNullOrEmpty(resourceIdString)) { - resourceId.v = ResourceId.parse(resourceIdString); - - if (resourceId.v.getDocumentCollection() != 0 && - collectionName != null && - !ReplicatedResourceClientUtils.isReadingFromMaster(request.getResourceType(), request.getOperationType())) { - return true; - } - } - - return false; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/SessionTokenHelper.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/SessionTokenHelper.java deleted file mode 100644 index 5906ade34050..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/SessionTokenHelper.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import org.apache.commons.lang3.StringUtils; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -/** - * Used internally to provides helper functions to work with session tokens in the Azure Cosmos DB database service. - */ -public class SessionTokenHelper { - - public static void setOriginalSessionToken(RxDocumentServiceRequest request, String originalSessionToken) { - if (request == null) { - throw new IllegalArgumentException("request is null"); - } - - if (originalSessionToken == null) { - request.getHeaders().remove(HttpConstants.HttpHeaders.SESSION_TOKEN); - } else { - request.getHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, originalSessionToken); - } - } - - public static void setPartitionLocalSessionToken(RxDocumentServiceRequest request, ISessionContainer sessionContainer) throws DocumentClientException { - String originalSessionToken = request.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - String partitionKeyRangeId = request.requestContext.resolvedPartitionKeyRange.getId(); - - - if (Strings.isNullOrEmpty(partitionKeyRangeId)) { - // AddressCache/address resolution didn't produce partition key range id. - // In this case it is a bug. - throw new InternalServerErrorException(RMResources.PartitionKeyRangeIdAbsentInContext); - } - - if (StringUtils.isNotEmpty(originalSessionToken)) { - ISessionToken sessionToken = getLocalSessionToken(request, originalSessionToken, partitionKeyRangeId); - request.requestContext.sessionToken = sessionToken; - } else { - // use ambient session token. - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, partitionKeyRangeId); - request.requestContext.sessionToken = sessionToken; - } - - if (request.requestContext.sessionToken == null) { - request.getHeaders().remove(HttpConstants.HttpHeaders.SESSION_TOKEN); - } else { - request.getHeaders().put(HttpConstants.HttpHeaders.SESSION_TOKEN, - String.format("%1s:%2s", partitionKeyRangeId, request.requestContext.sessionToken.convertToString())); - } - } - - private static ISessionToken getLocalSessionToken( - RxDocumentServiceRequest request, - String globalSessionToken, - String partitionKeyRangeId) throws DocumentClientException { - - if (partitionKeyRangeId == null || partitionKeyRangeId.isEmpty()) { - // AddressCache/address resolution didn't produce partition key range id. - // In this case it is a bug. - throw new IllegalStateException("Partition key range Id is absent in the context."); - } - - // Convert global session token to local - there's no point in sending global token over the wire to the backend. - // Global session token is comma separated array of : pairs. For example: - // 2:425344,748:2341234,99:42344 - // Local session token is single : pair. - // Backend only cares about pair which relates to the range owned by the partition. - String[] localTokens = StringUtils.split(globalSessionToken, ","); - Set partitionKeyRangeSet = new HashSet<>(); - partitionKeyRangeSet.add(partitionKeyRangeId); - - ISessionToken highestSessionToken = null; - - if (request.requestContext.resolvedPartitionKeyRange != null && request.requestContext.resolvedPartitionKeyRange.getParents() != null) { - partitionKeyRangeSet.addAll(request.requestContext.resolvedPartitionKeyRange.getParents()); - } - - for (String localToken : localTokens) { - String[] items = StringUtils.split(localToken, ":"); - if (items.length != 2) { - throw new BadRequestException(String.format(RMResources.InvalidSessionToken, partitionKeyRangeId)); - } - - ISessionToken parsedSessionToken = SessionTokenHelper.parse(items[1]); - - if (partitionKeyRangeSet.contains(items[0])) { - - if (highestSessionToken == null) { - highestSessionToken = parsedSessionToken; - } else { - highestSessionToken = highestSessionToken.merge(parsedSessionToken); - } - - } - } - - return highestSessionToken; - } - - static ISessionToken resolvePartitionLocalSessionToken(RxDocumentServiceRequest request, - String partitionKeyRangeId, - ConcurrentHashMap rangeIdToTokenMap) { - if (rangeIdToTokenMap != null) { - if (rangeIdToTokenMap.containsKey(partitionKeyRangeId)) { - return rangeIdToTokenMap.get(partitionKeyRangeId); - } else { - Collection parents = request.requestContext.resolvedPartitionKeyRange.getParents(); - if (parents != null) { - List parentsList = new ArrayList<>(parents); - for (int i = parentsList.size() - 1; i >= 0; i--) { - String parentId = parentsList.get(i); - if (rangeIdToTokenMap.containsKey(parentId)) { - return rangeIdToTokenMap.get(parentId); - } - } - } - } - } - - return null; - } - - public static ISessionToken parse(String sessionToken) { - ValueHolder partitionKeyRangeSessionToken = ValueHolder.initialize(null); - - if (SessionTokenHelper.tryParse(sessionToken, partitionKeyRangeSessionToken)) { - return partitionKeyRangeSessionToken.v; - } else { - throw new RuntimeException(new BadRequestException(String.format(RMResources.InvalidSessionToken, sessionToken))); - } - } - - static boolean tryParse(String sessionToken, ValueHolder parsedSessionToken) { - parsedSessionToken.v = null; - if (!Strings.isNullOrEmpty(sessionToken)) { - String[] sessionTokenSegments = StringUtils.split(sessionToken,":"); - return VectorSessionToken.tryCreate(sessionTokenSegments[sessionTokenSegments.length - 1], parsedSessionToken); - } else { - return false; - } - } - - public static void validateAndRemoveSessionToken(RxDocumentServiceRequest request) throws DocumentClientException { - String sessionToken = request.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - if (!Strings.isNullOrEmpty(sessionToken)) { - getLocalSessionToken(request, sessionToken, StringUtils.EMPTY); - request.getHeaders().remove(HttpConstants.HttpHeaders.SESSION_TOKEN); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/UserAgentContainer.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/UserAgentContainer.java deleted file mode 100644 index 5f11ff50fe5f..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/UserAgentContainer.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -/** - * Used internally. The user agent object, which is used to track the version of the Java SDK of the Azure Cosmos DB database service. - */ -public class UserAgentContainer { - - private static final int MAX_SUFFIX_LENGTH = 64; - private final String baseUserAgent; - private String suffix; - private String userAgent; - - private UserAgentContainer(String sdkName, String sdkVersion) { - this.baseUserAgent = Utils.getUserAgent(sdkName, sdkVersion); - this.suffix = ""; - this.userAgent = baseUserAgent; - } - - public UserAgentContainer() { - this(HttpConstants.Versions.SDK_NAME, HttpConstants.Versions.SDK_VERSION); - } - - public String getSuffix() { - return this.suffix; - } - - public void setSuffix(String suffix) { - if (suffix.length() > MAX_SUFFIX_LENGTH) { - suffix = suffix.substring(0, MAX_SUFFIX_LENGTH); - } - - this.suffix = suffix; - this.userAgent = baseUserAgent.concat(this.suffix); - } - - public String getUserAgent() { - return this.userAgent; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/VectorSessionToken.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/VectorSessionToken.java deleted file mode 100644 index f3b04712dbda..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/VectorSessionToken.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.apache.commons.collections4.map.UnmodifiableMap; -import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; -import java.util.stream.Collectors; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -/** - * Models vector clock bases session token. Session token has the following format: - * {Version}#{GlobalLSN}#{RegionId1}={LocalLsn1}#{RegionId2}={LocalLsn2}....#{RegionIdN}={LocalLsnN} - * 'Version' captures the configuration number of the partition which returned this session token. - * 'Version' is incremented everytime topology of the partition is updated (say due to Add/Remove/Failover). - * * The choice of separators '#' and '=' is important. Separators ';' and ',' are used to delimit - * per-partitionKeyRange session token - * session - * - * We make assumption that instances of this class are immutable (read only after they are constructed), so if you want to change - * this behaviour please review all of its uses and make sure that mutability doesn't break anything. - */ -public class VectorSessionToken implements ISessionToken { - private final static Logger logger = LoggerFactory.getLogger(VectorSessionToken.class); - private final static char SegmentSeparator = '#'; - private final static char RegionProgressSeparator = '='; - - private final long version; - private final long globalLsn; - private final UnmodifiableMap localLsnByRegion; - private final String sessionToken; - - private VectorSessionToken(long version, long globalLsn, UnmodifiableMap localLsnByRegion) { - this(version, globalLsn, localLsnByRegion, null); - } - - private VectorSessionToken(long version, long globalLsn, UnmodifiableMap localLsnByRegion, String sessionToken) { - this.version = version; - this.globalLsn = globalLsn; - this.localLsnByRegion = localLsnByRegion; - if (sessionToken == null) { - String regionProgress = String.join( - Character.toString(VectorSessionToken.SegmentSeparator), - localLsnByRegion. - entrySet() - .stream() - .map(kvp -> new StringBuilder().append(kvp.getKey()).append(VectorSessionToken.RegionProgressSeparator).append(kvp.getValue())) - .collect(Collectors.toList())); - - if (Strings.isNullOrEmpty(regionProgress)) { - StringBuilder sb = new StringBuilder(); - sb.append(this.version) - .append(VectorSessionToken.SegmentSeparator) - .append(this.globalLsn); - this.sessionToken = sb.toString(); - } else { - StringBuilder sb = new StringBuilder(); - sb.append(this.version) - .append(VectorSessionToken.SegmentSeparator) - .append(this.globalLsn) - .append(VectorSessionToken.SegmentSeparator) - .append(regionProgress); - this.sessionToken = sb.toString(); - } - } else { - this.sessionToken = sessionToken; - } - } - - public static boolean tryCreate(String sessionToken, ValueHolder parsedSessionToken) { - ValueHolder versionHolder = ValueHolder.initialize(-1l); - ValueHolder globalLsnHolder = ValueHolder.initialize(-1l); - - ValueHolder> localLsnByRegion = ValueHolder.initialize(null); - - if (VectorSessionToken.tryParseSessionToken( - sessionToken, - versionHolder, - globalLsnHolder, - localLsnByRegion)) { - parsedSessionToken.v = new VectorSessionToken(versionHolder.v, globalLsnHolder.v, localLsnByRegion.v, sessionToken); - return true; - } else { - return false; - } - } - - public long getLSN() { - return this.globalLsn; - } - - @Override - public boolean equals(Object obj) { - VectorSessionToken other = Utils.as(obj, VectorSessionToken.class); - - if (other == null) { - return false; - } - - return this.version == other.version - && this.globalLsn == other.globalLsn - && this.areRegionProgressEqual(other.localLsnByRegion); - } - - public boolean isValid(ISessionToken otherSessionToken) throws DocumentClientException { - VectorSessionToken other = Utils.as(otherSessionToken, VectorSessionToken.class); - - if (other == null) { - throw new IllegalArgumentException("otherSessionToken"); - } - - if (other.version < this.version || other.globalLsn < this.globalLsn) { - return false; - } - - if (other.version == this.version && other.localLsnByRegion.size() != this.localLsnByRegion.size()) { - throw new InternalServerErrorException( - String.format(RMResources.InvalidRegionsInSessionToken, this.sessionToken, other.sessionToken)); - } - - for (Map.Entry kvp : other.localLsnByRegion.entrySet()) { - Integer regionId = kvp.getKey(); - long otherLocalLsn = kvp.getValue(); - ValueHolder localLsn = ValueHolder.initialize(-1l); - - - if (!Utils.tryGetValue(this.localLsnByRegion, regionId, localLsn)) { - // Region mismatch: other session token has progress for a region which is missing in this session token - // Region mismatch can be ignored only if this session token version is smaller than other session token version - if (this.version == other.version) { - throw new InternalServerErrorException( - String.format(RMResources.InvalidRegionsInSessionToken, this.sessionToken, other.sessionToken)); - } else { - // ignore missing region as other session token version > this session token version - } - } else { - // region is present in both session tokens. - if (otherLocalLsn < localLsn.v) { - return false; - } - } - } - - return true; - } - - // Merge is commutative operation, so a.Merge(b).Equals(b.Merge(a)) - public ISessionToken merge(ISessionToken obj) throws DocumentClientException { - VectorSessionToken other = Utils.as(obj, VectorSessionToken.class); - - if (other == null) { - throw new IllegalArgumentException("obj"); - } - - if (this.version == other.version && this.localLsnByRegion.size() != other.localLsnByRegion.size()) { - throw new InternalServerErrorException( - String.format(RMResources.InvalidRegionsInSessionToken, this.sessionToken, other.sessionToken)); - } - - VectorSessionToken sessionTokenWithHigherVersion; - VectorSessionToken sessionTokenWithLowerVersion; - - if (this.version < other.version) { - sessionTokenWithLowerVersion = this; - sessionTokenWithHigherVersion = other; - } else { - sessionTokenWithLowerVersion = other; - sessionTokenWithHigherVersion = this; - } - - Map highestLocalLsnByRegion = new HashMap<>(); - - for (Map.Entry kvp : sessionTokenWithHigherVersion.localLsnByRegion.entrySet()) { - Integer regionId = kvp.getKey(); - - long localLsn1 = kvp.getValue(); - ValueHolder localLsn2 = ValueHolder.initialize(-1l); - - if (Utils.tryGetValue(sessionTokenWithLowerVersion.localLsnByRegion, regionId, localLsn2)) { - highestLocalLsnByRegion.put(regionId, Math.max(localLsn1, localLsn2.v)); - } else if (this.version == other.version) { - throw new InternalServerErrorException( - String.format(RMResources.InvalidRegionsInSessionToken, this.sessionToken, other.sessionToken)); - } else { - highestLocalLsnByRegion.put(regionId, localLsn1); - } - } - - return new VectorSessionToken( - Math.max(this.version, other.version), - Math.max(this.globalLsn, other.globalLsn), - (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(highestLocalLsnByRegion)); - } - - public String convertToString() { - return this.sessionToken; - } - - private boolean areRegionProgressEqual(UnmodifiableMap other) { - if (this.localLsnByRegion.size() != other.size()) { - return false; - } - - for (Map.Entry kvp : this.localLsnByRegion.entrySet()) { - Integer regionId = kvp.getKey(); - ValueHolder localLsn1 = ValueHolder.initialize(kvp.getValue()); - ValueHolder localLsn2 = ValueHolder.initialize(-1l); - - if (Utils.tryGetValue(other, regionId, localLsn2)) { - if (ObjectUtils.notEqual(localLsn1.v, localLsn2.v)) { - return false; - } - } - } - - return true; - } - - private static boolean tryParseSessionToken( - String sessionToken, - ValueHolder version, - ValueHolder globalLsn, - ValueHolder> localLsnByRegion) { - version.v = 0L; - localLsnByRegion.v = null; - globalLsn.v = -1L; - - if (Strings.isNullOrEmpty(sessionToken)) { - logger.warn("Session token is empty"); - return false; - } - - String[] segments = StringUtils.split(sessionToken, VectorSessionToken.SegmentSeparator); - - if (segments.length < 2) { - return false; - } - - if (!tryParseLong(segments[0], version) - || !tryParseLong(segments[1], globalLsn)) { - logger.warn("Unexpected session token version number '{}' OR global lsn '{}'.", segments[0], segments[1]); - return false; - } - - Map lsnByRegion = new HashMap<>(); - - for (int i = 2; i < segments.length; i++) { - String regionSegment = segments[i]; - - String[] regionIdWithLsn = StringUtils.split(regionSegment, VectorSessionToken.RegionProgressSeparator); - - if (regionIdWithLsn.length != 2) { - logger.warn("Unexpected region progress segment length '{}' in session token.", regionIdWithLsn.length); - return false; - } - - ValueHolder regionId = ValueHolder.initialize(0); - ValueHolder localLsn = ValueHolder.initialize(-1l); - - if (!tryParseInt(regionIdWithLsn[0], regionId) - || !tryParseLong(regionIdWithLsn[1], localLsn)) { - logger.warn("Unexpected region progress '{}' for region '{}' in session token.", regionIdWithLsn[0], regionIdWithLsn[1]); - return false; - } - - lsnByRegion.put(regionId.v, localLsn.v); - } - - localLsnByRegion.v = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(lsnByRegion); - return true; - } - - private static boolean tryParseLong(String str, ValueHolder value) { - try { - value.v = Long.parseLong(str); - return true; - } catch (Exception e) { - return false; - } - } - - private static boolean tryParseInt(String str, ValueHolder value) { - try { - value.v = Integer.parseInt(str); - return true; - } catch (Exception e) { - return false; - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WebExceptionUtility.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WebExceptionUtility.java deleted file mode 100644 index c90fdf1e1b47..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/WebExceptionUtility.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import io.netty.channel.ChannelException; -import io.reactivex.netty.client.PoolExhaustedException; - -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.SSLPeerUnverifiedException; -import java.io.IOException; -import java.net.ConnectException; -import java.net.NoRouteToHostException; -import java.net.UnknownHostException; - -public class WebExceptionUtility { - public static boolean isWebExceptionRetriable(Exception ex) { - Exception iterator = ex; - - while (iterator != null) { - if (WebExceptionUtility.isWebExceptionRetriableInternal(iterator)) { - return true; - } - - Throwable t = iterator.getCause(); - iterator = Utils.as(t, Exception.class); - } - - return false; - } - - private static boolean isWebExceptionRetriableInternal(Exception ex) { - if (ex instanceof PoolExhaustedException) { - return true; - } - - IOException webEx = Utils.as(ex, IOException.class); - if (webEx == null) { - return false; - } - - // any network failure for which we are certain the request hasn't reached the service endpoint. - if (webEx instanceof ConnectException || - webEx instanceof UnknownHostException || - webEx instanceof SSLHandshakeException || - webEx instanceof NoRouteToHostException || - webEx instanceof SSLPeerUnverifiedException) { - return true; - } - - return false; - } - - public static boolean isNetworkFailure(Exception ex) { - Exception iterator = ex; - - while (iterator != null) { - if (WebExceptionUtility.isNetworkFailureInternal(iterator)) { - return true; - } - - Throwable t = iterator.getCause(); - iterator = Utils.as(t, Exception.class); - } - - return false; - } - - private static boolean isNetworkFailureInternal(Exception ex) { - if (ex instanceof IOException) { - return true; - } - - if (ex instanceof ChannelException) { - return true; - } - - return false; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ExceptionHelper.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ExceptionHelper.java deleted file mode 100644 index 1bf8481c9add..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ExceptionHelper.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -import java.util.concurrent.ExecutionException; - -class ExceptionHelper { - - private ExceptionHelper() {} - - public static Throwable unwrap(Throwable e) { - if (e.getCause() == null) { - return e; - } - if (e instanceof IllegalStateException || e instanceof ExecutionException) { - return unwrap(e.getCause()); - } - return e; - } - - public static Throwable unwrapIllegalStateException(Exception e) { - if (e instanceof IllegalStateException && e.getCause() != null) { - return e.getCause(); - } - return e; - } - - public static Throwable unwrapExecutionException(Exception e) { - if (e instanceof RuntimeException && e.getCause() != null) { - return e.getCause(); - } - return e; - } - - public static RuntimeException toRuntimeException(Throwable e) { - if (e instanceof RuntimeException) { - return (RuntimeException) e; - } - throw new IllegalStateException(e); - } - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemComparator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemComparator.java deleted file mode 100644 index a3f35ee181f3..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemComparator.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -import java.util.Comparator; - -public final class ItemComparator implements Comparator { - private ItemComparator() { - } - - private static class SingletonHelper { - private static final ItemComparator INSTANCE = new ItemComparator(); - } - - public static ItemComparator getInstance() { - return SingletonHelper.INSTANCE; - } - - @Override - public int compare(Object obj1, Object obj2) { - ItemType type1 = ItemTypeHelper.getOrderByItemType(obj1); - ItemType type2 = ItemTypeHelper.getOrderByItemType(obj2); - - int cmp = Integer.compare(type1.getVal(), type2.getVal()); - - if (cmp != 0) { - return cmp; - } - - switch (type1) { - case NoValue: - case Null: - return 0; - case Boolean: - return Boolean.compare((Boolean) obj1, (Boolean) obj2); - case Number: - return Double.compare(((Number) obj1).doubleValue(), ((Number) obj2).doubleValue()); - case String: - return ((String) obj1).compareTo((String) obj2); - default: - throw new ClassCastException(String.format("Unexpected type: %s", type1.toString())); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemType.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemType.java deleted file mode 100644 index 508e8f7cdd9d..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemType.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -public enum ItemType { - NoValue(0x0), Null(0x1), Boolean(0x2), Number(0x4), String(0x5); - - private final int val; - - ItemType(int val) { - this.val = val; - } - - public int getVal() { - return this.val; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemTypeHelper.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemTypeHelper.java deleted file mode 100644 index 9798739b6ea5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/ItemTypeHelper.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -import com.microsoft.azure.cosmosdb.Undefined; - -public final class ItemTypeHelper { - public static ItemType getOrderByItemType(Object obj) { - if (obj == null) { - return ItemType.Null; - } - - if (obj instanceof Undefined) { - return ItemType.NoValue; - } - - if (obj instanceof Boolean) { - return ItemType.Boolean; - } - - if (obj instanceof Number) { - return ItemType.Number; - } - - if (obj instanceof String) { - return ItemType.String; - } - - throw new IllegalArgumentException(String.format("Unexpected type: %s", obj.getClass().toString())); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/PartitionedQueryExecutionInfo.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/PartitionedQueryExecutionInfo.java deleted file mode 100644 index 5bcf61ef9ba2..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/PartitionedQueryExecutionInfo.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -import java.util.List; - -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.routing.Range; - -/** - * Used internally to encapsulates execution information for a query in the Azure Cosmos DB database service. - */ -public final class PartitionedQueryExecutionInfo extends JsonSerializable { - @SuppressWarnings("unchecked") - private static final Class> QUERY_RANGES_CLASS = (Class>) Range - .getEmptyRange((String) null).getClass(); - - private QueryInfo queryInfo; - private List> queryRanges; - - PartitionedQueryExecutionInfo(QueryInfo queryInfo, List> queryRanges) { - this.queryInfo = queryInfo; - this.queryRanges = queryRanges; - - super.set( - PartitionedQueryExecutionInfoInternal.PARTITIONED_QUERY_EXECUTION_INFO_VERSION_PROPERTY, - Constants.PartitionedQueryExecutionInfo.VERSION_1); - } - - public PartitionedQueryExecutionInfo(String jsonString) { - super(jsonString); - } - - public int getVersion() { - return super.getInt(PartitionedQueryExecutionInfoInternal.PARTITIONED_QUERY_EXECUTION_INFO_VERSION_PROPERTY); - } - - public QueryInfo getQueryInfo() { - return this.queryInfo != null ? this.queryInfo - : (this.queryInfo = super.getObject( - PartitionedQueryExecutionInfoInternal.QUERY_INFO_PROPERTY, QueryInfo.class)); - } - - public List> getQueryRanges() { - return this.queryRanges != null ? this.queryRanges - : (this.queryRanges = super.getList( - PartitionedQueryExecutionInfoInternal.QUERY_RANGES_PROPERTY, QUERY_RANGES_CLASS)); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/PartitionedQueryExecutionInfoInternal.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/PartitionedQueryExecutionInfoInternal.java deleted file mode 100644 index cd4e4d673ebc..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/PartitionedQueryExecutionInfoInternal.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -import java.util.List; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.internal.routing.Range; - -public final class PartitionedQueryExecutionInfoInternal extends JsonSerializable { - static final String QUERY_INFO_PROPERTY = "queryInfo"; - static final String QUERY_RANGES_PROPERTY = "queryRanges"; - static final String PARTITIONED_QUERY_EXECUTION_INFO_VERSION_PROPERTY = "partitionedQueryExecutionInfoVersion"; - - @SuppressWarnings("unchecked") - private static final Class> QUERY_RANGE_CLASS = (Class>) Range - .getEmptyRange((PartitionKeyInternal) null).getClass(); - - private QueryInfo queryInfo; - private List> queryRanges; - - public PartitionedQueryExecutionInfoInternal() { - super.set(PARTITIONED_QUERY_EXECUTION_INFO_VERSION_PROPERTY, Constants.PartitionedQueryExecutionInfo.VERSION_1); - } - - public PartitionedQueryExecutionInfoInternal(String jsonString) { - super(jsonString); - } - - public int getVersion() { - return super.getInt(PARTITIONED_QUERY_EXECUTION_INFO_VERSION_PROPERTY); - } - - public QueryInfo getQueryInfo() { - return this.queryInfo != null ? this.queryInfo - : (this.queryInfo = super.getObject(QUERY_INFO_PROPERTY, QueryInfo.class)); - } - - public void setQueryInfo(QueryInfo queryInfo) { - this.queryInfo = queryInfo; - } - - public List> getQueryRanges() { - return this.queryRanges != null ? this.queryRanges - : (this.queryRanges = super.getList(QUERY_RANGES_PROPERTY, QUERY_RANGE_CLASS)); - } - - public void setQueryRanges(List> queryRanges) { - this.queryRanges = queryRanges; - } - - public String toJson() { - try { - return Utils.getSimpleObjectMapper().writeValueAsString(this); - } catch (JsonProcessingException e) { - throw new IllegalStateException("Unable to serialize partition query execution info internal."); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/QueryInfo.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/QueryInfo.java deleted file mode 100644 index 666011b837da..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/QueryInfo.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -import java.util.Collection; -import java.util.List; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.AggregateOperator; - -/** - * Used internally to encapsulates a query's information in the Azure Cosmos DB database service. - */ -public final class QueryInfo extends JsonSerializable { - private Integer top; - private List orderBy; - private Collection aggregates; - private Collection orderByExpressions; - private String rewrittenQuery; - - public QueryInfo() { } - - public QueryInfo(String jsonString) { - super(jsonString); - } - - public Integer getTop() { - return this.top != null ? this.top : (this.top = super.getInt("top")); - } - - public List getOrderBy() { - return this.orderBy != null ? this.orderBy : (this.orderBy = super.getList("orderBy", SortOrder.class)); - } - - public String getRewrittenQuery() { - return this.rewrittenQuery != null ? this.rewrittenQuery - : (this.rewrittenQuery = super.getString("rewrittenQuery")); - } - - public boolean hasTop() { - return this.getTop() != null; - } - - public boolean hasOrderBy() { - Collection orderBy = this.getOrderBy(); - return orderBy != null && orderBy.size() > 0; - } - - public boolean hasRewrittenQuery() { - return !StringUtils.isEmpty(this.getRewrittenQuery()); - } - - public boolean hasAggregates() { - Collection aggregates = this.getAggregates(); - return aggregates != null && aggregates.size() > 0; - } - - public Collection getAggregates() { - return this.aggregates != null - ? this.aggregates - : (this.aggregates = super.getCollection("aggregates", AggregateOperator.class)); - } - - public Collection getOrderByExpressions() { - return this.orderByExpressions != null - ? this.orderByExpressions - : (this.orderByExpressions = super.getCollection("orderByExpressions", String.class)); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/QueryItem.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/QueryItem.java deleted file mode 100644 index e9756aa55161..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/QueryItem.java +++ /dev/null @@ -1,48 +0,0 @@ - -/** - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.Undefined; - -/** - * Used internally for query in the Azure Cosmos DB database service. - */ -public final class QueryItem extends JsonSerializable { - private Object item; - - public QueryItem(String jsonString) { - super(jsonString); - } - - public Object getItem() { - if (this.item == null) { - Object rawItem = super.get("item"); - this.item = super.has("item") ? rawItem : Undefined.Value(); - } - - return this.item; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/SortOrder.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/SortOrder.java deleted file mode 100644 index af02ac9530ab..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/SortOrder.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query; - -/** - * Sort order in the Azure Cosmos DB database service. - */ -public enum SortOrder { - Ascending, Descending, -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/AggregateOperator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/AggregateOperator.java deleted file mode 100644 index 18b9b7edeb8b..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/AggregateOperator.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.aggregation; - -public enum AggregateOperator { - Average, - Count, - Max, - Min, - Sum -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/Aggregator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/Aggregator.java deleted file mode 100644 index ea4ad348f5ec..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/Aggregator.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.aggregation; - -public interface Aggregator { - void aggregate(Object item); - - Object getResult(); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/AverageAggregator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/AverageAggregator.java deleted file mode 100644 index d2b66dd60826..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/AverageAggregator.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.aggregation; - -import java.io.IOException; - -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.Utils; - -public class AverageAggregator implements Aggregator { - private AverageInfo averageInfo; - - public AverageAggregator() { - this.averageInfo = new AverageInfo(); - } - - @Override - public void aggregate(Object item) { - AverageInfo averageInfo; - try { - averageInfo = Utils.getSimpleObjectMapper().readValue(item.toString(), AverageInfo.class); - } catch (IOException e) { - throw new IllegalStateException("Failed to deserialize aggregate result"); - } - this.averageInfo.add(averageInfo); - } - - @Override - public Object getResult() { - return this.averageInfo.getAverage(); - } - - private static class AverageInfo { - public Double sum; - public long count; - - public void add(AverageInfo other) { - if (other == null) { - throw new IllegalArgumentException("other"); - } - if (other.sum == null) { - return; - } - if (this.sum == null) { - this.sum = 0.0; - } - - this.sum += other.sum; - this.count += other.count; - } - - Object getAverage() { - if (this.sum == null || this.count <= 0) { - return Undefined.Value(); - } - return this.sum / this.count; - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/CountAggregator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/CountAggregator.java deleted file mode 100644 index 2589f0699006..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/CountAggregator.java +++ /dev/null @@ -1,39 +0,0 @@ - -/** - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.aggregation; - -public class CountAggregator implements Aggregator { - private long value; - - @Override - public void aggregate(Object item) { - value += Long.parseLong(item.toString()); - } - - @Override - public Object getResult() { - return value; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/MaxAggregator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/MaxAggregator.java deleted file mode 100644 index fc3ba6d86094..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/MaxAggregator.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.aggregation; - -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.query.ItemComparator; - -public class MaxAggregator implements Aggregator { - private Object value; - - public MaxAggregator() { - this.value = Undefined.Value(); - } - - @Override - public void aggregate(Object item) { - if (Undefined.Value().equals(this.value)) { - this.value = item; - } else if (ItemComparator.getInstance().compare(item, this.value) > 0) { - this.value = item; - } - - } - - @Override - public Object getResult() { - return this.value; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/MinAggregator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/MinAggregator.java deleted file mode 100644 index 344b24f3ba80..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/MinAggregator.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.aggregation; - -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.query.ItemComparator; - -public class MinAggregator implements Aggregator { - private Object value; - - public MinAggregator() { - this.value = Undefined.Value(); - } - - @Override - public void aggregate(Object item) { - if (Undefined.Value().equals(this.value)) { - this.value = item; - } else if (ItemComparator.getInstance().compare(item, this.value) < 0) { - this.value = item; - } - } - - @Override - public Object getResult() { - return this.value; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/SumAggregator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/SumAggregator.java deleted file mode 100644 index ebf2b23437e0..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/aggregation/SumAggregator.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.aggregation; - -import com.microsoft.azure.cosmosdb.Undefined; - -public class SumAggregator implements Aggregator { - private Double sum; - - @Override - public void aggregate(Object item) { - if (Undefined.Value().equals(item)) { - return; - } - - if (this.sum == null) { - this.sum = 0.0; - } - this.sum += ((Number) item).doubleValue(); - } - - @Override - public Object getResult() { - if (this.sum == null) { - return Undefined.Value(); - } - return this.sum; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/orderbyquery/OrderByRowResult.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/orderbyquery/OrderByRowResult.java deleted file mode 100644 index 18a0ffa102d0..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/orderbyquery/OrderByRowResult.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.orderbyquery; - -import java.util.List; - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; - -/** - * Represents the result of a query in the Azure Cosmos DB database service. - */ -public final class OrderByRowResult extends Document { - private final Class klass; - private volatile List orderByItems; - private volatile T payload; - private final PartitionKeyRange targetRange; - private final String backendContinuationToken; - - public OrderByRowResult( - Class klass, - String jsonString, - PartitionKeyRange targetRange, - String backendContinuationToken) { - super(jsonString); - this.klass = klass; - this.targetRange = targetRange; - this.backendContinuationToken = backendContinuationToken; - } - - public List getOrderByItems() { - return this.orderByItems != null ? this.orderByItems - : (this.orderByItems = super.getList("orderByItems", QueryItem.class)); - } - - public T getPayload() { - return this.payload != null ? this.payload : (this.payload = super.getObject("payload", klass)); - } - - public PartitionKeyRange getSourcePartitionKeyRange() { - return this.targetRange; - } - - public String getSourceBackendContinuationToken() { - return this.backendContinuationToken; - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/orderbyquery/OrderbyRowComparer.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/orderbyquery/OrderbyRowComparer.java deleted file mode 100644 index 7606c7262949..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/query/orderbyquery/OrderbyRowComparer.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.query.orderbyquery; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.internal.query.ItemComparator; -import com.microsoft.azure.cosmosdb.internal.query.ItemType; -import com.microsoft.azure.cosmosdb.internal.query.ItemTypeHelper; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; -import com.microsoft.azure.cosmosdb.internal.query.SortOrder; - -public final class OrderbyRowComparer implements Comparator> { - private static final Logger logger = LoggerFactory.getLogger(OrderbyRowComparer.class); - - private final List sortOrders; - private volatile List itemTypes; - - public OrderbyRowComparer(Collection sortOrders) { - this.sortOrders = new ArrayList<>(sortOrders); - } - - @Override - public int compare(OrderByRowResult r1, OrderByRowResult r2) { - try { - // comparing document (row) vs document (row) - List result1 = r1.getOrderByItems(); - List result2 = r2.getOrderByItems(); - - if (result1.size() != result2.size()) { - throw new IllegalStateException("OrderByItems cannot have different sizes."); - } - - if (result1.size() != this.sortOrders.size()) { - throw new IllegalStateException( - String.format("OrderByItems cannot have a different size than sort orders.")); - } - - if (this.itemTypes == null) { - synchronized (this) { - if (this.itemTypes == null) { - this.itemTypes = new ArrayList(result1.size()); - for (QueryItem item : result1) { - this.itemTypes.add(ItemTypeHelper.getOrderByItemType(item.getItem())); - } - } - } - } - - this.checkOrderByItemType(result1); - this.checkOrderByItemType(result2); - - for (int i = 0; i < result1.size(); ++i) { - int cmp = ItemComparator.getInstance().compare(result1.get(i).getItem(), result2.get(i).getItem()); - if (cmp != 0) { - switch (this.sortOrders.get(i)) { - case Ascending: - return cmp; - case Descending: - return -cmp; - } - } - } - - return r1.getSourcePartitionKeyRange().getMinInclusive().compareTo(r2.getSourcePartitionKeyRange().getMinInclusive()); - } catch (Exception e) { - // Due to a bug in rxjava-extras <= 0.8.0.15 dependency, - // if OrderbyRowComparer throws an unexpected exception, - // then the observable returned by Transformers.orderedMergeWith(.) will never emit a terminal event. - // rxjava-extras lib provided a quick fix on the bugreport: - // https://github.com/davidmoten/rxjava-extras/issues/30 (0.8.0.16) - // we are also capturing the exception stacktrace here - logger.error("Orderby Row comparision failed {}, {}", r1.toJson(), r2.toJson(), e); - throw e; - } - } - - private void checkOrderByItemType(List orderByItems) { - for (int i = 0; i < this.itemTypes.size(); ++i) { - ItemType type = ItemTypeHelper.getOrderByItemType(orderByItems.get(i).getItem()); - if (type != this.itemTypes.get(i)) { - throw new UnsupportedOperationException( - String.format("Expected %s, but got %s.", this.itemTypes.get(i).toString(), type.toString())); - } - } - } - - public List getSortOrders() { - return this.sortOrders; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/CaseInsensitiveHashMap.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/CaseInsensitiveHashMap.java deleted file mode 100644 index 086508469532..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/CaseInsensitiveHashMap.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.function.Function; - - -// TODO: commons-collections lib has CaseInsensitiveHashMap we should switch to that. -// https://commons.apache.org/proper/commons-collections/javadocs/api-3.2.2/org/apache/commons/collections/map/CaseInsensitiveMap.html -public class CaseInsensitiveHashMap extends HashMap { - - private static String safeToLower(String key) { - return key != null ? key.toLowerCase() : null; - } - - @Override - public V get(Object key) { - return super.get(safeToLower((String) key)); - } - - - @Override - public void putAll(Map m) { - super.putAll(m); - } - - @Override - public V put(String key, V value) { - return super.put(safeToLower(key), value); - } - - @Override - public V putIfAbsent(String key, V value) { - return super.putIfAbsent(safeToLower(key), value); - } - - @Override - public V compute(String key, BiFunction remappingFunction) { - return super.compute(safeToLower(key), remappingFunction); - } - - @Override - public V computeIfAbsent(String key, Function mappingFunction) { - return super.computeIfAbsent(safeToLower(key), mappingFunction); - } - - @Override - public V computeIfPresent(String key, BiFunction remappingFunction) { - return super.computeIfPresent(safeToLower(key), remappingFunction); - } - - @Override - public boolean containsKey(Object key) { - return super.containsKey(safeToLower((String) key)); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/CollectionRoutingMap.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/CollectionRoutingMap.java deleted file mode 100644 index 5cc477ac4694..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/CollectionRoutingMap.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.util.Collection; -import java.util.List; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import org.apache.commons.lang3.tuple.ImmutablePair; - -/** - * Used internally in request routing in the Azure Cosmos DB database service. - */ -public interface CollectionRoutingMap { - List getOrderedPartitionKeyRanges(); - - PartitionKeyRange getRangeByEffectivePartitionKey(String effectivePartitionKeyValue); - - PartitionKeyRange getRangeByPartitionKeyRangeId(String partitionKeyRangeId); - - Collection getOverlappingRanges(Range range); - - Collection getOverlappingRanges(Collection> providedPartitionKeyRanges); - - PartitionKeyRange tryGetRangeByPartitionKeyRangeId(String partitionKeyRangeId); - - IServerIdentity tryGetInfoByPartitionKeyRangeId(String partitionKeyRangeId); - - boolean IsGone(String partitionKeyRangeId); - - String getCollectionUniqueId(); - - CollectionRoutingMap tryCombine(List> ranges); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/IServerIdentity.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/IServerIdentity.java deleted file mode 100644 index ca5a849739e8..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/IServerIdentity.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -public interface IServerIdentity { -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/InMemoryCollectionRoutingMap.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/InMemoryCollectionRoutingMap.java deleted file mode 100644 index b17205ddd6e8..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/InMemoryCollectionRoutingMap.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; -import java.util.stream.Collectors; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import org.apache.commons.lang3.tuple.Pair; - -/** - * Used internally to cache partition key ranges of a collection in the Azure Cosmos DB database service. - */ -public class InMemoryCollectionRoutingMap implements CollectionRoutingMap { - private final Map> rangeById; - private final List orderedPartitionKeyRanges; - private final List> orderedRanges; - - private final Set goneRanges; - - private String collectionUniqueId; - - private InMemoryCollectionRoutingMap(Map> rangeById, - List orderedPartitionKeyRanges, - String collectionUniqueId) { - this.rangeById = rangeById; - this.orderedPartitionKeyRanges = orderedPartitionKeyRanges; - this.orderedRanges = orderedPartitionKeyRanges.stream().map( - range -> - new Range<>( - range.getMinInclusive(), - range.getMaxExclusive(), - true, - false)).collect(Collectors.toList()); - - this.collectionUniqueId = collectionUniqueId; - this.goneRanges = new HashSet<>(orderedPartitionKeyRanges.stream().flatMap(r -> CollectionUtils.emptyIfNull(r.getParents()).stream()).collect(Collectors.toSet())); - - } - - public static InMemoryCollectionRoutingMap tryCreateCompleteRoutingMap( - Iterable> ranges, String collectionUniqueId) { - - Map> rangeById = - new HashMap<>(); - - for (ImmutablePair range: ranges) { - rangeById.put(range.left.getId(), range); - } - - List> sortedRanges = new ArrayList<>(rangeById.values()); - Collections.sort(sortedRanges, new MinPartitionKeyPairComparator()); - List orderedRanges = sortedRanges.stream().map(range -> range.left).collect(Collectors.toList()); - - if (!isCompleteSetOfRanges(orderedRanges)) { - return null; - } - - return new InMemoryCollectionRoutingMap(rangeById, orderedRanges, collectionUniqueId); - } - - private static boolean isCompleteSetOfRanges(List orderedRanges) { - boolean isComplete = false; - if (orderedRanges.size() > 0) { - PartitionKeyRange firstRange = orderedRanges.get(0); - PartitionKeyRange lastRange = orderedRanges.get(orderedRanges.size() - 1); - isComplete = firstRange.getMinInclusive() - .compareTo(PartitionKeyRange.MINIMUM_INCLUSIVE_EFFECTIVE_PARTITION_KEY) == 0; - isComplete &= lastRange.getMaxExclusive() - .compareTo(PartitionKeyRange.MAXIMUM_EXCLUSIVE_EFFECTIVE_PARTITION_KEY) == 0; - - for (int i = 1; i < orderedRanges.size(); i++) { - PartitionKeyRange previousRange = orderedRanges.get(i - 1); - PartitionKeyRange currentRange = orderedRanges.get(i); - isComplete &= previousRange.getMaxExclusive().compareTo(currentRange.getMinInclusive()) == 0; - - if (!isComplete) { - if (previousRange.getMaxExclusive().compareTo(currentRange.getMinInclusive()) > 0) { - throw new IllegalStateException("Ranges overlap"); - } - - break; - } - } - } - - return isComplete; - } - - public String getCollectionUniqueId() { - return collectionUniqueId; - } - - @Override - public List getOrderedPartitionKeyRanges() { - return this.orderedPartitionKeyRanges; - } - - @Override - public PartitionKeyRange getRangeByEffectivePartitionKey(String effectivePartitionKeyValue) { - if (PartitionKeyRange.MINIMUM_INCLUSIVE_EFFECTIVE_PARTITION_KEY.compareTo(effectivePartitionKeyValue) == 0) { - return this.orderedPartitionKeyRanges.get(0); - } - - if (PartitionKeyRange.MAXIMUM_EXCLUSIVE_EFFECTIVE_PARTITION_KEY.compareTo(effectivePartitionKeyValue) == 0) { - return null; - } - - int index = Collections.binarySearch(this.orderedRanges, Range.getPointRange(effectivePartitionKeyValue), - new Range.MinComparator()); - - if (index < 0) { - index = Math.max(0, -index - 2); - } - - return this.orderedPartitionKeyRanges.get(index); - } - - @Override - public PartitionKeyRange getRangeByPartitionKeyRangeId(String partitionKeyRangeId) { - ImmutablePair pair = this.rangeById.get(partitionKeyRangeId); - return pair == null ? null : pair.left; - } - - - @Override - public Collection getOverlappingRanges(Range range) { - return this.getOverlappingRanges(Collections.singletonList(range)); - } - - @Override - public Collection getOverlappingRanges(Collection> providedPartitionKeyRanges) { - if (providedPartitionKeyRanges == null) { - throw new IllegalArgumentException("providedPartitionKeyRanges"); - } - - Map partitionRanges = new TreeMap(); - - for (Range range : providedPartitionKeyRanges) { - int minIndex = Collections.binarySearch(this.orderedRanges, range, new Range.MinComparator()); - if (minIndex < 0) { - minIndex = Math.max(minIndex, -minIndex - 2); - } - - int maxIndex = Collections.binarySearch(this.orderedRanges, range, new Range.MaxComparator()); - if (maxIndex < 0) { - maxIndex = Math.min(this.orderedRanges.size() - 1, -maxIndex - 1); - } - - for (int i = minIndex; i <= maxIndex; ++i) { - if (Range.checkOverlapping(this.orderedRanges.get(i), range)) { - PartitionKeyRange partitionKeyRange = this.orderedPartitionKeyRanges.get(i); - partitionRanges.put(partitionKeyRange.getMinInclusive(), partitionKeyRange); - } - } - } - - return partitionRanges.values(); - } - - - @Override - public PartitionKeyRange tryGetRangeByPartitionKeyRangeId(String partitionKeyRangeId) - { - Pair addresses; - addresses = this.rangeById.get(partitionKeyRangeId); - if (addresses != null) { - return addresses.getLeft(); - } - - return null; - } - - @Override - public IServerIdentity tryGetInfoByPartitionKeyRangeId(String partitionKeyRangeId) - { - Pair addresses; - addresses = this.rangeById.get(partitionKeyRangeId); - if (addresses != null) { - return addresses.getRight(); - } - - return null; - } - - @Override - public boolean IsGone(String partitionKeyRangeId) { - return this.goneRanges.contains(partitionKeyRangeId); - } - - private static class MinPartitionKeyPairComparator - implements Comparator> { - public int compare(ImmutablePair pair1, - ImmutablePair pair2) { - return pair1.left.getMinInclusive().compareTo(pair2.left.getMinInclusive()); - } - } - - - public CollectionRoutingMap tryCombine( - List> ranges) { - Set newGoneRanges = new HashSet<>(ranges.stream().flatMap(tuple -> CollectionUtils.emptyIfNull(tuple.getLeft().getParents()).stream()).collect(Collectors.toSet())); - newGoneRanges.addAll(this.goneRanges); - - Map> newRangeById = - this.rangeById.values().stream().filter(tuple -> !newGoneRanges.contains(tuple.left.getId())).collect(Collectors. - toMap(tuple -> tuple.left.getId(), tuple -> tuple)); - - for (ImmutablePair tuple : ranges.stream().filter(tuple -> !newGoneRanges.contains(tuple.getLeft().getId())).collect(Collectors.toList())) { - newRangeById.put(tuple.getLeft().getId(), tuple); - } - - List> sortedRanges = newRangeById.values().stream().collect(Collectors.toList()); - - Collections.sort(sortedRanges, new MinPartitionKeyPairComparator()); - - List newOrderedRanges = sortedRanges.stream().map(range -> range.left).collect(Collectors.toList()); - - if (!isCompleteSetOfRanges(newOrderedRanges)) { - return null; - } - - return new InMemoryCollectionRoutingMap(newRangeById, newOrderedRanges, this.getCollectionUniqueId()); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/LocationCache.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/LocationCache.java deleted file mode 100644 index d730343526ab..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/LocationCache.java +++ /dev/null @@ -1,581 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.DatabaseAccountLocation; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.apache.commons.collections4.map.CaseInsensitiveMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.commons.collections4.list.UnmodifiableList; -import org.apache.commons.collections4.map.UnmodifiableMap; -import java.net.URL; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.BiFunction; -import java.util.stream.Collectors; - -/** - * Implements the abstraction to resolve target location for geo-replicated DatabaseAccount - * with multiple writable and readable locations. - */ -public class LocationCache { - private final static Logger logger = LoggerFactory.getLogger(LocationCache.class); - - private final boolean enableEndpointDiscovery; - private final URL defaultEndpoint; - private final boolean useMultipleWriteLocations; - private final Object lockObject; - private final Duration unavailableLocationsExpirationTime; - private final ConcurrentHashMap locationUnavailabilityInfoByEndpoint; - - private DatabaseAccountLocationsInfo locationInfo; - - private Instant lastCacheUpdateTimestamp; - private boolean enableMultipleWriteLocations; - - public LocationCache( - List preferredLocations, - URL defaultEndpoint, - boolean enableEndpointDiscovery, - boolean useMultipleWriteLocations, - Configs configs) { - this.locationInfo = new DatabaseAccountLocationsInfo(preferredLocations, defaultEndpoint); - this.defaultEndpoint = defaultEndpoint; - this.enableEndpointDiscovery = enableEndpointDiscovery; - this.useMultipleWriteLocations = useMultipleWriteLocations; - - this.lockObject = new Object(); - - - this.locationUnavailabilityInfoByEndpoint = new ConcurrentHashMap<>(); - - this.lastCacheUpdateTimestamp = Instant.MIN; - this.enableMultipleWriteLocations = false; - this.unavailableLocationsExpirationTime = Duration.ofSeconds(configs.getUnavailableLocationsExpirationTimeInSeconds()); - } - - /** - * Gets list of read endpoints ordered by - * - * 1. Preferred location - * 2. Endpoint availability - * @return - */ - public UnmodifiableList getReadEndpoints() { - if (this.locationUnavailabilityInfoByEndpoint.size() > 0 - && unavailableLocationsExpirationTimePassed()) { - this.updateLocationCache(); - } - - return this.locationInfo.readEndpoints; - } - - /** - * Gets list of write endpoints ordered by - * 1. Preferred location - * 2. Endpoint availability - * @return - */ - public UnmodifiableList getWriteEndpoints() { - if (this.locationUnavailabilityInfoByEndpoint.size() > 0 - && unavailableLocationsExpirationTimePassed()) { - this.updateLocationCache(); - } - - return this.locationInfo.writeEndpoints; - } - - /** - * Marks the current location unavailable for read - */ - public void markEndpointUnavailableForRead(URL endpoint) { - this.markEndpointUnavailable(endpoint, OperationType.Read); - } - - /** - * Marks the current location unavailable for write - */ - public void markEndpointUnavailableForWrite(URL endpoint) { - this.markEndpointUnavailable(endpoint, OperationType.Write); - } - - /** - * Invoked when {@link DatabaseAccount} is read - * @param databaseAccount Read DatabaseAccount - */ - public void onDatabaseAccountRead(DatabaseAccount databaseAccount) { - this.updateLocationCache( - databaseAccount.getWritableLocations(), - databaseAccount.getReadableLocations(), - null, - BridgeInternal.isEnableMultipleWriteLocations(databaseAccount)); - } - - void onLocationPreferenceChanged(UnmodifiableList preferredLocations) { - this.updateLocationCache( - null, null , preferredLocations, null); - } - - /** - * Resolves request to service endpoint. - * 1. If this is a write request - * (a) If UseMultipleWriteLocations = true - * (i) For document writes, resolve to most preferred and available write endpoint. - * Once the endpoint is marked unavailable, it is moved to the end of available write endpoint. Current request will - * be retried on next preferred available write endpoint. - * (ii) For all other resources, always resolve to first/second (regardless of preferred locations) - * write endpoint in {@link DatabaseAccount#getWritableLocations()}. - * Endpoint of first write location in {@link DatabaseAccount#getWritableLocations()} is the only endpoint that supports - * write operation on all resource types (except during that region's failover). - * Only during manual failover, client would retry write on second write location in {@link DatabaseAccount#getWritableLocations()}. - * (b) Else resolve the request to first write endpoint in {@link DatabaseAccount#getWritableLocations()} OR - * second write endpoint in {@link DatabaseAccount#getWritableLocations()} in case of manual failover of that location. - * 2. Else resolve the request to most preferred available read endpoint (automatic failover for read requests) - * @param request Request for which endpoint is to be resolved - * @return Resolved endpoint - */ - public URL resolveServiceEndpoint(RxDocumentServiceRequest request) { - if(request.requestContext != null && request.requestContext.locationEndpointToRoute != null) { - return request.requestContext.locationEndpointToRoute; - } - - int locationIndex = Utils.getValueOrDefault(request.requestContext.locationIndexToRoute, 0); - - boolean usePreferredLocations = request.requestContext.usePreferredLocations != null ? request.requestContext.usePreferredLocations : true; - if(!usePreferredLocations || (request.getOperationType().isWriteOperation() && !this.canUseMultipleWriteLocations(request))) { - // For non-document resource types in case of client can use multiple write locations - // or when client cannot use multiple write locations, flip-flop between the - // first and the second writable region in DatabaseAccount (for manual failover) - DatabaseAccountLocationsInfo currentLocationInfo = this.locationInfo; - - if(this.enableEndpointDiscovery && currentLocationInfo.availableWriteLocations.size() > 0) { - locationIndex = Math.min(locationIndex%2, currentLocationInfo.availableWriteLocations.size()-1); - String writeLocation = currentLocationInfo.availableWriteLocations.get(locationIndex); - return currentLocationInfo.availableWriteEndpointByLocation.get(writeLocation); - } else { - return this.defaultEndpoint; - } - } else { - UnmodifiableList endpoints = request.getOperationType().isWriteOperation()? this.getWriteEndpoints() : this.getReadEndpoints(); - return endpoints.get(locationIndex % endpoints.size()); - } - } - - public boolean shouldRefreshEndpoints(Utils.ValueHolder canRefreshInBackground) { - canRefreshInBackground.v = true; - DatabaseAccountLocationsInfo currentLocationInfo = this.locationInfo; - String mostPreferredLocation = Utils.firstOrDefault(currentLocationInfo.preferredLocations); - - // we should schedule refresh in background if we are unable to target the user's most preferredLocation. - if (this.enableEndpointDiscovery) { - - boolean shouldRefresh = this.useMultipleWriteLocations && !this.enableMultipleWriteLocations; - if (!Strings.isNullOrEmpty(mostPreferredLocation)) { - Utils.ValueHolder mostPreferredReadEndpointHolder = new Utils.ValueHolder<>(); - List readLocationEndpoints = currentLocationInfo.readEndpoints; - logger.debug("getReadEndpoints [{}]", readLocationEndpoints); - - if (Utils.tryGetValue(currentLocationInfo.availableReadEndpointByLocation, mostPreferredLocation, mostPreferredReadEndpointHolder)) { - logger.debug("most preferred is [{}], most preferred available is [{}]", - mostPreferredLocation, mostPreferredReadEndpointHolder.v); - if (!areEqual(mostPreferredReadEndpointHolder.v, readLocationEndpoints.get(0))) { - // For reads, we can always refresh in background as we can alternate to - // other available read endpoints - logger.debug("shouldRefreshEndpoints = true, most preferred location [{}]" + - " is not available for read.", mostPreferredLocation); - return true; - } - - logger.debug("most preferred is [{}], and most preferred available [{}] are the same", - mostPreferredLocation, mostPreferredReadEndpointHolder.v); - } - else { - logger.debug("shouldRefreshEndpoints = true, most preferred location [{}] " + - "is not in available read locations.", mostPreferredLocation); - return true; - } - } - - Utils.ValueHolder mostPreferredWriteEndpointHolder = new Utils.ValueHolder<>(); - List writeLocationEndpoints = currentLocationInfo.writeEndpoints; - logger.debug("getWriteEndpoints [{}]", writeLocationEndpoints); - - if (!this.canUseMultipleWriteLocations()) { - if (this.isEndpointUnavailable(writeLocationEndpoints.get(0), OperationType.Write)) { - // Since most preferred write endpoint is unavailable, we can only refresh in background if - // we have an alternate write endpoint - canRefreshInBackground.v = writeLocationEndpoints.size() > 1; - logger.debug("shouldRefreshEndpoints = true, most preferred location " + - "[{}] endpoint [{}] is not available for write. canRefreshInBackground = [{}]", - mostPreferredLocation, - writeLocationEndpoints.get(0), - canRefreshInBackground.v); - - return true; - } else { - logger.debug("shouldRefreshEndpoints: false, [{}] is available for Write", writeLocationEndpoints.get(0)); - return shouldRefresh; - } - } else if (!Strings.isNullOrEmpty(mostPreferredLocation)) { - if (Utils.tryGetValue(currentLocationInfo.availableWriteEndpointByLocation, mostPreferredLocation, mostPreferredWriteEndpointHolder)) { - shouldRefresh = ! areEqual(mostPreferredWriteEndpointHolder.v,writeLocationEndpoints.get(0)); - - if (shouldRefresh) { - logger.debug("shouldRefreshEndpoints: true, write endpoint [{}] is not the same as most preferred [{}]", - writeLocationEndpoints.get(0), mostPreferredWriteEndpointHolder.v); - } else { - logger.debug("shouldRefreshEndpoints: false, write endpoint [{}] is the same as most preferred [{}]", - writeLocationEndpoints.get(0), mostPreferredWriteEndpointHolder.v); - } - - return shouldRefresh; - } else { - logger.debug("shouldRefreshEndpoints = true, most preferred location [{}] is not in available write locations", - mostPreferredLocation); - return true; - } - } else { - logger.debug("shouldRefreshEndpoints: false, mostPreferredLocation [{}] is empty", mostPreferredLocation); - return shouldRefresh; - } - } else { - logger.debug("shouldRefreshEndpoints: false, endpoint discovery not enabled"); - return false; - } - } - private boolean areEqual(URL url1, URL url2) { - return url1.equals(url2); - } - - private void clearStaleEndpointUnavailabilityInfo() { - if (!this.locationUnavailabilityInfoByEndpoint.isEmpty()) { - List unavailableEndpoints = new ArrayList<>(this.locationUnavailabilityInfoByEndpoint.keySet()); - - for (URL unavailableEndpoint: unavailableEndpoints) { - Utils.ValueHolder unavailabilityInfoHolder = new Utils.ValueHolder<>(); - Utils.ValueHolder removedHolder = new Utils.ValueHolder<>(); - - if (Utils.tryGetValue(this.locationUnavailabilityInfoByEndpoint, unavailableEndpoint, unavailabilityInfoHolder) - && - durationPassed(Instant.now(), unavailabilityInfoHolder.v.LastUnavailabilityCheckTimeStamp, - this.unavailableLocationsExpirationTime) - - && Utils.tryRemove(this.locationUnavailabilityInfoByEndpoint, unavailableEndpoint, removedHolder)) { - logger.debug( - "Removed endpoint [{}] unavailable for operations [{}] from unavailableEndpoints", - unavailableEndpoint, - unavailabilityInfoHolder.v.UnavailableOperations); - } - } - } - } - - private boolean isEndpointUnavailable(URL endpoint, OperationType expectedAvailableOperations) { - Utils.ValueHolder unavailabilityInfoHolder = new Utils.ValueHolder<>(); - - if (expectedAvailableOperations == OperationType.None - || !Utils.tryGetValue(this.locationUnavailabilityInfoByEndpoint, endpoint, unavailabilityInfoHolder) - || !unavailabilityInfoHolder.v.UnavailableOperations.supports(expectedAvailableOperations)) { - return false; - } else { - if (durationPassed(Instant.now(), unavailabilityInfoHolder.v.LastUnavailabilityCheckTimeStamp, this.unavailableLocationsExpirationTime)) { - return false; - } else { - logger.debug( - "Endpoint [{}] unavailable for operations [{}] present in unavailableEndpoints", - endpoint, - unavailabilityInfoHolder.v.UnavailableOperations); - // Unexpired entry present. Endpoint is unavailable - return true; - } - } - } - - private void markEndpointUnavailable( - URL unavailableEndpoint, - OperationType unavailableOperationType) { - Instant currentTime = Instant.now(); - LocationUnavailabilityInfo updatedInfo = this.locationUnavailabilityInfoByEndpoint.compute( - unavailableEndpoint, - new BiFunction() { - @Override - public LocationUnavailabilityInfo apply(URL url, LocationUnavailabilityInfo info) { - - if (info == null) { - // not already present, add - return new LocationUnavailabilityInfo(currentTime, unavailableOperationType); - } else { - // already present, update - info.LastUnavailabilityCheckTimeStamp = currentTime; - info.UnavailableOperations = OperationType.combine(info.UnavailableOperations, unavailableOperationType); - return info; - } - - } - }); - - this.updateLocationCache(); - - logger.debug( - "Endpoint [{}] unavailable for [{}] added/updated to unavailableEndpoints with timestamp [{}]", - unavailableEndpoint, - unavailableOperationType, - updatedInfo.LastUnavailabilityCheckTimeStamp); - } - - private void updateLocationCache(){ - updateLocationCache(null, null, null, null); - } - - private void updateLocationCache( - Iterable writeLocations, - Iterable readLocations, - UnmodifiableList preferenceList, - Boolean enableMultipleWriteLocations) { - synchronized (this.lockObject) { - DatabaseAccountLocationsInfo nextLocationInfo = new DatabaseAccountLocationsInfo(this.locationInfo); - logger.debug("updating location cache ..., current readLocations [{}], current writeLocations [{}]", - nextLocationInfo.readEndpoints, nextLocationInfo.writeEndpoints); - - if (preferenceList != null) { - nextLocationInfo.preferredLocations = preferenceList; - } - - if (enableMultipleWriteLocations != null) { - this.enableMultipleWriteLocations = enableMultipleWriteLocations; - } - - this.clearStaleEndpointUnavailabilityInfo(); - - if (readLocations != null) { - Utils.ValueHolder> out = Utils.ValueHolder.initialize(nextLocationInfo.availableReadLocations); - nextLocationInfo.availableReadEndpointByLocation = this.getEndpointByLocation(readLocations, out); - nextLocationInfo.availableReadLocations = out.v; - } - - if (writeLocations != null) { - Utils.ValueHolder> out = Utils.ValueHolder.initialize(nextLocationInfo.availableWriteLocations); - nextLocationInfo.availableWriteEndpointByLocation = this.getEndpointByLocation(writeLocations, out); - nextLocationInfo.availableWriteLocations = out.v; - } - - nextLocationInfo.writeEndpoints = this.getPreferredAvailableEndpoints(nextLocationInfo.availableWriteEndpointByLocation, nextLocationInfo.availableWriteLocations, OperationType.Write, this.defaultEndpoint); - nextLocationInfo.readEndpoints = this.getPreferredAvailableEndpoints(nextLocationInfo.availableReadEndpointByLocation, nextLocationInfo.availableReadLocations, OperationType.Read, nextLocationInfo.writeEndpoints.get(0)); - this.lastCacheUpdateTimestamp = Instant.now(); - - logger.debug("updating location cache finished, new readLocations [{}], new writeLocations [{}]", - nextLocationInfo.readEndpoints, nextLocationInfo.writeEndpoints); - this.locationInfo = nextLocationInfo; - } - } - - private UnmodifiableList getPreferredAvailableEndpoints(UnmodifiableMap endpointsByLocation, - UnmodifiableList orderedLocations, - OperationType expectedAvailableOperation, - URL fallbackEndpoint) { - List endpoints = new ArrayList<>(); - DatabaseAccountLocationsInfo currentLocationInfo = this.locationInfo; - // if enableEndpointDiscovery is false, we always use the defaultEndpoint that user passed in during documentClient init - if (this.enableEndpointDiscovery) { - if (this.canUseMultipleWriteLocations() || expectedAvailableOperation.supports(OperationType.Read)) { - List unavailableEndpoints = new ArrayList<>(); - - // When client can not use multiple write locations, preferred locations list should only be used - // determining read endpoints order. - // If client can use multiple write locations, preferred locations list should be used for determining - // both read and write endpoints order. - - for (String location: currentLocationInfo.preferredLocations) { - Utils.ValueHolder endpoint = new Utils.ValueHolder<>(); - if (Utils.tryGetValue(endpointsByLocation, location, endpoint)) { - if (this.isEndpointUnavailable(endpoint.v, expectedAvailableOperation)) { - unavailableEndpoints.add(endpoint.v); - } else { - endpoints.add(endpoint.v); - } - } - } - - if (endpoints.isEmpty()) { - endpoints.add(fallbackEndpoint); - } - - endpoints.addAll(unavailableEndpoints); - } else { - for (String location : orderedLocations) { - - Utils.ValueHolder endpoint = Utils.ValueHolder.initialize(null); - if (!Strings.isNullOrEmpty(location) && // location is empty during manual failover - Utils.tryGetValue(endpointsByLocation, location, endpoint)) { - endpoints.add(endpoint.v); - } - } - } - } - - if (endpoints.isEmpty()) { - endpoints.add(fallbackEndpoint); - } - - return new UnmodifiableList(endpoints); - } - - private UnmodifiableMap getEndpointByLocation(Iterable locations, - Utils.ValueHolder> orderedLocations) { - Map endpointsByLocation = new CaseInsensitiveMap<>(); - List parsedLocations = new ArrayList<>(); - - for (DatabaseAccountLocation location: locations) { - if (!Strings.isNullOrEmpty(location.getName())) { - try { - URL endpoint = new URL(location.getEndpoint().toLowerCase()); - endpointsByLocation.put(location.getName().toLowerCase(), endpoint); - parsedLocations.add(location.getName()); - - } catch (Exception e) { - logger.warn("GetAvailableEndpointsByLocation() - skipping add for location = [{}] as it is location name is either empty or endpoint is malformed [{}]", - location.getName(), - location.getEndpoint()); - } - } - } - - orderedLocations.v = new UnmodifiableList(parsedLocations); - return (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(endpointsByLocation); - } - - private boolean canUseMultipleWriteLocations() { - return this.useMultipleWriteLocations && this.enableMultipleWriteLocations; - } - - public boolean canUseMultipleWriteLocations(RxDocumentServiceRequest request) { - return this.canUseMultipleWriteLocations() && - (request.getResourceType() == ResourceType.Document || - (request.getResourceType() == ResourceType.StoredProcedure && request.getOperationType() == - com.microsoft.azure.cosmosdb.internal.OperationType.ExecuteJavaScript)); - } - - - private class LocationUnavailabilityInfo { - LocationUnavailabilityInfo(Instant instant, OperationType type) { - this.LastUnavailabilityCheckTimeStamp = instant; - this.UnavailableOperations = type; - } - - public Instant LastUnavailabilityCheckTimeStamp; - public OperationType UnavailableOperations; - } - - private enum OperationType { - None(0x0), - Read(0x1), - Write(0x2), - ReadAndWrite(0x3); - - private final int flag; - - public boolean hasReadFlag() { - return (flag & Read.flag) != 0; - } - - public boolean hasWriteFlag() { - return (flag & Write.flag) != 0; - } - - public static OperationType combine(OperationType t1, OperationType t2) { - switch (t1.flag | t2.flag) { - case 0x0: - return None; - case 0x1: - return Read; - case 0x2: - return Write; - default: - return ReadAndWrite; - } - } - - public boolean supports(OperationType type) { - return (flag & type.flag) != 0; - } - - OperationType(int flag) { - this.flag = flag; - } - } - - private boolean durationPassed(Instant end, Instant start, Duration duration) { - return end.minus(duration).isAfter(start); - } - - private boolean unavailableLocationsExpirationTimePassed() { - return durationPassed(Instant.now(), this.lastCacheUpdateTimestamp, this.unavailableLocationsExpirationTime); - } - - class DatabaseAccountLocationsInfo { - private UnmodifiableList preferredLocations; - // lower-case region - private UnmodifiableList availableWriteLocations; - // lower-case region - private UnmodifiableList availableReadLocations; - private UnmodifiableMap availableWriteEndpointByLocation; - private UnmodifiableMap availableReadEndpointByLocation; - - private UnmodifiableList writeEndpoints; - private UnmodifiableList readEndpoints; - - public DatabaseAccountLocationsInfo(List preferredLocations, - URL defaultEndpoint) { - this.preferredLocations = new UnmodifiableList<>(preferredLocations.stream().map(loc -> loc.toLowerCase()).collect(Collectors.toList())); - this.availableWriteEndpointByLocation = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); - this.availableReadEndpointByLocation = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(new CaseInsensitiveMap<>()); - this.availableReadLocations = new UnmodifiableList<>(Collections.emptyList()); - this.availableWriteLocations = new UnmodifiableList<>(Collections.emptyList()); - this.readEndpoints = new UnmodifiableList<>(Collections.singletonList(defaultEndpoint)); - this.writeEndpoints = new UnmodifiableList<>(Collections.singletonList(defaultEndpoint)); - } - - public DatabaseAccountLocationsInfo(DatabaseAccountLocationsInfo other) { - this.preferredLocations = other.preferredLocations; - this.availableWriteLocations = other.availableWriteLocations; - this.availableReadLocations = other.availableReadLocations; - this.availableWriteEndpointByLocation = other.availableWriteEndpointByLocation; - this.availableReadEndpointByLocation = other.availableReadEndpointByLocation; - this.writeEndpoints = other.writeEndpoints; - this.readEndpoints = other.readEndpoints; - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProvider.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProvider.java deleted file mode 100644 index ce7be3bdf86c..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.util.Collection; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; - -/** - * Used internally in request routing in the Azure Cosmos DB database service. - */ -public interface RoutingMapProvider { - Collection getOverlappingRanges(String collectionSelfLink, Range range, boolean forceRefresh); - - PartitionKeyRange tryGetRangeByEffectivePartitionKey(String collectionSelfLink, String effectivePartitionKey); - - PartitionKeyRange getPartitionKeyRangeById(String collectionSelfLink, String partitionKeyRangeId, boolean forceRefresh); - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProviderHelper.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProviderHelper.java deleted file mode 100644 index ef4311699fa3..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProviderHelper.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; - -/** - * Provide utility functionality to route request in direct connectivity mode in the Azure Cosmos DB database service. - */ -public final class RoutingMapProviderHelper { - private static final Range.MaxComparator MAX_COMPARATOR = new Range.MaxComparator(); - - private static String max(String left, String right) { - return left.compareTo(right) < 0 ? right : left; - } - - private static > boolean IsSortedAndNonOverlapping(List> list) { - for (int i = 1; i < list.size(); i++) { - Range previousRange = list.get(i - 1); - Range currentRange = list.get(i); - - int compareResult = previousRange.getMax().compareTo(currentRange.getMin()); - if (compareResult > 0) { - return false; - } else if (compareResult == 0 && previousRange.isMaxInclusive() && currentRange.isMinInclusive()) { - return false; - } - } - - return true; - } - - public static Collection getOverlappingRanges(RoutingMapProvider routingMapProvider, - String collectionSelfLink, List> sortedRanges) { - if (!IsSortedAndNonOverlapping(sortedRanges)) { - throw new IllegalArgumentException("sortedRanges"); - } - - List targetRanges = new ArrayList(); - int currentProvidedRange = 0; - while (currentProvidedRange < sortedRanges.size()) { - if (sortedRanges.get(currentProvidedRange).isEmpty()) { - currentProvidedRange++; - continue; - } - - Range queryRange; - if (!targetRanges.isEmpty()) { - String left = max(targetRanges.get(targetRanges.size() - 1).getMaxExclusive(), - sortedRanges.get(currentProvidedRange).getMin()); - - boolean leftInclusive = left.compareTo(sortedRanges.get(currentProvidedRange).getMin()) == 0 - ? sortedRanges.get(currentProvidedRange).isMinInclusive() : false; - - queryRange = new Range(left, sortedRanges.get(currentProvidedRange).getMax(), leftInclusive, - sortedRanges.get(currentProvidedRange).isMaxInclusive()); - } else { - queryRange = sortedRanges.get(currentProvidedRange); - } - - targetRanges.addAll(routingMapProvider.getOverlappingRanges(collectionSelfLink, queryRange, false)); - - Range lastKnownTargetRange = targetRanges.get(targetRanges.size() - 1).toRange(); - while (currentProvidedRange < sortedRanges.size() - && MAX_COMPARATOR.compare(sortedRanges.get(currentProvidedRange), lastKnownTargetRange) <= 0) { - currentProvidedRange++; - } - } - - return targetRanges; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/BackoffRetryUtility.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/BackoffRetryUtility.java deleted file mode 100644 index e5240e2fd093..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/BackoffRetryUtility.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; - - -import com.microsoft.azure.cosmosdb.internal.Quadruple; - -import rx.Observable; -import rx.Single; -import rx.functions.Action1; -import rx.functions.Func0; -import rx.functions.Func1; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class BackoffRetryUtility { - - // transforms a retryFunc to a function which can be used by Observable.retryWhen(.) - // also it invokes preRetryCallback prior to doing retry. - public static final Quadruple InitialArgumentValuePolicyArg = Quadruple.with(false, false, - Duration.ofSeconds(60), 0); - - static Func1, Observable> toRetryWhenFunc( - Func1> retryFunc, Action1 preRetryCallback) { - - return new Func1, Observable>() { - - @Override - public Observable call(Observable t) { - - return t.flatMap(f -> { - Exception e = Utils.as(f, Exception.class); - if (e instanceof Exception) { - if (preRetryCallback != null) { - - // TODO: is retry callback invoked immediately on the same thread? - // we should verify this - return retryFunc.call(e).doOnSuccess(v -> preRetryCallback.call(e)).toObservable(); - } else { - return retryFunc.call(e).toObservable(); - } - } else { - return Observable.error(f); - } - }); - } - }; - } - - @SuppressWarnings("unused") - static private Single executeRetry(Func0> callbackMethod, - Func1> callShouldRetry, Action1 preRetryCallback) { - - return Single.defer(() -> { - return callbackMethod.call(); - - }).retryWhen(toRetryWhenFunc(callShouldRetry, preRetryCallback)); - } - - // a helper method for invoking callback method given the retry policy. - // it also invokes the pre retry callback prior to retrying - static public Single executeRetry(Func0> callbackMethod, - IRetryPolicy retryPolicy, - Action1 preRetryCallback) { - - return Single.defer(() -> { - // TODO: is defer required? - return callbackMethod.call(); - }).retryWhen(RetryUtils.toRetryWhenFunc(retryPolicy)); - } - - // a helper method for invoking callback method given the retry policy - static public Single executeRetry(Func0> callbackMethod, - IRetryPolicy retryPolicy) { - - return Single.defer(() -> { - // TODO: is defer required? - return callbackMethod.call(); - }).retryWhen(RetryUtils.toRetryWhenFunc(retryPolicy)); - } - - static public Single executeAsync( - Func1, Single> callbackMethod, IRetryPolicy retryPolicy, - Func1, Single> inBackoffAlternateCallbackMethod, - Duration minBackoffForInBackoffCallback) { - Quadruple policyArg1 = InitialArgumentValuePolicyArg; - - return Single.defer(() -> { - // TODO: is defer required? - return callbackMethod.call(policyArg1).onErrorResumeNext( - RetryUtils.toRetryWithAlternateFunc(callbackMethod,retryPolicy, inBackoffAlternateCallbackMethod,minBackoffForInBackoffCallback)); - }); - } - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ClearingSessionContainerClientRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ClearingSessionContainerClientRetryPolicy.java deleted file mode 100644 index 0ba6bb83f53e..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ClearingSessionContainerClientRetryPolicy.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - * - * This retry policy is designed to work with in a pair with ClientRetryPolicy. - * The inner retryPolicy must be a ClientRetryPolicy or a retry policy delegating to it. - * - * The expectation that is the outer retry policy in the retry policy chain and nobody can overwrite ShouldRetryResult. - * Once we clear the session we expect call to fail and throw exception to the client. Otherwise we may violate session consistency. - */ -public class ClearingSessionContainerClientRetryPolicy implements IDocumentClientRetryPolicy { - - private final static Logger logger = LoggerFactory.getLogger(ClearingSessionContainerClientRetryPolicy.class); - - private final IDocumentClientRetryPolicy retryPolicy; - private final ISessionContainer sessionContainer; - private RxDocumentServiceRequest request; - private boolean hasTriggered = false; - - public ClearingSessionContainerClientRetryPolicy(ISessionContainer sessionContainer, IDocumentClientRetryPolicy retryPolicy) { - this.sessionContainer = sessionContainer; - this.retryPolicy = retryPolicy; - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - this.request = request; - this.retryPolicy.onBeforeSendRequest(request); - } - - @Override - public Single shouldRetry(Exception e) { - - return this.retryPolicy.shouldRetry(e).flatMap(shouldRetryResult -> { - - if (!shouldRetryResult.shouldRetry && !this.hasTriggered) - { - DocumentClientException clientException = Utils.as(e, DocumentClientException.class); - - if (this.request == null) { - // someone didn't call OnBeforeSendRequest - nothing we can do - logger.error("onBeforeSendRequest is not invoked, encountered failure due to request being null", e); - return Single.just(ShouldRetryResult.error(e)); - } - - if (clientException != null && this.request.getIsNameBased() && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.NOTFOUND) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)) - { - // Clear the session token, because the collection name might be reused. - logger.warn("Clear the token for named base request {}", request.getResourceAddress()); - - this.sessionContainer.clearTokenByCollectionFullName(request.getResourceAddress()); - - this.hasTriggered = true; - } - } - - return Single.just(shouldRetryResult); - }); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ClientRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ClientRetryPolicy.java deleted file mode 100644 index a4297517e1a3..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ClientRetryPolicy.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ClientSideRequestStatistics; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.RetryOptions; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WebExceptionUtility; -import org.apache.commons.collections4.list.UnmodifiableList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; - -import java.net.URL; -import java.time.Duration; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - * - * Client policy is combination of endpoint change retry + throttling retry. - */ -public class ClientRetryPolicy implements IDocumentClientRetryPolicy { - - private final static Logger logger = LoggerFactory.getLogger(ClientRetryPolicy.class); - - final static int RetryIntervalInMS = 1000; //Once we detect failover wait for 1 second before retrying request. - final static int MaxRetryCount = 120; - - private final IDocumentClientRetryPolicy throttlingRetry; - private final ConnectionPoolExhaustedRetry rxNettyConnectionPoolExhaustedRetry; - private final GlobalEndpointManager globalEndpointManager; - private final boolean enableEndpointDiscovery; - private int failoverRetryCount; - - private int sessionTokenRetryCount; - private boolean isReadRequest; - private boolean canUseMultipleWriteLocations; - private URL locationEndpoint; - private RetryContext retryContext; - private ClientSideRequestStatistics clientSideRequestStatistics; - - public ClientRetryPolicy(GlobalEndpointManager globalEndpointManager, - boolean enableEndpointDiscovery, - RetryOptions retryOptions) { - - this.throttlingRetry = new ResourceThrottleRetryPolicy( - retryOptions.getMaxRetryAttemptsOnThrottledRequests(), - retryOptions.getMaxRetryWaitTimeInSeconds()); - this.rxNettyConnectionPoolExhaustedRetry = new ConnectionPoolExhaustedRetry(); - this.globalEndpointManager = globalEndpointManager; - this.failoverRetryCount = 0; - this.enableEndpointDiscovery = enableEndpointDiscovery; - this.sessionTokenRetryCount = 0; - this.canUseMultipleWriteLocations = false; - this.clientSideRequestStatistics = new ClientSideRequestStatistics(); - } - - @Override - public Single shouldRetry(Exception e) { - if (this.locationEndpoint == null) { - // on before request is not invoked because Document Service Request creation failed. - logger.error("locationEndpoint is null because ClientRetryPolicy::onBeforeRequest(.) is not invoked, " + - "probably request creation failed due to invalid options, serialization setting, etc."); - return Single.just(ShouldRetryResult.error(e)); - } - - if (ConnectionPoolExhaustedRetry.isConnectionPoolExhaustedException(e)) { - return rxNettyConnectionPoolExhaustedRetry.shouldRetry(e); - } - - this.retryContext = null; - // Received 403.3 on write region, initiate the endpoint re-discovery - DocumentClientException clientException = Utils.as(e, DocumentClientException.class); - if (clientException != null && clientException.getClientSideRequestStatistics() != null) { - this.clientSideRequestStatistics = clientException.getClientSideRequestStatistics(); - } - if (clientException != null && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.FORBIDDEN) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.FORBIDDEN_WRITEFORBIDDEN)) - { - logger.warn("Endpoint not writable. Will refresh cache and retry. {}", e.toString()); - return this.shouldRetryOnEndpointFailureAsync(false); - } - - // Regional endpoint is not available yet for reads (e.g. add/ online of region is in progress) - if (clientException != null && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.FORBIDDEN) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.DATABASE_ACCOUNT_NOTFOUND) && - this.isReadRequest) - { - logger.warn("Endpoint not available for reads. Will refresh cache and retry. {}", e.toString()); - return this.shouldRetryOnEndpointFailureAsync(true); - } - - // Received Connection error (HttpRequestException), initiate the endpoint rediscovery - if (WebExceptionUtility.isNetworkFailure(e)) { - logger.warn("Endpoint not reachable. Will refresh cache and retry. {}" , e.toString()); - return this.shouldRetryOnEndpointFailureAsync(this.isReadRequest); - } - - if (clientException != null && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.NOTFOUND) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)) { - return Single.just(this.shouldRetryOnSessionNotAvailable()); - } - - return this.throttlingRetry.shouldRetry(e); - } - - private ShouldRetryResult shouldRetryOnSessionNotAvailable() { - this.sessionTokenRetryCount++; - - if (!this.enableEndpointDiscovery) { - // if endpoint discovery is disabled, the request cannot be retried anywhere else - return ShouldRetryResult.noRetry(); - } else { - if (this.canUseMultipleWriteLocations) { - UnmodifiableList endpoints = this.isReadRequest ? this.globalEndpointManager.getReadEndpoints() : this.globalEndpointManager.getWriteEndpoints(); - - if (this.sessionTokenRetryCount > endpoints.size()) { - // When use multiple write locations is true and the request has been tried - // on all locations, then don't retry the request - return ShouldRetryResult.noRetry(); - } else { - this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, this.sessionTokenRetryCount > 1); - return ShouldRetryResult.retryAfter(Duration.ZERO); - } - } else { - if (this.sessionTokenRetryCount > 1) { - // When cannot use multiple write locations, then don't retry the request if - // we have already tried this request on the write location - return ShouldRetryResult.noRetry(); - } else { - this.retryContext = new RetryContext(this.sessionTokenRetryCount - 1, false); - return ShouldRetryResult.retryAfter(Duration.ZERO); - } - } - } - } - - private Single shouldRetryOnEndpointFailureAsync(boolean isReadRequest) { - if (!this.enableEndpointDiscovery || this.failoverRetryCount > MaxRetryCount) { - logger.warn("ShouldRetryOnEndpointFailureAsync() Not retrying. Retry count = {}", this.failoverRetryCount); - return Single.just(ShouldRetryResult.noRetry()); - } - - this.failoverRetryCount++; - - // Mark the current read endpoint as unavailable - if (this.isReadRequest) { - logger.warn("marking the endpoint {} as unavailable for read",this.locationEndpoint); - this.globalEndpointManager.markEndpointUnavailableForRead(this.locationEndpoint); - } else { - logger.warn("marking the endpoint {} as unavailable for write",this.locationEndpoint); - this.globalEndpointManager.markEndpointUnavailableForWrite(this.locationEndpoint); - } - - // Some requests may be in progress when the endpoint manager and client are closed. - // In that case, the request won't succeed since the http client is closed. - // Therefore just skip the retry here to avoid the delay because retrying won't go through in the end. - - Duration retryDelay = Duration.ZERO; - if (!this.isReadRequest) { - logger.debug("Failover happening. retryCount {}", this.failoverRetryCount); - if (this.failoverRetryCount > 1) { - //if retried both endpoints, follow regular retry interval. - retryDelay = Duration.ofMillis(ClientRetryPolicy.RetryIntervalInMS); - } - } else { - retryDelay = Duration.ofMillis(ClientRetryPolicy.RetryIntervalInMS); - } - this.retryContext = new RetryContext(this.failoverRetryCount, false); - return this.globalEndpointManager.refreshLocationAsync(null) - .andThen(Single.just(ShouldRetryResult.retryAfter(retryDelay))); - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - this.isReadRequest = request.isReadOnlyRequest(); - this.canUseMultipleWriteLocations = this.globalEndpointManager.CanUseMultipleWriteLocations(request); - if (request.requestContext != null) { - request.requestContext.clientSideRequestStatistics = this.clientSideRequestStatistics; - } - - // clear previous location-based routing directive - if (request.requestContext != null) { - request.requestContext.ClearRouteToLocation(); - } - if (this.retryContext != null) { - // set location-based routing directive based on request retry context - request.requestContext.RouteToLocation(this.retryContext.retryCount, this.retryContext.retryRequestOnPreferredLocations); - } - - // Resolve the endpoint for the request and pin the resolution to the resolved endpoint - // This enables marking the endpoint unavailability on endpoint failover/unreachability - this.locationEndpoint = this.globalEndpointManager.resolveServiceEndpoint(request); - if (request.requestContext != null) { - request.requestContext.RouteToLocation(this.locationEndpoint); - } - } - private class RetryContext { - - public int retryCount; - public boolean retryRequestOnPreferredLocations; - - public RetryContext(int retryCount, - boolean retryRequestOnPreferredLocations) { - this.retryCount = retryCount; - this.retryRequestOnPreferredLocations = retryRequestOnPreferredLocations; - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ConnectionPoolExhaustedRetry.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ConnectionPoolExhaustedRetry.java deleted file mode 100644 index 5f2e166e6ddb..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ConnectionPoolExhaustedRetry.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import io.reactivex.netty.client.PoolExhaustedException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; - -import java.time.Duration; - -// rxnetty in servicing a new request throws PoolExhaustedException -// if all connections are in used and max connection pool size is configured. -class ConnectionPoolExhaustedRetry implements IDocumentClientRetryPolicy { - private static final Logger logger = LoggerFactory.getLogger(ConnectionPoolExhaustedRetry.class); - static final Duration RETRY_WAIT_TIME = Duration.ofMillis(10); - static final int MAX_RETRY_COUNT = 10; - - private int retryCount = 0; - - @Override - public Single shouldRetry(Exception e) { - boolean isConnectionPoolExhaustedException = isConnectionPoolExhaustedException(e); - assert isConnectionPoolExhaustedException; - if (!isConnectionPoolExhaustedException) { - logger.error("Fatal error invalid retry path for {}", e.getMessage(), e); - return Single.just(ShouldRetryResult.error(e)); - } - - if (++retryCount <= MAX_RETRY_COUNT) { - logger.warn("PoolExhaustedException failure indicates" + - " the load on the SDK is higher than what current connection pool size can support" + - " either increase the connection pool size for the configured connection mode," + - " or distribute the load on more machines. retry count {}", retryCount); - return Single.just(ShouldRetryResult.retryAfter(RETRY_WAIT_TIME)); - } else { - logger.error("PoolExhaustedException failure indicates" + - " the load on the SDK is higher than what current connection pool size can support" + - " either increase the connection pool size for the configured connection mode," + - " or distribute the load on more machines. All retries exhausted!"); - return Single.just(ShouldRetryResult.error(e)); - } - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - // no op - } - - static boolean isConnectionPoolExhaustedException(Exception ex) { - while (ex != null) { - if (ex instanceof PoolExhaustedException) { - return true; - } - - Throwable t = ex.getCause(); - if (!(t instanceof Exception)) { - break; - } - - ex = (Exception) t; - } - - return false; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/GlobalEndpointManager.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/GlobalEndpointManager.java deleted file mode 100644 index 6e304f39b7a9..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/GlobalEndpointManager.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.DatabaseAccountManagerInternal; -import com.microsoft.azure.cosmosdb.internal.routing.LocationCache; -import com.microsoft.azure.cosmosdb.rx.internal.routing.LocationHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Completable; -import rx.Observable; -import rx.Scheduler; -import rx.Single; -import rx.functions.Func1; -import rx.schedulers.Schedulers; -import org.apache.commons.collections4.list.UnmodifiableList; - - -import java.net.URISyntaxException; -import java.net.URL; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * Endpoint region cache manager implementation. Supports cross region address routing based on - * availability and preference list. - */ -public class GlobalEndpointManager implements AutoCloseable { - private static final Logger logger = LoggerFactory.getLogger(GlobalEndpointManager.class); - - private final int backgroundRefreshLocationTimeIntervalInMS; - private final LocationCache locationCache; - private final URL defaultEndpoint; - private final ConnectionPolicy connectionPolicy; - private final DatabaseAccountManagerInternal owner; - private final AtomicBoolean isRefreshing; - private final ExecutorService executor = Executors.newSingleThreadExecutor(); - private final Scheduler scheduler = Schedulers.from(executor); - private volatile boolean isClosed; - - public GlobalEndpointManager(DatabaseAccountManagerInternal owner, ConnectionPolicy connectionPolicy, Configs configs) { - this.backgroundRefreshLocationTimeIntervalInMS = configs.getUnavailableLocationsExpirationTimeInSeconds() * 1000; - try { - this.locationCache = new LocationCache( - new ArrayList<>(connectionPolicy.getPreferredLocations() != null ? - connectionPolicy.getPreferredLocations(): - Collections.emptyList() - ), - owner.getServiceEndpoint().toURL(), - connectionPolicy.getEnableEndpointDiscovery(), - BridgeInternal.getUseMultipleWriteLocations(connectionPolicy), - configs); - - this.owner = owner; - this.defaultEndpoint = owner.getServiceEndpoint().toURL(); - this.connectionPolicy = connectionPolicy; - - this.isRefreshing = new AtomicBoolean(false); - this.isClosed = false; - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - } - - public void init() { - // TODO: add support for openAsync - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/332589 - startRefreshLocationTimerAsync(true).toCompletable().await(); - } - - public UnmodifiableList getReadEndpoints() { - // readonly - return this.locationCache.getReadEndpoints(); - } - - public UnmodifiableList getWriteEndpoints() { - //readonly - return this.locationCache.getWriteEndpoints(); - } - - public static Single getDatabaseAccountFromAnyLocationsAsync( - URL defaultEndpoint, List locations, Func1> getDatabaseAccountFn) { - - return getDatabaseAccountFn.call(defaultEndpoint).onErrorResumeNext( - e -> { - logger.error("Fail to reach global gateway [{}], [{}]", defaultEndpoint, e.getMessage()); - if (locations.isEmpty()) { - return Single.error(e); - } - - Observable> obs = Observable.range(0, locations.size()) - .map(index -> getDatabaseAccountFn.call(LocationHelper.getLocationEndpoint(defaultEndpoint, locations.get(index))).toObservable()); - - // iterate and get the database account from the first non failure, otherwise get the last error. - Observable res = Observable.concatDelayError(obs).first().single(); - return res.toSingle().doOnError( - innerE -> { - logger.error("Fail to reach location any of locations", String.join(",", locations), innerE.getMessage()); - }); - }); - } - - public URL resolveServiceEndpoint(RxDocumentServiceRequest request) { - return this.locationCache.resolveServiceEndpoint(request); - } - - public void markEndpointUnavailableForRead(URL endpoint) { - logger.debug("Marking endpoint {} unavailable for read",endpoint); - this.locationCache.markEndpointUnavailableForRead(endpoint);; - } - - public void markEndpointUnavailableForWrite(URL endpoint) { - logger.debug("Marking endpoint {} unavailable for Write",endpoint); - this.locationCache.markEndpointUnavailableForWrite(endpoint); - } - - public boolean CanUseMultipleWriteLocations(RxDocumentServiceRequest request) { - return this.locationCache.canUseMultipleWriteLocations(request); - } - - public void close() { - this.isClosed = true; - this.executor.shutdown(); - logger.debug("GlobalEndpointManager closed."); - } - - public Completable refreshLocationAsync(DatabaseAccount databaseAccount) { - return Completable.defer(() -> { - logger.debug("refreshLocationAsync() invoked"); - if (!isRefreshing.compareAndSet(false, true)) { - logger.debug("in the middle of another refresh. Not invoking a new refresh."); - return Completable.complete(); - } - - logger.debug("will refresh"); - return this.refreshLocationPrivateAsync(databaseAccount).doOnError(e -> this.isRefreshing.set(false)); - }); - } - - private Completable refreshLocationPrivateAsync(DatabaseAccount databaseAccount) { - return Completable.defer(() -> { - logger.debug("refreshLocationPrivateAsync() refreshing locations"); - - if (databaseAccount != null) { - this.locationCache.onDatabaseAccountRead(databaseAccount); - } - - Utils.ValueHolder canRefreshInBackground = new Utils.ValueHolder(); - if (this.locationCache.shouldRefreshEndpoints(canRefreshInBackground)) { - logger.debug("shouldRefreshEndpoints: true"); - - if (databaseAccount == null && !canRefreshInBackground.v) { - logger.debug("shouldRefreshEndpoints: can't be done in background"); - - Single databaseAccountObs = getDatabaseAccountFromAnyLocationsAsync( - this.defaultEndpoint, - new ArrayList<>(this.connectionPolicy.getPreferredLocations()), - url -> this.getDatabaseAccountAsync(url)); - - return databaseAccountObs.map(dbAccount -> { - this.locationCache.onDatabaseAccountRead(dbAccount); - return dbAccount; - }).flatMapCompletable(dbAccount -> { - // trigger a startRefreshLocationTimerAsync don't wait on it. - this.startRefreshLocationTimerAsync(); - return Completable.complete(); - }); - } - - // trigger a startRefreshLocationTimerAsync don't wait on it. - this.startRefreshLocationTimerAsync(); - - return Completable.complete(); - } else { - logger.debug("shouldRefreshEndpoints: false, nothing to do."); - this.isRefreshing.set(false); - return Completable.complete(); - } - }); - } - - private void startRefreshLocationTimerAsync() { - startRefreshLocationTimerAsync(false).subscribe(); - } - - private Observable startRefreshLocationTimerAsync(boolean initialization) { - - if (this.isClosed) { - logger.debug("startRefreshLocationTimerAsync: nothing to do, it is closed"); - // if client is already closed, nothing to be done, just return. - return Observable.empty(); - } - - logger.debug("registering a refresh in [{}] ms", this.backgroundRefreshLocationTimeIntervalInMS); - LocalDateTime now = LocalDateTime.now(); - - int delayInMillis = initialization ? 0: this.backgroundRefreshLocationTimeIntervalInMS; - - return Observable.timer(delayInMillis, TimeUnit.MILLISECONDS) - .toSingle().flatMapCompletable( - t -> { - if (this.isClosed) { - logger.warn("client already closed"); - // if client is already closed, nothing to be done, just return. - return Completable.complete(); - } - - logger.debug("startRefreshLocationTimerAsync() - Invoking refresh, I was registered on [{}]", now); - Single databaseAccountObs = GlobalEndpointManager.getDatabaseAccountFromAnyLocationsAsync(this.defaultEndpoint, new ArrayList<>(this.connectionPolicy.getPreferredLocations()), - url -> this.getDatabaseAccountAsync(url)).toObservable().toSingle(); - - return databaseAccountObs.flatMapCompletable(dbAccount -> { - logger.debug("db account retrieved"); - return this.refreshLocationPrivateAsync(dbAccount); - }); - }).onErrorResumeNext(ex -> { - logger.error("startRefreshLocationTimerAsync() - Unable to refresh database account from any location. Exception: {}", ex.toString(), ex); - - this.startRefreshLocationTimerAsync(); - return Completable.complete(); - }).toObservable().subscribeOn(scheduler); - } - - private Single getDatabaseAccountAsync(URL serviceEndpoint) { - try { - return this.owner.getDatabaseAccountFromEndpoint(serviceEndpoint.toURI()) - .doOnNext(i -> logger.debug("account retrieved: {}", i)).toSingle(); - } catch (URISyntaxException e) { - return Single.error(e); - } - } - - public boolean isClosed() { - return this.isClosed; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IAuthorizationTokenProvider.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IAuthorizationTokenProvider.java deleted file mode 100644 index d67b23f6bbe1..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IAuthorizationTokenProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.util.Map; - -import com.microsoft.azure.cosmosdb.internal.ResourceType; - -public interface IAuthorizationTokenProvider { - String getUserAuthorizationToken(String resourceAddress, - ResourceType resourceType, - String get, - Map headers, - AuthorizationTokenType primarymasterkey, - Map properties); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ICollectionRoutingMapCache.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ICollectionRoutingMapCache.java deleted file mode 100644 index bd34d1b82d97..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ICollectionRoutingMapCache.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; - -import rx.Single; - -import java.util.Map; - -// TODO: add documentation -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - **/ -public interface ICollectionRoutingMapCache { - default Single tryLookupAsync( - String collectionRid, - CollectionRoutingMap previousValue, - Map properties) { - return tryLookupAsync(collectionRid, previousValue, false, properties); - } - - Single tryLookupAsync( - String collectionRid, - CollectionRoutingMap previousValue, - boolean forceRefreshCollectionRoutingMap, - Map properties); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IDocumentClientRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IDocumentClientRetryPolicy.java deleted file mode 100644 index 7f78ad446cf5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IDocumentClientRetryPolicy.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public interface IDocumentClientRetryPolicy extends IRetryPolicy { - - // TODO: this is just a place holder for now. As .Net has this method. - // I have to spend more time figure out what's the right pattern for this (if method needed) - - /// - /// Method that is called before a request is sent to allow the retry policy implementation - /// to modify the state of the request. - /// - /// The request being sent to the service. - /// - /// Currently only read operations will invoke this method. There is no scenario for write - /// operations to modify requests before retrying. - /// - - // TODO: I need to investigate what's the right contract here and/or if/how this is useful - void onBeforeSendRequest(RxDocumentServiceRequest request); - - - class NoRetry implements IDocumentClientRetryPolicy { - - private static NoRetry instance = new NoRetry(); - - private NoRetry() {} - - public static NoRetry getInstance() { - return instance; - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - // no op - } - - @Override - public Single shouldRetry(Exception e) { - return Single.just(ShouldRetryResult.error(e)); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRetryPolicy.java deleted file mode 100644 index 066e4f39509b..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRetryPolicy.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; - -import com.microsoft.azure.cosmosdb.internal.Quadruple; - -import rx.Single; - -// TODO update documentation -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public interface IRetryPolicy { - // this capture all the retry logic - // TODO: design decision should this return a single or an observable? - - /// - /// Method that is called to determine from the policy that needs to retry on the exception - /// - /// Exception during the callback method invocation - /// - /// If the retry needs to be attempted or not - Single shouldRetry(Exception e); - - - class ShouldRetryResult { - /// - /// How long to wait before next retry. 0 indicates retry immediately. - /// - public final Duration backOffTime; - public final Exception exception; - public boolean shouldRetry; - public final Quadruple policyArg; - - private ShouldRetryResult(Duration dur, Exception e, boolean shouldRetry, - Quadruple policyArg) { - this.backOffTime = dur; - this.exception = e; - this.shouldRetry = shouldRetry; - this.policyArg = policyArg; - } - - public static ShouldRetryResult retryAfter(Duration dur) { - Utils.checkNotNullOrThrow(dur, "duration", "cannot be null"); - return new ShouldRetryResult(dur, null, true, null); - } - - public static ShouldRetryResult retryAfter(Duration dur, - Quadruple policyArg) { - Utils.checkNotNullOrThrow(dur, "duration", "cannot be null"); - return new ShouldRetryResult(dur, null, true, policyArg); - } - - public static ShouldRetryResult error(Exception e) { - Utils.checkNotNullOrThrow(e, "exception", "cannot be null"); - return new ShouldRetryResult(null, e, false, null); - } - - public static ShouldRetryResult noRetry() { - return new ShouldRetryResult(null, null, false, null); - } - - public void throwIfDoneTrying(Exception capturedException) throws Exception { - if (this.shouldRetry) { - return; - } - - if (this.exception == null) { - throw capturedException; - } else { - throw this.exception; - } - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRetryPolicyFactory.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRetryPolicyFactory.java deleted file mode 100644 index 3c36fd5fa0c6..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRetryPolicyFactory.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public interface IRetryPolicyFactory { - IDocumentClientRetryPolicy getRequestPolicy(); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRoutingMapProvider.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRoutingMapProvider.java deleted file mode 100644 index 34f270b493fc..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/IRoutingMapProvider.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.util.List; -import java.util.Map; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.routing.Range; - -import rx.Single; - -//TODO: update documentation -//TODO: add two overload methods for forceRefresh = false -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - **/ -public interface IRoutingMapProvider { - /// - /// Returns list of effective partition key ranges for a collection. - /// - /// Collection for which to retrieve routing map. - /// This method will return all ranges which overlap this range. - /// Whether forcefully refreshing the routing map is necessary - /// List of effective partition key ranges for a collection or null if collection doesn't exist. - Single> tryGetOverlappingRangesAsync(String collectionResourceId, Range range, - boolean forceRefresh /* = false */, Map properties); - - Single tryGetPartitionKeyRangeByIdAsync(String collectionResourceId, String partitionKeyRangeId, - boolean forceRefresh /* = false */, Map properties); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InvalidPartitionException.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InvalidPartitionException.java deleted file mode 100644 index 2710eaf0cce5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InvalidPartitionException.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class InvalidPartitionException extends DocumentClientException { - - private static final long serialVersionUID = 1L; - - public InvalidPartitionException() { - this(RMResources.Gone); - } - - public InvalidPartitionException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.GONE, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public InvalidPartitionException(String msg) { - super(HttpConstants.StatusCodes.GONE, msg); - setSubStatus(); - } - - public InvalidPartitionException(String msg, String resourceAddress) { - super(msg, null, null, HttpConstants.StatusCodes.GONE, resourceAddress); - setSubStatus(); - } - - public InvalidPartitionException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public InvalidPartitionException(Exception innerException) { - this(RMResources.Gone, innerException, null, null); - } - - public InvalidPartitionException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.Gone, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.GONE, - requestUri); - - setSubStatus(); - } - - private void setSubStatus() { - this.getResponseHeaders().put( - WFConstants.BackendHeaders.SUB_STATUS, - Integer.toString(HttpConstants.SubStatusCodes.NAME_CACHE_IS_STALE)); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InvalidPartitionExceptionRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InvalidPartitionExceptionRetryPolicy.java deleted file mode 100644 index cdd7540ddb08..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/InvalidPartitionExceptionRetryPolicy.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; - -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class InvalidPartitionExceptionRetryPolicy implements IDocumentClientRetryPolicy { - - private final RxCollectionCache clientCollectionCache; - private final IDocumentClientRetryPolicy nextPolicy; - private final String collectionLink; - private final FeedOptions feedOptions; - - private volatile boolean retried = false; - - public InvalidPartitionExceptionRetryPolicy(RxCollectionCache collectionCache, - IDocumentClientRetryPolicy nextPolicy, - String resourceFullName, - FeedOptions feedOptions) { - - this.clientCollectionCache = collectionCache; - this.nextPolicy = nextPolicy; - - // TODO the resource address should be inferred from exception - this.collectionLink = com.microsoft.azure.cosmosdb.internal.Utils.getCollectionName(resourceFullName); - this.feedOptions = feedOptions; - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - this.nextPolicy.onBeforeSendRequest(request); - } - - @Override - public Single shouldRetry(Exception e) { - DocumentClientException clientException = Utils.as(e, DocumentClientException.class); - if (clientException != null && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.GONE) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.NAME_CACHE_IS_STALE)) { - if (!this.retried) { - // TODO: resource address should be accessible from the exception - //this.clientCollectionCache.Refresh(clientException.ResourceAddress); - // TODO: this is blocking. is that fine? - if(this.feedOptions != null) { - this.clientCollectionCache.refresh(collectionLink,this.feedOptions.getProperties()); - } else { - this.clientCollectionCache.refresh(collectionLink,null); - } - - this.retried = true; - return Single.just(ShouldRetryResult.retryAfter(Duration.ZERO)); - } else { - return Single.just(ShouldRetryResult.error(e)); - } - } - - return this.nextPolicy.shouldRetry(e); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/NotFoundException.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/NotFoundException.java deleted file mode 100644 index 3e949875c4d2..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/NotFoundException.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.net.URI; -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class NotFoundException extends DocumentClientException { - private static final long serialVersionUID = 1L; - - public NotFoundException() { - this(RMResources.NotFound); - } - - public NotFoundException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.NOTFOUND, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public NotFoundException(String message) { - this(message, (Exception) null, (HttpResponseHeaders) null, null); - } - - public NotFoundException(String message, Map headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public NotFoundException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public NotFoundException(String message, HttpResponseHeaders headers, URI requestUri) { - this(message, headers, requestUri != null ? requestUri.toString() : null); - } - - public NotFoundException(Exception innerException) { - this(RMResources.NotFound, innerException, (Map) null, null); - } - - public NotFoundException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - this(message, innerException, HttpUtils.asMap(headers), requestUri); - } - - public NotFoundException(String message, - Exception innerException, - Map headers, - String requestUri) { - super(String.format("%s: %s", RMResources.NotFound, message), - innerException, - headers, - HttpConstants.StatusCodes.NOTFOUND, - requestUri); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ObservableHelper.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ObservableHelper.java deleted file mode 100644 index 80bf892dedcd..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ObservableHelper.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import rx.Observable; -import rx.Single; -import rx.functions.Func0; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - * - **/ -public class ObservableHelper { - - static public Single inlineIfPossible(Func0> function, IRetryPolicy retryPolicy) { - - if (retryPolicy == null) { - // shortcut - return function.call(); - } else { - return BackoffRetryUtility.executeRetry(function, retryPolicy); - } - } - - static public Observable inlineIfPossibleAsObs(Func0> function, IRetryPolicy retryPolicy) { - - if (retryPolicy == null) { - // shortcut - return Observable.defer(() -> { - return function.call(); - }); - - } else { - return BackoffRetryUtility.executeRetry(() -> function.call().toSingle(), retryPolicy).toObservable(); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionIsMigratingException.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionIsMigratingException.java deleted file mode 100644 index adf2fe3217cc..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionIsMigratingException.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class PartitionIsMigratingException extends DocumentClientException { - - private static final long serialVersionUID = 1L; - - public PartitionIsMigratingException() { - this(RMResources.Gone); - } - - public PartitionIsMigratingException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.GONE, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public PartitionIsMigratingException(String msg) { - super(HttpConstants.StatusCodes.GONE, msg); - setSubStatus(); - } - - public PartitionIsMigratingException(String msg, String resourceAddress) { - super(msg, null, null, HttpConstants.StatusCodes.GONE, resourceAddress); - setSubStatus(); - } - - public PartitionIsMigratingException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public PartitionIsMigratingException(Exception innerException) { - this(RMResources.Gone, innerException, null, null); - } - - public PartitionIsMigratingException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.Gone, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.GONE, - requestUri); - - setSubStatus(); - } - - private void setSubStatus() { - this.getResponseHeaders().put( - WFConstants.BackendHeaders.SUB_STATUS, - Integer.toString(HttpConstants.SubStatusCodes.COMPLETING_PARTITION_MIGRATION)); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyMismatchRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyMismatchRetryPolicy.java deleted file mode 100644 index 45dc11cc0d13..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyMismatchRetryPolicy.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; -import java.util.concurrent.atomic.AtomicInteger; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxClientCollectionCache; - -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - * - * A RetryPolicy implementation that ensures the PartitionKeyDefinitionMap is up-to-date. - * Entries in the PartitionKeyDefinitionMap can become stale if a collection is deleted - * and then recreated with the same name but a different partition key definition, if - * the request is made using name-based links. - * - * TODO: verify with Sergii, other than collection deleted and recreated with the same name - * is there any other scenario which this should be used? - * - */ -public class PartitionKeyMismatchRetryPolicy implements IDocumentClientRetryPolicy { - private RxClientCollectionCache clientCollectionCache; - private IDocumentClientRetryPolicy nextRetryPolicy; - private AtomicInteger retriesAttempted = new AtomicInteger(0); - private String collectionLink; - private RequestOptions options; - private final static int MaxRetries = 1; - - - public PartitionKeyMismatchRetryPolicy( - RxClientCollectionCache clientCollectionCache, - IDocumentClientRetryPolicy nextRetryPolicy, - String resourceFullName, - RequestOptions requestOptions) { - this.clientCollectionCache = clientCollectionCache; - this.nextRetryPolicy = nextRetryPolicy; - - // TODO: this should be retrievable from document client exception. - collectionLink = com.microsoft.azure.cosmosdb.internal.Utils.getCollectionName(resourceFullName); - this.options = options; - } - - - /// - /// Should the caller retry the operation. - /// - /// Exception that occured when the operation was tried - /// - /// True indicates caller should retry, False otherwise - public Single shouldRetry(Exception exception) { - DocumentClientException clientException = Utils.as(exception, DocumentClientException.class) ; - - if (clientException != null && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.BADREQUEST) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH) - && this.retriesAttempted.get() < MaxRetries) { - //Debug.Assert(clientException.ResourceAddress != null); - - // TODO: - //this.clientCollectionCache.refresh(clientException.ResourceAddress); - if (this.options != null) { - this.clientCollectionCache.refresh(collectionLink, this.options.getProperties()); - } else { - this.clientCollectionCache.refresh(collectionLink, null); - } - - this.retriesAttempted.incrementAndGet(); - - return Single.just(ShouldRetryResult.retryAfter(Duration.ZERO)); - } - - return this.nextRetryPolicy.shouldRetry(exception); - } - - - /* (non-Javadoc) - * @see com.microsoft.azure.cosmosdb.rx.internal.query.IDocumentClientRetryPolicy#onBeforeSendRequest(rx.Observable) - */ - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - // TODO Auto-generated method stub - this.nextRetryPolicy.onBeforeSendRequest(request); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyRangeGoneRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyRangeGoneRetryPolicy.java deleted file mode 100644 index 3a2c60a5de24..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyRangeGoneRetryPolicy.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import com.microsoft.azure.cosmosdb.rx.internal.caches.IPartitionKeyRangeCache; - -import rx.Observable; -import rx.Single; - -// TODO: this need testing -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class PartitionKeyRangeGoneRetryPolicy implements IDocumentClientRetryPolicy { - - private final RxCollectionCache collectionCache; - private final IDocumentClientRetryPolicy nextRetryPolicy; - private final IPartitionKeyRangeCache partitionKeyRangeCache; - private final String collectionLink; - private final FeedOptions feedOptions; - private volatile boolean retried; - - public PartitionKeyRangeGoneRetryPolicy( - RxCollectionCache collectionCache, - IPartitionKeyRangeCache partitionKeyRangeCache, - String collectionLink, - IDocumentClientRetryPolicy nextRetryPolicy, - FeedOptions feedOptions) { - this.collectionCache = collectionCache; - this.partitionKeyRangeCache = partitionKeyRangeCache; - this.collectionLink = collectionLink; - this.nextRetryPolicy = nextRetryPolicy; - this.feedOptions = feedOptions; - } - - /// - /// Should the caller retry the operation. - /// - /// Exception that occured when the operation was tried - /// - /// True indicates caller should retry, False otherwise - public Single shouldRetry(Exception exception) { - DocumentClientException clientException = Utils.as(exception, DocumentClientException.class); - if (clientException != null && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.GONE) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE)) { - - if (this.retried){ - return Single.just(ShouldRetryResult.error(clientException)); - } - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - this.collectionLink, - null - // AuthorizationTokenType.PrimaryMasterKey) - ); - if (this.feedOptions != null) { - request.properties = this.feedOptions.getProperties(); - } - Single collectionObs = this.collectionCache.resolveCollectionAsync(request); - - Single retryTimeObservable = collectionObs.flatMap(collection -> { - - Single routingMapObs = this.partitionKeyRangeCache.tryLookupAsync(collection.getResourceId(), null, request.properties); - - Single refreshedRoutingMapObs = routingMapObs.flatMap(routingMap -> { - if (routingMap != null) { - // Force refresh. - return this.partitionKeyRangeCache.tryLookupAsync( - collection.getResourceId(), - routingMap, - request.properties); - } else { - return Observable.just((CollectionRoutingMap) null).toSingle(); - } - }); - - return refreshedRoutingMapObs.flatMap(rm -> { - this.retried = true; - return Single.just(ShouldRetryResult.retryAfter(Duration.ZERO)); - }); - - }); - return retryTimeObservable; - - } else { - return this.nextRetryPolicy.shouldRetry(exception); - } - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - this.nextRetryPolicy.onBeforeSendRequest(request); - } - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyRangeIsSplittingException.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyRangeIsSplittingException.java deleted file mode 100644 index c3a564fa083f..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/PartitionKeyRangeIsSplittingException.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; - -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class PartitionKeyRangeIsSplittingException extends DocumentClientException { - - private static final long serialVersionUID = 1L; - - public PartitionKeyRangeIsSplittingException() { - this(RMResources.Gone); - } - - public PartitionKeyRangeIsSplittingException(Error error, long lsn, String partitionKeyRangeId, Map responseHeaders) { - super(HttpConstants.StatusCodes.GONE, error, responseHeaders); - BridgeInternal.setLSN(this, lsn); - BridgeInternal.setPartitionKeyRangeId(this, partitionKeyRangeId); - } - - public PartitionKeyRangeIsSplittingException(String msg) { - super(HttpConstants.StatusCodes.GONE, msg); - setSubStatus(); - } - - public PartitionKeyRangeIsSplittingException(String msg, String resourceAddress) { - super(msg, null, null, HttpConstants.StatusCodes.GONE, resourceAddress); - setSubStatus(); - } - - public PartitionKeyRangeIsSplittingException(String message, HttpResponseHeaders headers, String requestUri) { - this(message, null, headers, requestUri); - } - - public PartitionKeyRangeIsSplittingException(Exception innerException) { - this(RMResources.Gone, innerException, null, null); - } - - public PartitionKeyRangeIsSplittingException(String message, - Exception innerException, - HttpResponseHeaders headers, - String requestUri) { - super(String.format("%s: %s", RMResources.Gone, message), - innerException, - HttpUtils.asMap(headers), - HttpConstants.StatusCodes.GONE, - requestUri); - - setSubStatus(); - } - - private void setSubStatus() { - this.getResponseHeaders().put( - WFConstants.BackendHeaders.SUB_STATUS, - Integer.toString(HttpConstants.SubStatusCodes.COMPLETING_SPLIT)); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RenameCollectionAwareClientRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RenameCollectionAwareClientRetryPolicy.java deleted file mode 100644 index 613bd70b07d5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RenameCollectionAwareClientRetryPolicy.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxClientCollectionCache; - -import org.apache.commons.lang3.StringUtils; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import rx.Single; - -import java.time.Duration; - -public class RenameCollectionAwareClientRetryPolicy implements IDocumentClientRetryPolicy { - - private final static Logger logger = LoggerFactory.getLogger(RenameCollectionAwareClientRetryPolicy.class); - - private final IDocumentClientRetryPolicy retryPolicy; - private final ISessionContainer sessionContainer; - private final RxClientCollectionCache collectionCache; - private RxDocumentServiceRequest request; - private boolean hasTriggered = false; - - public RenameCollectionAwareClientRetryPolicy(ISessionContainer sessionContainer, RxClientCollectionCache collectionCache, IDocumentClientRetryPolicy retryPolicy) { - this.retryPolicy = retryPolicy; - this.sessionContainer = sessionContainer; - this.collectionCache = collectionCache; - this.request = null; - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - this.request = request; - this.retryPolicy.onBeforeSendRequest(request); - } - - @Override - public Single shouldRetry(Exception e) { - return this.retryPolicy.shouldRetry(e).flatMap(shouldRetryResult -> { - if (!shouldRetryResult.shouldRetry && !this.hasTriggered) { - DocumentClientException clientException = Utils.as(e, DocumentClientException.class); - - if (this.request == null) { - // someone didn't call OnBeforeSendRequest - nothing we can do - logger.error("onBeforeSendRequest is not invoked, encountered failure due to request being null", e); - return Single.just(ShouldRetryResult.error(e)); - } - - if (clientException != null && this.request.getIsNameBased() && - Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.NOTFOUND) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)) { - // Clear the session token, because the collection name might be reused. - logger.warn("Clear the token for named base request {}", request.getResourceAddress()); - - this.sessionContainer.clearTokenByCollectionFullName(request.getResourceAddress()); - - this.hasTriggered = true; - - String oldCollectionRid = request.requestContext.resolvedCollectionRid; - - request.forceNameCacheRefresh = true; - request.requestContext.resolvedCollectionRid = null; - - Single collectionObs = this.collectionCache.resolveCollectionAsync(request); - - return collectionObs.flatMap(collectionInfo -> { - if (collectionInfo == null) { - logger.warn("Can't recover from session unavailable exception because resolving collection name {} returned null", request.getResourceAddress()); - } else if (!StringUtils.isEmpty(oldCollectionRid) && !StringUtils.isEmpty(collectionInfo.getResourceId())) { - return Single.just(ShouldRetryResult.retryAfter(Duration.ZERO)); - } - return Single.just(shouldRetryResult); - }).onErrorResumeNext(throwable -> { - // When resolveCollectionAsync throws an exception ignore it because it's an attempt to recover an existing - // error. When the recovery fails we return ShouldRetryResult.noRetry and propagate the original exception to the client - - logger.warn("Can't recover from session unavailable exception because resolving collection name {} failed with {}", request.getResourceAddress(), throwable.getMessage()); - if (throwable instanceof Exception) { - return Single.just(ShouldRetryResult.error((Exception) throwable)); - } - return Single.error(throwable); - }); - } - } - return Single.just(shouldRetryResult); - }); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ReplicatedResourceClientUtils.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ReplicatedResourceClientUtils.java deleted file mode 100644 index d1f4429cbe01..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ReplicatedResourceClientUtils.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class ReplicatedResourceClientUtils { - - public static boolean isReadingFromMaster(ResourceType resourceType, OperationType operationType) { - if (resourceType == ResourceType.Offer || - resourceType == ResourceType.Database || - resourceType == ResourceType.User || - resourceType == ResourceType.UserDefinedType || - resourceType == ResourceType.Permission || - resourceType == ResourceType.Topology || - resourceType == ResourceType.DatabaseAccount || - (resourceType == ResourceType.PartitionKeyRange && operationType != OperationType.GetSplitPoint && operationType != OperationType.AbortSplit) || - (resourceType == ResourceType.DocumentCollection && (operationType == OperationType.ReadFeed || operationType == OperationType.Query || operationType == OperationType.SqlQuery))) - { - return true; - } - - return false; - } - - public static boolean isMasterResource(ResourceType resourceType) { - if (resourceType == ResourceType.Offer || - resourceType == ResourceType.Database || - resourceType == ResourceType.User || - resourceType == ResourceType.UserDefinedType || - resourceType == ResourceType.Permission || - resourceType == ResourceType.Topology || - resourceType == ResourceType.DatabaseAccount || - resourceType == ResourceType.PartitionKeyRange || - resourceType == ResourceType.DocumentCollection) { - return true; - } - - return false; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ResetSessionTokenRetryPolicyFactory.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ResetSessionTokenRetryPolicyFactory.java deleted file mode 100644 index 1d6e888c61f5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ResetSessionTokenRetryPolicyFactory.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxClientCollectionCache; - -public class ResetSessionTokenRetryPolicyFactory implements IRetryPolicyFactory { - - private final IRetryPolicyFactory retryPolicy; - private final ISessionContainer sessionContainer; - private final RxClientCollectionCache collectionCache; - - public ResetSessionTokenRetryPolicyFactory(ISessionContainer sessionContainer, RxClientCollectionCache collectionCache, IRetryPolicyFactory retryPolicy) { - this.retryPolicy = retryPolicy; - this.sessionContainer = sessionContainer; - this.collectionCache = collectionCache; - } - - @Override - public IDocumentClientRetryPolicy getRequestPolicy() { - return new RenameCollectionAwareClientRetryPolicy(this.sessionContainer, this.collectionCache, retryPolicy.getRequestPolicy()); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ResourceThrottleRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ResourceThrottleRetryPolicy.java deleted file mode 100644 index 8aeb8e037dfb..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ResourceThrottleRetryPolicy.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class ResourceThrottleRetryPolicy implements IDocumentClientRetryPolicy{ - - private final static Logger logger = LoggerFactory.getLogger(ResourceThrottleRetryPolicy.class); - - private final static int DefaultMaxWaitTimeInSeconds = 60; - private final static int DefaultRetryInSeconds = 5; - private final int backoffDelayFactor; - private final int maxAttemptCount; - private final Duration maxWaitTime; - - // TODO: is this thread safe? - // should we make this atomic int? - private int currentAttemptCount; - private Duration cumulativeRetryDelay; - - public ResourceThrottleRetryPolicy(int maxAttemptCount, int maxWaitTimeInSeconds) { - this(maxAttemptCount, maxWaitTimeInSeconds, 1); - } - - public ResourceThrottleRetryPolicy(int maxAttemptCount) { - this(maxAttemptCount, DefaultMaxWaitTimeInSeconds, 1); - } - - public ResourceThrottleRetryPolicy(int maxAttemptCount, int maxWaitTimeInSeconds, int backoffDelayFactor) { - Utils.checkStateOrThrow(maxWaitTimeInSeconds < Integer.MAX_VALUE / 1000, "maxWaitTimeInSeconds", "maxWaitTimeInSeconds must be less than " + Integer.MAX_VALUE / 1000); - - this.maxAttemptCount = maxAttemptCount; - this.backoffDelayFactor = backoffDelayFactor; - this.maxWaitTime = Duration.ofSeconds(maxWaitTimeInSeconds); - this.currentAttemptCount = 0; - this.cumulativeRetryDelay = Duration.ZERO; - } - - @Override - public Single shouldRetry(Exception exception) { - Duration retryDelay = Duration.ZERO; - - if (this.currentAttemptCount < this.maxAttemptCount && - (retryDelay = checkIfRetryNeeded(exception)) != null) { - this.currentAttemptCount++; - logger.warn( - "Operation will be retried after {} milliseconds. Current attempt {}, Cumulative delay {}", - retryDelay.toMillis(), - this.currentAttemptCount, - this.cumulativeRetryDelay, - exception); - return Single.just(ShouldRetryResult.retryAfter(retryDelay)); - } else { - logger.debug( - "Operation will NOT be retried. Current attempt {}", - this.currentAttemptCount, - exception); - return Single.just(ShouldRetryResult.noRetry()); - } - } - - @Override - public void onBeforeSendRequest(RxDocumentServiceRequest request) { - // no op - } - - // if retry not needed reaturns null - /// - /// Returns True if the given exception is retriable - /// - /// Exception to examine - /// retryDelay - /// True if the exception is retriable; False otherwise - private Duration checkIfRetryNeeded(Exception exception) { - Duration retryDelay = Duration.ZERO; - - DocumentClientException dce = Utils.as(exception, DocumentClientException.class); - - if (dce != null){ - - if (Exceptions.isStatusCode(dce, HttpConstants.StatusCodes.TOO_MANY_REQUESTS)) { - retryDelay = Duration.ofMillis(dce.getRetryAfterInMilliseconds()); - if (this.backoffDelayFactor > 1) { - retryDelay = Duration.ofNanos(retryDelay.toNanos() * this.backoffDelayFactor); - } - - if (retryDelay.toMillis() < this.maxWaitTime.toMillis() && - this.maxWaitTime.toMillis() >= (this.cumulativeRetryDelay = retryDelay.plus(this.cumulativeRetryDelay)).toMillis()) - { - if (retryDelay == Duration.ZERO){ - // we should never reach here as BE should turn non-zero of retryDelay - logger.trace("Received retryDelay of 0 with Http 429", exception); - retryDelay = Duration.ofSeconds(DefaultRetryInSeconds); - } - - return retryDelay; - } - } - } - // if retry not needed returns null - return null; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RetryPolicy.java deleted file mode 100644 index 9ac61a56f331..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RetryPolicy.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.RetryOptions; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - * - * Represents the retry policy configuration associated with a DocumentClient instance. - */ -public class RetryPolicy implements IRetryPolicyFactory { - private final GlobalEndpointManager globalEndpointManager; - private final boolean enableEndpointDiscovery; - private final RetryOptions retryOptions; - - public RetryPolicy(GlobalEndpointManager globalEndpointManager, ConnectionPolicy connectionPolicy) { - this.enableEndpointDiscovery = connectionPolicy.getEnableEndpointDiscovery(); - this.globalEndpointManager = globalEndpointManager; - this.retryOptions = connectionPolicy.getRetryOptions(); - } - - @Override - public IDocumentClientRetryPolicy getRequestPolicy() { - ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(this.globalEndpointManager, - this.enableEndpointDiscovery, this.retryOptions); - - return clientRetryPolicy; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RetryUtils.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RetryUtils.java deleted file mode 100644 index 7432a3ebdef6..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RetryUtils.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.lang3.time.StopWatch; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.internal.Quadruple; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicy.ShouldRetryResult; - -import rx.Observable; -import rx.Single; -import rx.functions.Func1; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class RetryUtils { - private final static Logger logger = LoggerFactory.getLogger(BackoffRetryUtility.class); - - public static Func1, Observable> toRetryWhenFunc(IRetryPolicy policy) { - return new Func1, Observable>() { - - @Override - public Observable call(Observable throwableObs) { - return throwableObs.flatMap( t -> { - Exception e = Utils.as(t, Exception.class); - if (e == null) { - return Observable.error(t); - } - - return policy.shouldRetry(e).toObservable().flatMap(s -> { - - if (s.backOffTime != null) { - return Observable.timer(s.backOffTime.toMillis(), TimeUnit.MILLISECONDS); - } else if (s.exception != null) { - return Observable.error(s.exception); - } else { - // NoRetry return original failure - return Observable.error(t); - } - }); - }); - } - }; - } - - /** - * This method will be called after getting error on callbackMethod , and then keep trying between - * callbackMethod and inBackoffAlternateCallbackMethod until success or as stated in - * retry policy. - * @param callbackMethod The callbackMethod - * @param policy Retry policy - * @param inBackoffAlternateCallbackMethod The inBackoffAlternateCallbackMethod - * @param minBackoffForInBackoffCallback Minimum backoff for InBackoffCallbackMethod - * @return - */ - static Func1> toRetryWithAlternateFunc( - Func1, Single> callbackMethod, IRetryPolicy policy, - Func1, Single> inBackoffAlternateCallbackMethod, - Duration minBackoffForInBackoffCallback) { - return new Func1>() { - - @Override - public Single call(Throwable t) { - Exception e = Utils.as(t, Exception.class); - if (e == null) { - return Single.error(t); - } - - return policy.shouldRetry(e).flatMap(shouldRetryResult -> { - if (!shouldRetryResult.shouldRetry) { - if(shouldRetryResult.exception == null) { - return Single.error(e); - } else { - return Single.error(shouldRetryResult.exception); - } - } - - if (inBackoffAlternateCallbackMethod != null - && shouldRetryResult.backOffTime.compareTo(minBackoffForInBackoffCallback) > 0) { - StopWatch stopwatch = new StopWatch(); - startStopWatch(stopwatch); - return inBackoffAlternateCallbackMethod.call(shouldRetryResult.policyArg) - .onErrorResumeNext(recurrsiveWithAlternateFunc(callbackMethod, policy, - inBackoffAlternateCallbackMethod, shouldRetryResult, stopwatch, - minBackoffForInBackoffCallback)); - } else { - return recurrsiveFunc(callbackMethod, policy, inBackoffAlternateCallbackMethod, - shouldRetryResult, minBackoffForInBackoffCallback) - .delaySubscription(Observable.timer(shouldRetryResult.backOffTime.toMillis(), - TimeUnit.MILLISECONDS)); - } - }); - } - }; - - } - - private static Single recurrsiveFunc( - Func1, Single> callbackMethod, IRetryPolicy policy, - Func1, Single> inBackoffAlternateCallbackMethod, - ShouldRetryResult shouldRetryResult, Duration minBackoffForInBackoffCallback) { - return callbackMethod.call(shouldRetryResult.policyArg).onErrorResumeNext(toRetryWithAlternateFunc( - callbackMethod, policy, inBackoffAlternateCallbackMethod, minBackoffForInBackoffCallback)); - - } - - private static Func1> recurrsiveWithAlternateFunc( - Func1, Single> callbackMethod, IRetryPolicy policy, - Func1, Single> inBackoffAlternateCallbackMethod, - ShouldRetryResult shouldRetryResult, StopWatch stopwatch, Duration minBackoffForInBackoffCallback) { - return new Func1>() { - - @Override - public Single call(Throwable t) { - - Exception e = Utils.as(t, Exception.class); - if (e == null) { - return Single.error(t); - } - - stopStopWatch(stopwatch); - logger.info("Failed inBackoffAlternateCallback with {}, proceeding with retry. Time taken: {}ms", - e.toString(), stopwatch.getTime()); - Duration backoffTime = shouldRetryResult.backOffTime.toMillis() > stopwatch.getTime() - ? Duration.ofMillis(shouldRetryResult.backOffTime.toMillis() - stopwatch.getTime()) - : Duration.ZERO; - return recurrsiveFunc(callbackMethod, policy, inBackoffAlternateCallbackMethod, shouldRetryResult, - minBackoffForInBackoffCallback) - .delaySubscription(Observable.timer(backoffTime.toMillis(), TimeUnit.MILLISECONDS)); - } - - }; - } - - private static void stopStopWatch(StopWatch stopwatch) { - synchronized (stopwatch) { - stopwatch.stop(); - } - } - - private static void startStopWatch(StopWatch stopwatch) { - synchronized (stopwatch) { - stopwatch.start(); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxGatewayStoreModel.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxGatewayStoreModel.java deleted file mode 100644 index 7de0b323f9d9..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxGatewayStoreModel.java +++ /dev/null @@ -1,555 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.QueryCompatibilityMode; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.RuntimeConstants; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpUtils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreResponse; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Single; -import rx.functions.Func0; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - * - * Used internally to provide functionality to communicate and process response from Gateway in the Azure Cosmos DB database service. - */ -class RxGatewayStoreModel implements RxStoreModel { - - private final static int INITIAL_RESPONSE_BUFFER_SIZE = 1024; - private final Logger logger = LoggerFactory.getLogger(RxGatewayStoreModel.class); - private final Map defaultHeaders; - private final CompositeHttpClient httpClient; - private final QueryCompatibilityMode queryCompatibilityMode; - private final GlobalEndpointManager globalEndpointManager; - private ConsistencyLevel defaultConsistencyLevel; - private ISessionContainer sessionContainer; - - public RxGatewayStoreModel( - ISessionContainer sessionContainer, - ConsistencyLevel defaultConsistencyLevel, - QueryCompatibilityMode queryCompatibilityMode, - UserAgentContainer userAgentContainer, - GlobalEndpointManager globalEndpointManager, - CompositeHttpClient httpClient) { - this.defaultHeaders = new HashMap<>(); - this.defaultHeaders.put(HttpConstants.HttpHeaders.CACHE_CONTROL, - "no-cache"); - this.defaultHeaders.put(HttpConstants.HttpHeaders.VERSION, - HttpConstants.Versions.CURRENT_VERSION); - - if (userAgentContainer == null) { - userAgentContainer = new UserAgentContainer(); - } - - this.defaultHeaders.put(HttpConstants.HttpHeaders.USER_AGENT, userAgentContainer.getUserAgent()); - - if (defaultConsistencyLevel != null) { - this.defaultHeaders.put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, - defaultConsistencyLevel.toString()); - } - - this.defaultConsistencyLevel = defaultConsistencyLevel; - this.globalEndpointManager = globalEndpointManager; - this.queryCompatibilityMode = queryCompatibilityMode; - - this.httpClient = httpClient; - this.sessionContainer = sessionContainer; - } - - private Observable doCreate(RxDocumentServiceRequest request) { - return this.performRequest(request, HttpMethod.POST); - } - - private Observable upsert(RxDocumentServiceRequest request) { - return this.performRequest(request, HttpMethod.POST); - } - - private Observable read(RxDocumentServiceRequest request) { - return this.performRequest(request, HttpMethod.GET); - } - - private Observable replace(RxDocumentServiceRequest request) { - return this.performRequest(request, HttpMethod.PUT); - } - - private Observable delete(RxDocumentServiceRequest request) { - return this.performRequest(request, HttpMethod.DELETE); - } - - private Observable execute(RxDocumentServiceRequest request) { - return this.performRequest(request, HttpMethod.POST); - } - - private Observable readFeed(RxDocumentServiceRequest request) { - return this.performRequest(request, HttpMethod.GET); - } - - private Observable query(RxDocumentServiceRequest request) { - request.getHeaders().put(HttpConstants.HttpHeaders.IS_QUERY, "true"); - - switch (this.queryCompatibilityMode) { - case SqlQuery: - request.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE, - RuntimeConstants.MediaTypes.SQL); - break; - case Default: - case Query: - default: - request.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE, - RuntimeConstants.MediaTypes.QUERY_JSON); - break; - } - return this.performRequest(request, HttpMethod.POST); - } - - /** - * Given the request it creates an observable which upon subscription issues HTTP call and emits one RxDocumentServiceResponse. - * - * @param request - * @param method - * @return Observable - */ - public Observable performRequest(RxDocumentServiceRequest request, HttpMethod method) { - - try { - URI uri = getUri(request); - HttpClientRequest httpRequest = HttpClientRequest.create(method, uri.toString()); - - this.fillHttpRequestBaseWithHeaders(request.getHeaders(), httpRequest); - - if (request.getContentObservable() != null) { - - // TODO validate this - // convert byte[] to ByteBuf - // why not use Observable directly? - Observable byteBufObservable = request.getContentObservable() - .map(bytes -> Unpooled.wrappedBuffer(bytes)); - - httpRequest.withContentSource(byteBufObservable); - } else if (request.getContent() != null){ - httpRequest.withContent(request.getContent()); - } - - RxClient.ServerInfo serverInfo = new RxClient.ServerInfo(uri.getHost(), uri.getPort()); - - Observable> clientResponseObservable = this.httpClient.submit(serverInfo, httpRequest); - - return toDocumentServiceResponse(clientResponseObservable, request); - - } catch (Exception e) { - return Observable.error(e); - } - } - - private void fillHttpRequestBaseWithHeaders(Map headers, HttpClientRequest req) { - // Add default headers. - for (Entry entry : this.defaultHeaders.entrySet()) { - if (!headers.containsKey(entry.getKey())) { - // populate default header only if there is no overwrite by the request header - req.withHeader(entry.getKey(), entry.getValue()); - } - } - - // Add override headers. - if (headers != null) { - for (Entry entry : headers.entrySet()) { - if (entry.getValue() == null) { - // netty doesn't allow setting null value in header - req.withHeader(entry.getKey(), ""); - } else { - req.withHeader(entry.getKey(), entry.getValue()); - } - } - } - } - - private URI getUri(RxDocumentServiceRequest request) throws URISyntaxException { - URI rootUri = request.getEndpointOverride(); - if (rootUri == null) { - if (request.getIsMedia()) { - // For media read request, always use the write endpoint. - rootUri = this.globalEndpointManager.getWriteEndpoints().get(0).toURI(); - } else { - rootUri = this.globalEndpointManager.resolveServiceEndpoint(request).toURI(); - } - } - - String path = PathsHelper.generatePath(request.getResourceType(), request, request.isFeed); - if(request.getResourceType().equals(ResourceType.DatabaseAccount)) { - path = StringUtils.EMPTY; - } - - URI uri = new URI("https", - null, - rootUri.getHost(), - rootUri.getPort(), - ensureSlashPrefixed(path), - null, // Query string not used. - null); - - return uri; - } - - private String ensureSlashPrefixed(String path) { - if (path == null) { - return path; - } - - if (path.startsWith("/")) { - return path; - } - - return "/" + path; - } - - private Observable toInputStream(Observable contentObservable) { - // TODO: this is a naive approach for converting to InputStream - // this first reads and buffers everything in memory and then translate that to an input stream - // this means - // 1) there is some performance implication - // 2) this may result in OutOfMemoryException if used for reading huge content, e.g., a media - // - // see this: https://github.com/ReactiveX/RxNetty/issues/391 for some similar discussion on how to - // convert to an input stream - return contentObservable - .reduce( - new ByteArrayOutputStream(), - (out, bb) -> { - try { - bb.readBytes(out, bb.readableBytes()); - return out; - } - catch (IOException e) { - throw new RuntimeException(e); - } - }) - .map(out -> { - return new ByteArrayInputStream(out.toByteArray()); - }); - } - - private Observable toString(Observable contentObservable) { - return contentObservable - .reduce( - new ByteArrayOutputStream(INITIAL_RESPONSE_BUFFER_SIZE), - (out, bb) -> { - try { - bb.readBytes(out, bb.readableBytes()); - return out; - } - catch (IOException e) { - throw new RuntimeException(e); - } - }) - .map(out -> { - return new String(out.toByteArray(), StandardCharsets.UTF_8); - }); - } - - /** - * Transforms the rxNetty's client response Observable to RxDocumentServiceResponse Observable. - * - * - * Once the customer code subscribes to the observable returned by the CRUD APIs, - * the subscription goes up till it reaches the source rxNetty's observable, and at that point the HTTP invocation will be made. - * - * @param clientResponseObservable - * @param request - * @return {@link Observable} - */ - private Observable toDocumentServiceResponse(Observable> clientResponseObservable, - RxDocumentServiceRequest request) { - - if (request.getIsMedia()) { - return clientResponseObservable.flatMap(clientResponse -> { - - // header key/value pairs - HttpResponseHeaders httpResponseHeaders = clientResponse.getHeaders(); - HttpResponseStatus httpResponseStatus = clientResponse.getStatus(); - - Observable inputStreamObservable; - - if (request.getOperationType() == OperationType.Delete) { - // for delete we don't expect any body - inputStreamObservable = Observable.just(null); - } else { - // transforms the observable to Observable - inputStreamObservable = toInputStream(clientResponse.getContent()); - } - - Observable storeResponseObservable = inputStreamObservable - .flatMap(contentInputStream -> { - try { - // If there is any error in the header response this throws exception - // TODO: potential performance improvement: return Observable.error(exception) on failure instead of throwing Exception - validateOrThrow(request, httpResponseStatus, httpResponseHeaders, null, contentInputStream); - - // transforms to Observable - StoreResponse rsp = new StoreResponse(httpResponseStatus.code(), HttpUtils.unescape(httpResponseHeaders.entries()), contentInputStream); - return Observable.just(rsp); - } catch (Exception e) { - return Observable.error(e); - } - }); - - return storeResponseObservable; - - }).map(storeResponse -> new RxDocumentServiceResponse(storeResponse)); - - } else { - return clientResponseObservable.flatMap(clientResponse -> { - - // header key/value pairs - HttpResponseHeaders httpResponseHeaders = clientResponse.getHeaders(); - HttpResponseStatus httpResponseStatus = clientResponse.getStatus(); - - Observable contentObservable; - - if (request.getOperationType() == OperationType.Delete) { - // for delete we don't expect any body - contentObservable = Observable.just(null); - } else { - // transforms the observable to Observable - contentObservable = toString(clientResponse.getContent()); - } - - Observable storeResponseObservable = contentObservable - .flatMap(content -> { - try { - // If there is any error in the header response this throws exception - // TODO: potential performance improvement: return Observable.error(exception) on failure instead of throwing Exception - validateOrThrow(request, httpResponseStatus, httpResponseHeaders, content, null); - - // transforms to Observable - StoreResponse rsp = new StoreResponse(httpResponseStatus.code(), HttpUtils.unescape(httpResponseHeaders.entries()), content); - return Observable.just(rsp); - } catch (Exception e) { - return Observable.error(e); - } - }); - - return storeResponseObservable; - - }).map(storeResponse -> new RxDocumentServiceResponse(storeResponse)) - .onErrorResumeNext(throwable -> { - if (!(throwable instanceof Exception)) { - // fatal error - logger.error("Unexpected failure {}", throwable.getMessage(), throwable); - return Observable.error(throwable); - } - - Exception exception = (Exception) throwable; - if (!(exception instanceof DocumentClientException)) { - // wrap in DocumentClientException - logger.error("Network failure", exception); - DocumentClientException dce = new DocumentClientException(0, exception); - BridgeInternal.setRequestHeaders(dce, request.getHeaders()); - return Observable.error(dce); - } - - return Observable.error(exception); - }); - } - } - - private void validateOrThrow(RxDocumentServiceRequest request, HttpResponseStatus status, HttpResponseHeaders headers, String body, - InputStream inputStream) throws DocumentClientException { - - int statusCode = status.code(); - - if (statusCode >= HttpConstants.StatusCodes.MINIMUM_STATUSCODE_AS_ERROR_GATEWAY) { - if (body == null && inputStream != null) { - try { - body = IOUtils.toString(inputStream, StandardCharsets.UTF_8); - } catch (IOException e) { - logger.error("Failed to get content from the http response", e); - DocumentClientException dce = new DocumentClientException(0, e); - BridgeInternal.setRequestHeaders(dce, request.getHeaders()); - throw dce; - } finally { - IOUtils.closeQuietly(inputStream); - } - } - - String statusCodeString = status.reasonPhrase() != null - ? status.reasonPhrase().replace(" ", "") - : ""; - Error error = null; - error = (body != null) ? new Error(body) : new Error(); - error = new Error(statusCodeString, - String.format("%s, StatusCode: %s", error.getMessage(), statusCodeString), - error.getPartitionedQueryExecutionInfo()); - - DocumentClientException dce = new DocumentClientException(statusCode, error, HttpUtils.asMap(headers)); - BridgeInternal.setRequestHeaders(dce, request.getHeaders()); - throw dce; - } - } - - private Observable invokeAsyncInternal(RxDocumentServiceRequest request) { - switch (request.getOperationType()) { - case Create: - return this.doCreate(request); - case Upsert: - return this.upsert(request); - case Delete: - return this.delete(request); - case ExecuteJavaScript: - return this.execute(request); - case Read: - return this.read(request); - case ReadFeed: - return this.readFeed(request); - case Replace: - return this.replace(request); - case SqlQuery: - case Query: - return this.query(request); - default: - throw new IllegalStateException("Unknown operation type " + request.getOperationType()); - } - } - - private Observable invokeAsync(RxDocumentServiceRequest request) { - Func0> funcDelegate = () -> invokeAsyncInternal(request).toSingle(); - return BackoffRetryUtility.executeRetry(funcDelegate, new WebExceptionRetryPolicy()).toObservable(); - } - - @Override - public Observable processMessage(RxDocumentServiceRequest request) { - this.applySessionToken(request); - - Observable responseObs = invokeAsync(request); - - return responseObs.onErrorResumeNext( - e -> { - DocumentClientException dce = Utils.as(e, DocumentClientException.class); - - if (dce == null) { - logger.error("unexpected failure {}", e.getMessage(), e); - return Observable.error(e); - } - - if ((!ReplicatedResourceClientUtils.isMasterResource(request.getResourceType())) && - (dce.getStatusCode() == HttpConstants.StatusCodes.PRECONDITION_FAILED || - dce.getStatusCode() == HttpConstants.StatusCodes.CONFLICT || - ( - dce.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND && - !Exceptions.isSubStatusCode(dce, - HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)))) { - this.captureSessionToken(request, dce.getResponseHeaders()); - } - - return Observable.error(dce); - } - ).map(response -> - { - this.captureSessionToken(request, response.getResponseHeaders()); - return response; - } - ); - } - - private void captureSessionToken(RxDocumentServiceRequest request, Map responseHeaders) { - if (request.getResourceType() == ResourceType.DocumentCollection && request.getOperationType() == OperationType.Delete) { - String resourceId; - if (request.getIsNameBased()) { - resourceId = responseHeaders.get(HttpConstants.HttpHeaders.OWNER_ID); - } else { - resourceId = request.getResourceId(); - } - this.sessionContainer.clearTokenByResourceId(resourceId); - } else { - this.sessionContainer.setSessionToken(request, responseHeaders); - } - } - - private void applySessionToken(RxDocumentServiceRequest request) { - Map headers = request.getHeaders(); - - if (headers != null && - !Strings.isNullOrEmpty(request.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN))) { - if (ReplicatedResourceClientUtils.isMasterResource(request.getResourceType())) { - request.getHeaders().remove(HttpConstants.HttpHeaders.SESSION_TOKEN); - } - return; //User is explicitly controlling the session. - } - - String requestConsistencyLevel = headers.get(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL); - - boolean sessionConsistency = - this.defaultConsistencyLevel == ConsistencyLevel.Session || - (!Strings.isNullOrEmpty(requestConsistencyLevel) - && Strings.areEqual(requestConsistencyLevel, ConsistencyLevel.Session.name())); - - if (!sessionConsistency || ReplicatedResourceClientUtils.isMasterResource(request.getResourceType())) { - return; // Only apply the session token in case of session consistency and when resource is not a master resource - } - - //Apply the ambient session. - String sessionToken = this.sessionContainer.resolveGlobalSessionToken(request); - - if (!Strings.isNullOrEmpty(sessionToken)) { - headers.put(HttpConstants.HttpHeaders.SESSION_TOKEN, sessionToken); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxStoreModel.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxStoreModel.java deleted file mode 100644 index ca5184c221ed..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxStoreModel.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import rx.Observable; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public interface RxStoreModel { - - /** - * Given the request, it returns an Observable of the response. - * - * The Observable upon subscription will execute the request and upon successful execution request returns a single {@link RxDocumentServiceResponse}. - * If the execution of the request fails it returns an error. - * - * @param request - * @return - */ - Observable processMessage(RxDocumentServiceRequest request); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/WebExceptionRetryPolicy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/WebExceptionRetryPolicy.java deleted file mode 100644 index 48f61b07ef9e..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/WebExceptionRetryPolicy.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WebExceptionUtility; -import org.apache.commons.lang3.time.StopWatch; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Single; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -public class WebExceptionRetryPolicy implements IRetryPolicy { - private final static Logger logger = LoggerFactory.getLogger(WebExceptionRetryPolicy.class); - - // total wait time in seconds to retry. should be max of primary reconfigrations/replication wait duration etc - private final static int waitTimeInSeconds = 30; - private final static int initialBackoffSeconds = 1; - private final static int backoffMultiplier = 2; - - private StopWatch durationTimer = new StopWatch(); - private int attemptCount = 1; - // Don't penalise first retry with delay. - private int currentBackoffSeconds = WebExceptionRetryPolicy.initialBackoffSeconds; - - public WebExceptionRetryPolicy() { - durationTimer.start(); - } - - - @Override - public Single shouldRetry(Exception exception) { - Duration backoffTime = Duration.ofSeconds(0); - - if (!WebExceptionUtility.isWebExceptionRetriable(exception)) { - // Have caller propagate original exception. - this.durationTimer.stop(); - return Single.just(ShouldRetryResult.noRetry()); - } - - // Don't penalise first retry with delay. - if (attemptCount++ > 1) { - int remainingSeconds = WebExceptionRetryPolicy.waitTimeInSeconds - Math.toIntExact(this.durationTimer.getTime(TimeUnit.SECONDS)); - if (remainingSeconds <= 0) { - this.durationTimer.stop(); - return Single.just(ShouldRetryResult.noRetry()); - } - - backoffTime = Duration.ofSeconds(Math.min(this.currentBackoffSeconds, remainingSeconds)); - this.currentBackoffSeconds *= WebExceptionRetryPolicy.backoffMultiplier; - } - - logger.warn("Received retriable web exception, will retry", exception); - - return Single.just(ShouldRetryResult.retryAfter(backoffTime)); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncCache.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncCache.java deleted file mode 100644 index 58ad25c7bd9d..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncCache.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -import java.util.concurrent.ConcurrentHashMap; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import rx.Observable; -import rx.Single; -import rx.functions.Func0; - -public class AsyncCache { - - private final Logger logger = LoggerFactory.getLogger(AsyncCache.class); - private final ConcurrentHashMap> values = new ConcurrentHashMap<>(); - - private final IEqualityComparer equalityComparer; - - public AsyncCache(IEqualityComparer equalityComparer) { - this.equalityComparer = equalityComparer; - } - - public AsyncCache() { - this(new IEqualityComparer() { - @Override - public boolean areEqual(TValue value1, TValue value2) { - if (value1 == value2) - return true; - if (value1 == null || value2 == null) - return false; - return value1.equals(value2); - } - }); - } - - public void set(TKey key, TValue value) { - logger.debug("set cache[{}]={}", key, value); - values.put(key, new AsyncLazy<>(value)); - } - - /** - * Gets value corresponding to key - * - *

- * If another initialization function is already running, new initialization function will not be started. - * The result will be result of currently running initialization function. - *

- * - *

- * If previous initialization function is successfully completed - value returned by it will be returned unless - * it is equal to obsoleteValue, in which case new initialization function will be started. - *

- *

- * If previous initialization function failed - new one will be launched. - *

- * - * @param key Key for which to get a value. - * @param obsoleteValue Value which is obsolete and needs to be refreshed. - * @param singleValueInitFunc Initialization function. - * @return Cached value or value returned by initialization function. - */ - public Single getAsync( - TKey key, - TValue obsoleteValue, - Func0> singleValueInitFunc) { - - AsyncLazy initialLazyValue = values.get(key); - if (initialLazyValue != null) { - - logger.debug("cache[{}] exists", key); - return initialLazyValue.single().toObservable().flatMap(vaule -> { - - if (!equalityComparer.areEqual(vaule, obsoleteValue)) { - logger.debug("Returning cache[{}] as it is different from obsoleteValue", key); - return Observable.just(vaule); - } - - logger.debug("cache[{}] result value is obsolete ({}), computing new value", key, obsoleteValue); - AsyncLazy asyncLazy = new AsyncLazy<>(singleValueInitFunc); - AsyncLazy actualValue = values.merge(key, asyncLazy, - (lazyValue1, lazyValu2) -> lazyValue1 == initialLazyValue ? lazyValu2 : lazyValue1); - return actualValue.single().toObservable(); - - }, err -> { - - logger.debug("cache[{}] resulted in error {}, computing new value", key, err); - AsyncLazy asyncLazy = new AsyncLazy<>(singleValueInitFunc); - AsyncLazy resultAsyncLazy = values.merge(key, asyncLazy, - (lazyValue1, lazyValu2) -> lazyValue1 == initialLazyValue ? lazyValu2 : lazyValue1); - return resultAsyncLazy.single().toObservable(); - - }, () -> Observable.empty()).toSingle(); - } - - logger.debug("cache[{}] doesn't exist, computing new value", key); - AsyncLazy asyncLazy = new AsyncLazy<>(singleValueInitFunc); - AsyncLazy resultAsyncLazy = values.merge(key, asyncLazy, - (lazyValue1, lazyValu2) -> lazyValue1 == initialLazyValue ? lazyValu2 : lazyValue1); - return resultAsyncLazy.single(); - } - - public void remove(TKey key) { - values.remove(key); - } - - /** - * Remove value from cache and return it if present - * @param key - * @return Value if present, default value if not present - */ - public Single removeAsync(TKey key) { - AsyncLazy lazy = values.remove(key); - return lazy.single(); - // TODO: .Net returns default value on failure of single why? - } - - public void clear() { - this.values.clear(); - } - - /** - * Forces refresh of the cached item if it is not being refreshed at the moment. - * @param key - * @param singleValueInitFunc - */ - public void refresh( - TKey key, - Func0> singleValueInitFunc) { - logger.debug("refreshing cache[{}]", key); - AsyncLazy initialLazyValue = values.get(key); - if (initialLazyValue != null && (initialLazyValue.isSucceeded() || initialLazyValue.isFaulted())) { - AsyncLazy newLazyValue = new AsyncLazy<>(singleValueInitFunc); - - // Update the new task in the cache, - values.merge(key, newLazyValue, - (lazyValue1, lazyValu2) -> lazyValue1 == initialLazyValue ? lazyValu2 : lazyValue1); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncLazy.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncLazy.java deleted file mode 100644 index 79a2c377b7a1..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncLazy.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import rx.Single; -import rx.functions.Func0; - -class AsyncLazy { - - private final static Logger logger = LoggerFactory.getLogger(AsyncLazy.class); - - private final Single single; - - private volatile boolean succeeded; - private volatile boolean failed; - - public AsyncLazy(Func0> func) { - this(Single.defer(() -> { - logger.debug("using Func0> {}", func); - return func.call(); - })); - } - - public AsyncLazy(TValue value) { - this.single = Single.just(value); - this.succeeded = true; - this.failed = false; - } - - private AsyncLazy(Single single) { - logger.debug("constructor"); - this.single = single - .doOnSuccess(v -> this.succeeded = true) - .doOnError(e -> this.failed = true) - .cache(); - } - - public Single single() { - return single; - } - - public boolean isSucceeded() { - return succeeded; - } - - public boolean isFaulted() { - return failed; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/IEqualityComparer.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/IEqualityComparer.java deleted file mode 100644 index a9cd210edb5f..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/IEqualityComparer.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -interface IEqualityComparer { - boolean areEqual(TValue v1, TValue v2); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/IPartitionKeyRangeCache.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/IPartitionKeyRangeCache.java deleted file mode 100644 index 1d92cf412dba..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/IPartitionKeyRangeCache.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * The MIT License (MIT) - * Copyright (c) 2017 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -import java.util.List; -import java.util.Map; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.ICollectionRoutingMapCache; -import com.microsoft.azure.cosmosdb.rx.internal.IRoutingMapProvider; - -import rx.Single; - -/** - * - */ -public interface IPartitionKeyRangeCache extends IRoutingMapProvider, ICollectionRoutingMapCache { - - Single tryLookupAsync(String collectionRid, CollectionRoutingMap previousValue, Map properties); - - Single> tryGetOverlappingRangesAsync(String collectionRid, Range range, boolean forceRefresh, - Map properties); - - Single tryGetPartitionKeyRangeByIdAsync(String collectionResourceId, String partitionKeyRangeId, boolean forceRefresh, - Map properties); - - Single tryGetRangeByPartitionKeyRangeId(String collectionRid, String partitionKeyRangeId, Map properties); - -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxClientCollectionCache.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxClientCollectionCache.java deleted file mode 100644 index 64fecf3166ef..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxClientCollectionCache.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.HashMap; -import java.util.Map; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.rx.internal.AuthorizationTokenType; -import com.microsoft.azure.cosmosdb.rx.internal.ClearingSessionContainerClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicyFactory; -import com.microsoft.azure.cosmosdb.rx.internal.ObservableHelper; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.RxStoreModel; - -import rx.Observable; -import rx.Single; - -/** - * Caches collection information. - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class RxClientCollectionCache extends RxCollectionCache { - - private RxStoreModel storeModel; - private final IAuthorizationTokenProvider tokenProvider; - private final IRetryPolicyFactory retryPolicy; - private final ISessionContainer sessionContainer; - - public RxClientCollectionCache(ISessionContainer sessionContainer, - RxStoreModel storeModel, - IAuthorizationTokenProvider tokenProvider, - IRetryPolicyFactory retryPolicy) { - this.storeModel = storeModel; - this.tokenProvider = tokenProvider; - this.retryPolicy = retryPolicy; - this.sessionContainer = sessionContainer; - } - - protected Single getByRidAsync(String collectionRid, Map properties) { - IDocumentClientRetryPolicy retryPolicyInstance = new ClearingSessionContainerClientRetryPolicy(this.sessionContainer, this.retryPolicy.getRequestPolicy()); - return ObservableHelper.inlineIfPossible( - () -> this.readCollectionAsync(PathsHelper.generatePath(ResourceType.DocumentCollection, collectionRid, false), retryPolicyInstance, properties) - , retryPolicyInstance); - } - - protected Single getByNameAsync(String resourceAddress, Map properties) { - IDocumentClientRetryPolicy retryPolicyInstance = new ClearingSessionContainerClientRetryPolicy(this.sessionContainer, this.retryPolicy.getRequestPolicy()); - return ObservableHelper.inlineIfPossible( - () -> this.readCollectionAsync(resourceAddress, retryPolicyInstance, properties), - retryPolicyInstance); - } - - private Single readCollectionAsync(String collectionLink, IDocumentClientRetryPolicy retryPolicyInstance, Map properties) { - - String path = Utils.joinPath(collectionLink, null); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create( - OperationType.Read, - ResourceType.DocumentCollection, - path, - new HashMap()); - - request.getHeaders().put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); - - String resourceName = request.getResourceAddress(); - String authorizationToken = tokenProvider.getUserAuthorizationToken( - resourceName, - request.getResourceType(), - HttpConstants.HttpMethods.GET, - request.getHeaders(), - AuthorizationTokenType.PrimaryMasterKey, - properties); - - try { - authorizationToken = URLEncoder.encode(authorizationToken, "UTF-8"); - } catch (UnsupportedEncodingException e) { - return Single.error(new IllegalStateException("Failed to encode authtoken.", e)); - } - request.getHeaders().put(HttpConstants.HttpHeaders.AUTHORIZATION, authorizationToken); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - Observable responseObs = this.storeModel.processMessage(request); - return responseObs.map(response -> BridgeInternal.toResourceResponse(response, DocumentCollection.class) - .getResource()).toSingle(); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxCollectionCache.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxCollectionCache.java deleted file mode 100644 index e634593434ae..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxCollectionCache.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -import org.apache.commons.lang3.StringUtils; - -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.ResourceId; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionException; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import com.microsoft.azure.cosmosdb.rx.internal.RMResources; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import rx.Completable; -import rx.Single; - -import java.util.Map; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public abstract class RxCollectionCache { - - private final AsyncCache collectionInfoByNameCache; - private final AsyncCache collectionInfoByIdCache; - - protected RxCollectionCache() { - this.collectionInfoByNameCache = new AsyncCache(new CollectionRidComparer()); - this.collectionInfoByIdCache = new AsyncCache(new CollectionRidComparer()); - } - - /** - * Resolves a request to a collection in a sticky manner. - * Unless request.ForceNameCacheRefresh is equal to true, it will return the same collection. - * @param request Request to resolve. - * @return an instance of Single<DocumentCollection> - */ - public Single resolveCollectionAsync( - RxDocumentServiceRequest request) { - Completable init = null; - if (request.getIsNameBased()) { - if (request.isForceNameCacheRefresh()) { - Completable completable = this.refreshAsync(request); - init = completable.andThen(Completable.fromAction(() -> request.setForceNameCacheRefresh(false))); - } - - Single collectionInfoObs = this.resolveByPartitionKeyRangeIdentityAsync( - request.getPartitionKeyRangeIdentity(), request.properties); - - if (init != null) { - collectionInfoObs = init.andThen(collectionInfoObs); - } - - return collectionInfoObs.flatMap(collectionInfo -> { - if (collectionInfo != null) { - return Single.just(collectionInfo); - } - - if (request.requestContext.resolvedCollectionRid == null) { - - Single collectionInfoRes = this.resolveByNameAsync(request.getResourceAddress(), request.properties); - - return collectionInfoRes.flatMap(collection -> { - // TODO: how to async log this? - // logger.debug( - // "Mapped resourceName {} to resourceId {}.", - // request.getResourceAddress(), - // collectionInfo.getResourceId()); - - request.setResourceId(collection.getResourceId()); - request.requestContext.resolvedCollectionRid = collection.getResourceId(); - return Single.just(collection); - - }); - } else { - return this.resolveByRidAsync(request.requestContext.resolvedCollectionRid, request.properties); - } - }); - } else { - return resolveByPartitionKeyRangeIdentityAsync(request.getPartitionKeyRangeIdentity(),request.properties) - .flatMap(collection -> { - - if (collection != null) { - return Single.just(collection); - } - - return this.resolveByRidAsync(request.getResourceAddress(), request.properties); - }); - } - } - - /** - * This method is only used in retry policy as it doesn't have request handy. - * @param resourceAddress - */ - public void refresh(String resourceAddress, Map properties) { - if (PathsHelper.isNameBased(resourceAddress)) { - String resourceFullName = PathsHelper.getCollectionPath(resourceAddress); - - this.collectionInfoByNameCache.refresh( - resourceFullName, - () -> { - Single collectionObs = this.getByNameAsync(resourceFullName, properties); - return collectionObs.doOnSuccess(collection -> { - this.collectionInfoByIdCache.set(collection.getResourceId(), collection); - }); - }); - } - } - - protected abstract Single getByRidAsync(String collectionRid, Map properties); - - protected abstract Single getByNameAsync(String resourceAddress, Map properties); - - private Single resolveByPartitionKeyRangeIdentityAsync(PartitionKeyRangeIdentity partitionKeyRangeIdentity, Map properties) { - // if request is targeted at specific partition using x-ms-documentd-partitionkeyrangeid header, - // which contains value ",", then resolve to collection rid in this header. - if (partitionKeyRangeIdentity != null && partitionKeyRangeIdentity.getCollectionRid() != null) { - return this.resolveByRidAsync(partitionKeyRangeIdentity.getCollectionRid(), properties) - .onErrorResumeNext(e -> { - if (e instanceof NotFoundException) { - // This is signal to the upper logic either to refresh - // collection cache and retry. - return Single.error(new InvalidPartitionException(RMResources.InvalidDocumentCollection)); - } - return Single.error(e); - - }); - } - return Single.just(null); - } - - private Single resolveByRidAsync( - String resourceId, Map properties) { - - ResourceId resourceIdParsed = ResourceId.parse(resourceId); - String collectionResourceId = resourceIdParsed.getDocumentCollectionId().toString(); - - return this.collectionInfoByIdCache.getAsync( - collectionResourceId, - null, - () -> this.getByRidAsync(collectionResourceId, properties)); - } - - private Single resolveByNameAsync( - String resourceAddress, Map properties) { - - String resourceFullName = PathsHelper.getCollectionPath(resourceAddress); - - return this.collectionInfoByNameCache.getAsync( - resourceFullName, - null, - () -> { - Single collectionObs = this.getByNameAsync(resourceFullName, properties); - return collectionObs.doOnSuccess(collection -> { - this.collectionInfoByIdCache.set(collection.getResourceId(), collection); - }); - }); - } - - private Completable refreshAsync(RxDocumentServiceRequest request) { - // TODO System.Diagnostics.Debug.Assert(request.IsNameBased); - - String resourceFullName = PathsHelper.getCollectionPath(request.getResourceAddress()); - Completable completable = null; - - if (request.requestContext.resolvedCollectionRid != null) { - // Here we will issue backend call only if cache wasn't already refreshed (if whatever is there corresponds to previously resolved collection rid). - DocumentCollection obsoleteValue = new DocumentCollection(); - obsoleteValue.setResourceId(request.requestContext.resolvedCollectionRid); - - completable = this.collectionInfoByNameCache.getAsync( - resourceFullName, - obsoleteValue, - () -> { - Single collectionObs = this.getByNameAsync(resourceFullName, request.properties); - return collectionObs.doOnSuccess(collection -> { - this.collectionInfoByIdCache.set(collection.getResourceId(), collection); - }); - }).toCompletable(); - } else { - // In case of ForceRefresh directive coming from client, there will be no ResolvedCollectionRid, so we - // need to refresh unconditionally. - completable = Completable.fromAction(() -> this.refresh(request.getResourceAddress(), request.properties)); - } - - return completable.doOnCompleted(() -> request.requestContext.resolvedCollectionRid = null); - } - - private class CollectionRidComparer implements IEqualityComparer { - public boolean areEqual(DocumentCollection left, DocumentCollection right) { - if (left == null && right == null) { - return true; - } - - if ((left == null) ^ (right == null)) { - return false; - } - - return StringUtils.equals(left.getResourceId(), right.getResourceId()); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/AggregateDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/AggregateDocumentQueryExecutionContext.java deleted file mode 100644 index 8305732d9ff8..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/AggregateDocumentQueryExecutionContext.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.function.Function; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.AggregateOperator; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.Aggregator; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.AverageAggregator; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.CountAggregator; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.MaxAggregator; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.MinAggregator; -import com.microsoft.azure.cosmosdb.internal.query.aggregation.SumAggregator; -import com.microsoft.azure.cosmosdb.QueryMetrics; - -import rx.Observable; - -public class AggregateDocumentQueryExecutionContext implements IDocumentQueryExecutionComponent{ - - private IDocumentQueryExecutionComponent component; - private Aggregator aggregator; - private ConcurrentMap queryMetricsMap = new ConcurrentHashMap<>(); - - //QueryInfo class used in PipelinedDocumentQueryExecutionContext returns a Collection of AggregateOperators - //while Multiple aggregates are allowed in queries targeted at a single partition, only a single aggregate is allowed in x-partition queries (currently) - public AggregateDocumentQueryExecutionContext (IDocumentQueryExecutionComponent component, Collection aggregateOperators) { - - this.component = component; - AggregateOperator aggregateOperator = aggregateOperators.iterator().next(); - - switch (aggregateOperator) { - case Average: - this.aggregator = new AverageAggregator(); - break; - case Count: - this.aggregator = new CountAggregator(); - break; - case Max: - this.aggregator = new MaxAggregator(); - break; - case Min: - this.aggregator = new MinAggregator(); - break; - case Sum: - this.aggregator = new SumAggregator(); - break; - default: - throw new IllegalStateException("Unexpected value: " + aggregateOperator.toString()); - } - } - - @SuppressWarnings("unchecked") - @Override - public Observable> drainAsync(int maxPageSize) { - - return this.component.drainAsync(maxPageSize) - .toList() - .map( superList -> { - - double requestCharge = 0; - List aggregateResults = new ArrayList(); - HashMap headers = new HashMap(); - - for(FeedResponse page : superList) { - - if (page.getResults().size() == 0) { - headers.put(HttpConstants.HttpHeaders.REQUEST_CHARGE, Double.toString(requestCharge)); - FeedResponse frp = BridgeInternal.createFeedResponse(aggregateResults, headers); - return (FeedResponse) frp; - } - - Document doc = ((Document)page.getResults().get(0)); - requestCharge += page.getRequestCharge(); - QueryItem values = new QueryItem(doc.toJson()); - this.aggregator.aggregate(values.getItem()); - for(String key : page.getQueryMetrics().keySet()) { - if (queryMetricsMap.containsKey(key)) { - QueryMetrics qm = page.getQueryMetrics().get(key); - queryMetricsMap.get(key).add(qm); - } else { - queryMetricsMap.put(key, page.getQueryMetrics().get(key)); - } - } - } - - if (this.aggregator.getResult() == null || !this.aggregator.getResult().equals(Undefined.Value())) { - Document aggregateDocument = new Document(); - aggregateDocument.set(Constants.Properties.AGGREGATE, this.aggregator.getResult()); - aggregateResults.add(aggregateDocument); - } - - headers.put(HttpConstants.HttpHeaders.REQUEST_CHARGE, Double.toString(requestCharge)); - FeedResponse frp = BridgeInternal.createFeedResponse(aggregateResults, headers); - if(!queryMetricsMap.isEmpty()) { - for(String key: queryMetricsMap.keySet()) { - BridgeInternal.putQueryMetricsIntoMap(frp, key, queryMetricsMap.get(key)); - } - } - return (FeedResponse) frp; - }); - } - - public static Observable> createAsync( - Function>> createSourceComponentFunction, - Collection aggregates, - String continuationToken) { - - return createSourceComponentFunction - .apply(continuationToken) - .map( component -> { return new AggregateDocumentQueryExecutionContext(component, aggregates);}); - } - - public IDocumentQueryExecutionComponent getComponent() { - return this.component; - } - -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/CompositeContinuationToken.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/CompositeContinuationToken.java deleted file mode 100644 index 050c24b23ab6..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/CompositeContinuationToken.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public final class CompositeContinuationToken extends JsonSerializable { - private static final String TokenPropertyName = "token"; - private static final String RangePropertyName = "range"; - private static final Logger logger = LoggerFactory.getLogger(CompositeContinuationToken.class); - - public CompositeContinuationToken(String token, Range range) { - // token is allowed to be null - if (range == null) { - throw new IllegalArgumentException("range must not be null."); - } - - this.setToken(token); - this.setRange(range); - } - - private CompositeContinuationToken(String serializedCompositeContinuationToken) { - super(serializedCompositeContinuationToken); - } - - public static boolean tryParse(String serializedCompositeContinuationToken, - ValueHolder outCompositeContinuationToken) { - boolean parsed; - try { - CompositeContinuationToken compositeContinuationToken = new CompositeContinuationToken( - serializedCompositeContinuationToken); - compositeContinuationToken.getToken(); - - Range range = compositeContinuationToken.getRange(); - if (range == null) { - throw new IllegalArgumentException("range must not be null."); - } - - range.getMax(); - range.getMin(); - range.isEmpty(); - range.isMaxInclusive(); - range.isMinInclusive(); - range.isSingleValue(); - - outCompositeContinuationToken.v = compositeContinuationToken; - parsed = true; - } catch (Exception ex) { - logger.debug( - "Received exception {} when trying to parse: {}", - ex.getMessage(), - serializedCompositeContinuationToken); - parsed = false; - outCompositeContinuationToken.v = null; - } - - return parsed; - } - - /** - * @return the token - */ - public String getToken() { - return super.getString(TokenPropertyName); - } - - /** - * @return the range - */ - public Range getRange() { - return new Range(super.getString(RangePropertyName)); - } - - /** - * @param token - * the token to set - */ - private void setToken(String token) { - super.set(TokenPropertyName, token); - } - - /** - * @param range - * the range to set - */ - private void setRange(Range range) { - /* TODO: Don't stringify the range */ - super.set(RangePropertyName, range.toString()); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DefaultDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DefaultDocumentQueryExecutionContext.java deleted file mode 100644 index b29ab978a577..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DefaultDocumentQueryExecutionContext.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.BackoffRetryUtility; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.InvalidPartitionExceptionRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.PartitionKeyRangeGoneRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import com.microsoft.azure.cosmosdb.rx.internal.caches.IPartitionKeyRangeCache; -import com.microsoft.azure.cosmosdb.internal.query.metrics.ClientSideMetrics; -import com.microsoft.azure.cosmosdb.internal.query.metrics.FetchExecutionRangeAccumulator; -import com.microsoft.azure.cosmosdb.QueryMetrics; -import com.microsoft.azure.cosmosdb.internal.query.metrics.SchedulingStopwatch; -import com.microsoft.azure.cosmosdb.internal.query.metrics.SchedulingTimeSpan; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import rx.Observable; -import rx.Single; -import rx.functions.Func1; -import rx.functions.Func2; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class DefaultDocumentQueryExecutionContext extends DocumentQueryExecutionContextBase { - - private boolean isContinuationExpected; - private volatile int retries = -1; - - private final SchedulingStopwatch fetchSchedulingMetrics; - private final FetchExecutionRangeAccumulator fetchExecutionRangeAccumulator; - private static final String DEFAULT_PARTITION_KEY_RANGE_ID = "0"; - - public DefaultDocumentQueryExecutionContext(IDocumentQueryClient client, ResourceType resourceTypeEnum, - Class resourceType, SqlQuerySpec query, FeedOptions feedOptions, String resourceLink, - UUID correlatedActivityId, boolean isContinuationExpected) { - - super(client, - resourceTypeEnum, - resourceType, - query, - feedOptions, - resourceLink, - false, - correlatedActivityId); - - this.isContinuationExpected = isContinuationExpected; - this.fetchSchedulingMetrics = new SchedulingStopwatch(); - this.fetchSchedulingMetrics.ready(); - this.fetchExecutionRangeAccumulator = new FetchExecutionRangeAccumulator(DEFAULT_PARTITION_KEY_RANGE_ID); - } - - protected PartitionKeyInternal getPartitionKeyInternal() { - return this.feedOptions.getPartitionKey() == null ? null : feedOptions.getPartitionKey().getInternalPartitionKey(); - } - - @Override - public Observable> executeAsync() { - - if (feedOptions == null) { - feedOptions = new FeedOptions(); - } - - FeedOptions newFeedOptions = new FeedOptions(feedOptions); - - // We can not go to backend with the composite continuation token, - // but we still need the gateway for the query plan. - // The workaround is to try and parse the continuation token as a composite continuation token. - // If it is, then we send the query to the gateway with max degree of parallelism to force getting back the query plan - - String originalContinuation = newFeedOptions.getRequestContinuation(); - - if (isClientSideContinuationToken(originalContinuation)) { - // At this point we know we want back a query plan - newFeedOptions.setRequestContinuation(null); - newFeedOptions.setMaxDegreeOfParallelism(Integer.MAX_VALUE); - } - - int maxPageSize = newFeedOptions.getMaxItemCount() != null ? newFeedOptions.getMaxItemCount() : Constants.Properties.DEFAULT_MAX_PAGE_SIZE; - - Func2 createRequestFunc = (continuationToken, pageSize) -> this.createRequestAsync(continuationToken, pageSize); - - // TODO: clean up if we want to use single vs observable. - Func1>> executeFunc = executeInternalAsyncFunc(); - - return Paginator - .getPaginatedQueryResultAsObservable(newFeedOptions, createRequestFunc, executeFunc, resourceType, maxPageSize); - } - - public Single> getTargetPartitionKeyRanges(String resourceId, List> queryRanges) { - // TODO: FIXME this needs to be revisited - - Range r = new Range<>("", "FF", true, false); - return client.getPartitionKeyRangeCache().tryGetOverlappingRangesAsync(resourceId, r, false, null); - } - - protected Func1>> executeInternalAsyncFunc() { - RxCollectionCache collectionCache = this.client.getCollectionCache(); - IPartitionKeyRangeCache partitionKeyRangeCache = this.client.getPartitionKeyRangeCache(); - IDocumentClientRetryPolicy retryPolicyInstance = this.client.getResetSessionTokenRetryPolicy().getRequestPolicy(); - - retryPolicyInstance = new InvalidPartitionExceptionRetryPolicy(collectionCache, retryPolicyInstance, resourceLink, feedOptions); - if (super.resourceTypeEnum.isPartitioned()) { - retryPolicyInstance = new PartitionKeyRangeGoneRetryPolicy( - collectionCache, - partitionKeyRangeCache, - PathsHelper.getCollectionPath(super.resourceLink), - retryPolicyInstance, - feedOptions); - } - - final IDocumentClientRetryPolicy finalRetryPolicyInstance = retryPolicyInstance; - - Func1>> executeFunc = req -> { - finalRetryPolicyInstance.onBeforeSendRequest(req); - this.fetchExecutionRangeAccumulator.beginFetchRange(); - this.fetchSchedulingMetrics.start(); - return BackoffRetryUtility.executeRetry(() -> { - ++this.retries; - return executeRequestAsync(req); - }, finalRetryPolicyInstance).toObservable() - .map(tFeedResponse -> { - this.fetchSchedulingMetrics.stop(); - this.fetchExecutionRangeAccumulator.endFetchRange(tFeedResponse.getActivityId(), - tFeedResponse.getResults().size(), - this.retries); - ImmutablePair schedulingTimeSpanMap = - new ImmutablePair<>(DEFAULT_PARTITION_KEY_RANGE_ID, this.fetchSchedulingMetrics.getElapsedTime()); - if (!StringUtils.isEmpty(tFeedResponse.getResponseHeaders().get(HttpConstants.HttpHeaders.QUERY_METRICS))) { - QueryMetrics qm = - BridgeInternal.createQueryMetricsFromDelimitedStringAndClientSideMetrics(tFeedResponse.getResponseHeaders() - .get(HttpConstants.HttpHeaders.QUERY_METRICS), - new ClientSideMetrics(this.retries, - tFeedResponse.getRequestCharge(), - this.fetchExecutionRangeAccumulator.getExecutionRanges(), - Arrays.asList(schedulingTimeSpanMap)), - tFeedResponse.getActivityId()); - BridgeInternal.putQueryMetricsIntoMap(tFeedResponse, DEFAULT_PARTITION_KEY_RANGE_ID, qm); - } - return tFeedResponse; - }); - }; - - return executeFunc; - } - - private Single> executeOnceAsync(IDocumentClientRetryPolicy retryPolicyInstance, String continuationToken) { - // Don't reuse request, as the rest of client SDK doesn't reuse requests between retries. - // The code leaves some temporary garbage in request (in RequestContext etc.), - // which shold be erased during retries. - - RxDocumentServiceRequest request = this.createRequestAsync(continuationToken, this.feedOptions.getMaxItemCount()); - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - if (!Strings.isNullOrEmpty(request.getHeaders().get(HttpConstants.HttpHeaders.PARTITION_KEY)) - || !request.getResourceType().isPartitioned()) { - return this.executeRequestAsync(request); - } - - - // TODO: remove this as partition key range id is not relevant - // TODO; has to be rx async - //CollectionCache collectionCache = this.client.getCollectionCache(); - - // TODO: has to be rx async - //DocumentCollection collection = - // collectionCache.resolveCollection(request); - - // TODO: this code is not relevant because partition key range id should not be exposed - // if (!Strings.isNullOrEmpty(super.getPartitionKeyId())) - // { - // request.RouteTo(new PartitionKeyRangeIdentity(collection.ResourceId, base.PartitionKeyRangeId)); - // return await this.ExecuteRequestAsync(request); - // } - - request.UseGatewayMode = true; - return this.executeRequestAsync(request); - } - - public RxDocumentServiceRequest createRequestAsync(String continuationToken, Integer maxPageSize) { - - // TODO this should be async - Map requestHeaders = this.createCommonHeadersAsync( - this.getFeedOptions(continuationToken, maxPageSize)); - - // TODO: add support for simple continuation for single partition query - //requestHeaders.put(keyHttpConstants.HttpHeaders.IsContinuationExpected, isContinuationExpected.ToString()) - - RxDocumentServiceRequest request = this.createDocumentServiceRequest( - requestHeaders, - this.query, - this.getPartitionKeyInternal()); - - if (!StringUtils.isEmpty(feedOptions.getPartitionKeyRangeIdInternal())) { - request.routeTo(new PartitionKeyRangeIdentity(feedOptions.getPartitionKeyRangeIdInternal())); - } - - return request; - } - - private static boolean isClientSideContinuationToken(String continuationToken) { - if (continuationToken != null) { - ValueHolder outCompositeContinuationToken = new ValueHolder(); - if (CompositeContinuationToken.tryParse(continuationToken, outCompositeContinuationToken)) { - return true; - } - - ValueHolder outOrderByContinuationToken = new ValueHolder(); - if (OrderByContinuationToken.tryParse(continuationToken, outOrderByContinuationToken)) { - return true; - } - - ValueHolder outTakeContinuationToken = new ValueHolder(); - if (TakeContinuationToken.tryParse(continuationToken, outTakeContinuationToken)) { - return true; - } - } - - return false; - } -} - diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentProducer.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentProducer.java deleted file mode 100644 index 37303c96ad40..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentProducer.java +++ /dev/null @@ -1,270 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.ObservableHelper; -import com.microsoft.azure.cosmosdb.internal.query.metrics.ClientSideMetrics; -import com.microsoft.azure.cosmosdb.internal.query.metrics.FetchExecutionRangeAccumulator; -import com.microsoft.azure.cosmosdb.QueryMetrics; -import com.microsoft.azure.cosmosdb.QueryMetricsConstants; -import com.microsoft.azure.cosmosdb.internal.query.metrics.SchedulingStopwatch; -import com.microsoft.azure.cosmosdb.internal.query.metrics.SchedulingTimeSpan; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.Exceptions; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -import rx.Observable; -import rx.Single; -import rx.functions.Func0; -import rx.functions.Func1; -import rx.functions.Func2; -import rx.functions.Func3; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -class DocumentProducer { - private static final Logger logger = LoggerFactory.getLogger(DocumentProducer.class); - private int retries; - - class DocumentProducerFeedResponse { - FeedResponse pageResult; - PartitionKeyRange sourcePartitionKeyRange; - - DocumentProducerFeedResponse(FeedResponse pageResult) { - this.pageResult = pageResult; - this.sourcePartitionKeyRange = DocumentProducer.this.targetRange; - populatePartitionedQueryMetrics(); - } - - DocumentProducerFeedResponse(FeedResponse pageResult, PartitionKeyRange pkr) { - this.pageResult = pageResult; - this.sourcePartitionKeyRange = pkr; - populatePartitionedQueryMetrics(); - } - - void populatePartitionedQueryMetrics() { - String queryMetricsDelimitedString = pageResult.getResponseHeaders().get(HttpConstants.HttpHeaders.QUERY_METRICS); - if (!StringUtils.isEmpty(queryMetricsDelimitedString)) { - queryMetricsDelimitedString += String.format(";%s=%.2f", QueryMetricsConstants.RequestCharge, pageResult.getRequestCharge()); - ImmutablePair schedulingTimeSpanMap = - new ImmutablePair<>(targetRange.getId(), fetchSchedulingMetrics.getElapsedTime()); - - QueryMetrics qm =BridgeInternal.createQueryMetricsFromDelimitedStringAndClientSideMetrics(queryMetricsDelimitedString, - new ClientSideMetrics(retries, - pageResult.getRequestCharge(), - fetchExecutionRangeAccumulator.getExecutionRanges(), - Arrays.asList(schedulingTimeSpanMap) - ), pageResult.getActivityId()); - BridgeInternal.putQueryMetricsIntoMap(pageResult, targetRange.getId(), qm); - } - } - } - - protected final IDocumentQueryClient client; - protected final String collectionRid; - protected final FeedOptions feedOptions; - protected final Class resourceType; - protected final PartitionKeyRange targetRange; - protected final String collectionLink; - protected final Func3 createRequestFunc; - protected final Func1>> executeRequestFuncWithRetries; - protected final Func0 createRetryPolicyFunc; - protected final int pageSize; - protected final UUID correlatedActivityId; - public int top; - private volatile String lastResponseContinuationToken; - private final SchedulingStopwatch fetchSchedulingMetrics; - private SchedulingStopwatch moveNextSchedulingMetrics; - private final FetchExecutionRangeAccumulator fetchExecutionRangeAccumulator; - - public DocumentProducer( - IDocumentQueryClient client, - String collectionResourceId, - FeedOptions feedOptions, - Func3 createRequestFunc, - Func1>> executeRequestFunc, - PartitionKeyRange targetRange, - String collectionLink, - Func0 createRetryPolicyFunc, - Class resourceType , - UUID correlatedActivityId, - int initialPageSize, // = -1, - String initialContinuationToken, - int top) { - - this.client = client; - this.collectionRid = collectionResourceId; - - this.createRequestFunc = createRequestFunc; - - this.fetchSchedulingMetrics = new SchedulingStopwatch(); - this.fetchSchedulingMetrics.ready(); - this.fetchExecutionRangeAccumulator = new FetchExecutionRangeAccumulator(targetRange.getId()); - - this.executeRequestFuncWithRetries = request -> { - retries = -1; - this.fetchSchedulingMetrics.start(); - this.fetchExecutionRangeAccumulator.beginFetchRange(); - IDocumentClientRetryPolicy retryPolicy = null; - if (createRetryPolicyFunc != null) { - retryPolicy = createRetryPolicyFunc.call(); - retryPolicy.onBeforeSendRequest(request); - } - return ObservableHelper.inlineIfPossibleAsObs( - () -> { - ++retries; - return executeRequestFunc.call(request); - }, retryPolicy); - }; - - this.correlatedActivityId = correlatedActivityId; - - this.feedOptions = feedOptions != null ? feedOptions : new FeedOptions(); - this.feedOptions.setRequestContinuation(initialContinuationToken); - this.lastResponseContinuationToken = initialContinuationToken; - this.resourceType = resourceType; - this.targetRange = targetRange; - this.collectionLink = collectionLink; - this.createRetryPolicyFunc = createRetryPolicyFunc; - this.pageSize = initialPageSize; - this.top = top; - } - - public Observable produceAsync() { - Func2 sourcePartitionCreateRequestFunc = - (token, maxItemCount) -> createRequestFunc.call(targetRange, token, maxItemCount); - Observable> obs = Paginator - .getPaginatedQueryResultAsObservable( - feedOptions, - sourcePartitionCreateRequestFunc, - executeRequestFuncWithRetries, - resourceType, - top, - pageSize) - .map(rsp -> { - lastResponseContinuationToken = rsp.getResponseContinuation(); - this.fetchExecutionRangeAccumulator.endFetchRange(rsp.getActivityId(), - rsp.getResults().size(), - this.retries); - this.fetchSchedulingMetrics.stop(); - return rsp;}); - - return splitProof(obs.map(page -> new DocumentProducerFeedResponse(page))); - } - - private Observable splitProof(Observable sourceFeedResponseObservable) { - return sourceFeedResponseObservable.onErrorResumeNext( t -> { - DocumentClientException dce = Utils.as(t, DocumentClientException.class); - if (dce == null || !isSplit(dce)) { - logger.error("Unexpected failure", t); - return Observable.error(t); - } - - // we are dealing with Split - logger.info("DocumentProducer handling a partition split in [{}], detail:[{}]", targetRange, dce); - Single> replacementRangesObs = getReplacementRanges(targetRange.toRange()); - - // Since new DocumentProducers are instantiated for the new replacement ranges, if for the new - // replacement partitions split happens the corresponding DocumentProducer can recursively handle splits. - // so this is resilient to split on splits. - Observable> replacementProducers = replacementRangesObs.toObservable().flatMap( - partitionKeyRanges -> { - if (logger.isDebugEnabled()) { - logger.info("Cross Partition Query Execution detected partition [{}] split into [{}] partitions," - + " last continuation token is [{}].", - targetRange.toJson(), - String.join(", ", partitionKeyRanges.stream() - .map(pkr -> pkr.toJson()).collect(Collectors.toList())), - lastResponseContinuationToken); - } - return Observable.from(createReplacingDocumentProducersOnSplit(partitionKeyRanges)); - }); - - return produceOnSplit(replacementProducers); - }); - } - - protected Observable produceOnSplit(Observable> replacingDocumentProducers) { - return replacingDocumentProducers.flatMap(dp -> dp.produceAsync(), 1); - } - - private List> createReplacingDocumentProducersOnSplit(List partitionKeyRanges) { - - List> replacingDocumentProducers = new ArrayList<>(partitionKeyRanges.size()); - for(PartitionKeyRange pkr: partitionKeyRanges) { - replacingDocumentProducers.add(createChildDocumentProducerOnSplit(pkr, lastResponseContinuationToken)); - } - return replacingDocumentProducers; - } - - protected DocumentProducer createChildDocumentProducerOnSplit( - PartitionKeyRange targetRange, - String initialContinuationToken) { - - return new DocumentProducer( - client, - collectionRid, - feedOptions, - createRequestFunc, - executeRequestFuncWithRetries, - targetRange, - collectionLink, - null, - resourceType , - correlatedActivityId, - pageSize, - initialContinuationToken, - top); - } - - private Single> getReplacementRanges(Range range) { - return client.getPartitionKeyRangeCache().tryGetOverlappingRangesAsync(collectionRid, range, true, feedOptions.getProperties()); - } - - private boolean isSplit(DocumentClientException e) { - return Exceptions.isPartitionSplit(e); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentQueryExecutionContextBase.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentQueryExecutionContextBase.java deleted file mode 100644 index 3692ee46e0f1..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentQueryExecutionContextBase.java +++ /dev/null @@ -1,299 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlParameterCollection; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.RuntimeConstants.MediaTypes; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.ReplicatedResourceClientUtils; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -import rx.Observable; -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public abstract class DocumentQueryExecutionContextBase -implements IDocumentQueryExecutionContext { - - protected ResourceType resourceTypeEnum; - protected String resourceLink; - protected IDocumentQueryClient client; - protected Class resourceType; - protected FeedOptions feedOptions; - protected SqlQuerySpec query; - protected UUID correlatedActivityId; - protected boolean shouldExecuteQueryRequest; - - protected DocumentQueryExecutionContextBase(IDocumentQueryClient client, ResourceType resourceTypeEnum, - Class resourceType, SqlQuerySpec query, FeedOptions feedOptions, String resourceLink, - boolean getLazyFeedResponse, UUID correlatedActivityId) { - - // TODO: validate args are not null: client and feedOption should not be null - this.client = client; - this.resourceTypeEnum = resourceTypeEnum; - this.resourceType = resourceType; - this.query = query; - this.shouldExecuteQueryRequest = (query != null); - this.feedOptions = feedOptions; - this.resourceLink = resourceLink; - // this.getLazyFeedResponse = getLazyFeedResponse; - this.correlatedActivityId = correlatedActivityId; - } - - @Override - abstract public Observable> executeAsync(); - - public String getPartitionKeyId() { - // TODO Auto-generated method stub - return this.feedOptions.getPartitionKeyRangeIdInternal(); - } - - public RxDocumentServiceRequest createDocumentServiceRequest(Map requestHeaders, - SqlQuerySpec querySpec, - PartitionKeyInternal partitionKey) { - - RxDocumentServiceRequest request = querySpec != null - ? this.createQueryDocumentServiceRequest(requestHeaders, querySpec) - : this.createReadFeedDocumentServiceRequest(requestHeaders); - - this.populatePartitionKeyInfo(request, partitionKey); - - return request; - } - - protected RxDocumentServiceRequest createDocumentServiceRequest(Map requestHeaders, - SqlQuerySpec querySpec, - PartitionKeyRange targetRange, - String collectionRid) { - RxDocumentServiceRequest request = querySpec != null - ? this.createQueryDocumentServiceRequest(requestHeaders, querySpec) - : this.createReadFeedDocumentServiceRequest(requestHeaders); - - this.populatePartitionKeyRangeInfo(request, targetRange, collectionRid); - - return request; - } - - public Single> executeRequestAsync(RxDocumentServiceRequest request) { - return (this.shouldExecuteQueryRequest ? this.executeQueryRequestAsync(request) - : this.executeReadFeedRequestAsync(request)); - } - - public Single> executeQueryRequestAsync(RxDocumentServiceRequest request) { - return this.getFeedResponse(this.executeQueryRequestInternalAsync(request)); - } - - public Single> executeReadFeedRequestAsync(RxDocumentServiceRequest request) { - return this.getFeedResponse(this.client.readFeedAsync(request)); - } - - protected Single> getFeedResponse(Single response) { - return response.map(resp -> BridgeInternal.toFeedResponsePage(resp, resourceType)); - } - - public FeedOptions getFeedOptions(String continuationToken, Integer maxPageSize) { - FeedOptions options = new FeedOptions(this.feedOptions); - options.setRequestContinuation(continuationToken); - options.setMaxItemCount(maxPageSize); - return options; - } - - private Single executeQueryRequestInternalAsync(RxDocumentServiceRequest request) { - return this.client.executeQueryAsync(request); - } - - public Map createCommonHeadersAsync(FeedOptions feedOptions) { - Map requestHeaders = new HashMap<>(); - - ConsistencyLevel defaultConsistencyLevel = this.client.getDefaultConsistencyLevelAsync(); - ConsistencyLevel desiredConsistencyLevel = this.client.getDesiredConsistencyLevelAsync(); - if (!Strings.isNullOrEmpty(feedOptions.getSessionToken()) - && !ReplicatedResourceClientUtils.isReadingFromMaster(this.resourceTypeEnum, OperationType.ReadFeed)) { - if (defaultConsistencyLevel == ConsistencyLevel.Session - || (desiredConsistencyLevel == ConsistencyLevel.Session)) { - // Query across partitions is not supported today. Master resources (for e.g., - // database) - // can span across partitions, whereas server resources (viz: collection, - // document and attachment) - // don't span across partitions. Hence, session token returned by one partition - // should not be used - // when quering resources from another partition. - // Since master resources can span across partitions, don't send session token - // to the backend. - // As master resources are sync replicated, we should always get consistent - // query result for master resources, - // irrespective of the chosen replica. - // For server resources, which don't span partitions, specify the session token - // for correct replica to be chosen for servicing the query result. - requestHeaders.put(HttpConstants.HttpHeaders.SESSION_TOKEN, feedOptions.getSessionToken()); - } - } - - requestHeaders.put(HttpConstants.HttpHeaders.CONTINUATION, feedOptions.getRequestContinuation()); - requestHeaders.put(HttpConstants.HttpHeaders.IS_QUERY, Strings.toString(true)); - - // Flow the pageSize only when we are not doing client eval - if (feedOptions.getMaxItemCount() != null && feedOptions.getMaxItemCount() > 0) { - requestHeaders.put(HttpConstants.HttpHeaders.PAGE_SIZE, Strings.toString(feedOptions.getMaxItemCount())); - } - - if (feedOptions.getEnableCrossPartitionQuery() != null) { - - requestHeaders.put(HttpConstants.HttpHeaders.ENABLE_CROSS_PARTITION_QUERY, - Strings.toString(feedOptions.getEnableCrossPartitionQuery())); - } - - if (feedOptions.getMaxDegreeOfParallelism() != 0) { - requestHeaders.put(HttpConstants.HttpHeaders.PARALLELIZE_CROSS_PARTITION_QUERY, Strings.toString(true)); - } - - if (this.feedOptions.getEnableCrossPartitionQuery() != null) { - requestHeaders.put(HttpConstants.HttpHeaders.ENABLE_SCAN_IN_QUERY, - Strings.toString(this.feedOptions.getEnableCrossPartitionQuery())); - } - - if (this.feedOptions.getResponseContinuationTokenLimitInKb() > 0) { - requestHeaders.put(HttpConstants.HttpHeaders.RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB, - Strings.toString(feedOptions.getResponseContinuationTokenLimitInKb())); - } - - if (desiredConsistencyLevel != null) { - requestHeaders.put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, desiredConsistencyLevel.name()); - } - - if(feedOptions.getPopulateQueryMetrics()){ - requestHeaders.put(HttpConstants.HttpHeaders.POPULATE_QUERY_METRICS, String.valueOf(feedOptions.getPopulateQueryMetrics())); - } - - return requestHeaders; - } - - private void populatePartitionKeyInfo(RxDocumentServiceRequest request, PartitionKeyInternal partitionKey) { - if (request == null) { - throw new NullPointerException("request"); - } - - if (this.resourceTypeEnum.isPartitioned()) { - if (partitionKey != null) { - request.getHeaders().put(HttpConstants.HttpHeaders.PARTITION_KEY, partitionKey.toJson()); - } - } - } - - public void populatePartitionKeyRangeInfo(RxDocumentServiceRequest request, PartitionKeyRange range, - String collectionRid) { - if (request == null) { - throw new NullPointerException("request"); - } - - if (range == null) { - throw new NullPointerException("range"); - } - - if (this.resourceTypeEnum.isPartitioned()) { - request.routeTo(new PartitionKeyRangeIdentity(collectionRid, range.getId())); - } - } - - private RxDocumentServiceRequest createQueryDocumentServiceRequest(Map requestHeaders, - SqlQuerySpec querySpec) { - RxDocumentServiceRequest executeQueryRequest; - - String queryText; - switch (this.client.getQueryCompatibilityMode()) { - case SqlQuery: - SqlParameterCollection params = querySpec.getParameters(); - Utils.checkStateOrThrow(params != null && params.size() > 0, "query.parameters", - "Unsupported argument in query compatibility mode '%s'", - this.client.getQueryCompatibilityMode().toString()); - - executeQueryRequest = RxDocumentServiceRequest.create(OperationType.SqlQuery, this.resourceTypeEnum, - this.resourceLink, - // AuthorizationTokenType.PrimaryMasterKey, - requestHeaders); - - executeQueryRequest.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE, MediaTypes.JSON); - queryText = querySpec.getQueryText(); - break; - - case Default: - case Query: - default: - executeQueryRequest = RxDocumentServiceRequest.create(OperationType.Query, this.resourceTypeEnum, - this.resourceLink, - // AuthorizationTokenType.PrimaryMasterKey, - requestHeaders); - - executeQueryRequest.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE, MediaTypes.QUERY_JSON); - queryText = querySpec.toJson(); - break; - } - - try { - executeQueryRequest.setContentBytes(queryText.getBytes("UTF-8")); - } catch (UnsupportedEncodingException e) { - // TODO Auto-generated catch block - // TODO: exception should be handled differently - e.printStackTrace(); - } - - return executeQueryRequest; - } - - private RxDocumentServiceRequest createReadFeedDocumentServiceRequest(Map requestHeaders) { - if (this.resourceTypeEnum == ResourceType.Database || this.resourceTypeEnum == ResourceType.Offer) { - return RxDocumentServiceRequest.create(OperationType.ReadFeed, null, this.resourceTypeEnum, - // TODO: we may want to add a constructor to RxDocumentRequest supporting authorization type similar to .net - // AuthorizationTokenType.PrimaryMasterKey, - requestHeaders); - } else { - return RxDocumentServiceRequest.create(OperationType.ReadFeed, this.resourceTypeEnum, this.resourceLink, - // TODO: we may want to add a constructor to RxDocumentRequest supporting authorization type similar to .net - // AuthorizationTokenType.PrimaryMasterKey, - requestHeaders); - } - } - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentQueryExecutionContextFactory.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentQueryExecutionContextFactory.java deleted file mode 100644 index 4b4b2891dfe5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentQueryExecutionContextFactory.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.List; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.query.PartitionedQueryExecutionInfo; -import com.microsoft.azure.cosmosdb.internal.query.QueryInfo; -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; - -import rx.Observable; -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class DocumentQueryExecutionContextFactory { - - private final static int PageSizeFactorForTop = 5; - - private static Single resolveCollection(IDocumentQueryClient client, SqlQuerySpec query, - ResourceType resourceTypeEnum, String resourceLink) { - - RxCollectionCache collectionCache = client.getCollectionCache(); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create( - OperationType.Query, - resourceTypeEnum, - resourceLink, null - // TODO AuthorizationTokenType.Invalid) - ); //this request doesnt actually go to server - return collectionCache.resolveCollectionAsync(request); - } - - public static Observable> createDocumentQueryExecutionContextAsync( - IDocumentQueryClient client, - ResourceType resourceTypeEnum, - Class resourceType, - SqlQuerySpec query, - FeedOptions feedOptions, - String resourceLink, - boolean isContinuationExpected, - UUID correlatedActivityId) { - - // return proxy - Observable collectionObs = Observable.just(null); - - if (resourceTypeEnum.isCollectionChild()) { - collectionObs = resolveCollection(client, query, resourceTypeEnum, resourceLink).toObservable(); - } - - // We create a ProxyDocumentQueryExecutionContext that will be initialized with DefaultDocumentQueryExecutionContext - // which will be used to send the query to Gateway and on getting 400(bad request) with 1004(cross parition query not servable), we initialize it with - // PipelinedDocumentQueryExecutionContext by providing the partition query execution info that's needed(which we get from the exception returned from Gateway). - - Observable> proxyQueryExecutionContext = - collectionObs.flatMap(collection -> - ProxyDocumentQueryExecutionContext.createAsync( - client, - resourceTypeEnum, - resourceType, - query, - feedOptions, - resourceLink, - collection, - isContinuationExpected, - correlatedActivityId)); - - return proxyQueryExecutionContext; - } - - public static Observable> createSpecializedDocumentQueryExecutionContextAsync( - IDocumentQueryClient client, - ResourceType resourceTypeEnum, - Class resourceType, - SqlQuerySpec query, - FeedOptions feedOptions, - String resourceLink, - boolean isContinuationExpected, - PartitionedQueryExecutionInfo partitionedQueryExecutionInfo, - List targetRanges, - String collectionRid, - UUID correlatedActivityId) { - - int initialPageSize = Utils.getValueOrDefault(feedOptions.getMaxItemCount(), ParallelQueryConfig.ClientInternalPageSize); - - BadRequestException validationError = Utils.checkRequestOrReturnException - (initialPageSize > 0, "MaxItemCount", "Invalid MaxItemCount %s", initialPageSize); - if (validationError != null) { - return Observable.error(validationError); - } - - QueryInfo queryInfo = partitionedQueryExecutionInfo.getQueryInfo(); - - boolean getLazyFeedResponse = queryInfo.hasTop(); - - // We need to compute the optimal initial page size for order-by queries - if (queryInfo.hasOrderBy()) { - int top; - if (queryInfo.hasTop() && (top = partitionedQueryExecutionInfo.getQueryInfo().getTop()) > 0) { - int pageSizeWithTop = Math.min( - (int)Math.ceil(top / (double)targetRanges.size()) * PageSizeFactorForTop, - top); - - if (initialPageSize > 0) { - initialPageSize = Math.min(pageSizeWithTop, initialPageSize); - } - else { - initialPageSize = pageSizeWithTop; - } - } - // TODO: do not support continuation in string format right now - // else if (isContinuationExpected) - // { - // if (initialPageSize < 0) - // { - // initialPageSize = (int)Math.Max(feedOptions.MaxBufferedItemCount, ParallelQueryConfig.GetConfig().DefaultMaximumBufferSize); - // } - // - // initialPageSize = Math.Min( - // (int)Math.Ceiling(initialPageSize / (double)targetRanges.Count) * PageSizeFactorForTop, - // initialPageSize); - // } - } - - return PipelinedDocumentQueryExecutionContext.createAsync( - client, - resourceTypeEnum, - resourceType, - query, - feedOptions, - resourceLink, - collectionRid, - partitionedQueryExecutionInfo, - targetRanges, - initialPageSize, - isContinuationExpected, - getLazyFeedResponse, - correlatedActivityId); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/Fetcher.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/Fetcher.java deleted file mode 100644 index 07f5e6daad9f..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/Fetcher.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.FeedOptionsBase; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import rx.Observable; -import rx.functions.Func1; -import rx.functions.Func2; - -class Fetcher { - private final static Logger logger = LoggerFactory.getLogger(Fetcher.class); - - private final Func2 createRequestFunc; - private final Func1>> executeFunc; - private final boolean isChangeFeed; - - private volatile boolean shouldFetchMore; - private volatile int maxItemCount; - private volatile int top; - private volatile String continuationToken; - - public Fetcher(Func2 createRequestFunc, - Func1>> executeFunc, - FeedOptionsBase options, - boolean isChangeFeed, - int top, - int maxItemCount) { - - this.createRequestFunc = createRequestFunc; - this.executeFunc = executeFunc; - this.isChangeFeed = isChangeFeed; - - this.continuationToken = options.getRequestContinuation(); - this.top = top; - if (top == -1) { - this.maxItemCount = maxItemCount; - } else { - // it is a top query, we should not retrieve more than requested top. - this.maxItemCount = Math.min(maxItemCount, top); - } - this.shouldFetchMore = true; - } - - public boolean shouldFetchMore() { - return shouldFetchMore; - } - - public Observable> nextPage() { - RxDocumentServiceRequest request = createRequest(); - return nextPage(request); - } - - private void updateState(FeedResponse response) { - continuationToken = response.getResponseContinuation(); - if (top != -1) { - top -= response.getResults().size(); - if (top < 0) { - // this shouldn't happen - // this means backend retrieved more items than requested - logger.warn("Azure Cosmos DB BackEnd Service returned more than requested {} items", maxItemCount); - top = 0; - } - maxItemCount = Math.min(maxItemCount, top); - } - - shouldFetchMore = shouldFetchMore && - // if token is null or top == 0 then done - (!StringUtils.isEmpty(continuationToken) && (top != 0)) && - // if change feed query and no changes then done - (!isChangeFeed || !BridgeInternal.noChanges(response)); - - logger.debug("Fetcher state updated: " + - "isChangeFeed = {}, continuation token = {}, max item count = {}, should fetch more = {}", - isChangeFeed, continuationToken, maxItemCount, shouldFetchMore); - } - - private RxDocumentServiceRequest createRequest() { - if (!shouldFetchMore) { - // this should never happen - logger.error("invalid state, trying to fetch more after completion"); - throw new IllegalStateException("Invalid state, trying to fetch more after completion"); - } - - return createRequestFunc.call(continuationToken, maxItemCount); - } - - private Observable> nextPage(RxDocumentServiceRequest request) { - return executeFunc.call(request).map(rsp -> { - updateState(rsp); - return rsp; - }); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryClient.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryClient.java deleted file mode 100644 index 3ac016471730..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryClient.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicyFactory; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import com.microsoft.azure.cosmosdb.rx.internal.caches.IPartitionKeyRangeCache; - -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public interface IDocumentQueryClient { - - /** - * TODO: this should be async returning observable - * @return - */ - RxCollectionCache getCollectionCache(); - - /** - * TODO: this should be async returning observable - * @return - */ - IPartitionKeyRangeCache getPartitionKeyRangeCache(); - - /** - * @return - */ - IRetryPolicyFactory getResetSessionTokenRetryPolicy(); - - /** - * TODO: this should be async returning observable - * @return - */ - ConsistencyLevel getDefaultConsistencyLevelAsync(); - - /** - * TODO: this should be async returning observable - * @return - */ - ConsistencyLevel getDesiredConsistencyLevelAsync(); - - Single executeQueryAsync(RxDocumentServiceRequest request); - - QueryCompatibilityMode getQueryCompatibilityMode(); - - /// - /// A client query compatibility mode when making query request. - /// Can be used to force a specific query request format. - /// - enum QueryCompatibilityMode { - /// - /// Default (latest) query format. - /// - Default, - - /// - /// Query (application/query+json). - /// Default. - /// - Query, - - /// - /// SqlQuery (application/sql). - /// - SqlQuery - } - - Single readFeedAsync(RxDocumentServiceRequest request); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryExecutionComponent.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryExecutionComponent.java deleted file mode 100644 index b1a260e54911..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryExecutionComponent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; - -import rx.Observable; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public interface IDocumentQueryExecutionComponent { - - Observable> drainAsync(int maxPageSize); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryExecutionContext.java deleted file mode 100644 index bb2cd7f1787a..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/IDocumentQueryExecutionContext.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; - -import rx.Observable; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public interface IDocumentQueryExecutionContext { - - Observable> executeAsync(); -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByContinuationToken.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByContinuationToken.java deleted file mode 100644 index 79b04551db6b..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByContinuationToken.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.ArrayList; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public final class OrderByContinuationToken extends JsonSerializable { - private static final String CompositeContinuationTokenPropertyName = "compositeToken"; - private static final String OrderByItemsPropetryName = "orderByItems"; - private static final String RidPropertyName = "rid"; - private static final String InclusivePropertyName = "inclusive"; - private static final Logger logger = LoggerFactory.getLogger(OrderByContinuationToken.class); - - public OrderByContinuationToken(CompositeContinuationToken compositeContinuationToken, QueryItem[] orderByItems, - String rid, boolean inclusive) { - if (compositeContinuationToken == null) { - throw new IllegalArgumentException("CompositeContinuationToken must not be null."); - } - - if (orderByItems == null) { - throw new IllegalArgumentException("orderByItems must not be null."); - } - - if (orderByItems.length == 0) { - throw new IllegalArgumentException("orderByItems must not be empty."); - } - - if (rid == null) { - throw new IllegalArgumentException("rid must not be null."); - } - - this.setCompositeContinuationToken(compositeContinuationToken); - this.setOrderByItems(orderByItems); - this.setRid(rid); - this.setInclusive(inclusive); - } - - private OrderByContinuationToken(String serializedOrderByContinuationToken) { - super(serializedOrderByContinuationToken); - } - - public static boolean tryParse(String serializedOrderByContinuationToken, - ValueHolder outOrderByContinuationToken) { - boolean parsed; - try { - OrderByContinuationToken orderByContinuationToken = new OrderByContinuationToken( - serializedOrderByContinuationToken); - CompositeContinuationToken compositeContinuationToken = orderByContinuationToken - .getCompositeContinuationToken(); - if (compositeContinuationToken == null) { - throw new IllegalArgumentException("compositeContinuationToken must not be null."); - } - - orderByContinuationToken.getOrderByItems(); - orderByContinuationToken.getRid(); - orderByContinuationToken.getInclusive(); - - outOrderByContinuationToken.v = orderByContinuationToken; - parsed = true; - } catch (Exception ex) { - logger.debug( - "Received exception {} when trying to parse: {}", - ex.getMessage(), - serializedOrderByContinuationToken); - parsed = false; - outOrderByContinuationToken.v = null; - } - - return parsed; - } - - public CompositeContinuationToken getCompositeContinuationToken() { - ValueHolder outCompositeContinuationToken = new ValueHolder(); - boolean succeeded = CompositeContinuationToken.tryParse(super.getString(CompositeContinuationTokenPropertyName), - outCompositeContinuationToken); - if (!succeeded) { - throw new IllegalArgumentException("Continuation Token was not able to be parsed"); - } - - return outCompositeContinuationToken.v; - } - - public QueryItem[] getOrderByItems() { - List queryItems = new ArrayList(); - ArrayNode arrayNode = (ArrayNode) super.get(OrderByItemsPropetryName); - for (JsonNode jsonNode : arrayNode) { - QueryItem queryItem = new QueryItem(jsonNode.toString()); - queryItems.add(queryItem); - } - - QueryItem[] queryItemsArray = new QueryItem[queryItems.size()]; - - return queryItems.toArray(queryItemsArray); - } - - public String getRid() { - return super.getString(RidPropertyName); - } - - public boolean getInclusive() { - return super.getBoolean(InclusivePropertyName); - } - - private void setCompositeContinuationToken(CompositeContinuationToken compositeContinuationToken) { - super.set(CompositeContinuationTokenPropertyName, compositeContinuationToken.toJson()); - } - - private void setOrderByItems(QueryItem[] orderByItems) { - super.set(OrderByItemsPropetryName, orderByItems); - } - - private void setRid(String rid) { - super.set(RidPropertyName, rid); - } - - private void setInclusive(boolean inclusive) { - super.set(InclusivePropertyName, inclusive); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByDocumentProducer.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByDocumentProducer.java deleted file mode 100644 index 8d36a6ce8f68..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByDocumentProducer.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderByRowResult; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderbyRowComparer; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -import com.microsoft.azure.cosmosdb.QueryMetrics; -import rx.Observable; -import rx.functions.Func0; -import rx.functions.Func1; -import rx.functions.Func3; - -class OrderByDocumentProducer extends DocumentProducer { - private final OrderbyRowComparer consumeComparer; - private final Map targetRangeToOrderByContinuationTokenMap; - - OrderByDocumentProducer( - OrderbyRowComparer consumeComparer, - IDocumentQueryClient client, - String collectionResourceId, - FeedOptions feedOptions, - Func3 createRequestFunc, - Func1>> executeRequestFunc, - PartitionKeyRange targetRange, - String collectionLink, - Func0 createRetryPolicyFunc, - Class resourceType, - UUID correlatedActivityId, - int initialPageSize, - String initialContinuationToken, - int top, - Map targetRangeToOrderByContinuationTokenMap) { - super(client, collectionResourceId, feedOptions, createRequestFunc, executeRequestFunc, targetRange, collectionLink, - createRetryPolicyFunc, resourceType, correlatedActivityId, initialPageSize, initialContinuationToken, top); - this.consumeComparer = consumeComparer; - this.targetRangeToOrderByContinuationTokenMap = targetRangeToOrderByContinuationTokenMap; - } - - protected Observable produceOnSplit(Observable> replacementProducers) { - Observable res = replacementProducers.toList().single().flatMap(documentProducers -> { - RequestChargeTracker tracker = new RequestChargeTracker(); - Map queryMetricsMap = new HashMap<>(); - return OrderByUtils.orderedMerge(resourceType, consumeComparer, tracker, documentProducers, queryMetricsMap, - targetRangeToOrderByContinuationTokenMap) - .map(orderByQueryResult -> resultPageFrom(tracker, orderByQueryResult)); - }); - - return res; - } - - @SuppressWarnings("unchecked") - private DocumentProducerFeedResponse resultPageFrom(RequestChargeTracker tracker, OrderByRowResult row) { - double requestCharge = tracker.getAndResetCharge(); - Map headers = Utils.immutableMapOf(HttpConstants.HttpHeaders.REQUEST_CHARGE, String.valueOf(requestCharge)); - FeedResponse fr = BridgeInternal.createFeedResponse(Collections.singletonList((T) row), headers); - return new DocumentProducerFeedResponse(fr, row.getSourcePartitionKeyRange()); - } - - protected DocumentProducer createChildDocumentProducerOnSplit( - PartitionKeyRange targetRange, - String initialContinuationToken) { - - return new OrderByDocumentProducer<>( - consumeComparer, - client, - collectionRid, - feedOptions, - createRequestFunc, - executeRequestFuncWithRetries, - targetRange, - collectionLink, - createRetryPolicyFunc, - resourceType , - correlatedActivityId, - pageSize, - initialContinuationToken, - top, - this.targetRangeToOrderByContinuationTokenMap); - } - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByDocumentQueryExecutionContext.java deleted file mode 100644 index 64edee55c03c..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByDocumentQueryExecutionContext.java +++ /dev/null @@ -1,654 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.function.Function; - -import org.apache.commons.lang3.NotImplementedException; -import org.apache.commons.lang3.tuple.ImmutablePair; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.query.PartitionedQueryExecutionInfo; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; -import com.microsoft.azure.cosmosdb.internal.query.SortOrder; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderByRowResult; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderbyRowComparer; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import com.microsoft.azure.cosmosdb.QueryMetrics; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -import rx.Observable; -import rx.Observable.Transformer; -import rx.functions.Func0; -import rx.functions.Func1; -import rx.functions.Func3; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class OrderByDocumentQueryExecutionContext - extends ParallelDocumentQueryExecutionContextBase { - private final String FormatPlaceHolder = "{documentdb-formattableorderbyquery-filter}"; - private final String True = "true"; - private final String collectionRid; - private final OrderbyRowComparer consumeComparer; - private final RequestChargeTracker tracker; - private final ConcurrentMap queryMetricMap; - private Observable> orderByObservable; - private final Map targetRangeToOrderByContinuationTokenMap; - - private OrderByDocumentQueryExecutionContext( - IDocumentQueryClient client, - List partitionKeyRanges, - ResourceType resourceTypeEnum, - Class klass, - SqlQuerySpec query, - FeedOptions feedOptions, - String resourceLink, - String rewrittenQuery, - boolean isContinuationExpected, - boolean getLazyFeedResponse, - OrderbyRowComparer consumeComparer, - String collectionRid, - UUID correlatedActivityId) { - super(client, partitionKeyRanges, resourceTypeEnum, klass, query, feedOptions, resourceLink, rewrittenQuery, - isContinuationExpected, getLazyFeedResponse, correlatedActivityId); - this.collectionRid = collectionRid; - this.consumeComparer = consumeComparer; - this.tracker = new RequestChargeTracker(); - this.queryMetricMap = new ConcurrentHashMap<>(); - targetRangeToOrderByContinuationTokenMap = new HashMap<>(); - } - - public static Observable> createAsync( - IDocumentQueryClient client, - ResourceType resourceTypeEnum, - Class resourceType, - SqlQuerySpec expression, - FeedOptions feedOptions, - String resourceLink, - String collectionRid, - PartitionedQueryExecutionInfo partitionedQueryExecutionInfo, - List partitionKeyRanges, - int initialPageSize, - boolean isContinuationExpected, - boolean getLazyFeedResponse, - UUID correlatedActivityId) { - - OrderByDocumentQueryExecutionContext context = new OrderByDocumentQueryExecutionContext(client, - partitionKeyRanges, - resourceTypeEnum, - resourceType, - expression, - feedOptions, - resourceLink, - partitionedQueryExecutionInfo.getQueryInfo().getRewrittenQuery(), - isContinuationExpected, - getLazyFeedResponse, - new OrderbyRowComparer(partitionedQueryExecutionInfo.getQueryInfo().getOrderBy()), - collectionRid, - correlatedActivityId); - - try { - context.initialize(partitionKeyRanges, - partitionedQueryExecutionInfo.getQueryInfo().getOrderBy(), - partitionedQueryExecutionInfo.getQueryInfo().getOrderByExpressions(), - initialPageSize, - feedOptions.getRequestContinuation()); - - return Observable.just(context); - } catch (DocumentClientException dce) { - return Observable.error(dce); - } - } - - private void initialize( - List partitionKeyRanges, - List sortOrders, - Collection orderByExpressions, - int initialPageSize, - String continuationToken) throws DocumentClientException { - if (continuationToken == null) { - // First iteration so use null continuation tokens and "true" filters - Map partitionKeyRangeToContinuationToken = new HashMap(); - for (PartitionKeyRange partitionKeyRange : partitionKeyRanges) { - partitionKeyRangeToContinuationToken.put(partitionKeyRange, - null); - } - - super.initialize(collectionRid, - partitionKeyRangeToContinuationToken, - initialPageSize, - new SqlQuerySpec(querySpec.getQueryText().replace(FormatPlaceHolder, - True), - querySpec.getParameters())); - } else { - // Check to see if order by continuation token is a valid JSON. - OrderByContinuationToken orderByContinuationToken; - ValueHolder outOrderByContinuationToken = new ValueHolder(); - if (!OrderByContinuationToken.tryParse(continuationToken, - outOrderByContinuationToken)) { - String message = String.format("Invalid JSON in continuation token %s for OrderBy~Context", - continuationToken); - throw new DocumentClientException(HttpConstants.StatusCodes.BADREQUEST, - message); - } - - orderByContinuationToken = outOrderByContinuationToken.v; - - CompositeContinuationToken compositeContinuationToken = orderByContinuationToken - .getCompositeContinuationToken(); - // Check to see if the ranges inside are valid - if (compositeContinuationToken.getRange().isEmpty()) { - String message = String.format("Invalid Range in the continuation token %s for OrderBy~Context.", - continuationToken); - throw new DocumentClientException(HttpConstants.StatusCodes.BADREQUEST, - message); - } - - // At this point the token is valid. - ImmutablePair targetIndexAndFilters = this.GetFiltersForPartitions( - orderByContinuationToken, - partitionKeyRanges, - sortOrders, - orderByExpressions); - - int targetIndex = targetIndexAndFilters.left; - targetRangeToOrderByContinuationTokenMap.put(String.valueOf(targetIndex), orderByContinuationToken); - FormattedFilterInfo formattedFilterInfo = targetIndexAndFilters.right; - - // Left - String filterForRangesLeftOfTheTargetRange = formattedFilterInfo.getFilterForRangesLeftOfTheTargetRange(); - this.initializeRangeWithContinuationTokenAndFilter(partitionKeyRanges, - /* startInclusive */ 0, - /* endExclusive */ targetIndex, - /* continuationToken */ null, - filterForRangesLeftOfTheTargetRange, - initialPageSize); - - // Target - String filterForTargetRange = formattedFilterInfo.getFilterForTargetRange(); - this.initializeRangeWithContinuationTokenAndFilter(partitionKeyRanges, - /* startInclusive */ targetIndex, - /* endExclusive */ targetIndex + 1, - null, - filterForTargetRange, - initialPageSize); - - // Right - String filterForRangesRightOfTheTargetRange = formattedFilterInfo.getFilterForRangesRightOfTheTargetRange(); - this.initializeRangeWithContinuationTokenAndFilter(partitionKeyRanges, - /* startInclusive */ targetIndex + 1, - /* endExclusive */ partitionKeyRanges.size(), - /* continuationToken */ null, - filterForRangesRightOfTheTargetRange, - initialPageSize); - } - - orderByObservable = OrderByUtils.orderedMerge(resourceType, - consumeComparer, - tracker, - documentProducers, - queryMetricMap, - targetRangeToOrderByContinuationTokenMap); - } - - private void initializeRangeWithContinuationTokenAndFilter( - List partitionKeyRanges, - int startInclusive, - int endExclusive, - String continuationToken, - String filter, - int initialPageSize) { - Map partitionKeyRangeToContinuationToken = new HashMap(); - for (int i = startInclusive; i < endExclusive; i++) { - PartitionKeyRange partitionKeyRange = partitionKeyRanges.get(i); - partitionKeyRangeToContinuationToken.put(partitionKeyRange, - continuationToken); - } - - super.initialize(collectionRid, - partitionKeyRangeToContinuationToken, - initialPageSize, - new SqlQuerySpec(querySpec.getQueryText().replace(FormatPlaceHolder, - filter), - querySpec.getParameters())); - } - - private ImmutablePair GetFiltersForPartitions( - OrderByContinuationToken orderByContinuationToken, - List partitionKeyRanges, - List sortOrders, - Collection orderByExpressions) throws DocumentClientException { - // Find the partition key range we left off on - int startIndex = this.FindTargetRangeAndExtractContinuationTokens(partitionKeyRanges, - orderByContinuationToken.getCompositeContinuationToken().getRange()); - - // Get the filters. - FormattedFilterInfo formattedFilterInfo = this.GetFormattedFilters(orderByExpressions, - orderByContinuationToken.getOrderByItems(), - sortOrders, - orderByContinuationToken.getInclusive()); - - return new ImmutablePair(startIndex, - formattedFilterInfo); - } - - private OrderByDocumentQueryExecutionContext.FormattedFilterInfo GetFormattedFilters( - Collection orderByExpressionCollection, - QueryItem[] orderByItems, - Collection sortOrderCollection, - boolean inclusive) { - // Convert to arrays - SortOrder[] sortOrders = new SortOrder[sortOrderCollection.size()]; - sortOrderCollection.toArray(sortOrders); - - String[] expressions = new String[orderByExpressionCollection.size()]; - orderByExpressionCollection.toArray(expressions); - - // Validate the inputs - if (expressions.length != sortOrders.length) { - throw new IllegalArgumentException("expressions.size() != sortOrders.size()"); - } - - if (expressions.length != orderByItems.length) { - throw new IllegalArgumentException("expressions.size() != orderByItems.length"); - } - - // When we run cross partition queries, - // we only serialize the continuation token for the partition that we left off - // on. - // The only problem is that when we resume the order by query, - // we don't have continuation tokens for all other partitions. - // The saving grace is that the data has a composite sort order(query sort - // order, partition key range id) - // so we can generate range filters which in turn the backend will turn into rid - // based continuation tokens, - // which is enough to get the streams of data flowing from all partitions. - // The details of how this is done is described below: - - int numOrderByItems = expressions.length; - boolean isSingleOrderBy = numOrderByItems == 1; - StringBuilder left = new StringBuilder(); - StringBuilder target = new StringBuilder(); - StringBuilder right = new StringBuilder(); - - if (isSingleOrderBy) { - // For a single order by query we resume the continuations in this manner - // Suppose the query is SELECT* FROM c ORDER BY c.string ASC - // And we left off on partition N with the value "B" - // Then - // All the partitions to the left will have finished reading "B" - // Partition N is still reading "B" - // All the partitions to the right have let to read a "B - // Therefore the filters should be - // > "B" , >= "B", and >= "B" respectively - // Repeat the same logic for DESC and you will get - // < "B", <= "B", and <= "B" respectively - // The general rule becomes - // For ASC - // > for partitions to the left - // >= for the partition we left off on - // >= for the partitions to the right - // For DESC - // < for partitions to the left - // <= for the partition we left off on - // <= for the partitions to the right - String expression = expressions[0]; - SortOrder sortOrder = sortOrders[0]; - QueryItem orderByItem = orderByItems[0]; - Object rawItem = orderByItem.getItem(); - String orderByItemToString; - if (rawItem instanceof String) { - orderByItemToString = "\"" + rawItem.toString().replaceAll("\"", - "\\\"") + "\""; - } else { - orderByItemToString = rawItem.toString(); - } - - left.append(String.format("%s %s %s", - expression, - (sortOrder == SortOrder.Descending ? "<" : ">"), - orderByItemToString)); - - if (inclusive) { - target.append(String.format("%s %s %s", - expression, - (sortOrder == SortOrder.Descending ? "<=" : ">="), - orderByItemToString)); - } else { - target.append(String.format("%s %s %s", - expression, - (sortOrder == SortOrder.Descending ? "<" : ">"), - orderByItemToString)); - } - - right.append(String.format("%s %s %s", - expression, - (sortOrder == SortOrder.Descending ? "<=" : ">="), - orderByItemToString)); - } else { - // This code path needs to be implemented, but it's error prone and needs - // testing. - // You can port the implementation from the .net SDK and it should work if - // ported right. - throw new NotImplementedException( - "Resuming a multi order by query from a continuation token is not supported yet."); - } - - return new FormattedFilterInfo(left.toString(), - target.toString(), - right.toString()); - } - - protected OrderByDocumentProducer createDocumentProducer( - String collectionRid, - PartitionKeyRange targetRange, - String continuationToken, - int initialPageSize, - FeedOptions feedOptions, - SqlQuerySpec querySpecForInit, - Map commonRequestHeaders, - Func3 createRequestFunc, - Func1>> executeFunc, - Func0 createRetryPolicyFunc) { - return new OrderByDocumentProducer(consumeComparer, - client, - collectionRid, - feedOptions, - createRequestFunc, - executeFunc, - targetRange, - collectionRid, - () -> client.getResetSessionTokenRetryPolicy().getRequestPolicy(), - resourceType, - correlatedActivityId, - initialPageSize, - continuationToken, - top, - this.targetRangeToOrderByContinuationTokenMap); - } - - private static class ItemToPageTransformer - implements Transformer, FeedResponse> { - private final static int DEFAULT_PAGE_SIZE = 100; - private final RequestChargeTracker tracker; - private final int maxPageSize; - private final ConcurrentMap queryMetricMap; - private final Function, String> orderByContinuationTokenCallback; - private volatile FeedResponse> previousPage; - - public ItemToPageTransformer( - RequestChargeTracker tracker, - int maxPageSize, - ConcurrentMap queryMetricsMap, - Function, String> orderByContinuationTokenCallback) { - this.tracker = tracker; - this.maxPageSize = maxPageSize > 0 ? maxPageSize : DEFAULT_PAGE_SIZE; - this.queryMetricMap = queryMetricsMap; - this.orderByContinuationTokenCallback = orderByContinuationTokenCallback; - this.previousPage = null; - } - - private static Map headerResponse( - double requestCharge) { - return Utils.immutableMapOf(HttpConstants.HttpHeaders.REQUEST_CHARGE, - String.valueOf(requestCharge)); - } - - private FeedResponse> addOrderByContinuationToken( - FeedResponse> page, - String orderByContinuationToken) { - Map headers = new HashMap<>(page.getResponseHeaders()); - headers.put(HttpConstants.HttpHeaders.CONTINUATION, - orderByContinuationToken); - return BridgeInternal.createFeedResponseWithQueryMetrics(page.getResults(), - headers, - page.getQueryMetrics()); - } - - @Override - public Observable> call( - Observable> source) { - return source - // .windows: creates an observable of observable where inner observable - // emits max maxPageSize elements - .window(maxPageSize).map(o -> o.toList()) - // flattens the observable>>> to - // Observable>> - .flatMap(resultListObs -> resultListObs, - 1) - // translates Observable>> to - // Observable>>> - .map(orderByRowResults -> { - // construct a page from result with request charge - FeedResponse> feedResponse = BridgeInternal.createFeedResponse( - orderByRowResults, - headerResponse(tracker.getAndResetCharge())); - if (!queryMetricMap.isEmpty()) { - for (String key : queryMetricMap.keySet()) { - BridgeInternal.putQueryMetricsIntoMap(feedResponse, - key, - queryMetricMap.get(key)); - } - } - return feedResponse; - }) - // Emit an empty page so the downstream observables know when there are no more - // results. - .concatWith(Observable.defer(() -> { - return Observable.just(BridgeInternal.createFeedResponse(Utils.immutableListOf(), - null)); - })) - // Create pairs from the stream to allow the observables downstream to "peek" - // 1, 2, 3, null -> (null, 1), (1, 2), (2, 3), (3, null) - .map(orderByRowResults -> { - ImmutablePair>, FeedResponse>> previousCurrent = new ImmutablePair>, FeedResponse>>( - this.previousPage, - orderByRowResults); - this.previousPage = orderByRowResults; - return previousCurrent; - }) - // remove the (null, 1) - .skip(1) - // Add the continuation token based on the current and next page. - .map(currentNext -> { - FeedResponse> current = currentNext.left; - FeedResponse> next = currentNext.right; - - FeedResponse> page; - if (next.getResults().size() == 0) { - // No more pages no send current page with null continuation token - page = current; - page = this.addOrderByContinuationToken(page, - null); - } else { - // Give the first page but use the first value in the next page to generate the - // continuation token - page = current; - List> results = next.getResults(); - OrderByRowResult firstElementInNextPage = results.get(0); - String orderByContinuationToken = this.orderByContinuationTokenCallback - .apply(firstElementInNextPage); - page = this.addOrderByContinuationToken(page, - orderByContinuationToken); - } - - return page; - }).map(feedOfOrderByRowResults -> { - // FeedResponse> to FeedResponse - List unwrappedResults = new ArrayList(); - for (OrderByRowResult orderByRowResult : feedOfOrderByRowResults.getResults()) { - unwrappedResults.add(orderByRowResult.getPayload()); - } - - return BridgeInternal.createFeedResponseWithQueryMetrics(unwrappedResults, - feedOfOrderByRowResults.getResponseHeaders(), - feedOfOrderByRowResults.getQueryMetrics()); - }).switchIfEmpty(Observable.defer(() -> { - // create an empty page if there is no result - return Observable.just(BridgeInternal.createFeedResponse(Utils.immutableListOf(), - headerResponse(tracker.getAndResetCharge()))); - })); - } - } - - @Override - public Observable> drainAsync( - int maxPageSize) { - //// In order to maintain the continuation token for the user we must drain with - //// a few constraints - //// 1) We always drain from the partition, which has the highest priority item - //// first - //// 2) If multiple partitions have the same priority item then we drain from - //// the left most first - //// otherwise we would need to keep track of how many of each item we drained - //// from each partition - //// (just like parallel queries). - //// Visually that look the following case where we have three partitions that - //// are numbered and store letters. - //// For teaching purposes I have made each item a tuple of the following form: - //// - //// So that duplicates across partitions are distinct, but duplicates within - //// partitions are indistinguishable. - //// |-------| |-------| |-------| - //// | | | | | | - //// | | | | | | - //// | | | | | | - //// | | | | | | - //// | | | | | | - //// | | | | | | - //// | | | | | | - //// |-------| |-------| |-------| - //// Now the correct drain order in this case is: - //// ,,,,,,,,,,, - //// ,,,,,,,,, - //// In more mathematical terms - //// 1) always comes before where x < z - //// 2) always come before where j < k - return this.orderByObservable.compose(new ItemToPageTransformer(tracker, - maxPageSize, - this.queryMetricMap, - ( - orderByRowResult) -> { - return this.getContinuationToken(orderByRowResult); - })); - } - - @Override - public Observable> executeAsync() { - return drainAsync(feedOptions.getMaxItemCount()); - } - - private String getContinuationToken( - OrderByRowResult orderByRowResult) { - // rid - String rid = orderByRowResult.getResourceId(); - - // CompositeContinuationToken - String backendContinuationToken = orderByRowResult.getSourceBackendContinuationToken(); - Range range = orderByRowResult.getSourcePartitionKeyRange().toRange(); - - boolean inclusive = true; - CompositeContinuationToken compositeContinuationToken = new CompositeContinuationToken(backendContinuationToken, - range); - - // OrderByItems - QueryItem[] orderByItems = new QueryItem[orderByRowResult.getOrderByItems().size()]; - orderByRowResult.getOrderByItems().toArray(orderByItems); - - return new OrderByContinuationToken(compositeContinuationToken, - orderByItems, - rid, - inclusive).toJson(); - } - - private final class FormattedFilterInfo { - private final String filterForRangesLeftOfTheTargetRange; - private final String filterForTargetRange; - private final String filterForRangesRightOfTheTargetRange; - - public FormattedFilterInfo( - String filterForRangesLeftOfTheTargetRange, - String filterForTargetRange, - String filterForRangesRightOfTheTargetRange) { - if (filterForRangesLeftOfTheTargetRange == null) { - throw new IllegalArgumentException("filterForRangesLeftOfTheTargetRange must not be null."); - } - - if (filterForTargetRange == null) { - throw new IllegalArgumentException("filterForTargetRange must not be null."); - } - - if (filterForRangesRightOfTheTargetRange == null) { - throw new IllegalArgumentException("filterForRangesRightOfTheTargetRange must not be null."); - } - - this.filterForRangesLeftOfTheTargetRange = filterForRangesLeftOfTheTargetRange; - this.filterForTargetRange = filterForTargetRange; - this.filterForRangesRightOfTheTargetRange = filterForRangesRightOfTheTargetRange; - } - - /** - * @return the filterForRangesLeftOfTheTargetRange - */ - public String getFilterForRangesLeftOfTheTargetRange() { - return filterForRangesLeftOfTheTargetRange; - } - - /** - * @return the filterForTargetRange - */ - public String getFilterForTargetRange() { - return filterForTargetRange; - } - - /** - * @return the filterForRangesRightOfTheTargetRange - */ - public String getFilterForRangesRightOfTheTargetRange() { - return filterForRangesRightOfTheTargetRange; - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByUtils.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByUtils.java deleted file mode 100644 index e7eb77377b7f..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/OrderByUtils.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.github.davidmoten.rx.Transformers; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.ResourceId; -import com.microsoft.azure.cosmosdb.internal.query.ItemComparator; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; -import com.microsoft.azure.cosmosdb.internal.query.SortOrder; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderByRowResult; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderbyRowComparer; -import com.microsoft.azure.cosmosdb.QueryMetrics; - -import com.microsoft.azure.cosmosdb.rx.internal.BadRequestException; -import org.apache.commons.lang3.tuple.Pair; -import rx.Observable; -import rx.Observable.Transformer; - -class OrderByUtils { - - public static Observable> orderedMerge(Class klass, - OrderbyRowComparer consumeComparer, - RequestChargeTracker tracker, - List> documentProducers, - Map queryMetricsMap, - Map targetRangeToOrderByContinuationTokenMap) { - return toOrderByQueryResultObservable(klass, documentProducers.get(0), tracker, queryMetricsMap, targetRangeToOrderByContinuationTokenMap, consumeComparer.getSortOrders()) - .compose( - Transformers.orderedMergeWith( - documentProducers.subList(1, documentProducers.size()) - .stream() - .map(producer -> toOrderByQueryResultObservable(klass, producer, tracker, queryMetricsMap, targetRangeToOrderByContinuationTokenMap, consumeComparer.getSortOrders())) - .collect(Collectors.toList()), consumeComparer, false, 1)); - } - - private static Observable> toOrderByQueryResultObservable(Class klass, - DocumentProducer producer, - RequestChargeTracker tracker, - Map queryMetricsMap, - Map targetRangeToOrderByContinuationTokenMap, - List sortOrders) { - return producer - .produceAsync() - .compose(new OrderByUtils.PageToItemTransformer(klass, tracker, queryMetricsMap, targetRangeToOrderByContinuationTokenMap, sortOrders)); - } - - private static class PageToItemTransformer implements Transformer.DocumentProducerFeedResponse, OrderByRowResult> { - private final RequestChargeTracker tracker; - private final Class klass; - private final Map queryMetricsMap; - private final Map targetRangeToOrderByContinuationTokenMap; - private final List sortOrders; - - public PageToItemTransformer(Class klass, RequestChargeTracker tracker, Map queryMetricsMap, - Map targetRangeToOrderByContinuationTokenMap, List sortOrders) { - this.klass = klass; - this.tracker = tracker; - this.queryMetricsMap = queryMetricsMap; - this.targetRangeToOrderByContinuationTokenMap = targetRangeToOrderByContinuationTokenMap; - this.sortOrders = sortOrders; - } - - @Override - public Observable> call(Observable.DocumentProducerFeedResponse> source) { - return source.flatMap(documentProducerFeedResponse -> { - for (String key : documentProducerFeedResponse.pageResult.getQueryMetrics().keySet()) { - if (queryMetricsMap.containsKey(key)) { - QueryMetrics qm = documentProducerFeedResponse.pageResult.getQueryMetrics().get(key); - queryMetricsMap.get(key).add(qm); - } else { - queryMetricsMap.put(key, documentProducerFeedResponse.pageResult.getQueryMetrics().get(key)); - } - } - List results = documentProducerFeedResponse.pageResult.getResults(); - OrderByContinuationToken orderByContinuationToken = targetRangeToOrderByContinuationTokenMap.get(documentProducerFeedResponse.sourcePartitionKeyRange.getId()); - if (orderByContinuationToken != null) { - Pair booleanResourceIdPair = ResourceId.tryParse(orderByContinuationToken.getRid()); - if (!booleanResourceIdPair.getLeft()) { - return Observable.error(new BadRequestException(String.format("Invalid Rid in the continuation token %s for OrderBy~Context.", - orderByContinuationToken.getCompositeContinuationToken().getToken()))); - } - ResourceId continuationTokenRid = booleanResourceIdPair.getRight(); - results = results.stream() - .filter(tOrderByRowResult -> { - // When we resume a query on a partition there is a possibility that we only read a partial page from the backend - // meaning that will we repeat some documents if we didn't do anything about it. - // The solution is to filter all the documents that come before in the sort order, since we have already emitted them to the client. - // The key is to seek until we get an order by value that matches the order by value we left off on. - // Once we do that we need to seek to the correct _rid within the term, - // since there might be many documents with the same order by value we left off on. - List queryItems = new ArrayList(); - ArrayNode arrayNode = (ArrayNode) tOrderByRowResult.get("orderByItems"); - for (JsonNode jsonNode : arrayNode) { - QueryItem queryItem = new QueryItem(jsonNode.toString()); - queryItems.add(queryItem); - } - - // Check if its the same orderby item from the token - long cmp = 0; - for (int i = 0; i < sortOrders.size(); i++) { - cmp = ItemComparator.getInstance().compare(orderByContinuationToken.getOrderByItems()[i].getItem(), - queryItems.get(i).getItem()); - if (cmp != 0) { - cmp = sortOrders.get(i).equals(SortOrder.Descending) ? -cmp : cmp; - break; - } - } - - if (cmp == 0) { - // Once the item matches the order by items from the continuation tokens - // We still need to remove all the documents that have a lower rid in the rid sort order. - // If there is a tie in the sort order the documents should be in _rid order in the same direction as the first order by field. - // So if it's ORDER BY c.age ASC, c.name DESC the _rids are ASC - // If ti's ORDER BY c.age DESC, c.name DESC the _rids are DESC - cmp = (continuationTokenRid.getDocument() - ResourceId.tryParse(tOrderByRowResult.getResourceId()).getRight().getDocument()); - - if (sortOrders.iterator().next().equals(SortOrder.Descending)) { - cmp = -cmp; - } - return (cmp <= 0); - } - return true; - - }) - .collect(Collectors.toList()); - - } - - tracker.addCharge(documentProducerFeedResponse.pageResult.getRequestCharge()); - Observable x = Observable.from(results); - - return x.map(r -> new OrderByRowResult( - klass, - r.toJson(), - documentProducerFeedResponse.sourcePartitionKeyRange, - documentProducerFeedResponse.pageResult.getResponseContinuation())); - }, 1); - } - } - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/Paginator.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/Paginator.java deleted file mode 100644 index 45ec5692e769..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/Paginator.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedOptionsBase; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Observer; -import rx.functions.Func1; -import rx.functions.Func2; -import rx.observables.AsyncOnSubscribe; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class Paginator { - - private final static Logger logger = LoggerFactory.getLogger(Paginator.class); - - public static Observable> getPaginatedChangeFeedQueryResultAsObservable( - ChangeFeedOptions feedOptions, Func2 createRequestFunc, - Func1>> executeFunc, Class resourceType, - int maxPageSize) { - return getPaginatedQueryResultAsObservable(feedOptions, createRequestFunc, executeFunc, resourceType, - -1, maxPageSize, true); - } - - public static Observable> getPaginatedQueryResultAsObservable( - FeedOptions feedOptions, - Func2 createRequestFunc, - Func1>> executeFunc, Class resourceType, - int maxPageSize) { - return getPaginatedQueryResultAsObservable(feedOptions, createRequestFunc, executeFunc, resourceType, - -1, maxPageSize); - } - - public static Observable> getPaginatedQueryResultAsObservable( - FeedOptions options, - Func2 createRequestFunc, - Func1>> executeFunc, Class resourceType, - int top, int maxPageSize) { - return getPaginatedQueryResultAsObservable(options, createRequestFunc, executeFunc, resourceType, - top, maxPageSize, false); - } - - private static Observable> getPaginatedQueryResultAsObservable( - FeedOptionsBase options, - Func2 createRequestFunc, - Func1>> executeFunc, Class resourceType, - int top, int maxPageSize, boolean isChangeFeed) { - - Observable> obs = Observable.defer(() -> { - return Observable.create(new AsyncOnSubscribe>() { - @Override - protected Fetcher generateState() { - return new Fetcher(createRequestFunc, executeFunc, options, isChangeFeed, top, maxPageSize); - } - - @Override - protected Fetcher next(Fetcher fetcher, long requested, Observer>> observer) { - assert requested == 1 : "requested amount expected to be 1"; // as there is a rebatchRequests(1) - - if (fetcher.shouldFetchMore()) { - Observable> respObs = fetcher.nextPage(); - observer.onNext(respObs); - } else { - logger.debug("No more results"); - observer.onCompleted(); - } - - return fetcher; - } - }).rebatchRequests(1); - }); - - return obs; - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelDocumentQueryExecutionContext.java deleted file mode 100644 index f7fe88c34454..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelDocumentQueryExecutionContext.java +++ /dev/null @@ -1,369 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.tuple.ImmutablePair; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.RequestChargeTracker; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.query.PartitionedQueryExecutionInfo; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -import rx.Observable; -import rx.Observable.Transformer; -import rx.functions.Func0; -import rx.functions.Func1; -import rx.functions.Func3; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class ParallelDocumentQueryExecutionContext - extends ParallelDocumentQueryExecutionContextBase { - - private ParallelDocumentQueryExecutionContext( - IDocumentQueryClient client, - List partitionKeyRanges, - ResourceType resourceTypeEnum, - Class resourceType, - SqlQuerySpec query, - FeedOptions feedOptions, - String resourceLink, - String rewrittenQuery, - String collectionRid, - boolean isContinuationExpected, - boolean getLazyFeedResponse, - UUID correlatedActivityId) { - super(client, partitionKeyRanges, resourceTypeEnum, resourceType, query, feedOptions, resourceLink, - rewrittenQuery, isContinuationExpected, getLazyFeedResponse, correlatedActivityId); - } - - public static Observable> createAsync( - IDocumentQueryClient client, - ResourceType resourceTypeEnum, - Class resourceType, - SqlQuerySpec query, - FeedOptions feedOptions, - String resourceLink, - String collectionRid, - PartitionedQueryExecutionInfo partitionedQueryExecutionInfo, - List targetRanges, - int initialPageSize, - boolean isContinuationExpected, - boolean getLazyFeedResponse, - UUID correlatedActivityId) { - - ParallelDocumentQueryExecutionContext context = new ParallelDocumentQueryExecutionContext(client, - targetRanges, - resourceTypeEnum, - resourceType, - query, - feedOptions, - resourceLink, - partitionedQueryExecutionInfo.getQueryInfo().getRewrittenQuery(), - collectionRid, - isContinuationExpected, - getLazyFeedResponse, - correlatedActivityId); - - try { - context.initialize(collectionRid, - targetRanges, - initialPageSize, - feedOptions.getRequestContinuation()); - return Observable.just(context); - } catch (DocumentClientException dce) { - return Observable.error(dce); - } - } - - private void initialize( - String collectionRid, - List targetRanges, - int initialPageSize, - String continuationToken) throws DocumentClientException { - // Generate the corresponding continuation token map. - Map partitionKeyRangeToContinuationTokenMap = new HashMap(); - if (continuationToken == null) { - // If the user does not give a continuation token, - // then just start the query from the first partition. - for (PartitionKeyRange targetRange : targetRanges) { - partitionKeyRangeToContinuationTokenMap.put(targetRange, - null); - } - } else { - // Figure out which partitions to resume from: - - // If a continuation token is given then we need to figure out partition key - // range it maps to - // in order to filter the partition key ranges. - // For example if suppliedCompositeContinuationToken.Range.Min == - // partition3.Range.Min, - // then we know that partitions 0, 1, 2 are fully drained. - - // Check to see if composite continuation token is a valid JSON. - ValueHolder outCompositeContinuationToken = new ValueHolder(); - if (!CompositeContinuationToken.tryParse(continuationToken, - outCompositeContinuationToken)) { - String message = String.format("Invalid JSON in continuation token %s for Parallel~Context", - continuationToken); - throw new DocumentClientException(HttpConstants.StatusCodes.BADREQUEST, - message); - } - - CompositeContinuationToken compositeContinuationToken = outCompositeContinuationToken.v; - - // Get the right hand side of the query ranges: - List filteredPartitionKeyRanges = this.getPartitionKeyRangesForContinuation( - compositeContinuationToken, - targetRanges); - - // The first partition is the one we left off on and have a backend continuation - // token for. - partitionKeyRangeToContinuationTokenMap.put(filteredPartitionKeyRanges.get(0), - compositeContinuationToken.getToken()); - - // The remaining partitions we have yet to touch / have null continuation tokens - for (int i = 1; i < filteredPartitionKeyRanges.size(); i++) { - partitionKeyRangeToContinuationTokenMap.put(filteredPartitionKeyRanges.get(i), - null); - } - } - - super.initialize(collectionRid, - partitionKeyRangeToContinuationTokenMap, - initialPageSize, - this.querySpec); - } - - private List getPartitionKeyRangesForContinuation( - CompositeContinuationToken compositeContinuationToken, - List partitionKeyRanges) throws DocumentClientException { - // Find the partition key range we left off on - int startIndex = this.FindTargetRangeAndExtractContinuationTokens(partitionKeyRanges, - compositeContinuationToken.getRange()); - - List rightHandSideRanges = new ArrayList(); - for (int i = startIndex; i < partitionKeyRanges.size(); i++) { - rightHandSideRanges.add(partitionKeyRanges.get(i)); - } - - return rightHandSideRanges; - } - - private static class EmptyPagesFilterTransformer - implements Transformer.DocumentProducerFeedResponse, FeedResponse> { - private final RequestChargeTracker tracker; - private DocumentProducer.DocumentProducerFeedResponse previousPage; - - public EmptyPagesFilterTransformer( - RequestChargeTracker tracker) { - - if (tracker == null) { - throw new IllegalArgumentException("Request Charge Tracker must not be null."); - } - - this.tracker = tracker; - this.previousPage = null; - } - - private DocumentProducer.DocumentProducerFeedResponse plusCharge( - DocumentProducer.DocumentProducerFeedResponse documentProducerFeedResponse, - double charge) { - FeedResponse page = documentProducerFeedResponse.pageResult; - Map headers = new HashMap<>(page.getResponseHeaders()); - double pageCharge = page.getRequestCharge(); - pageCharge += charge; - headers.put(HttpConstants.HttpHeaders.REQUEST_CHARGE, - String.valueOf(pageCharge)); - FeedResponse newPage = BridgeInternal.createFeedResponseWithQueryMetrics(page.getResults(), - headers, - page.getQueryMetrics()); - documentProducerFeedResponse.pageResult = newPage; - return documentProducerFeedResponse; - } - - private DocumentProducer.DocumentProducerFeedResponse addCompositeContinuationToken( - DocumentProducer.DocumentProducerFeedResponse documentProducerFeedResponse, - String compositeContinuationToken) { - FeedResponse page = documentProducerFeedResponse.pageResult; - Map headers = new HashMap<>(page.getResponseHeaders()); - headers.put(HttpConstants.HttpHeaders.CONTINUATION, - compositeContinuationToken); - FeedResponse newPage = BridgeInternal.createFeedResponseWithQueryMetrics(page.getResults(), - headers, - page.getQueryMetrics()); - documentProducerFeedResponse.pageResult = newPage; - return documentProducerFeedResponse; - } - - private static Map headerResponse( - double requestCharge) { - return Utils.immutableMapOf(HttpConstants.HttpHeaders.REQUEST_CHARGE, - String.valueOf(requestCharge)); - } - - @Override - public Observable> call( - Observable.DocumentProducerFeedResponse> source) { - return source.filter(documentProducerFeedResponse -> { - if (documentProducerFeedResponse.pageResult.getResults().isEmpty()) { - // filter empty pages and accumulate charge - tracker.addCharge(documentProducerFeedResponse.pageResult.getRequestCharge()); - return false; - } - return true; - }).map(documentProducerFeedResponse -> { - // Add the request charge - double charge = tracker.getAndResetCharge(); - if (charge > 0) { - return plusCharge(documentProducerFeedResponse, - charge); - } else { - return documentProducerFeedResponse; - } - }).concatWith(Observable.defer(() -> { - // Emit an empty page so the downstream observables know when there are no more - // results. - return Observable.just(null); - })).map(documentProducerFeedResponse -> { - // Create pairs from the stream to allow the observables downstream to "peek" - // 1, 2, 3, null -> (null, 1), (1, 2), (2, 3), (3, null) - ImmutablePair.DocumentProducerFeedResponse, DocumentProducer.DocumentProducerFeedResponse> previousCurrent = new ImmutablePair.DocumentProducerFeedResponse, DocumentProducer.DocumentProducerFeedResponse>( - this.previousPage, - documentProducerFeedResponse); - this.previousPage = documentProducerFeedResponse; - return previousCurrent; - }).skip(1).map(currentNext -> { - // remove the (null, 1) - // Add the continuation token based on the current and next page. - DocumentProducer.DocumentProducerFeedResponse current = currentNext.left; - DocumentProducer.DocumentProducerFeedResponse next = currentNext.right; - - String compositeContinuationToken; - String backendContinuationToken = current.pageResult.getResponseContinuation(); - if (backendContinuationToken == null) { - // We just finished reading the last document from a partition - if (next == null) { - // It was the last partition and we are done - compositeContinuationToken = null; - } else { - // It wasn't the last partition, so we need to give the next range, but with a - // null continuation - CompositeContinuationToken compositeContinuationTokenDom = new CompositeContinuationToken(null, - next.sourcePartitionKeyRange.toRange()); - compositeContinuationToken = compositeContinuationTokenDom.toJson(); - } - } else { - // We are in the middle of reading a partition, - // so give back this partition with a backend continuation token - CompositeContinuationToken compositeContinuationTokenDom = new CompositeContinuationToken( - backendContinuationToken, - current.sourcePartitionKeyRange.toRange()); - compositeContinuationToken = compositeContinuationTokenDom.toJson(); - } - - DocumentProducer.DocumentProducerFeedResponse page; - page = current; - page = this.addCompositeContinuationToken(page, - compositeContinuationToken); - - return page; - }).map(documentProducerFeedResponse -> { - // Unwrap the documentProducerFeedResponse and get back the feedResponse - return documentProducerFeedResponse.pageResult; - }).switchIfEmpty(Observable.defer(() -> { - // create an empty page if there is no result - return Observable.just(BridgeInternal.createFeedResponse(Utils.immutableListOf(), - headerResponse(tracker.getAndResetCharge()))); - })); - } - } - - @Override - public Observable> drainAsync( - int maxPageSize) { - List.DocumentProducerFeedResponse>> obs = this.documentProducers - // Get the stream. - .stream() - // Start from the left most partition first. - .sorted(( - dp1, - dp2) -> dp1.targetRange.getMinInclusive().compareTo(dp2.targetRange.getMinInclusive())) - // For each partition get it's stream of results. - .map(dp -> dp.produceAsync()) - // Merge results from all partitions. - .collect(Collectors.toList()); - return Observable.concat(obs).compose(new EmptyPagesFilterTransformer<>(new RequestChargeTracker())); - } - - @Override - public Observable> executeAsync() { - return this.drainAsync(feedOptions.getMaxItemCount()); - } - - protected DocumentProducer createDocumentProducer( - String collectionRid, - PartitionKeyRange targetRange, - String initialContinuationToken, - int initialPageSize, - FeedOptions feedOptions, - SqlQuerySpec querySpecForInit, - Map commonRequestHeaders, - Func3 createRequestFunc, - Func1>> executeFunc, - Func0 createRetryPolicyFunc) { - return new DocumentProducer(client, - collectionRid, - feedOptions, - createRequestFunc, - executeFunc, - targetRange, - collectionRid, - () -> client.getResetSessionTokenRetryPolicy().getRequestPolicy(), - resourceType, - correlatedActivityId, - initialPageSize, - initialContinuationToken, - top); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelDocumentQueryExecutionContextBase.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelDocumentQueryExecutionContextBase.java deleted file mode 100644 index 8ed4f7138b24..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelDocumentQueryExecutionContextBase.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.IDocumentClientRetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Strings; - -import rx.Observable; -import rx.functions.Func0; -import rx.functions.Func1; -import rx.functions.Func3; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public abstract class ParallelDocumentQueryExecutionContextBase - extends DocumentQueryExecutionContextBase implements IDocumentQueryExecutionComponent { - - protected final List> documentProducers; - protected final List partitionKeyRanges; - protected final SqlQuerySpec querySpec; - protected int pageSize; - protected int top = -1; - - protected ParallelDocumentQueryExecutionContextBase(IDocumentQueryClient client, - List partitionKeyRanges, ResourceType resourceTypeEnum, Class resourceType, - SqlQuerySpec query, FeedOptions feedOptions, String resourceLink, String rewrittenQuery, - boolean isContinuationExpected, boolean getLazyFeedResponse, UUID correlatedActivityId) { - super(client, resourceTypeEnum, resourceType, query, feedOptions, resourceLink, getLazyFeedResponse, - correlatedActivityId); - - documentProducers = new ArrayList<>(); - - this.partitionKeyRanges = partitionKeyRanges; - - if (!Strings.isNullOrEmpty(rewrittenQuery)) { - this.querySpec = new SqlQuerySpec(rewrittenQuery, super.query.getParameters()); - } else { - this.querySpec = super.query; - } - } - - protected void initialize(String collectionRid, - Map partitionKeyRangeToContinuationTokenMap, int initialPageSize, - SqlQuerySpec querySpecForInit) { - this.pageSize = initialPageSize; - Map commonRequestHeaders = createCommonHeadersAsync(this.getFeedOptions(null, null)); - - for (PartitionKeyRange targetRange : partitionKeyRangeToContinuationTokenMap.keySet()) { - Func3 createRequestFunc = (partitionKeyRange, - continuationToken, pageSize) -> { - Map headers = new HashMap<>(commonRequestHeaders); - headers.put(HttpConstants.HttpHeaders.CONTINUATION, continuationToken); - headers.put(HttpConstants.HttpHeaders.PAGE_SIZE, Strings.toString(pageSize)); - return this.createDocumentServiceRequest(headers, querySpecForInit, partitionKeyRange, collectionRid); - }; - - Func1>> executeFunc = (request) -> { - return this.executeRequestAsync(request).toObservable(); - }; - - DocumentProducer dp = createDocumentProducer(collectionRid, targetRange, - partitionKeyRangeToContinuationTokenMap.get(targetRange), initialPageSize, feedOptions, - querySpecForInit, commonRequestHeaders, createRequestFunc, executeFunc, - () -> client.getResetSessionTokenRetryPolicy().getRequestPolicy()); - - documentProducers.add(dp); - } - } - - protected int FindTargetRangeAndExtractContinuationTokens( - List partitionKeyRanges, Range range) throws DocumentClientException { - if (partitionKeyRanges == null) { - throw new IllegalArgumentException("partitionKeyRanges can not be null."); - } - - if (partitionKeyRanges.size() < 1) { - throw new IllegalArgumentException("partitionKeyRanges must have atleast one element."); - } - - for (PartitionKeyRange partitionKeyRange : partitionKeyRanges) { - if (partitionKeyRange == null) { - throw new IllegalArgumentException("partitionKeyRanges can not have null elements."); - } - } - - // Find the minimum index. - PartitionKeyRange needle = new PartitionKeyRange(/* id */ null, range.getMin(), range.getMax()); - int minIndex; - for (minIndex = 0; minIndex < partitionKeyRanges.size(); minIndex++) { - if (needle.getMinInclusive().equals(partitionKeyRanges.get(minIndex).getMinInclusive())) { - break; - } - } - - if (minIndex == partitionKeyRanges.size()) { - throw new DocumentClientException(HttpConstants.StatusCodes.BADREQUEST, - String.format("Could not find partition key range for continuation token: {0}", needle)); - } - - return minIndex; - } - - abstract protected DocumentProducer createDocumentProducer(String collectionRid, PartitionKeyRange targetRange, - String initialContinuationToken, int initialPageSize, FeedOptions feedOptions, SqlQuerySpec querySpecForInit, - Map commonRequestHeaders, - Func3 createRequestFunc, - Func1>> executeFunc, - Func0 createRetryPolicyFunc); - - @Override - abstract public Observable> drainAsync(int maxPageSize); - - public void setTop(int newTop) { - this.top = newTop; - - for (DocumentProducer producer : this.documentProducers) { - producer.top = newTop; - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelQueryConfig.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelQueryConfig.java deleted file mode 100644 index 608c8c22c7a9..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ParallelQueryConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class ParallelQueryConfig { - - public static final int ClientInternalPageSize = 100; - -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/PipelinedDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/PipelinedDocumentQueryExecutionContext.java deleted file mode 100644 index ef0a0d3a88e5..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/PipelinedDocumentQueryExecutionContext.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.List; -import java.util.UUID; -import java.util.function.Function; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.query.PartitionedQueryExecutionInfo; -import com.microsoft.azure.cosmosdb.internal.query.QueryInfo; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -import rx.Observable; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class PipelinedDocumentQueryExecutionContext implements IDocumentQueryExecutionContext { - - private IDocumentQueryExecutionComponent component; - private int actualPageSize; - private UUID correlatedActivityId; - - private PipelinedDocumentQueryExecutionContext(IDocumentQueryExecutionComponent component, int actualPageSize, - UUID correlatedActivityId) { - this.component = component; - this.actualPageSize = actualPageSize; - this.correlatedActivityId = correlatedActivityId; - - // this.executeNextSchedulingMetrics = new SchedulingStopwatch(); - // this.executeNextSchedulingMetrics.Ready(); - - // DefaultTrace.TraceVerbose(string.Format( - // CultureInfo.InvariantCulture, - // "{0} Pipelined~Context, actual page size: {1}", - // DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture), - // this.actualPageSize)); - } - - public static Observable> createAsync( - IDocumentQueryClient client, ResourceType resourceTypeEnum, Class resourceType, SqlQuerySpec expression, - FeedOptions feedOptions, String resourceLink, String collectionRid, - PartitionedQueryExecutionInfo partitionedQueryExecutionInfo, List targetRanges, - int initialPageSize, boolean isContinuationExpected, boolean getLazyFeedResponse, - UUID correlatedActivityId) { - // Use nested callback pattern to unwrap the continuation token at each level. - Function>> createBaseComponentFunction; - - QueryInfo queryInfo = partitionedQueryExecutionInfo.getQueryInfo(); - - if (queryInfo.hasOrderBy()) { - createBaseComponentFunction = (continuationToken) -> { - FeedOptions orderByFeedOptions = new FeedOptions(feedOptions); - orderByFeedOptions.setRequestContinuation(continuationToken); - return OrderByDocumentQueryExecutionContext.createAsync(client, resourceTypeEnum, resourceType, - expression, orderByFeedOptions, resourceLink, collectionRid, partitionedQueryExecutionInfo, - targetRanges, initialPageSize, isContinuationExpected, getLazyFeedResponse, - correlatedActivityId); - }; - } else { - createBaseComponentFunction = (continuationToken) -> { - FeedOptions parallelFeedOptions = new FeedOptions(feedOptions); - parallelFeedOptions.setRequestContinuation(continuationToken); - return ParallelDocumentQueryExecutionContext.createAsync(client, resourceTypeEnum, resourceType, - expression, parallelFeedOptions, resourceLink, collectionRid, partitionedQueryExecutionInfo, - targetRanges, initialPageSize, isContinuationExpected, getLazyFeedResponse, - correlatedActivityId); - }; - } - - Function>> createAggregateComponentFunction; - if (queryInfo.hasAggregates()) { - createAggregateComponentFunction = (continuationToken) -> { - return AggregateDocumentQueryExecutionContext.createAsync(createBaseComponentFunction, - queryInfo.getAggregates(), continuationToken); - }; - } else { - createAggregateComponentFunction = createBaseComponentFunction; - } - - Function>> createTopComponentFunction; - if (queryInfo.hasTop()) { - createTopComponentFunction = (continuationToken) -> { - return TopDocumentQueryExecutionContext.createAsync(createAggregateComponentFunction, - queryInfo.getTop(), continuationToken); - }; - } else { - createTopComponentFunction = createAggregateComponentFunction; - } - - int actualPageSize = Utils.getValueOrDefault(feedOptions.getMaxItemCount(), - ParallelQueryConfig.ClientInternalPageSize); - - if (actualPageSize == -1) { - actualPageSize = Integer.MAX_VALUE; - } - - int pageSize = Math.min(actualPageSize, Utils.getValueOrDefault(queryInfo.getTop(), (actualPageSize))); - return createTopComponentFunction.apply(feedOptions.getRequestContinuation()) - .map(c -> new PipelinedDocumentQueryExecutionContext<>(c, pageSize, correlatedActivityId)); - } - - @Override - public Observable> executeAsync() { - // TODO Auto-generated method stub - - // TODO add more code here - return this.component.drainAsync(actualPageSize); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ProxyDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ProxyDocumentQueryExecutionContext.java deleted file mode 100644 index 607b84152147..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/ProxyDocumentQueryExecutionContext.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.lang.invoke.MethodHandles; -import java.util.List; -import java.util.UUID; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.query.PartitionedQueryExecutionInfo; -import com.microsoft.azure.cosmosdb.rx.internal.Exceptions; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -import rx.Observable; -import rx.Single; -import rx.functions.Func1; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - * - * This class is used as a proxy to wrap the - * DefaultDocumentQueryExecutionContext which is needed for sending the query to - * Gateway first and then uses PipelinedDocumentQueryExecutionContext after it - * gets the necessary info. - */ -public class ProxyDocumentQueryExecutionContext implements IDocumentQueryExecutionContext { - - private IDocumentQueryExecutionContext innerExecutionContext; - private IDocumentQueryClient client; - private ResourceType resourceTypeEnum; - private Class resourceType; - private FeedOptions feedOptions; - private SqlQuerySpec query; - private String resourceLink; - private DocumentCollection collection; - private UUID correlatedActivityId; - private boolean isContinuationExpected; - private final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); - - public ProxyDocumentQueryExecutionContext( - IDocumentQueryExecutionContext innerExecutionContext, - IDocumentQueryClient client, - ResourceType resourceTypeEnum, - Class resourceType, - SqlQuerySpec query, - FeedOptions feedOptions, - String resourceLink, - DocumentCollection collection, - boolean isContinuationExpected, - UUID correlatedActivityId) { - this.innerExecutionContext = innerExecutionContext; - - this.client = client; - this.resourceTypeEnum = resourceTypeEnum; - this.resourceType = resourceType; - this.query = query; - this.feedOptions = feedOptions; - this.resourceLink = resourceLink; - - this.collection = collection; - this.isContinuationExpected = isContinuationExpected; - this.correlatedActivityId = correlatedActivityId; - } - - @Override - public Observable> executeAsync() { - - Func1>> func = t -> { - - logger.debug("Received non result message from gateway", t); - if (!(t instanceof Exception)) { - logger.error("Unexpected failure", t); - return Observable.error(t); - } - - if (!isCrossPartitionQuery((Exception) t)) { - // If this is not a cross partition query then propagate error - logger.debug("Failure from gateway", t); - return Observable.error(t); - } - - logger.debug("Setting up query pipeline using the query plan received form gateway"); - - // cross partition query construct pipeline - - DocumentClientException dce = (DocumentClientException) t; - - PartitionedQueryExecutionInfo partitionedQueryExecutionInfo = new - PartitionedQueryExecutionInfo(dce.getError().getPartitionedQueryExecutionInfo()); - - logger.debug("Query Plan from gateway {}", partitionedQueryExecutionInfo); - - DefaultDocumentQueryExecutionContext queryExecutionContext = - (DefaultDocumentQueryExecutionContext) this.innerExecutionContext; - - Single> partitionKeyRanges = queryExecutionContext.getTargetPartitionKeyRanges(collection.getResourceId(), - partitionedQueryExecutionInfo.getQueryRanges()); - - Observable> exContext = partitionKeyRanges.toObservable() - .flatMap(pkranges -> { - return DocumentQueryExecutionContextFactory.createSpecializedDocumentQueryExecutionContextAsync( - this.client, - this.resourceTypeEnum, - this.resourceType, - this.query, - this.feedOptions, - this.resourceLink, - isContinuationExpected, - partitionedQueryExecutionInfo, - pkranges, - this.collection.getResourceId(), - this.correlatedActivityId); - }); - - return exContext.flatMap(context -> context.executeAsync()); - }; - - return this.innerExecutionContext.executeAsync().onErrorResumeNext(func); - } - - private boolean isCrossPartitionQuery(Exception exception) { - - DocumentClientException clientException = Utils.as(exception, DocumentClientException.class); - - if (clientException == null) { - return false; - } - - return (Exceptions.isStatusCode(clientException, HttpConstants.StatusCodes.BADREQUEST) && - Exceptions.isSubStatusCode(clientException, HttpConstants.SubStatusCodes.CROSS_PARTITION_QUERY_NOT_SERVABLE)); - } - - public static Observable> createAsync(IDocumentQueryClient client, - ResourceType resourceTypeEnum, Class resourceType, SqlQuerySpec query, FeedOptions feedOptions, - String resourceLink, DocumentCollection collection, boolean isContinuationExpected, - UUID correlatedActivityId) { - - IDocumentQueryExecutionContext innerExecutionContext = - new DefaultDocumentQueryExecutionContext( - client, - resourceTypeEnum, - resourceType, - query, - feedOptions, - resourceLink, - correlatedActivityId, - isContinuationExpected); - - return Observable.just(new ProxyDocumentQueryExecutionContext(innerExecutionContext, client, - resourceTypeEnum, - resourceType, - query, - feedOptions, - resourceLink, - collection, - isContinuationExpected, - correlatedActivityId)); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/TakeContinuationToken.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/TakeContinuationToken.java deleted file mode 100644 index e8a60c2967cd..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/TakeContinuationToken.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public final class TakeContinuationToken extends JsonSerializable { - private static final String LimitPropertyName = "limit"; - private static final String SourceTokenPropetryName = "sourceToken"; - private static final Logger logger = LoggerFactory.getLogger(TakeContinuationToken.class); - - public TakeContinuationToken(int takeCount, String sourceToken) { - if (takeCount < 0) { - throw new IllegalArgumentException("takeCount must be a non negative number."); - } - - // sourceToken is allowed to be null. - this.setTakeCount(takeCount); - this.setSourceToken(sourceToken); - } - - private TakeContinuationToken(String serializedTakeContinuationToken) { - super(serializedTakeContinuationToken); - } - - public static boolean tryParse(String serializedTakeContinuationToken, - ValueHolder outTakeContinuationToken) { - boolean parsed; - try { - TakeContinuationToken takeContinuationToken = new TakeContinuationToken(serializedTakeContinuationToken); - takeContinuationToken.getSourceToken(); - takeContinuationToken.getTakeCount(); - outTakeContinuationToken.v = takeContinuationToken; - parsed = true; - } catch (Exception ex) { - logger.debug( - "Received exception {} when trying to parse: {}", - ex.getMessage(), - serializedTakeContinuationToken); - parsed = false; - outTakeContinuationToken.v = null; - } - - return parsed; - } - - public int getTakeCount() { - return super.getInt(LimitPropertyName); - } - - public String getSourceToken() { - return super.getString(SourceTokenPropetryName); - } - - private void setTakeCount(int takeCount) { - super.set(LimitPropertyName, takeCount); - } - - private void setSourceToken(String sourceToken) { - super.set(SourceTokenPropetryName, sourceToken); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/TopDocumentQueryExecutionContext.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/TopDocumentQueryExecutionContext.java deleted file mode 100644 index afa80ca43d3c..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/query/TopDocumentQueryExecutionContext.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; - -import rx.Observable; -import rx.functions.Func1; - -public class TopDocumentQueryExecutionContext implements IDocumentQueryExecutionComponent { - - private final IDocumentQueryExecutionComponent component; - private final int top; - - public TopDocumentQueryExecutionContext(IDocumentQueryExecutionComponent component, int top) { - this.component = component; - this.top = top; - } - - public static Observable> createAsync( - Function>> createSourceComponentFunction, - int topCount, String topContinuationToken) { - TakeContinuationToken takeContinuationToken; - - if (topContinuationToken == null) { - takeContinuationToken = new TakeContinuationToken(topCount, null); - } else { - ValueHolder outTakeContinuationToken = new ValueHolder(); - if (!TakeContinuationToken.tryParse(topContinuationToken, outTakeContinuationToken)) { - String message = String.format("Invalid JSON in continuation token %s for Top~Context", - topContinuationToken); - DocumentClientException dce = new DocumentClientException(HttpConstants.StatusCodes.BADREQUEST, - message); - return Observable.error(dce); - } - - takeContinuationToken = outTakeContinuationToken.v; - } - - if (takeContinuationToken.getTakeCount() > topCount) { - String message = String.format( - "top count in continuation token: %d can not be greater than the top count in the query: %d.", - takeContinuationToken.getTakeCount(), topCount); - DocumentClientException dce = new DocumentClientException(HttpConstants.StatusCodes.BADREQUEST, message); - return Observable.error(dce); - } - - return createSourceComponentFunction.apply(takeContinuationToken.getSourceToken()).map(component -> { - return new TopDocumentQueryExecutionContext(component, takeContinuationToken.getTakeCount()); - }); - } - - @Override - public Observable> drainAsync(int maxPageSize) { - ParallelDocumentQueryExecutionContextBase context; - - if (this.component instanceof AggregateDocumentQueryExecutionContext) { - context = (ParallelDocumentQueryExecutionContextBase) ((AggregateDocumentQueryExecutionContext) this.component) - .getComponent(); - } else { - context = (ParallelDocumentQueryExecutionContextBase) this.component; - } - - context.setTop(this.top); - - return this.component.drainAsync(maxPageSize).takeUntil(new Func1, Boolean>() { - - private volatile int fetchedItems = 0; - - @Override - public Boolean call(FeedResponse frp) { - - fetchedItems += frp.getResults().size(); - - // take until we have at least top many elements fetched - return fetchedItems >= top; - } - }).map(new Func1, FeedResponse>() { - - private volatile int collectedItems = 0; - private volatile boolean lastPage = false; - - @Override - public FeedResponse call(FeedResponse t) { - - if (collectedItems + t.getResults().size() <= top) { - collectedItems += t.getResults().size(); - - Map headers = new HashMap<>(t.getResponseHeaders()); - if (top != collectedItems) { - // Add Take Continuation Token - String sourceContinuationToken = t.getResponseContinuation(); - TakeContinuationToken takeContinuationToken = new TakeContinuationToken(top - collectedItems, - sourceContinuationToken); - headers.put(HttpConstants.HttpHeaders.CONTINUATION, takeContinuationToken.toJson()); - } else { - // Null out the continuation token - headers.put(HttpConstants.HttpHeaders.CONTINUATION, null); - } - - return BridgeInternal.createFeedResponseWithQueryMetrics(t.getResults(), headers, - t.getQueryMetrics()); - } else { - assert lastPage == false; - lastPage = true; - int lastPageSize = top - collectedItems; - collectedItems += lastPageSize; - - // Null out the continuation token - Map headers = new HashMap<>(t.getResponseHeaders()); - headers.put(HttpConstants.HttpHeaders.CONTINUATION, null); - - return BridgeInternal.createFeedResponseWithQueryMetrics(t.getResults().subList(0, lastPageSize), - headers, t.getQueryMetrics()); - } - } - }); - } -} diff --git a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/routing/LocationHelper.java b/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/routing/LocationHelper.java deleted file mode 100644 index 9cc5fd08442f..000000000000 --- a/cosmosdb/data-plane/gateway/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/routing/LocationHelper.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.routing; - -import org.apache.commons.lang3.StringUtils; - -import java.net.URL; - -public class LocationHelper { - /** - * For example, for https://contoso.documents.azure.com:443/ and "West US", this will return https://contoso-westus.documents.azure.com:443/ - * NOTE: This ONLY called by client first boot when the input endpoint is not available. - * - * @param serviceEndpoint - * @param location - * @return - */ - public static URL getLocationEndpoint(URL serviceEndpoint, String location) { - - // Split the host into 2 parts seperated by '.' - // For example, "contoso.documents.azure.com" is separated into "contoso" and "documents.azure.com" - // If the host doesn't contains '.', this will return the host as is, as the only element - String[] hostParts = StringUtils.split(serviceEndpoint.getHost(), ".", 2); - - String host; - if (hostParts.length != 0) { - // hostParts[0] will be the global account name - hostParts[0] = hostParts[0] + "-" + dataCenterToUriPostfix(location); - - // if hostParts has only one element, '.' is not included in the returned string - host = String.join(".", hostParts); - } else { - host = serviceEndpoint.getHost(); - } - - try { - return new URL(serviceEndpoint.getProtocol(), host, serviceEndpoint.getPort(), serviceEndpoint.getFile()); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static String dataCenterToUriPostfix(String dataCenter) { - return dataCenter.replace(" ", ""); - } -} - diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/GatewayTestUtils.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/GatewayTestUtils.java deleted file mode 100644 index 8292a4c0f399..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/GatewayTestUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb; - -import java.util.List; - -public class GatewayTestUtils { - - public static PartitionKeyRange setParent(PartitionKeyRange pkr, List parents) { - pkr.setParents(parents); - return pkr; - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/LocationHelperTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/LocationHelperTest.java deleted file mode 100644 index 5bc606e29c25..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/LocationHelperTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.microsoft.azure.cosmosdb.internal; - -import com.microsoft.azure.cosmosdb.rx.internal.routing.LocationHelper; -import org.testng.annotations.Test; - -import java.net.URI; -import java.net.URL; - -import static org.assertj.core.api.Assertions.assertThat; - -public class LocationHelperTest { - @Test(groups = "unit") - public void getLocationEndpoint() throws Exception { - URL globalServiceEndpoint = URI.create("https://account-name.documents.azure.com:443").toURL(); - URL expectedRegionServiceEndpoint = URI.create("https://account-name-east-us.documents.azure.com:443").toURL(); - assertThat(LocationHelper.getLocationEndpoint(globalServiceEndpoint, "east-us")) - .isEqualTo(expectedRegionServiceEndpoint); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/SessionContainerTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/SessionContainerTest.java deleted file mode 100644 index a66625dbf890..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/SessionContainerTest.java +++ /dev/null @@ -1,644 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.microsoft.azure.cosmosdb.GatewayTestUtils; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.rx.internal.DocumentServiceRequestContext; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.mockito.Mockito; -import org.mockito.internal.util.collections.Sets; -import org.testng.annotations.Test; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link SessionContainer} - */ -public class SessionContainerTest { - - private final static Random random = new Random(); - - @Test(groups = "unit") - public void sessionContainer() throws Exception { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - - int numCollections = 2; - int numPartitionKeyRangeIds = 5; - - for (int i = 0; i < numCollections; i++) { - String collectionResourceId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId() + i).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls/collName_" + i; - - for (int j = 0; j < numPartitionKeyRangeIds; j++) { - - String partitionKeyRangeId = "range_" + j; - String lsn = "1#" + j + "#4=90#5=2"; - - sessionContainer.setSessionToken( - collectionResourceId, - collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":" + lsn)); - } - } - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.ReadFeed, ResourceType.DocumentCollection, - "dbs/db1/colls/collName_1", IOUtils.toInputStream("content1", "UTF-8"), new HashMap<>()); - - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_1"); - assertThat(sessionToken.getLSN()).isEqualTo(1); - - DocumentServiceRequestContext dsrContext = new DocumentServiceRequestContext(); - PartitionKeyRange resolvedPKRange = new PartitionKeyRange(); - resolvedPKRange.setId("range_" + (numPartitionKeyRangeIds + 10)); - GatewayTestUtils.setParent(resolvedPKRange, ImmutableList.of("range_2", "range_x")); - dsrContext.resolvedPartitionKeyRange = resolvedPKRange; - request.requestContext = dsrContext; - - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, resolvedPKRange.getId()); - assertThat(sessionToken.getLSN()).isEqualTo(2); - } - - @Test(groups = "unit") - public void setSessionToken_NoSessionTokenForPartitionKeyRangeId() throws Exception { - String collectionRid = "uf4PAK6T-Cw="; - long collectionRidAsLong = ResourceId.parse(collectionRid).getUniqueDocumentCollectionId(); - String partitionKeyRangeId = "test_range_id"; - String sessionToken = "1#100#1=20#2=5#3=30"; - String collectionName = "dbs/db1/colls/collName_1"; - - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - - RxDocumentServiceRequest request1 = RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document, - collectionName + "/docs", IOUtils.toInputStream("content1", "UTF-8"), new HashMap<>()); - - Map respHeaders = new HashMap<>(); - RxDocumentServiceResponse resp = Mockito.mock(RxDocumentServiceResponse.class); - Mockito.doReturn(respHeaders).when(resp).getResponseHeaders(); - respHeaders.put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":" + sessionToken); - respHeaders.put(HttpConstants.HttpHeaders.OWNER_FULL_NAME, collectionName); - respHeaders.put(HttpConstants.HttpHeaders.OWNER_ID, collectionRid); - sessionContainer.setSessionToken(request1, resp.getResponseHeaders()); - - ConcurrentHashMap collectionNameToCollectionResourceId = (ConcurrentHashMap) FieldUtils.readField(sessionContainer, "collectionNameToCollectionResourceId", true); - ConcurrentHashMap> collectionResourceIdToSessionTokens = (ConcurrentHashMap>) FieldUtils.readField(sessionContainer, "collectionResourceIdToSessionTokens", true); - assertThat(collectionNameToCollectionResourceId).hasSize(1); - assertThat(collectionResourceIdToSessionTokens).hasSize(1); - assertThat(collectionNameToCollectionResourceId.get(collectionName)).isEqualTo(collectionRidAsLong); - assertThat(collectionResourceIdToSessionTokens.get(collectionRidAsLong)).isNotNull(); - assertThat(collectionResourceIdToSessionTokens.get(collectionRidAsLong)).hasSize(1); - assertThat(collectionResourceIdToSessionTokens.get(collectionRidAsLong).get(partitionKeyRangeId).convertToString()).isEqualTo(sessionToken); - - RxDocumentServiceRequest request2 = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document, - collectionName + "/docs", IOUtils.toInputStream("", "UTF-8"), new HashMap<>()); - - ISessionToken resolvedSessionToken = sessionContainer.resolvePartitionLocalSessionToken(request2, partitionKeyRangeId); - assertThat(resolvedSessionToken.convertToString()).isEqualTo(sessionToken); - } - - @Test(groups = "unit") - public void setSessionToken_MergeOldWithNew() throws Exception { - String collectionRid = "uf4PAK6T-Cw="; - String collectionName = "dbs/db1/colls/collName_1"; - String initialSessionToken = "1#100#1=20#2=5#3=30"; - String newSessionTokenInServerResponse = "1#100#1=31#2=5#3=21"; - String partitionKeyRangeId = "test_range_id"; - String expectedMergedSessionToken = "1#100#1=31#2=5#3=30"; - - Map respHeaders = new HashMap<>(); - - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - - RxDocumentServiceRequest request1 = RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document, - collectionName + "/docs", IOUtils.toInputStream("content1", "UTF-8"), new HashMap<>()); - - RxDocumentServiceResponse resp = Mockito.mock(RxDocumentServiceResponse.class); - Mockito.doReturn(respHeaders).when(resp).getResponseHeaders(); - respHeaders.put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":" + initialSessionToken); - respHeaders.put(HttpConstants.HttpHeaders.OWNER_FULL_NAME, collectionName); - respHeaders.put(HttpConstants.HttpHeaders.OWNER_ID, collectionRid); - sessionContainer.setSessionToken(request1, resp.getResponseHeaders()); - - resp = Mockito.mock(RxDocumentServiceResponse.class); - Mockito.doReturn(respHeaders).when(resp).getResponseHeaders(); - respHeaders.put(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":" + newSessionTokenInServerResponse); - respHeaders.put(HttpConstants.HttpHeaders.OWNER_FULL_NAME, collectionName); - respHeaders.put(HttpConstants.HttpHeaders.OWNER_ID, collectionRid); - sessionContainer.setSessionToken(request1, resp.getResponseHeaders()); - - RxDocumentServiceRequest request2 = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document, - collectionName + "/docs", IOUtils.toInputStream("", "UTF-8"), new HashMap<>()); - - ISessionToken resolvedSessionToken = sessionContainer.resolvePartitionLocalSessionToken(request2, partitionKeyRangeId); - assertThat(resolvedSessionToken.convertToString()).isEqualTo(expectedMergedSessionToken); - } - - - @Test(groups = "unit") - public void resolveGlobalSessionTokenReturnsEmptyStringOnEmptyCache() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document, - "dbs/db1/colls/collName/docs/doc1", new HashMap<>()); - assertThat(StringUtils.EMPTY).isEqualTo(sessionContainer.resolveGlobalSessionToken(request)); - } - - @Test(groups = "unit") - public void resolveGlobalSessionTokenReturnsEmptyStringOnCacheMiss() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String partitionKeyRangeId = "range_0"; - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String initialSessionToken = "1#100#1=20#2=5#3=30"; - sessionContainer.setSessionToken(documentCollectionId, "dbs/db1/colls1/collName", - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, partitionKeyRangeId + ":" + initialSessionToken)); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Document, - "dbs/db1/colls1/collName2/docs/doc1", new HashMap<>()); - assertThat(StringUtils.EMPTY).isEqualTo(sessionContainer.resolveGlobalSessionToken(request)); - } - - @Test(groups = "unit") - public void resolveGlobalSessionTokenReturnsTokenMapUsingName() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30")); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document); - String sessionToken = sessionContainer.resolveGlobalSessionToken(request); - Set tokens = Sets.newSet(sessionToken.split(",")); - - assertThat(tokens.size()).isEqualTo(2); - assertThat(tokens.contains("range_0:1#100#1=20#2=5#3=30")).isTrue(); - assertThat(tokens.contains("range_1:1#101#1=20#2=5#3=30")).isTrue(); - } - - @Test(groups = "unit") - public void resolveGlobalSessionTokenReturnsTokenMapUsingResourceId() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30")); - String sessionToken = sessionContainer.resolveGlobalSessionToken(request); - - Set tokens = Sets.newSet(sessionToken.split(",")); - assertThat(tokens.size()).isEqualTo(2); - assertThat(tokens.contains("range_0:1#100#1=20#2=5#3=30")).isTrue(); - assertThat(tokens.contains("range_1:1#101#1=20#2=5#3=30")).isTrue(); - } - - - @Test(groups = "unit") - public void resolveLocalSessionTokenReturnsTokenMapUsingName() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30")); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_1"); - assertThat(sessionToken.getLSN()).isEqualTo(101); - } - - @Test(groups = "unit") - public void resolveLocalSessionTokenReturnsTokenMapUsingResourceId() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30")); - - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_1"); - assertThat(sessionToken.getLSN()).isEqualTo(101); - } - - @Test(groups = "unit") - public void resolveLocalSessionTokenReturnsNullOnPartitionMiss() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30")); - request.requestContext.resolvedPartitionKeyRange = new PartitionKeyRange(); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_2"); - assertThat(sessionToken).isNull(); - } - - @Test(groups = "unit") - public void resolveLocalSessionTokenReturnsNullOnCollectionMiss() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - int randomCollectionId = getRandomCollectionId(); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), randomCollectionId).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceId.newDocumentCollectionId(getRandomDbId(), randomCollectionId - 1).getDocumentCollectionId().toString(), - ResourceType.Document, new HashMap<>()); - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30")); - request.requestContext.resolvedPartitionKeyRange = new PartitionKeyRange(); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_1"); - assertThat(sessionToken).isNull(); - } - - @Test(groups = "unit") - public void resolvePartitionLocalSessionTokenReturnsTokenOnParentMatch() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_1:1#101#1=20#2=5#3=30")); - request.requestContext.resolvedPartitionKeyRange = new PartitionKeyRange(); - GatewayTestUtils.setParent(request.requestContext.resolvedPartitionKeyRange, ImmutableList.of("range_1")); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_2"); - assertThat(sessionToken.getLSN()).isEqualTo(101); - } - - @Test(groups = "unit") - public void clearTokenByCollectionFullNameRemovesToken() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - - // Test resourceId based - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - - // Test names based - request = RxDocumentServiceRequest.createFromName(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - - sessionContainer.clearTokenByCollectionFullName(collectionFullName); - - // Test resourceId based - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - - // Test names based - request = RxDocumentServiceRequest.createFromName(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - } - - @Test(groups = "unit") - public void clearTokenByResourceIdRemovesToken() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - - // Test resourceId based - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - - // Test names based - request = RxDocumentServiceRequest.createFromName(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - - sessionContainer.clearTokenByResourceId(documentCollectionId); - - // Test resourceId based - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - - // Test names based - request = RxDocumentServiceRequest.createFromName(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - } - - @Test(groups = "unit") - public void clearTokenKeepsUnmatchedCollection() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - int randomCollectionId = getRandomCollectionId(); - String documentCollectionId1 = ResourceId.newDocumentCollectionId(getRandomDbId(), randomCollectionId).getDocumentCollectionId().toString(); - String collectionFullName1 = "dbs/db1/colls1/collName1"; - - sessionContainer.setSessionToken(documentCollectionId1, collectionFullName1, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - - // Test resourceId based - RxDocumentServiceRequest request1 = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId1, ResourceType.Document, new HashMap<>()); - String documentCollectionId2 = ResourceId.newDocumentCollectionId(getRandomDbId(), randomCollectionId - 1).getDocumentCollectionId().toString(); - String collectionFullName2 = "dbs/db1/colls1/collName2"; - - // Test resourceId based - RxDocumentServiceRequest request2 = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId2, ResourceType.Document, new HashMap<>()); - - sessionContainer.setSessionToken(documentCollectionId2, collectionFullName2, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#1=20#2=5#3=30")); - - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request1, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request2, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - - sessionContainer.clearTokenByResourceId(documentCollectionId2); - - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request1, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request2, "range_0"); - assertThat(sessionToken).isNull(); - } - - @Test(groups = "unit") - public void setSessionTokenDoesntFailOnEmptySessionTokenHeader() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - sessionContainer.setSessionToken(null, new HashMap<>()); - } - - @Test(groups = "unit") - public void setSessionTokenSetsTokenWhenRequestIsntNameBased() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - - assertThat(request.getIsNameBased()).isFalse(); - sessionContainer.setSessionToken(request, ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#4=90#5=1")); - request = RxDocumentServiceRequest.create(OperationType.Read, documentCollectionId, ResourceType.Document, new HashMap<>()); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - - request = RxDocumentServiceRequest.createFromName(OperationType.Read, collectionFullName + "/docs/doc1", ResourceType.Document); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - } - - @Test(groups = "unit") - public void setSessionTokenGivesPriorityToOwnerFullNameOverResourceAddress() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName1 = "dbs/db1/colls1/collName1"; - String collectionFullName2 = "dbs/db1/colls1/collName2"; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - collectionFullName1 + "/docs/doc1", ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - sessionContainer.setSessionToken(request, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#4=90#5=1", - HttpConstants.HttpHeaders.OWNER_FULL_NAME, collectionFullName2)); - - request = RxDocumentServiceRequest.createFromName(OperationType.Read, collectionFullName1 + "/docs/doc1", ResourceType.Document); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - - request = RxDocumentServiceRequest.createFromName(OperationType.Read, collectionFullName2 + "/docs/doc1", ResourceType.Document); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - } - - @Test(groups = "unit") - public void setSessionTokenIgnoresOwnerIdWhenRequestIsntNameBased() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - int randomCollectionId = getRandomCollectionId(); - int randomDbId = getRandomDbId(); - String documentCollectionId1 = ResourceId.newDocumentCollectionId(randomDbId, randomCollectionId).getDocumentCollectionId().toString(); - String documentCollectionId2 = ResourceId.newDocumentCollectionId(randomDbId, randomCollectionId - 1).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName1"; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId1); - assertThat(request.getIsNameBased()).isFalse(); - - sessionContainer.setSessionToken(request, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#4=90#5=1", - HttpConstants.HttpHeaders.OWNER_ID, documentCollectionId2)); - - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId1, ResourceType.Document, new HashMap<>()); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - - - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId2, ResourceType.Document, new HashMap<>()); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - } - - @Test(groups = "unit") - public void setSessionTokenGivesPriorityToOwnerIdOverResourceIdWhenRequestIsNameBased() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - int randomCollectionId = getRandomCollectionId(); - int randomDbId = getRandomDbId(); - String documentCollectionId1 = ResourceId.newDocumentCollectionId(randomDbId, randomCollectionId).getDocumentCollectionId().toString(); - String documentCollectionId2 = ResourceId.newDocumentCollectionId(randomDbId, randomCollectionId - 1).getDocumentCollectionId().toString(); - - String collectionFullName = "dbs/db1/colls1/collName1"; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document); - request.setResourceId(documentCollectionId1); - assertThat(request.getIsNameBased()).isTrue(); - - sessionContainer.setSessionToken(request, - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#4=90#5=1", - HttpConstants.HttpHeaders.OWNER_ID, documentCollectionId2)); - - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId1, ResourceType.Document, new HashMap<>()); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - - - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId2, ResourceType.Document, new HashMap<>()); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(100); - } - - @Test(groups = "unit") - public void setSessionTokenDoesntWorkForMasterQueries() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.ReadFeed, - collectionFullName + "/docs/doc1", ResourceType.DocumentCollection, new HashMap<>()); - request.setResourceId(documentCollectionId); - sessionContainer.setSessionToken(request, ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1")); - - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - - request = RxDocumentServiceRequest.createFromName(OperationType.Read, collectionFullName + "/docs/doc1", ResourceType.Document); - sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken).isNull(); - } - - @Test(groups = "unit") - public void setSessionTokenDoesntOverwriteHigherLSN() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - sessionContainer.setSessionToken(request, ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#105#4=90#5=1")); - - - request = RxDocumentServiceRequest.create(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - sessionContainer.setSessionToken(request, ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#4=90#5=1")); - - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(105); - } - - @Test(groups = "unit") - public void setSessionTokenOverwriteLowerLSN() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - sessionContainer.setSessionToken(request, ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#4=90#5=1")); - - - request = RxDocumentServiceRequest.create(OperationType.Read, - collectionFullName + "/docs/doc1", ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - sessionContainer.setSessionToken(request, ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#105#4=90#5=1")); - - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - request.setResourceId(documentCollectionId); - ISessionToken sessionToken = sessionContainer.resolvePartitionLocalSessionToken(request, "range_0"); - assertThat(sessionToken.getLSN()).isEqualTo(105); - } - - @Test(groups = "unit") - public void setSessionTokenDoesNothingOnEmptySessionTokenHeader() { - SessionContainer sessionContainer = new SessionContainer("127.0.0.1"); - String documentCollectionId = ResourceId.newDocumentCollectionId(getRandomDbId(), getRandomCollectionId()).getDocumentCollectionId().toString(); - String collectionFullName = "dbs/db1/colls1/collName"; - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName + "/docs/doc1", - ImmutableMap.of(HttpConstants.HttpHeaders.SESSION_TOKEN, "range_0:1#100#4=90#5=1")); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - String sessionToken = sessionContainer.resolveGlobalSessionToken(request); - Set tokens = Sets.newSet(sessionToken.split(",")); - assertThat(tokens.size()).isEqualTo(1); - assertThat(tokens.contains("range_0:1#100#4=90#5=1")).isTrue(); - - sessionContainer.setSessionToken(documentCollectionId, collectionFullName, new HashMap<>()); - request = RxDocumentServiceRequest.create(OperationType.Read, - documentCollectionId, ResourceType.Document, new HashMap<>()); - sessionToken = sessionContainer.resolveGlobalSessionToken(request); - tokens = Sets.newSet(sessionToken.split(",")); - assertThat(tokens.size()).isEqualTo(1); - assertThat(tokens.contains("range_0:1#100#4=90#5=1")).isTrue(); - } - - private static int getRandomCollectionId() { - return random.nextInt(Integer.MAX_VALUE / 2) - (Integer.MAX_VALUE / 2); - } - - private static int getRandomDbId() { - return random.nextInt(Integer.MAX_VALUE / 2); - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/SessionTokenTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/SessionTokenTest.java deleted file mode 100644 index 15b46fdf006d..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/SessionTokenTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal; - -import org.testng.annotations.Test; - -import static com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -public class SessionTokenTest { - - @Test(groups = "unit") - public void validateSuccessfulSessionTokenParsing() { - // valid session token - String sessionToken = "1#100#1=20#2=5#3=30"; - ValueHolder parsedSessionToken = new ValueHolder<>(null); - - assertThat(VectorSessionToken.tryCreate(sessionToken, parsedSessionToken)).isTrue(); - } - - @Test(groups = "unit") - public void validateSessionTokenParsingWithInvalidVersion() { - String sessionToken = "foo#100#1=20#2=5#3=30"; - ValueHolder parsedSessionToken = new ValueHolder<>(null); - assertThat(VectorSessionToken.tryCreate(sessionToken, parsedSessionToken)).isFalse(); - } - - @Test(groups = "unit") - public void validateSessionTokenParsingWithInvalidGlobalLsn() { - String sessionToken = "1#foo#1=20#2=5#3=30"; - ValueHolder parsedSessionToken = new ValueHolder<>(null); - assertThat(VectorSessionToken.tryCreate(sessionToken, parsedSessionToken)).isFalse(); - } - - @Test(groups = "unit") - public void validateSessionTokenParsingWithInvalidRegionProgress() { - String sessionToken = "1#100#1=20#2=x#3=30"; - ValueHolder parsedSessionToken = new ValueHolder<>(null); - assertThat(VectorSessionToken.tryCreate(sessionToken, parsedSessionToken)).isFalse(); - - } - - @Test(groups = "unit") - public void validateSessionTokenParsingWithInvalidFormat() { - String sessionToken = "1;100#1=20#2=40"; - ValueHolder parsedSessionToken = new ValueHolder<>(null); - assertThat(VectorSessionToken.tryCreate(sessionToken, parsedSessionToken)).isFalse(); - } - - @Test(groups = "unit") - public void validateSessionTokenParsingFromEmptyString() { - String sessionToken = ""; - ValueHolder parsedSessionToken = new ValueHolder<>(null); - assertThat(VectorSessionToken.tryCreate(sessionToken, parsedSessionToken)).isFalse(); - } - - @Test(groups = "unit") - public void validateSessionTokenComparison() throws Exception { - // valid session token - ValueHolder sessionToken1 = new ValueHolder<>(null); - ValueHolder sessionToken2 = new ValueHolder<>(null); - ValueHolder sessionTokenMerged = new ValueHolder<>(null); - - assertThat(VectorSessionToken.tryCreate("1#100#1=20#2=5#3=30", sessionToken1)).isTrue(); - assertThat(VectorSessionToken.tryCreate("2#105#4=10#2=5#3=30", sessionToken2)).isTrue(); - - assertThat(sessionToken1.v).isNotEqualTo(sessionToken2.v); - assertThat(sessionToken2.v).isNotEqualTo(sessionToken1.v); - - assertThat(sessionToken1.v.isValid(sessionToken2.v)).isTrue(); - assertThat(sessionToken2.v.isValid(sessionToken1.v)).isFalse(); - - - assertThat(VectorSessionToken.tryCreate("2#105#2=5#3=30#4=10", sessionTokenMerged)).isTrue(); - assertThat(sessionTokenMerged.v).isEqualTo(sessionToken1.v.merge(sessionToken2.v)); - - assertThat(VectorSessionToken.tryCreate("1#100#1=20#2=5#3=30", sessionToken1)).isTrue(); - assertThat(VectorSessionToken.tryCreate("1#100#1=10#2=8#3=30", sessionToken2)).isTrue(); - - assertThat(sessionToken1.v.equals(sessionToken2.v)).isFalse(); - assertThat(sessionToken2.v.equals(sessionToken1.v)).isFalse(); - assertThat(sessionToken1.v.isValid(sessionToken2.v)).isFalse(); - assertThat(sessionToken2.v.isValid(sessionToken1.v)).isFalse(); - - assertThat(VectorSessionToken.tryCreate("1#100#1=20#2=8#3=30", sessionTokenMerged)).isTrue(); - assertThat(sessionTokenMerged.v.equals(sessionToken1.v.merge(sessionToken2.v))).isTrue(); - - assertThat(VectorSessionToken.tryCreate("1#100#1=20#2=5#3=30", sessionToken1)).isTrue(); - assertThat(VectorSessionToken.tryCreate("1#102#1=100#2=8#3=30", sessionToken2)).isTrue(); - - assertThat(sessionToken1.v.equals(sessionToken2.v)).isFalse(); - assertThat(sessionToken2.v.equals(sessionToken1.v)).isFalse(); - assertThat(sessionToken1.v.isValid(sessionToken2.v)).isTrue(); - assertThat(sessionToken2.v.isValid(sessionToken1.v)).isFalse(); - - assertThat(VectorSessionToken.tryCreate("1#102#2=8#3=30#1=100", sessionTokenMerged)).isTrue(); - - assertThat(sessionTokenMerged.v.equals(sessionToken1.v.merge(sessionToken2.v))).isTrue(); - - assertThat(VectorSessionToken.tryCreate("1#101#1=20#2=5#3=30", sessionToken1)).isTrue(); - assertThat(VectorSessionToken.tryCreate("1#100#1=20#2=5#3=30#4=40", sessionToken2)).isTrue(); - - - try { - sessionToken1.v.merge(sessionToken2.v); - fail("Region progress can not be different when version is same"); - } catch (InternalServerErrorException e) { - } - - try { - sessionToken2.v.isValid(sessionToken1.v); - fail("Region progress can not be different when version is same"); - } catch (InternalServerErrorException e) { - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/InMemoryCollectionRoutingMapTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/InMemoryCollectionRoutingMapTest.java deleted file mode 100644 index 6ae8eedd6a6f..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/InMemoryCollectionRoutingMapTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import com.google.common.collect.ImmutableList; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; - -public class InMemoryCollectionRoutingMapTest { - - static class ServerIdentityImp implements IServerIdentity { - private int value; - public ServerIdentityImp(int value) { - this.value = value; - } - - static ServerIdentityImp of(int value) { - return new ServerIdentityImp(value); - } - } - - @Test(groups = { "unit" }) - public void collectionRoutingMap() { - InMemoryCollectionRoutingMap routingMap = InMemoryCollectionRoutingMap - .tryCreateCompleteRoutingMap(Arrays.asList( - new ImmutablePair<>( - new PartitionKeyRange("2", "0000000050", "0000000070"), ServerIdentityImp.of(2)), - new ImmutablePair<>(new PartitionKeyRange("0", "", "0000000030"), - ServerIdentityImp.of(0)), - new ImmutablePair<>( - new PartitionKeyRange("1", "0000000030", "0000000050"), ServerIdentityImp.of(1)), - new ImmutablePair<>(new PartitionKeyRange("3", "0000000070", "FF"), - ServerIdentityImp.of(3))), - StringUtils.EMPTY); - - assertThat("0").isEqualTo(routingMap.getOrderedPartitionKeyRanges().get(0).getId()); - assertThat("1").isEqualTo(routingMap.getOrderedPartitionKeyRanges().get(1).getId()); - assertThat("2").isEqualTo(routingMap.getOrderedPartitionKeyRanges().get(2).getId()); - assertThat("3").isEqualTo(routingMap.getOrderedPartitionKeyRanges().get(3).getId()); - - - assertThat("0").isEqualTo(routingMap.getRangeByEffectivePartitionKey("").getId()); - assertThat("0").isEqualTo(routingMap.getRangeByEffectivePartitionKey("0000000000").getId()); - assertThat("1").isEqualTo(routingMap.getRangeByEffectivePartitionKey("0000000030").getId()); - assertThat("1").isEqualTo(routingMap.getRangeByEffectivePartitionKey("0000000031").getId()); - assertThat("3").isEqualTo(routingMap.getRangeByEffectivePartitionKey("0000000071").getId()); - - assertThat("0").isEqualTo(routingMap.getRangeByPartitionKeyRangeId("0").getId()); - assertThat("1").isEqualTo(routingMap.getRangeByPartitionKeyRangeId("1").getId()); - - assertThat(4).isEqualTo( - routingMap - .getOverlappingRanges(Collections.singletonList(new Range(PartitionKeyRange.MINIMUM_INCLUSIVE_EFFECTIVE_PARTITION_KEY, - PartitionKeyRange.MAXIMUM_EXCLUSIVE_EFFECTIVE_PARTITION_KEY, true, false))) - .size()); - assertThat(0).isEqualTo( - routingMap - .getOverlappingRanges(Collections.singletonList(new Range(PartitionKeyRange.MINIMUM_INCLUSIVE_EFFECTIVE_PARTITION_KEY, - PartitionKeyRange.MINIMUM_INCLUSIVE_EFFECTIVE_PARTITION_KEY, false, false))) - .size()); - - Collection partitionKeyRanges = routingMap - .getOverlappingRanges(Collections.singletonList(new Range("0000000040", "0000000040", true, true))); - - assertThat(1).isEqualTo(partitionKeyRanges.size()); - Iterator iterator = partitionKeyRanges.iterator(); - assertThat("1").isEqualTo(iterator.next().getId()); - - Collection partitionKeyRanges1 = routingMap - .getOverlappingRanges(Arrays.asList(new Range("0000000040", "0000000045", true, true), - new Range("0000000045", "0000000046", true, true), - new Range("0000000046", "0000000050", true, true))); - - assertThat(2).isEqualTo(partitionKeyRanges1.size()); - Iterator iterator1 = partitionKeyRanges1.iterator(); - assertThat("1").isEqualTo(iterator1.next().getId()); - assertThat("2").isEqualTo(iterator1.next().getId()); - } - - @Test(groups = { "unit" }, expectedExceptions = IllegalStateException.class) - public void invalidRoutingMap() { - InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap(Arrays.asList( - new ImmutablePair<>(new PartitionKeyRange("1", "0000000020", "0000000030"), - ServerIdentityImp.of(2)), - new ImmutablePair<>(new PartitionKeyRange("2", "0000000025", "0000000035"), - ServerIdentityImp.of(2))), - StringUtils.EMPTY); - } - - @Test(groups = { "unit" }) - public void incompleteRoutingMap() { - InMemoryCollectionRoutingMap routingMap = InMemoryCollectionRoutingMap - .tryCreateCompleteRoutingMap(Arrays.asList( - new ImmutablePair<>(new PartitionKeyRange("2", "", "0000000030"), - ServerIdentityImp.of(2)), - new ImmutablePair<>(new PartitionKeyRange("3", "0000000031", "FF"), - ServerIdentityImp.of(2))), - StringUtils.EMPTY); - - assertThat(routingMap).isNull(); - - routingMap = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap(Arrays.asList( - new ImmutablePair<>(new PartitionKeyRange("2", "", "0000000030"), ServerIdentityImp.of(2)), - new ImmutablePair<>(new PartitionKeyRange("3", "0000000030", "FF"), ServerIdentityImp.of(2))), - StringUtils.EMPTY); - - assertThat(routingMap).isNotNull(); - } - - @Test(groups = {"unit"}) - public void goneRanges() { - CollectionRoutingMap routingMap = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap( - ImmutableList.of( - new ImmutablePair(new PartitionKeyRange("2", "", "0000000030", ImmutableList.of("1", "0")), null), - new ImmutablePair(new PartitionKeyRange("3", "0000000030", "0000000032", ImmutableList.of("5")), null), - new ImmutablePair(new PartitionKeyRange("4", "0000000032", "FF"), null)), - StringUtils.EMPTY); - - assertThat(routingMap.IsGone("1")).isTrue(); - assertThat(routingMap.IsGone("0")).isTrue(); - assertThat(routingMap.IsGone("5")).isTrue(); - - assertThat(routingMap.IsGone("2")).isFalse(); - assertThat(routingMap.IsGone("3")).isFalse(); - assertThat(routingMap.IsGone("4")).isFalse(); - assertThat(routingMap.IsGone("100")).isFalse(); - } - - @Test(groups = {"unit"}) - public void tryCombineRanges() { - CollectionRoutingMap routingMap = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap( - ImmutableList.of( - new ImmutablePair( - new PartitionKeyRange( - "2", - "0000000050", - "0000000070"), - null), - - new ImmutablePair( - new PartitionKeyRange( - "0", - "", - "0000000030"), - null), - - new ImmutablePair( - new PartitionKeyRange( - "1", - "0000000030", - "0000000050"), - null), - - new ImmutablePair( - new PartitionKeyRange( - "3", - "0000000070", - "FF"), - null) - ), StringUtils.EMPTY); - - CollectionRoutingMap newRoutingMap = routingMap.tryCombine( - ImmutableList.of( - new ImmutablePair( - new PartitionKeyRange( - "4", - "", - "0000000010", - ImmutableList.of("0") - ), - null), - - new ImmutablePair( - new PartitionKeyRange( - "5", - "0000000010", - "0000000030", - ImmutableList.of("0") - ), - null) - )); - - assertThat(newRoutingMap).isNotNull(); - - newRoutingMap = routingMap.tryCombine( - ImmutableList.of( - new ImmutablePair( - new PartitionKeyRange( - "6", - "", - "0000000005", - ImmutableList.of("0", "4") - ), - null), - - new ImmutablePair( - new PartitionKeyRange( - "7", - "0000000005", - "0000000010", - ImmutableList.of("0", "4") - ), - null), - - new ImmutablePair( - new PartitionKeyRange( - "8", - "0000000010", - "0000000015", - ImmutableList.of("0", "5") - ), - null), - - new ImmutablePair( - new PartitionKeyRange( - "9", - "0000000015", - "0000000030", - ImmutableList.of("0", "5") - ), - null) - )); - - assertThat(newRoutingMap).isNotNull(); - - newRoutingMap = routingMap.tryCombine( - ImmutableList.of( - new ImmutablePair( - new PartitionKeyRange( - "10", - "", - "0000000002", - ImmutableList.of("0", "4", "6") - ), - null) - )); - - assertThat(newRoutingMap).isNull(); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/LocationCacheTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/LocationCacheTest.java deleted file mode 100644 index bb2d519a7fd7..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/LocationCacheTest.java +++ /dev/null @@ -1,444 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.BridgeUtils; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.DatabaseAccountLocation; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.internal.GlobalEndpointManager; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.DatabaseAccountManagerInternal; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; -import org.apache.commons.collections4.list.UnmodifiableList; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Completable; -import rx.Observable; - -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import static com.microsoft.azure.cosmosdb.BridgeUtils.createDatabaseAccountLocation; -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link LocationCache} - */ -public class LocationCacheTest { - private final static URL DefaultEndpoint = createUrl("https://default.documents.azure.com"); - private final static URL Location1Endpoint = createUrl("https://location1.documents.azure.com"); - private final static URL Location2Endpoint = createUrl("https://location2.documents.azure.com"); - private final static URL Location3Endpoint = createUrl("https://location3.documents.azure.com"); - private final static URL Location4Endpoint = createUrl("https://location4.documents.azure.com"); - - private static HashMap EndpointByLocation = new HashMap<>(); - - static { - EndpointByLocation.put("location1", LocationCacheTest.Location1Endpoint); - EndpointByLocation.put("location2", LocationCacheTest.Location2Endpoint); - EndpointByLocation.put("location3", LocationCacheTest.Location3Endpoint); - EndpointByLocation.put("location4", LocationCacheTest.Location4Endpoint); - } - - private final Configs configs = new Configs() { - @Override - public int getUnavailableLocationsExpirationTimeInSeconds() { - return 3; - } - }; - - private UnmodifiableList preferredLocations; - private DatabaseAccount databaseAccount; - private LocationCache cache; - private GlobalEndpointManager endpointManager; - private DatabaseAccountManagerInternalMock mockedClient; - - @DataProvider(name = "paramsProvider") - public Object[][] paramsProvider() { - // provides all possible combinations for - // useMultipleWriteEndpoints, endpointDiscoveryEnabled, isPreferredListEmpty - List list = new ArrayList<>(); - for (int i = 0; i < 8; i++) { - boolean useMultipleWriteEndpoints = (i & 1) > 0; - boolean endpointDiscoveryEnabled = (i & 2) > 0; - boolean isPreferredListEmpty = (i & 4) > 0; - list.add(new Object[]{useMultipleWriteEndpoints, endpointDiscoveryEnabled, isPreferredListEmpty}); - } - - return list.toArray(new Object[][]{}); - } - - @Test(groups = "long", dataProvider = "paramsProvider") - public void validateAsync(boolean useMultipleWriteEndpoints, - boolean endpointDiscoveryEnabled, - boolean isPreferredListEmpty) throws Exception { - validateLocationCacheAsync(useMultipleWriteEndpoints, - endpointDiscoveryEnabled, - isPreferredListEmpty); - } - - @Test(groups = "long") - public void validateWriteEndpointOrderWithClientSideDisableMultipleWriteLocation() throws Exception { - this.initialize(false, true, false); - assertThat(this.cache.getWriteEndpoints().get(0)).isEqualTo(LocationCacheTest.Location1Endpoint); - assertThat(this.cache.getWriteEndpoints().get(1)).isEqualTo(LocationCacheTest.Location2Endpoint); - assertThat(this.cache.getWriteEndpoints().get(2)).isEqualTo(LocationCacheTest.Location3Endpoint); - } - - private static DatabaseAccount createDatabaseAccount(boolean useMultipleWriteLocations) { - DatabaseAccount databaseAccount = BridgeUtils.createDatabaseAccount( - // read endpoints - ImmutableList.of( - createDatabaseAccountLocation("location1", LocationCacheTest.Location1Endpoint.toString()), - createDatabaseAccountLocation("location2", LocationCacheTest.Location2Endpoint.toString()), - createDatabaseAccountLocation("location4", LocationCacheTest.Location4Endpoint.toString())), - - // write endpoints - ImmutableList.of( - createDatabaseAccountLocation("location1", LocationCacheTest.Location1Endpoint.toString()), - createDatabaseAccountLocation("location2", LocationCacheTest.Location2Endpoint.toString()), - createDatabaseAccountLocation("location3", LocationCacheTest.Location3Endpoint.toString())), - // if the account supports multi master multi muster - useMultipleWriteLocations); - - return databaseAccount; - } - - private void initialize( - boolean useMultipleWriteLocations, - boolean enableEndpointDiscovery, - boolean isPreferredLocationsListEmpty) throws Exception { - - this.mockedClient = new DatabaseAccountManagerInternalMock(); - this.databaseAccount = LocationCacheTest.createDatabaseAccount(useMultipleWriteLocations); - - this.preferredLocations = isPreferredLocationsListEmpty ? - new UnmodifiableList<>(Collections.emptyList()) : - new UnmodifiableList<>(ImmutableList.of("location1", "location2", "location3")); - - this.cache = new LocationCache( - this.preferredLocations, - LocationCacheTest.DefaultEndpoint, - enableEndpointDiscovery, - useMultipleWriteLocations, - configs); - - this.cache.onDatabaseAccountRead(this.databaseAccount); - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setEnableEndpointDiscovery(enableEndpointDiscovery); - BridgeInternal.setUseMultipleWriteLocations(connectionPolicy, useMultipleWriteLocations); - connectionPolicy.setPreferredLocations(this.preferredLocations); - - this.endpointManager = new GlobalEndpointManager(mockedClient, connectionPolicy, configs); - } - - class DatabaseAccountManagerInternalMock implements DatabaseAccountManagerInternal { - private final AtomicInteger counter = new AtomicInteger(0); - - private void reset() { - counter.set(0); - } - - private int getInvocationCounter() { - return counter.get(); - } - - @Override - public Observable getDatabaseAccountFromEndpoint(URI endpoint) { - return Observable.just(LocationCacheTest.this.databaseAccount); - } - - @Override - public ConnectionPolicy getConnectionPolicy() { - throw new RuntimeException("not supported"); - } - - @Override - public URI getServiceEndpoint() { - try { - return LocationCacheTest.DefaultEndpoint.toURI(); - } catch (Exception e) { - throw new RuntimeException(); - } - } - } - - private static Stream toStream(Iterable iterable) { - return StreamSupport.stream(iterable.spliterator(), false); - } - - private void validateLocationCacheAsync( - boolean useMultipleWriteLocations, - boolean endpointDiscoveryEnabled, - boolean isPreferredListEmpty) throws Exception { - for (int writeLocationIndex = 0; writeLocationIndex < 3; writeLocationIndex++) { - for (int readLocationIndex = 0; readLocationIndex < 2; readLocationIndex++) { - this.initialize( - useMultipleWriteLocations, - endpointDiscoveryEnabled, - isPreferredListEmpty); - - UnmodifiableList currentWriteEndpoints = this.cache.getWriteEndpoints(); - UnmodifiableList currentReadEndpoints = this.cache.getReadEndpoints(); - for (int i = 0; i < readLocationIndex; i++) { - this.cache.markEndpointUnavailableForRead(createUrl(Iterables.get(this.databaseAccount.getReadableLocations(), i).getEndpoint())); - this.endpointManager.markEndpointUnavailableForRead(createUrl(Iterables.get(this.databaseAccount.getReadableLocations(), i).getEndpoint()));; - } - for (int i = 0; i < writeLocationIndex; i++) { - this.cache.markEndpointUnavailableForWrite(createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), i).getEndpoint())); - this.endpointManager.markEndpointUnavailableForWrite(createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), i).getEndpoint())); - } - - Map writeEndpointByLocation = toStream(this.databaseAccount.getWritableLocations()) - .collect(Collectors.toMap(i -> i.getName(), i -> createUrl(i.getEndpoint()))); - - Map readEndpointByLocation = toStream(this.databaseAccount.getReadableLocations()) - .collect(Collectors.toMap(i -> i.getName(), i -> createUrl(i.getEndpoint()))); - - URL[] preferredAvailableWriteEndpoints = toStream(this.preferredLocations).skip(writeLocationIndex) - .filter(location -> writeEndpointByLocation.containsKey(location)) - .map(location -> writeEndpointByLocation.get(location)) - .collect(Collectors.toList()).toArray(new URL[0]); - - URL[] preferredAvailableReadEndpoints = toStream(this.preferredLocations).skip(readLocationIndex) - .filter(location -> readEndpointByLocation.containsKey(location)) - .map(location -> readEndpointByLocation.get(location)) - .collect(Collectors.toList()).toArray(new URL[0]); - - this.validateEndpointRefresh( - useMultipleWriteLocations, - endpointDiscoveryEnabled, - preferredAvailableWriteEndpoints, - preferredAvailableReadEndpoints, - writeLocationIndex > 0); - - this.validateGlobalEndpointLocationCacheRefreshAsync(); - - this.validateRequestEndpointResolution( - useMultipleWriteLocations, - endpointDiscoveryEnabled, - preferredAvailableWriteEndpoints, - preferredAvailableReadEndpoints); - - // wait for TTL on unavailability info - - TimeUnit.SECONDS.sleep(configs.getUnavailableLocationsExpirationTimeInSeconds() + 1); - - assertThat(currentWriteEndpoints.toArray()).containsExactly(this.cache.getWriteEndpoints().toArray()); - assertThat(currentReadEndpoints.toArray()).containsExactly(this.cache.getReadEndpoints().toArray()); - } - } - } - - private void validateEndpointRefresh( - boolean useMultipleWriteLocations, - boolean endpointDiscoveryEnabled, - URL[] preferredAvailableWriteEndpoints, - URL[] preferredAvailableReadEndpoints, - boolean isFirstWriteEndpointUnavailable) { - - Utils.ValueHolder canRefreshInBackgroundHolder = new Utils.ValueHolder<>(); - canRefreshInBackgroundHolder.v = false; - - boolean shouldRefreshEndpoints = this.cache.shouldRefreshEndpoints(canRefreshInBackgroundHolder); - - boolean isMostPreferredLocationUnavailableForRead = false; - boolean isMostPreferredLocationUnavailableForWrite = useMultipleWriteLocations ? - false : isFirstWriteEndpointUnavailable; - if (this.preferredLocations.size() > 0) { - String mostPreferredReadLocationName = this.preferredLocations.stream() - .filter(location -> toStream(databaseAccount.getReadableLocations()) - .anyMatch(readLocation -> readLocation.getName().equals(location))) - .findFirst().orElse(null); - - URL mostPreferredReadEndpoint = LocationCacheTest.EndpointByLocation.get(mostPreferredReadLocationName); - isMostPreferredLocationUnavailableForRead = preferredAvailableReadEndpoints.length == 0 ? - true : (!areEqual(preferredAvailableReadEndpoints[0], mostPreferredReadEndpoint)); - - String mostPreferredWriteLocationName = this.preferredLocations.stream() - .filter(location -> toStream(databaseAccount.getWritableLocations()) - .anyMatch(writeLocation -> writeLocation.getName().equals(location))) - .findFirst().orElse(null); - - URL mostPreferredWriteEndpoint = LocationCacheTest.EndpointByLocation.get(mostPreferredWriteLocationName); - - if (useMultipleWriteLocations) { - isMostPreferredLocationUnavailableForWrite = preferredAvailableWriteEndpoints.length == 0 ? - true : (!areEqual(preferredAvailableWriteEndpoints[0], mostPreferredWriteEndpoint)); - } - } - - if (!endpointDiscoveryEnabled) { - assertThat(shouldRefreshEndpoints).isFalse(); - } else { - assertThat(shouldRefreshEndpoints).isEqualTo( - isMostPreferredLocationUnavailableForRead || isMostPreferredLocationUnavailableForWrite); - } - - if (shouldRefreshEndpoints) { - assertThat(canRefreshInBackgroundHolder.v).isTrue(); - } - } - - private boolean areEqual(URL url1, URL url2) { - return url1.equals(url2); - } - - private void validateGlobalEndpointLocationCacheRefreshAsync() throws Exception { - - mockedClient.reset(); - List list = IntStream.range(0, 10) - .mapToObj(index -> this.endpointManager.refreshLocationAsync(null)) - .collect(Collectors.toList()); - - Completable.merge(list).await(); - - assertThat(mockedClient.getInvocationCounter()).isLessThanOrEqualTo(1); - mockedClient.reset(); - - IntStream.range(0, 10) - .mapToObj(index -> this.endpointManager.refreshLocationAsync(null)) - .collect(Collectors.toList()); - for (Completable completable : list) { - completable.await(); - } - - assertThat(mockedClient.getInvocationCounter()).isLessThanOrEqualTo(1); - } - - private void validateRequestEndpointResolution( - boolean useMultipleWriteLocations, - boolean endpointDiscoveryEnabled, - URL[] availableWriteEndpoints, - URL[] availableReadEndpoints) throws MalformedURLException { - URL firstAvailableWriteEndpoint; - URL secondAvailableWriteEndpoint; - - if (!endpointDiscoveryEnabled) { - firstAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; - secondAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; - } else if (!useMultipleWriteLocations) { - firstAvailableWriteEndpoint = createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 0).getEndpoint()); - secondAvailableWriteEndpoint = createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 1).getEndpoint()); - } else if (availableWriteEndpoints.length > 1) { - firstAvailableWriteEndpoint = availableWriteEndpoints[0]; - secondAvailableWriteEndpoint = availableWriteEndpoints[1]; - } else if (availableWriteEndpoints.length > 0) { - firstAvailableWriteEndpoint = availableWriteEndpoints[0]; - Iterator writeLocationsIterator = databaseAccount.getWritableLocations().iterator(); - String writeEndpoint = writeLocationsIterator.next().getEndpoint(); - secondAvailableWriteEndpoint = writeEndpoint != firstAvailableWriteEndpoint.toString() - ? new URL(writeEndpoint) - : new URL(writeLocationsIterator.next().getEndpoint()); - } else { - firstAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; - secondAvailableWriteEndpoint = LocationCacheTest.DefaultEndpoint; - } - - URL firstAvailableReadEndpoint; - - if (!endpointDiscoveryEnabled) { - firstAvailableReadEndpoint = LocationCacheTest.DefaultEndpoint; - } else if (this.preferredLocations.size() == 0) { - firstAvailableReadEndpoint = firstAvailableWriteEndpoint; - } else if (availableReadEndpoints.length > 0) { - firstAvailableReadEndpoint = availableReadEndpoints[0]; - } else { - firstAvailableReadEndpoint = LocationCacheTest.EndpointByLocation.get(this.preferredLocations.get(0)); - } - - URL firstWriteEnpoint = !endpointDiscoveryEnabled ? - LocationCacheTest.DefaultEndpoint : - createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 0).getEndpoint()); - - URL secondWriteEnpoint = !endpointDiscoveryEnabled ? - LocationCacheTest.DefaultEndpoint : - createUrl(Iterables.get(this.databaseAccount.getWritableLocations(), 1).getEndpoint()); - - // If current write endpoint is unavailable, write endpoints order doesn't change - // All write requests flip-flop between current write and alternate write endpoint - UnmodifiableList writeEndpoints = this.cache.getWriteEndpoints(); - - assertThat(firstAvailableWriteEndpoint).isEqualTo(writeEndpoints.get(0)); - assertThat(secondAvailableWriteEndpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, true)); - assertThat(firstAvailableWriteEndpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Document, false)); - - // Writes to other resource types should be directed to first/second write endpoint - assertThat(firstWriteEnpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, false)); - assertThat(secondWriteEnpoint).isEqualTo(this.resolveEndpointForWriteRequest(ResourceType.Database, true)); - - // Reads should be directed to available read endpoints regardless of resource type - assertThat(firstAvailableReadEndpoint).isEqualTo(this.resolveEndpointForReadRequest(true)); - assertThat(firstAvailableReadEndpoint).isEqualTo(this.resolveEndpointForReadRequest(false)); - } - - private URL resolveEndpointForReadRequest(boolean masterResourceType) { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - masterResourceType ? ResourceType.Database : ResourceType.Document); - return this.cache.resolveServiceEndpoint(request); - } - - private URL resolveEndpointForWriteRequest(ResourceType resourceType, boolean useAlternateWriteEndpoint) { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Create, resourceType); - request.requestContext.RouteToLocation(useAlternateWriteEndpoint ? 1 : 0, resourceType.isCollectionChild()); - return this.cache.resolveServiceEndpoint(request); - } - - private RxDocumentServiceRequest CreateRequest(boolean isReadRequest, boolean isMasterResourceType) - { - if (isReadRequest) { - return RxDocumentServiceRequest.create(OperationType.Read, isMasterResourceType ? ResourceType.Database : ResourceType.Document); - } else { - return RxDocumentServiceRequest.create(OperationType.Create, isMasterResourceType ? ResourceType.Database : ResourceType.Document); - } - } - private static URL createUrl(String url) { - try { - return new URL(url); - } catch (MalformedURLException e) { - throw new IllegalArgumentException(e); - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProviderHelperTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProviderHelperTest.java deleted file mode 100644 index c0b105b5b6bb..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/internal/routing/RoutingMapProviderHelperTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.routing; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.PartitionKeyRange; - -public class RoutingMapProviderHelperTest { - private static final MockRoutingMapProvider ROUTING_MAP_PROVIDER = new MockRoutingMapProvider( - Arrays.asList(new PartitionKeyRange("0", "", "000A"), new PartitionKeyRange("1", "000A", "000D"), - new PartitionKeyRange("2", "000D", "0012"), new PartitionKeyRange("3", "0012", "0015"), - new PartitionKeyRange("4", "0015", "0020"), new PartitionKeyRange("5", "0020", "0040"), - new PartitionKeyRange("6", "0040", "FF"))); - - private static class MockRoutingMapProvider implements RoutingMapProvider { - private final CollectionRoutingMap routingMap; - - public MockRoutingMapProvider(Collection ranges) { - List> pairs = new ArrayList<>( - ranges.size()); - for (PartitionKeyRange range : ranges) { - pairs.add(new ImmutablePair<>(range, null)); - } - - this.routingMap = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap(pairs, StringUtils.EMPTY); - } - - @Override - public Collection getOverlappingRanges(String collectionIdOrNameBasedLink, - Range range, boolean forceRefresh) { - return this.routingMap.getOverlappingRanges(range); - } - - @Override - public PartitionKeyRange tryGetRangeByEffectivePartitionKey(String collectionRid, String effectivePartitionKey) { - return null; - } - - @Override - public PartitionKeyRange getPartitionKeyRangeById(String collectionLink, String partitionKeyRangeId, boolean forceRefresh) { - return null; - } - } - - @Test(groups = { "unit" }, expectedExceptions = IllegalArgumentException.class) - public void nonSortedRanges() { - RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Arrays.asList(new Range("0B", "0B", true, true), new Range("0A", "0A", true, true))); - } - - @Test(groups = { "unit" }, expectedExceptions = IllegalArgumentException.class) - public void overlappingRanges1() { - RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Arrays.asList(new Range("0A", "0D", true, true), new Range("0B", "0E", true, true))); - } - - @Test(groups = { "unit" }, expectedExceptions = IllegalArgumentException.class) - public void overlappingRanges2() { - RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Arrays.asList(new Range("0A", "0D", true, true), new Range("0D", "0E", true, true))); - } - - @Test(groups = { "unit" }) - public void getOverlappingRanges() { - Collection ranges = RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, - "dbs/db1/colls/coll1", - Arrays.asList(new Range("000B", "000E", true, false), - new Range("000E", "000F", true, false), new Range("000F", "0010", true, true), - new Range("0015", "0015", true, true))); - - Function func = new Function() { - @Override - public String apply(PartitionKeyRange range) { - return range.getId(); - } - }; - - assertThat("1,2,4").isEqualTo(ranges.stream().map(func).collect(Collectors.joining(","))); - - // query for minimal point - ranges = RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Collections.singletonList(new Range("", "", true, true))); - - assertThat("0").isEqualTo(ranges.stream().map(func).collect(Collectors.joining(","))); - - // query for empty range - ranges = RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Collections.singletonList(new Range("", "", true, false))); - - assertThat(0).isEqualTo(ranges.size()); - - // entire range - ranges = RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Collections.singletonList(new Range("", "FF", true, false))); - - assertThat("0,1,2,3,4,5,6").isEqualTo(ranges.stream().map(func).collect(Collectors.joining(","))); - - // matching range - ranges = RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Collections.singletonList(new Range("0012", "0015", true, false))); - - assertThat("3").isEqualTo(ranges.stream().map(func).collect(Collectors.joining(","))); - - // matching range with empty ranges - ranges = RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Arrays.asList(new Range("", "", true, false), new Range("0012", "0015", true, false))); - - assertThat("3").isEqualTo(ranges.stream().map(func).collect(Collectors.joining(","))); - - // matching range and a little bit more. - ranges = RoutingMapProviderHelper.getOverlappingRanges(ROUTING_MAP_PROVIDER, "dbs/db1/colls/coll1", - Collections.singletonList(new Range("0012", "0015", false, true))); - - assertThat("3,4").isEqualTo(ranges.stream().map(func).collect(Collectors.joining(","))); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ClientRetryPolicyTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ClientRetryPolicyTest.java deleted file mode 100644 index b6c6157fb9af..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ClientRetryPolicyTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.RetryOptions; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import io.netty.handler.timeout.ReadTimeoutException; -import org.mockito.Mockito; -import org.testng.annotations.Test; -import rx.Completable; -import rx.Single; -import rx.observers.TestSubscriber; - -import java.net.URL; -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -public class ClientRetryPolicyTest { - private final static int TIMEOUT = 10000; - - @Test(groups = "unit") - public void networkFailureOnRead() throws Exception { - RetryOptions retryOptions = new RetryOptions(); - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(new URL("http://localhost")).when(endpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null)); - ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(endpointManager, true, retryOptions); - - Exception exception = ReadTimeoutException.INSTANCE; - - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - - clientRetryPolicy.onBeforeSendRequest(dsr); - - for (int i = 0; i < 10; i++) { - Single shouldRetry = clientRetryPolicy.shouldRetry(exception); - - validateSuccess(shouldRetry, ShouldRetryValidator.builder() - .nullException() - .shouldRetry(true) - .backOfTime(Duration.ofMillis(ClientRetryPolicy.RetryIntervalInMS)) - .build()); - - Mockito.verify(endpointManager, Mockito.times(i + 1)).markEndpointUnavailableForRead(Mockito.any()); - Mockito.verify(endpointManager, Mockito.times(0)).markEndpointUnavailableForWrite(Mockito.any()); - } - } - - @Test(groups = "unit") - public void networkFailureOnWrite() throws Exception { - RetryOptions retryOptions = new RetryOptions(); - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(new URL("http://localhost")).when(endpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null)); - ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(endpointManager, true, retryOptions); - - Exception exception = ReadTimeoutException.INSTANCE; - - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - - clientRetryPolicy.onBeforeSendRequest(dsr); - for (int i = 0; i < 10; i++) { - Single shouldRetry = clientRetryPolicy.shouldRetry(exception); - validateSuccess(shouldRetry, ShouldRetryValidator.builder() - .nullException() - .shouldRetry(true) - .backOfTime(i > 0 ? Duration.ofMillis(ClientRetryPolicy.RetryIntervalInMS) : Duration.ZERO) - .build()); - - Mockito.verify(endpointManager, Mockito.times(0)).markEndpointUnavailableForRead(Mockito.any()); - Mockito.verify(endpointManager, Mockito.times(i + 1)).markEndpointUnavailableForWrite(Mockito.any()); - } - } - - @Test(groups = "unit") - public void onBeforeSendRequestNotInvoked() { - RetryOptions retryOptions = new RetryOptions(); - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - - Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null)); - ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(endpointManager, true, retryOptions); - - Exception exception = ReadTimeoutException.INSTANCE; - - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - - Single shouldRetry = clientRetryPolicy.shouldRetry(exception); - validateSuccess(shouldRetry, ShouldRetryValidator.builder() - .withException(exception) - .shouldRetry(false) - .build()); - - Mockito.verifyZeroInteractions(endpointManager); - } - - public static void validateSuccess(Single single, - ShouldRetryValidator validator) { - - validateSuccess(single, validator, TIMEOUT); - } - - public static void validateSuccess(Single single, - ShouldRetryValidator validator, - long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - single.toObservable().subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertCompleted(); - testSubscriber.assertNoErrors(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConfigsTests.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConfigsTests.java deleted file mode 100644 index 5ff8c28e33b0..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConfigsTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import static org.assertj.core.api.Assertions.assertThat; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.annotations.Test; - -public class ConfigsTests { - - @Test(groups = { "unit" }) - public void maxHttpHeaderSize() { - Configs config = new Configs(); - assertThat(config.getMaxHttpHeaderSize()).isEqualTo(32 * 1024); - } - - @Test(groups = { "unit" }) - public void maxHttpBodyLength() { - Configs config = new Configs(); - assertThat(config.getMaxHttpBodyLength()).isEqualTo(6 * 1024 * 1024); - } - - @Test(groups = { "unit" }) - public void getProtocol() { - Configs config = new Configs(); - assertThat(config.getProtocol()).isEqualTo(Protocol.valueOf(System.getProperty("COSMOS.PROTOCOL", "Https"))); - } - - @Test(groups = { "unit" }) - public void getDirectHttpsMaxConnectionLimit() { - Configs config = new Configs(); - assertThat(config.getDirectHttpsMaxConnectionLimit()).isEqualTo(Runtime.getRuntime().availableProcessors() * 500); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RenameCollectionAwareClientRetryPolicyTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RenameCollectionAwareClientRetryPolicyTest.java deleted file mode 100644 index bfb362d7b93c..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RenameCollectionAwareClientRetryPolicyTest.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxClientCollectionCache; -import io.netty.handler.timeout.ReadTimeoutException; -import org.mockito.Mockito; -import org.testng.annotations.Test; -import rx.Completable; -import rx.Single; - -import static com.microsoft.azure.cosmosdb.rx.internal.ClientRetryPolicyTest.validateSuccess; -import static org.assertj.core.api.Assertions.assertThat; - -public class RenameCollectionAwareClientRetryPolicyTest { - - private final static int TIMEOUT = 10000; - - @Test(groups = "unit", timeOut = TIMEOUT) - public void onBeforeSendRequestNotInvoked() { - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null)); - - IRetryPolicyFactory retryPolicyFactory = new RetryPolicy(endpointManager, ConnectionPolicy.GetDefault()); - RxClientCollectionCache rxClientCollectionCache = Mockito.mock(RxClientCollectionCache.class); - - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - RenameCollectionAwareClientRetryPolicy renameCollectionAwareClientRetryPolicy = new RenameCollectionAwareClientRetryPolicy(sessionContainer - , rxClientCollectionCache - , retryPolicyFactory.getRequestPolicy()); - - Exception exception = ReadTimeoutException.INSTANCE; - - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - - Single shouldRetry = renameCollectionAwareClientRetryPolicy.shouldRetry(exception); - validateSuccess(shouldRetry, ShouldRetryValidator.builder() - .withException(exception) - .shouldRetry(false) - .build()); - - Mockito.verifyZeroInteractions(endpointManager); - } - - @Test(groups = "unit", timeOut = TIMEOUT) - public void shouldRetryWithNotFoundStatusCode() { - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null)); - IRetryPolicyFactory retryPolicyFactory = new RetryPolicy(endpointManager, ConnectionPolicy.GetDefault()); - RxClientCollectionCache rxClientCollectionCache = Mockito.mock(RxClientCollectionCache.class); - - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - RenameCollectionAwareClientRetryPolicy renameCollectionAwareClientRetryPolicy = new RenameCollectionAwareClientRetryPolicy(sessionContainer - , rxClientCollectionCache - , retryPolicyFactory.getRequestPolicy()); - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - request.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - renameCollectionAwareClientRetryPolicy.onBeforeSendRequest(request); - - NotFoundException notFoundException = new NotFoundException(); - - Single singleShouldRetry = renameCollectionAwareClientRetryPolicy - .shouldRetry(notFoundException); - validateSuccess(singleShouldRetry, ShouldRetryValidator.builder() - .withException(notFoundException) - .shouldRetry(false) - .build()); - } - - @Test(groups = "unit", timeOut = TIMEOUT) - public void shouldRetryWithNotFoundStatusCodeAndReadSessionNotAvailableSubStatusCode() { - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null)); - IRetryPolicyFactory retryPolicyFactory = new RetryPolicy(endpointManager, ConnectionPolicy.GetDefault()); - RxClientCollectionCache rxClientCollectionCache = Mockito.mock(RxClientCollectionCache.class); - - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - RenameCollectionAwareClientRetryPolicy renameCollectionAwareClientRetryPolicy = new RenameCollectionAwareClientRetryPolicy(sessionContainer - , rxClientCollectionCache - , retryPolicyFactory.getRequestPolicy()); - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - request.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - request.requestContext.resolvedCollectionRid = "rid_0"; - renameCollectionAwareClientRetryPolicy.onBeforeSendRequest(request); - - NotFoundException notFoundException = new NotFoundException(); - notFoundException.getResponseHeaders().put(WFConstants.BackendHeaders.SUB_STATUS, - Integer.toString(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE)); - - DocumentCollection documentCollection = new DocumentCollection(); - documentCollection.setResourceId("rid_1"); - - Mockito.when(rxClientCollectionCache.resolveCollectionAsync(request)).thenReturn(Single.just(documentCollection)); - - Single singleShouldRetry = renameCollectionAwareClientRetryPolicy - .shouldRetry(notFoundException); - validateSuccess(singleShouldRetry, ShouldRetryValidator.builder() - .nullException() - .shouldRetry(true) - .build()); - } - - /** - * No retry on bad request exception - */ - @Test(groups = "unit", timeOut = TIMEOUT) - public void shouldRetryWithGenericException() { - GlobalEndpointManager endpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(Completable.complete()).when(endpointManager).refreshLocationAsync(Mockito.eq(null)); - IRetryPolicyFactory retryPolicyFactory = new RetryPolicy(endpointManager, ConnectionPolicy.GetDefault()); - RxClientCollectionCache rxClientCollectionCache = Mockito.mock(RxClientCollectionCache.class); - - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - RenameCollectionAwareClientRetryPolicy renameCollectionAwareClientRetryPolicy = new RenameCollectionAwareClientRetryPolicy(sessionContainer - , rxClientCollectionCache - , retryPolicyFactory.getRequestPolicy()); - RxDocumentServiceRequest request = RxDocumentServiceRequest.createFromName( - OperationType.Create, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - request.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - renameCollectionAwareClientRetryPolicy.onBeforeSendRequest(request); - - Single singleShouldRetry = renameCollectionAwareClientRetryPolicy - .shouldRetry(new BadRequestException()); - IRetryPolicy.ShouldRetryResult shouldRetryResult = singleShouldRetry.toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isFalse(); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RxGatewayStoreModelTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RxGatewayStoreModelTest.java deleted file mode 100644 index e4a550513010..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RxGatewayStoreModelTest.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.QueryCompatibilityMode; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import io.netty.buffer.ByteBuf; -import io.netty.handler.timeout.ReadTimeoutException; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import org.mockito.Mockito; -import org.testng.annotations.Test; -import rx.Observable; -import rx.observers.TestSubscriber; - -import java.net.URL; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; - -public class RxGatewayStoreModelTest { - private final static int TIMEOUT = 10000; - - @Test(groups = "unit") - public void readTimeout() throws Exception { - ISessionContainer sessionContainer = Mockito.mock(ISessionContainer.class); - QueryCompatibilityMode queryCompatibilityMode = QueryCompatibilityMode.Default; - UserAgentContainer userAgentContainer = new UserAgentContainer(); - GlobalEndpointManager globalEndpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(new URL("https://localhost")) - .when(globalEndpointManager).resolveServiceEndpoint(Mockito.any()); - CompositeHttpClient httpClient = Mockito.mock(CompositeHttpClient.class); - Mockito.doReturn(Observable.error(ReadTimeoutException.INSTANCE)) - .when(httpClient).submit(Mockito.any(RxClient.ServerInfo.class), Mockito.any(HttpClientRequest.class)); - - RxGatewayStoreModel storeModel = new RxGatewayStoreModel( - sessionContainer, - ConsistencyLevel.Session, - queryCompatibilityMode, - userAgentContainer, - globalEndpointManager, - httpClient); - - RxDocumentServiceRequest dsr = RxDocumentServiceRequest.createFromName( - OperationType.Read, "/dbs/db/colls/col/docs/docId", ResourceType.Document); - dsr.getHeaders().put("key", "value"); - dsr.requestContext = Mockito.mock(DocumentServiceRequestContext.class); - - Observable resp = storeModel.processMessage(dsr); - validateFailure(resp, FailureValidator.builder() - .instanceOf(DocumentClientException.class) - .causeInstanceOf(ReadTimeoutException.class) - .documentClientExceptionHeaderRequestContainsEntry("key", "value") - .statusCode(0).build()); - } - - public void validateFailure(Observable observable, - FailureValidator validator) { - validateFailure(observable, validator, TIMEOUT); - } - - public static void validateFailure(Observable observable, - FailureValidator validator, - long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ShouldRetryValidator.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ShouldRetryValidator.java deleted file mode 100644 index 1701c371dbf2..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ShouldRetryValidator.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.rx.FailureValidator; - -import java.time.Duration; -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This is a helper class for validating a partition address for tests. - */ -public interface ShouldRetryValidator { - - void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult); - - static Builder builder() { - return new Builder(); - } - - class Builder { - private List validators = new ArrayList<>(); - - public ShouldRetryValidator build() { - return new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - for (ShouldRetryValidator validator : validators) { - validator.validate(shouldRetryResult); - } - } - }; - } - - public Builder nullException() { - validators.add(new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - assertThat(shouldRetryResult.exception).isNull(); - } - }); - return this; - } - - public Builder hasException() { - validators.add(new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - assertThat(shouldRetryResult.exception).isNotNull(); - } - }); - return this; - } - - public Builder exceptionOfType(Class klass) { - validators.add(new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - assertThat(shouldRetryResult.exception).isNotNull(); - assertThat(shouldRetryResult.exception).isInstanceOf(klass); - } - }); - return this; - } - - public Builder withException(FailureValidator failureValidator) { - validators.add(new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - assertThat(shouldRetryResult.exception).isNotNull(); - failureValidator.validate(shouldRetryResult.exception); - } - }); - return this; - } - - public Builder withException(Exception exception) { - validators.add(new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - assertThat(shouldRetryResult.exception).isNotNull(); - assertThat(shouldRetryResult.exception).isEqualTo(exception); - } - }); - return this; - } - - public Builder shouldRetry(boolean value) { - validators.add(new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - assertThat(shouldRetryResult.shouldRetry).isEqualTo(value); - } - }); - return this; - } - - - public Builder backOfTime(Duration backOfTime) { - validators.add(new ShouldRetryValidator() { - - @Override - public void validate(IRetryPolicy.ShouldRetryResult shouldRetryResult) { - assertThat(shouldRetryResult.backOffTime).isEqualTo(backOfTime); - } - }); - return this; - } - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncCacheTest.java b/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncCacheTest.java deleted file mode 100644 index b6992f3b97b7..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/caches/AsyncCacheTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -import org.testng.annotations.Test; - -import rx.Observable; -import rx.Single; -import rx.functions.Func1; - -public class AsyncCacheTest { - - private static final int TIMEOUT = 2000; - - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void getAsync() { - AtomicInteger numberOfCacheRefreshes = new AtomicInteger(0); - final Func1> refreshFunc = key -> { - numberOfCacheRefreshes.incrementAndGet(); - return Single.just(key*2); - }; - - AsyncCache cache = new AsyncCache<>(); - - List> tasks = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - int key = j; - tasks.add(cache.getAsync(key, -1, () -> refreshFunc.call(key))); - } - } - - Observable o = Observable.merge(tasks.stream().map(s -> s.toObservable()).collect(Collectors.toList())); - o.toList().toSingle().toBlocking().value(); - - assertThat(numberOfCacheRefreshes.get()).isEqualTo(10); - assertThat(cache.getAsync(2, -1, () -> refreshFunc.call(2)).toBlocking().value()).isEqualTo(4); - - Func1> refreshFunc1 = key -> { - numberOfCacheRefreshes.incrementAndGet(); - return Single.just(key * 2 + 1); - }; - - List> tasks1 = new ArrayList<>(); - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10; j++) { - int key = j; - tasks1.add(cache.getAsync(key, key * 2, () -> refreshFunc1.call(key))); - } - - for (int j = 0; j < 10; j++) { - int key = j; - tasks1.add(cache.getAsync(key, key * 2 , () -> refreshFunc1.call(key))); - } - } - - Observable o1 = Observable.merge(tasks1.stream().map(s -> s.toObservable()).collect(Collectors.toList())); - o1.toList().toSingle().toBlocking().value(); - - assertThat(numberOfCacheRefreshes.get()).isEqualTo(20); - assertThat(cache.getAsync(2, -1, () -> refreshFunc.call(2)).toBlocking().value()).isEqualTo(5); - } -} diff --git a/cosmosdb/data-plane/gateway/src/test/resources/log4j.properties b/cosmosdb/data-plane/gateway/src/test/resources/log4j.properties deleted file mode 100644 index 1f3287c67a55..000000000000 --- a/cosmosdb/data-plane/gateway/src/test/resources/log4j.properties +++ /dev/null @@ -1,15 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -# Set HTTP components' logger to INFO - -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p %c - %m%n diff --git a/cosmosdb/data-plane/pom.xml b/cosmosdb/data-plane/pom.xml deleted file mode 100644 index e9d43250857f..000000000000 --- a/cosmosdb/data-plane/pom.xml +++ /dev/null @@ -1,370 +0,0 @@ - - - 4.0.0 - com.microsoft.azure - azure-cosmosdb-parent - 2.4.5 - pom - Azure Cosmos DB SQL API - Java Async SDK (with Reactive Extension RX support) for Azure Cosmos DB SQL API - https://docs.microsoft.com/en-us/azure/cosmos-db - - commons - gateway - examples - benchmark - commons-test-utils - sdk - direct-impl - - - UTF-8 - UTF-8 - 2.5 - 3.8.1 - 1.6 - 1.6 - 27.0.1-jre - 2.9.9 - 3.1.4 - 1.7.6 - 1.2.17 - 4.0.5 - 1.10.19 - 4.1.32.Final - 0.4.20 - 1.3.8 - 0.8.0.17 - 1.1.1 - 6.14.3 - 3.11.1 - 1.10.19 - 27.0.1-jre - 1.6 - unit - 2.4.5 - - - - - - unit - - default - unit - - - true - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - - - - - - - fast - - simple - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - long - - long - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - direct - - direct - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - multi-master - - multi-master - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - examples - - - samples,examples - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - integration-test - verify - - - - - - - - - - emulator - - emulator - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - non-emulator - - non-emulator - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.0 - - unit - - %regex[.*] - - - - surefire.testng.verbose - 2 - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.22.0 - - - %regex[.*] - - - - surefire.testng.verbose - 2 - - - ${test.groups} - - - - - integration-test - verify - - - - - - - - - maven-javadoc-plugin - 3.0.1 - true - - true - false - ${javadoc.opts} - - **/internal/**/*.java - - - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.22.0 - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - org.apache.maven.plugins - maven-jxr-plugin - 2.1 - - - - - - - com.microsoft.azure - azure-cosmosdb - ${project.parent.version} - - - com.microsoft.azure - azure-cosmosdb-commons - ${project.parent.version} - - - com.microsoft.azure - azure-cosmosdb-gateway - ${project.parent.version} - - - com.microsoft.azure - azure-cosmosdb-direct - ${cosmosdb-sdk-direct-impl.version} - - - com.microsoft.azure - azure-cosmosdb-commons-test-utils - ${project.parent.version} - - - - - - org.testng - testng - ${testng.version} - test - - - - - MIT License - http://www.opensource.org/licenses/mit-license.php - - - - scm:git:https://github.com/Azure/azure-cosmosdb-java.git - scm:git:https://github.com/Azure/azure-cosmosdb-java.git - https://github.com/Azure/azure-cosmosdb-java.git - - - - Azure Cosmos DB Developer Platform Devs - docdbdevplatdevs@microsoft.com - Microsoft - http://www.microsoft.com/ - - - diff --git a/cosmosdb/data-plane/sdk/pom.xml b/cosmosdb/data-plane/sdk/pom.xml deleted file mode 100644 index fbd7f035378b..000000000000 --- a/cosmosdb/data-plane/sdk/pom.xml +++ /dev/null @@ -1,267 +0,0 @@ - - - 4.0.0 - - com.microsoft.azure - azure-cosmosdb-parent - 2.4.5 - - azure-cosmosdb - Async SDK for SQL API of Azure Cosmos DB Service - Java Async SDK (with Reactive Extension rx support) for Azure Cosmos DB SQL API - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8 - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - - - - - fast - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - src/test/resources/fast-testng.xml - - - - - - - - - long - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - src/test/resources/long-testng.xml - - - - - - - - - emulator - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - src/test/resources/emulator-testng.xml - - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.19.1 - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.4 - - - org.apache.maven.plugins - maven-jxr-plugin - 2.1 - - - - - - com.microsoft.azure - azure-cosmosdb-commons - - - com.microsoft.azure - azure-cosmosdb-gateway - - - com.microsoft.azure - azure-cosmosdb-direct - - - com.microsoft.azure - azure-cosmosdb-commons-test-utils - test - - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind.version} - - - com.fasterxml.uuid - java-uuid-generator - ${java-uuid-generator.version} - - - commons-io - commons-io - ${commons-io.version} - - - com.github.davidmoten - rxjava-extras - ${rxjava-extras.version} - - - io.reactivex - rxjava - ${rxjava.version} - - - io.reactivex - rxjava-string - ${rxjava-string.version} - - - io.reactivex - rxnetty - ${rxnetty.version} - - - io.netty - netty-transport-native-epoll - - - - - io.netty - netty-codec-http - ${netty.version} - - - io.netty - netty-handler - ${netty.version} - - - io.netty - netty-transport - ${netty.version} - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.testng - testng - ${testng.version} - test - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.mockito - mockito-all - ${mockito.version} - test - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - test - - - log4j - log4j - ${log4j.version} - test - - - com.google.guava - guava - ${guava.version} - test - - - diff --git a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/AsyncDocumentClient.java b/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/AsyncDocumentClient.java deleted file mode 100644 index 513baf9a1b7c..000000000000 --- a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/AsyncDocumentClient.java +++ /dev/null @@ -1,1519 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; - -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.Conflict; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.MediaOptions; -import com.microsoft.azure.cosmosdb.MediaResponse; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.StoredProcedureResponse; -import com.microsoft.azure.cosmosdb.TokenResolver; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientImpl; - -import rx.Observable; - -/** - * Provides a client-side logical representation of the Azure Cosmos DB - * database service. This async client is used to configure and execute requests - * against the service. - * - *

- * {@link AsyncDocumentClient} async APIs return rxJava's {@code - * Observable}, and so you can use rxJava {@link Observable} functionality. - * The async {@link Observable} based APIs perform the requested operation only after - * subscription. - * - *

- * The service client encapsulates the endpoint and credentials used to access - * the Cosmos DB service. - *

- * To instantiate you can use the {@link Builder} - *

- * {@code
- * ConnectionPolicy connectionPolicy = new ConnectionPolicy();
- * connectionPolicy.setConnectionMode(ConnectionMode.Direct);
- * AsyncDocumentClient client = new AsyncDocumentClient.Builder()
- *         .withServiceEndpoint(serviceEndpoint)
- *         .withMasterKeyOrResourceToken(masterKey)
- *         .withConnectionPolicy(connectionPolicy)
- *         .withConsistencyLevel(ConsistencyLevel.Session)
- *         .build();
- * }
- * 
- */ -public interface AsyncDocumentClient { - - /** - * Helper class to build {@link AsyncDocumentClient} instances - * as logical representation of the Azure Cosmos DB database service. - * - *
-     * {@code
-     * ConnectionPolicy connectionPolicy = new ConnectionPolicy();
-     * connectionPolicy.setConnectionMode(ConnectionMode.Direct);
-     * AsyncDocumentClient client = new AsyncDocumentClient.Builder()
-     *         .withServiceEndpoint(serviceEndpoint)
-     *         .withMasterKeyOrResourceToken(masterKey)
-     *         .withConnectionPolicy(connectionPolicy)
-     *         .withConsistencyLevel(ConsistencyLevel.Session)
-     *         .build();
-     * }
-     * 
- */ - class Builder { - - Configs configs = new Configs(); - ConnectionPolicy connectionPolicy; - ConsistencyLevel desiredConsistencyLevel; - List permissionFeed; - String masterKeyOrResourceToken; - URI serviceEndpoint; - TokenResolver tokenResolver; - - public Builder withServiceEndpoint(String serviceEndpoint) { - try { - this.serviceEndpoint = new URI(serviceEndpoint); - } catch (URISyntaxException e) { - throw new IllegalArgumentException(e.getMessage()); - } - return this; - } - - /** - * New method withMasterKeyOrResourceToken will take either master key or resource token - * and perform authentication for accessing resource. - * - * @param masterKeyOrResourceToken MasterKey or resourceToken for authentication. - * @return current Builder. - * @deprecated use {@link #withMasterKeyOrResourceToken(String)} instead. - */ - @Deprecated - public Builder withMasterKey(String masterKeyOrResourceToken) { - this.masterKeyOrResourceToken = masterKeyOrResourceToken; - return this; - } - - /** - * This method will accept the master key , additionally it can also consume - * resource token too for authentication. - * - * @param masterKeyOrResourceToken MasterKey or resourceToken for authentication. - * @return current Builder. - */ - public Builder withMasterKeyOrResourceToken(String masterKeyOrResourceToken) { - this.masterKeyOrResourceToken = masterKeyOrResourceToken; - return this; - } - - /** - * This method will accept the permission list , which contains the - * resource tokens needed to access resources. - * - * @param permissionFeed Permission list for authentication. - * @return current Builder. - */ - public Builder withPermissionFeed(List permissionFeed) { - this.permissionFeed = permissionFeed; - return this; - } - - public Builder withConsistencyLevel(ConsistencyLevel desiredConsistencyLevel) { - this.desiredConsistencyLevel = desiredConsistencyLevel; - return this; - } - - public Builder withConfigs(Configs configs) { - this.configs = configs; - return this; - } - - public Builder withConnectionPolicy(ConnectionPolicy connectionPolicy) { - this.connectionPolicy = connectionPolicy; - return this; - } - - /** - * This method will accept tokenResolver which is rx function, it takes arguments
- * T1 requestVerb(String),
- * T2 resourceIdOrFullName(String),
- * T3 resourceType(com.microsoft.azure.cosmosdb.internal.ResourceType),
- * T4 request headers(Map)
- *
- * and return
- * R authenticationToken(String)
- * - * @param tokenResolver tokenResolver function for authentication. - * @return current Builder. - */ - /*public Builder withTokenResolver(Func4, String> tokenResolver) { - this.tokenResolver = tokenResolver; - return this; - }*/ - - /** - * This method will accept functional interface TokenResolver which helps in generation authorization - * token per request. AsyncDocumentClient can be successfully initialized with this API without passing any MasterKey, ResourceToken or PermissionFeed. - * @param tokenResolver The tokenResolver - * @return current Builder. - */ - public Builder withTokenResolver(TokenResolver tokenResolver) { - this.tokenResolver = tokenResolver; - return this; - } - - private void ifThrowIllegalArgException(boolean value, String error) { - if (value) { - throw new IllegalArgumentException(error); - } - } - - public AsyncDocumentClient build() { - - ifThrowIllegalArgException(this.serviceEndpoint == null, "cannot build client without service endpoint"); - ifThrowIllegalArgException( - this.masterKeyOrResourceToken == null && (permissionFeed == null || permissionFeed.isEmpty()) && this.tokenResolver == null, - "cannot build client without any one of masterKey, resource token, permissionFeed and tokenResolver"); - - RxDocumentClientImpl client = new RxDocumentClientImpl(serviceEndpoint, - masterKeyOrResourceToken, - permissionFeed, - connectionPolicy, - desiredConsistencyLevel, - configs, - tokenResolver); - client.init(); - return client; - } - - public Configs getConfigs() { - return configs; - } - - public void setConfigs(Configs configs) { - this.configs = configs; - } - - public ConnectionPolicy getConnectionPolicy() { - return connectionPolicy; - } - - public void setConnectionPolicy(ConnectionPolicy connectionPolicy) { - this.connectionPolicy = connectionPolicy; - } - - public ConsistencyLevel getDesiredConsistencyLevel() { - return desiredConsistencyLevel; - } - - public void setDesiredConsistencyLevel(ConsistencyLevel desiredConsistencyLevel) { - this.desiredConsistencyLevel = desiredConsistencyLevel; - } - - public List getPermissionFeed() { - return permissionFeed; - } - - public void setPermissionFeed(List permissionFeed) { - this.permissionFeed = permissionFeed; - } - - public String getMasterKeyOrResourceToken() { - return masterKeyOrResourceToken; - } - - public void setMasterKeyOrResourceToken(String masterKeyOrResourceToken) { - this.masterKeyOrResourceToken = masterKeyOrResourceToken; - } - - public URI getServiceEndpoint() { - return serviceEndpoint; - } - - public void setServiceEndpoint(URI serviceEndpoint) { - this.serviceEndpoint = serviceEndpoint; - } - - public TokenResolver getTokenResolver() { - return tokenResolver; - } - - public void setTokenResolver(TokenResolver tokenResolver) { - this.tokenResolver = tokenResolver; - } - } - - /** - * Gets the default service endpoint as passed in by the user during construction. - * - * @return the service endpoint URI - */ - URI getServiceEndpoint(); - - /** - * Gets the current write endpoint chosen based on availability and preference. - * - * @return the write endpoint URI - */ - URI getWriteEndpoint(); - - /** - * Gets the current read endpoint chosen based on availability and preference. - * - * @return the read endpoint URI - */ - URI getReadEndpoint(); - - /** - * Gets the connection policy - * - * @return the connection policy - */ - ConnectionPolicy getConnectionPolicy(); - - /** - * Creates a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created database. - * In case of failure the {@link Observable} will error. - * - * @param database the database. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created database or an error. - */ - Observable> createDatabase(Database database, RequestOptions options); - - /** - * Deletes a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the deleted database. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the deleted database or an error. - */ - Observable> deleteDatabase(String databaseLink, RequestOptions options); - - /** - * Reads a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read database. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read database or an error. - */ - Observable> readDatabase(String databaseLink, RequestOptions options); - - /** - * Reads all databases. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the read databases. - * In case of failure the {@link Observable} will error. - * - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of read databases or an error. - */ - Observable> readDatabases(FeedOptions options); - - /** - * Query for databases. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the read databases. - * In case of failure the {@link Observable} will error. - * - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of read databases or an error. - */ - Observable> queryDatabases(String query, FeedOptions options); - - /** - * Query for databases. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the obtained databases. - * In case of failure the {@link Observable} will error. - * - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained databases or an error. - */ - Observable> queryDatabases(SqlQuerySpec querySpec, FeedOptions options); - - /** - * Creates a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created collection. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param collection the collection. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created collection or an error. - */ - Observable> createCollection(String databaseLink, DocumentCollection collection, - RequestOptions options); - - /** - * Replaces a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced document collection. - * In case of failure the {@link Observable} will error. - * - * @param collection the document collection to use. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced document collection or an error. - */ - Observable> replaceCollection(DocumentCollection collection, RequestOptions options); - - /** - * Deletes a document collection by the collection link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted database. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted database or an error. - */ - Observable> deleteCollection(String collectionLink, RequestOptions options); - - /** - * Reads a document collection by the collection link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read collection. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read collection or an error. - */ - Observable> readCollection(String collectionLink, RequestOptions options); - - /** - * Reads all document collections in a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the read collections. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param options the fee options. - * @return an {@link Observable} containing one or several feed response pages of the read collections or an error. - */ - Observable> readCollections(String databaseLink, FeedOptions options); - - /** - * Query for document collections in a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the obtained collections. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained collections or an error. - */ - Observable> queryCollections(String databaseLink, String query, FeedOptions options); - - /** - * Query for document collections in a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the obtained collections. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained collections or an error. - */ - Observable> queryCollections(String databaseLink, SqlQuerySpec querySpec, FeedOptions options); - - /** - * Creates a document. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created document. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the link to the parent document collection. - * @param document the document represented as a POJO or Document object. - * @param options the request options. - * @param disableAutomaticIdGeneration the flag for disabling automatic id generation. - * @return an {@link Observable} containing the single resource response with the created document or an error. - */ - Observable> createDocument(String collectionLink, Object document, RequestOptions options, - boolean disableAutomaticIdGeneration); - - /** - * Upserts a document. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted document. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the link to the parent document collection. - * @param document the document represented as a POJO or Document object to upsert. - * @param options the request options. - * @param disableAutomaticIdGeneration the flag for disabling automatic id generation. - * @return an {@link Observable} containing the single resource response with the upserted document or an error. - */ - Observable> upsertDocument(String collectionLink, Object document, RequestOptions options, - boolean disableAutomaticIdGeneration); - - /** - * Replaces a document using a POJO object. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced document. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param document the document represented as a POJO or Document object. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced document or an error. - */ - Observable> replaceDocument(String documentLink, Object document, RequestOptions options); - - /** - * Replaces a document with the passed in document. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced document. - * In case of failure the {@link Observable} will error. - * - * @param document the document to replace (containing the document id). - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced document or an error. - */ - Observable> replaceDocument(Document document, RequestOptions options); - - /** - * Deletes a document by the document link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted document. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted document or an error. - */ - Observable> deleteDocument(String documentLink, RequestOptions options); - - /** - * Reads a document by the document link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read document. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read document or an error. - */ - Observable> readDocument(String documentLink, RequestOptions options); - - /** - * Reads all documents in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the read documents. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read documents or an error. - */ - Observable> readDocuments(String collectionLink, FeedOptions options); - - - /** - * Query for documents in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the obtained documents. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the link to the parent document collection. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained document or an error. - */ - Observable> queryDocuments(String collectionLink, String query, FeedOptions options); - - /** - * Query for documents in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response of the obtained documents. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the link to the parent document collection. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained documents or an error. - */ - Observable> queryDocuments(String collectionLink, SqlQuerySpec querySpec, FeedOptions options); - - /** - * Query for documents change feed in a document collection. - * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained documents. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the link to the parent document collection. - * @param changeFeedOptions the change feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained documents or an error. - */ - Observable> queryDocumentChangeFeed(String collectionLink, - ChangeFeedOptions changeFeedOptions); - - /** - * Reads all partition key ranges in a document collection. - * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained partition key ranges. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the link to the parent document collection. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained partition key ranges or an error. - */ - Observable> readPartitionKeyRanges(String collectionLink, FeedOptions options); - - /** - * Creates a stored procedure. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created stored procedure. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param storedProcedure the stored procedure to create. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created stored procedure or an error. - */ - Observable> createStoredProcedure(String collectionLink, StoredProcedure storedProcedure, - RequestOptions options); - - /** - * Upserts a stored procedure. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted stored procedure. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param storedProcedure the stored procedure to upsert. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the upserted stored procedure or an error. - */ - Observable> upsertStoredProcedure(String collectionLink, StoredProcedure storedProcedure, - RequestOptions options); - - /** - * Replaces a stored procedure. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced stored procedure. - * In case of failure the {@link Observable} will error. - * - * @param storedProcedure the stored procedure to use. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced stored procedure or an error. - */ - Observable> replaceStoredProcedure(StoredProcedure storedProcedure, RequestOptions options); - - /** - * Deletes a stored procedure by the stored procedure link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted stored procedure. - * In case of failure the {@link Observable} will error. - * - * @param storedProcedureLink the stored procedure link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted stored procedure or an error. - */ - Observable> deleteStoredProcedure(String storedProcedureLink, RequestOptions options); - - /** - * Read a stored procedure by the stored procedure link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read stored procedure. - * In case of failure the {@link Observable} will error. - * - * @param storedProcedureLink the stored procedure link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read stored procedure or an error. - */ - Observable> readStoredProcedure(String storedProcedureLink, RequestOptions options); - - /** - * Reads all stored procedures in a document collection link. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read stored procedures. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read stored procedures or an error. - */ - Observable> readStoredProcedures(String collectionLink, FeedOptions options); - - /** - * Query for stored procedures in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained stored procedures. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained stored procedures or an error. - */ - Observable> queryStoredProcedures(String collectionLink, String query, FeedOptions options); - - /** - * Query for stored procedures in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained stored procedures. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained stored procedures or an error. - */ - Observable> queryStoredProcedures(String collectionLink, SqlQuerySpec querySpec, - FeedOptions options); - - /** - * Executes a stored procedure by the stored procedure link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the stored procedure response. - * In case of failure the {@link Observable} will error. - * - * @param storedProcedureLink the stored procedure link. - * @param procedureParams the array of procedure parameter values. - * @return an {@link Observable} containing the single resource response with the stored procedure response or an error. - */ - Observable executeStoredProcedure(String storedProcedureLink, Object[] procedureParams); - - /** - * Executes a stored procedure by the stored procedure link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the stored procedure response. - * In case of failure the {@link Observable} will error. - * - * @param storedProcedureLink the stored procedure link. - * @param options the request options. - * @param procedureParams the array of procedure parameter values. - * @return an {@link Observable} containing the single resource response with the stored procedure response or an error. - */ - Observable executeStoredProcedure(String storedProcedureLink, RequestOptions options, - Object[] procedureParams); - - /** - * Creates a trigger. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created trigger. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param trigger the trigger. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created trigger or an error. - */ - Observable> createTrigger(String collectionLink, Trigger trigger, RequestOptions options); - - /** - * Upserts a trigger. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted trigger. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param trigger the trigger to upsert. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the upserted trigger or an error. - */ - Observable> upsertTrigger(String collectionLink, Trigger trigger, RequestOptions options); - - /** - * Replaces a trigger. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced trigger. - * In case of failure the {@link Observable} will error. - * - * @param trigger the trigger to use. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced trigger or an error. - */ - Observable> replaceTrigger(Trigger trigger, RequestOptions options); - - /** - * Deletes a trigger. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted trigger. - * In case of failure the {@link Observable} will error. - * - * @param triggerLink the trigger link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted trigger or an error. - */ - Observable> deleteTrigger(String triggerLink, RequestOptions options); - - /** - * Reads a trigger by the trigger link. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the read trigger. - * In case of failure the {@link Observable} will error. - * - * @param triggerLink the trigger link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the read trigger or an error. - */ - Observable> readTrigger(String triggerLink, RequestOptions options); - - /** - * Reads all triggers in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read triggers. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read triggers or an error. - */ - Observable> readTriggers(String collectionLink, FeedOptions options); - - /** - * Query for triggers. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained triggers. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained triggers or an error. - */ - Observable> queryTriggers(String collectionLink, String query, FeedOptions options); - - /** - * Query for triggers. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained triggers. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained triggers or an error. - */ - Observable> queryTriggers(String collectionLink, SqlQuerySpec querySpec, FeedOptions options); - - /** - * Creates a user defined function. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created user defined function. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param udf the user defined function. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created user defined function or an error. - */ - Observable> createUserDefinedFunction(String collectionLink, UserDefinedFunction udf, - RequestOptions options); - - /** - * Upserts a user defined function. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted user defined function. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param udf the user defined function to upsert. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the upserted user defined function or an error. - */ - Observable> upsertUserDefinedFunction(String collectionLink, UserDefinedFunction udf, - RequestOptions options); - - /** - * Replaces a user defined function. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced user defined function. - * In case of failure the {@link Observable} will error. - * - * @param udf the user defined function. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced user defined function or an error. - */ - Observable> replaceUserDefinedFunction(UserDefinedFunction udf, RequestOptions options); - - /** - * Deletes a user defined function. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted user defined function. - * In case of failure the {@link Observable} will error. - * - * @param udfLink the user defined function link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted user defined function or an error. - */ - Observable> deleteUserDefinedFunction(String udfLink, RequestOptions options); - - /** - * Read a user defined function. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the read user defined function. - * In case of failure the {@link Observable} will error. - * - * @param udfLink the user defined function link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the read user defined function or an error. - */ - Observable> readUserDefinedFunction(String udfLink, RequestOptions options); - - /** - * Reads all user defined functions in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read user defined functions. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read user defined functions or an error. - */ - Observable> readUserDefinedFunctions(String collectionLink, FeedOptions options); - - /** - * Query for user defined functions. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained user defined functions. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained user defined functions or an error. - */ - Observable> queryUserDefinedFunctions(String collectionLink, String query, - FeedOptions options); - - /** - * Query for user defined functions. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained user defined functions. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained user defined functions or an error. - */ - Observable> queryUserDefinedFunctions(String collectionLink, SqlQuerySpec querySpec, - FeedOptions options); - - /** - * Creates an attachment. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created attachment. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param attachment the attachment to create. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created attachment or an error. - */ - Observable> createAttachment(String documentLink, Attachment attachment, RequestOptions options); - - /** - * Upserts an attachment. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted attachment. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param attachment the attachment to upsert. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the upserted attachment or an error. - */ - Observable> upsertAttachment(String documentLink, Attachment attachment, RequestOptions options); - - /** - * Replaces an attachment. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced attachment. - * In case of failure the {@link Observable} will error. - * - * @param attachment the attachment to use. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced attachment or an error. - */ - Observable> replaceAttachment(Attachment attachment, RequestOptions options); - - /** - * Deletes an attachment. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted attachment. - * In case of failure the {@link Observable} will error. - * - * @param attachmentLink the attachment link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted attachment or an error. - */ - Observable> deleteAttachment(String attachmentLink, RequestOptions options); - - /** - * Reads an attachment. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read attachment. - * In case of failure the {@link Observable} will error. - * - * @param attachmentLink the attachment link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read attachment or an error. - */ - Observable> readAttachment(String attachmentLink, RequestOptions options); - - /** - * Reads all attachments in a document. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read attachments. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read attachments or an error. - */ - Observable> readAttachments(String documentLink, FeedOptions options); - - - /** - * Reads a media by the media link. - * - * @param mediaLink the media link. - * @return the media response. - */ - Observable readMedia(String mediaLink); - - /** - * Updates a media by the media link. - * - * @param mediaLink the media link. - * @param mediaStream the media stream to upload. - * @param options the media options. - * @return the media response. - */ - Observable updateMedia(String mediaLink, InputStream mediaStream, MediaOptions options); - - /** - * Query for attachments. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained attachments. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained attachments or an error. - */ - Observable> queryAttachments(String documentLink, String query, FeedOptions options); - - /** - * Query for attachments. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained attachments. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained attachments or an error. - */ - Observable> queryAttachments(String documentLink, SqlQuerySpec querySpec, FeedOptions options); - - /** - * Creates an attachment. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created attachment. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param mediaStream the media stream for creating the attachment. - * @param options the media options. - * @param requestOptions the request options - * @return an {@link Observable} containing the single resource response with the created attachment or an error. - */ - Observable> createAttachment(String documentLink, InputStream mediaStream, MediaOptions options, RequestOptions requestOptions); - - /** - * Upserts an attachment to the media stream - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted attachment. - * In case of failure the {@link Observable} will error. - * - * @param documentLink the document link. - * @param mediaStream the media stream for upserting the attachment. - * @param options the media options. - * @param requestOptions the request options - * @return an {@link Observable} containing the single resource response with the upserted attachment or an error. - */ - Observable> upsertAttachment(String documentLink, InputStream mediaStream, MediaOptions options, RequestOptions requestOptions); - - /** - * Reads a conflict. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read conflict. - * In case of failure the {@link Observable} will error. - * - * @param conflictLink the conflict link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read conflict or an error. - */ - Observable> readConflict(String conflictLink, RequestOptions options); - - /** - * Reads all conflicts in a document collection. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read conflicts. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read conflicts or an error. - */ - Observable> readConflicts(String collectionLink, FeedOptions options); - - /** - * Query for conflicts. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained conflicts. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained conflicts or an error. - */ - Observable> queryConflicts(String collectionLink, String query, FeedOptions options); - - /** - * Query for conflicts. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained conflicts. - * In case of failure the {@link Observable} will error. - * - * @param collectionLink the collection link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained conflicts or an error. - */ - Observable> queryConflicts(String collectionLink, SqlQuerySpec querySpec, FeedOptions options); - - /** - * Deletes a conflict. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted conflict. - * In case of failure the {@link Observable} will error. - * - * @param conflictLink the conflict link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted conflict or an error. - */ - Observable> deleteConflict(String conflictLink, RequestOptions options); - - /** - * Creates a user. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created user. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param user the user to create. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created user or an error. - */ - Observable> createUser(String databaseLink, User user, RequestOptions options); - - /** - * Upserts a user. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted user. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param user the user to upsert. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the upserted user or an error. - */ - Observable> upsertUser(String databaseLink, User user, RequestOptions options); - - /** - * Replaces a user. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced user. - * In case of failure the {@link Observable} will error. - * - * @param user the user to use. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced user or an error. - */ - Observable> replaceUser(User user, RequestOptions options); - - /** - * Deletes a user. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted user. - * In case of failure the {@link Observable} will error. - * - * @param userLink the user link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted user or an error. - */ - Observable> deleteUser(String userLink, RequestOptions options); - - /** - * Reads a user. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read user. - * In case of failure the {@link Observable} will error. - * - * @param userLink the user link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read user or an error. - */ - Observable> readUser(String userLink, RequestOptions options); - - /** - * Reads all users in a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read users. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read users or an error. - */ - Observable> readUsers(String databaseLink, FeedOptions options); - - /** - * Query for users. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained users. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained users or an error. - */ - Observable> queryUsers(String databaseLink, String query, FeedOptions options); - - /** - * Query for users. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained users. - * In case of failure the {@link Observable} will error. - * - * @param databaseLink the database link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained users or an error. - */ - Observable> queryUsers(String databaseLink, SqlQuerySpec querySpec, FeedOptions options); - - /** - * Creates a permission. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the created permission. - * In case of failure the {@link Observable} will error. - * - * @param userLink the user link. - * @param permission the permission to create. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the created permission or an error. - */ - Observable> createPermission(String userLink, Permission permission, RequestOptions options); - - /** - * Upserts a permission. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the upserted permission. - * In case of failure the {@link Observable} will error. - * - * @param userLink the user link. - * @param permission the permission to upsert. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the upserted permission or an error. - */ - Observable> upsertPermission(String userLink, Permission permission, RequestOptions options); - - /** - * Replaces a permission. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced permission. - * In case of failure the {@link Observable} will error. - * - * @param permission the permission to use. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the replaced permission or an error. - */ - Observable> replacePermission(Permission permission, RequestOptions options); - - /** - * Deletes a permission. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response for the deleted permission. - * In case of failure the {@link Observable} will error. - * - * @param permissionLink the permission link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response for the deleted permission or an error. - */ - Observable> deletePermission(String permissionLink, RequestOptions options); - - /** - * Reads a permission. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read permission. - * In case of failure the {@link Observable} will error. - * - * @param permissionLink the permission link. - * @param options the request options. - * @return an {@link Observable} containing the single resource response with the read permission or an error. - */ - Observable> readPermission(String permissionLink, RequestOptions options); - - /** - * Reads all permissions. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read permissions. - * In case of failure the {@link Observable} will error. - * - * @param permissionLink the permission link. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read permissions or an error. - */ - Observable> readPermissions(String permissionLink, FeedOptions options); - - /** - * Query for permissions. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained permissions. - * In case of failure the {@link Observable} will error. - * - * @param permissionLink the permission link. - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained permissions or an error. - */ - Observable> queryPermissions(String permissionLink, String query, FeedOptions options); - - /** - * Query for permissions. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the obtained permissions. - * In case of failure the {@link Observable} will error. - * - * @param permissionLink the permission link. - * @param querySpec the SQL query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained permissions or an error. - */ - Observable> queryPermissions(String permissionLink, SqlQuerySpec querySpec, FeedOptions options); - - /** - * Replaces an offer. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the replaced offer. - * In case of failure the {@link Observable} will error. - * - * @param offer the offer to use. - * @return an {@link Observable} containing the single resource response with the replaced offer or an error. - */ - Observable> replaceOffer(Offer offer); - - /** - * Reads an offer. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the read offer. - * In case of failure the {@link Observable} will error. - * - * @param offerLink the offer link. - * @return an {@link Observable} containing the single resource response with the read offer or an error. - */ - Observable> readOffer(String offerLink); - - /** - * Reads offers. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of the read offers. - * In case of failure the {@link Observable} will error. - * - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the read offers or an error. - */ - Observable> readOffers(FeedOptions options); - - /** - * Query for offers in a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of obtained obtained offers. - * In case of failure the {@link Observable} will error. - * - * @param query the query. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained offers or an error. - */ - Observable> queryOffers(String query, FeedOptions options); - - /** - * Query for offers in a database. - *

- * After subscription the operation will be performed. - * The {@link Observable} will contain one or several feed response pages of obtained obtained offers. - * In case of failure the {@link Observable} will error. - * - * @param querySpec the query specification. - * @param options the feed options. - * @return an {@link Observable} containing one or several feed response pages of the obtained offers or an error. - */ - Observable> queryOffers(SqlQuerySpec querySpec, FeedOptions options); - - /** - * Gets database account information. - *

- * After subscription the operation will be performed. - * The {@link Observable} upon successful completion will contain a single resource response with the database account. - * In case of failure the {@link Observable} will error. - * - * @return an {@link Observable} containing the single resource response with the database account or an error. - */ - Observable getDatabaseAccount(); - - /** - * Close this {@link AsyncDocumentClient} instance and cleans up the resources. - */ - void close(); - -} diff --git a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ChangeFeedQueryImpl.java b/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ChangeFeedQueryImpl.java deleted file mode 100644 index 4b988cd84bc7..000000000000 --- a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/ChangeFeedQueryImpl.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import java.util.HashMap; -import java.util.Map; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.Paths; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.query.Paginator; - -import rx.Observable; -import rx.Single; -import rx.functions.Func1; -import rx.functions.Func2; - -class ChangeFeedQueryImpl { - - private static final String IfNonMatchAllHeaderValue = "*"; - private final RxDocumentClientImpl client; - private final ResourceType resourceType; - private final Class klass; - private final String documentsLink; - private final ChangeFeedOptions options; - - public ChangeFeedQueryImpl(RxDocumentClientImpl client, - ResourceType resourceType, - Class klass, - String collectionLink, - ChangeFeedOptions changeFeedOptions) { - - this.client = client; - this.resourceType = resourceType; - this.klass = klass; - this.documentsLink = Utils.joinPath(collectionLink, Paths.DOCUMENTS_PATH_SEGMENT); - changeFeedOptions = changeFeedOptions != null ? changeFeedOptions: new ChangeFeedOptions(); - - - if (resourceType.isPartitioned() && changeFeedOptions.getPartitionKeyRangeId() == null && changeFeedOptions.getPartitionKey() == null) { - throw new IllegalArgumentException(RMResources.PartitionKeyRangeIdOrPartitionKeyMustBeSpecified); - } - - if (changeFeedOptions.getPartitionKey() != null && - !Strings.isNullOrEmpty(changeFeedOptions.getPartitionKeyRangeId())) { - - throw new IllegalArgumentException(String.format( - RMResources.PartitionKeyAndParitionKeyRangeIdBothSpecified - , "feedOptions")); - } - - String initialNextIfNoneMatch = null; - - boolean canUseStartFromBeginning = true; - if (changeFeedOptions.getRequestContinuation() != null) { - initialNextIfNoneMatch = changeFeedOptions.getRequestContinuation(); - canUseStartFromBeginning = false; - } - - if(changeFeedOptions.getStartDateTime() != null){ - canUseStartFromBeginning = false; - } - - if (canUseStartFromBeginning && !changeFeedOptions.isStartFromBeginning()) { - initialNextIfNoneMatch = IfNonMatchAllHeaderValue; - } - - this.options = getChangeFeedOptions(changeFeedOptions, initialNextIfNoneMatch); - } - - private RxDocumentServiceRequest createDocumentServiceRequest(String continuationToken, int pageSize) { - Map headers = new HashMap<>(); - - if (options.getMaxItemCount() != null) { - headers.put(HttpConstants.HttpHeaders.PAGE_SIZE, String.valueOf(options.getMaxItemCount())); - } - - // On REST level, change feed is using IfNoneMatch/ETag instead of continuation. - if(continuationToken != null) { - headers.put(HttpConstants.HttpHeaders.IF_NONE_MATCH, continuationToken); - } - - headers.put(HttpConstants.HttpHeaders.A_IM, HttpConstants.A_IMHeaderValues.INCREMENTAL_FEED); - - if (options.getPartitionKey() != null) { - PartitionKeyInternal partitionKey = options.getPartitionKey().getInternalPartitionKey(); - headers.put(HttpConstants.HttpHeaders.PARTITION_KEY, partitionKey.toJson()); - } - - if(options.getStartDateTime() != null){ - String dateTimeInHttpFormat = Utils.zonedDateTimeAsUTCRFC1123(options.getStartDateTime()); - headers.put(HttpConstants.HttpHeaders.IF_MODIFIED_SINCE, dateTimeInHttpFormat); - } - - RxDocumentServiceRequest req = RxDocumentServiceRequest.create( - OperationType.ReadFeed, - resourceType, - documentsLink, - headers, - options); - - if (options.getPartitionKeyRangeId() != null) { - req.routeTo(new PartitionKeyRangeIdentity(this.options.getPartitionKeyRangeId())); - } - - return req; - } - - private ChangeFeedOptions getChangeFeedOptions(ChangeFeedOptions options, String continuationToken) { - ChangeFeedOptions newOps = new ChangeFeedOptions(options); - newOps.setRequestContinuation(continuationToken); - return newOps; - } - - public Observable> executeAsync() { - - Func2 createRequestFunc = (continuationToken, pageSize) -> this.createDocumentServiceRequest(continuationToken, pageSize); - - // TODO: clean up if we want to use single vs observable. - Func1>> executeFunc = request -> this.executeRequestAsync(request).toObservable(); - - return Paginator.getPaginatedChangeFeedQueryResultAsObservable(options, createRequestFunc, executeFunc, klass, options.getMaxItemCount() != null ? options.getMaxItemCount(): -1); - } - - private Single> executeRequestAsync(RxDocumentServiceRequest request) { - return client.readFeed(request).toSingle() - .map( rsp -> BridgeInternal.toChaneFeedResponsePage(rsp, klass)); - } -} diff --git a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentClientImpl.java b/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentClientImpl.java deleted file mode 100644 index c64b74f03646..000000000000 --- a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentClientImpl.java +++ /dev/null @@ -1,3175 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.microsoft.azure.cosmosdb.AccessConditionType; -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.Conflict; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.CosmosResourceType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.DatabaseAccountManagerInternal; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedOptionsBase; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.JsonSerializable; -import com.microsoft.azure.cosmosdb.MediaOptions; -import com.microsoft.azure.cosmosdb.MediaReadMode; -import com.microsoft.azure.cosmosdb.MediaResponse; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.StoredProcedureResponse; -import com.microsoft.azure.cosmosdb.TokenResolver; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.internal.BaseAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.internal.Constants; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.LifeCycleUtils; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.PathInfo; -import com.microsoft.azure.cosmosdb.internal.PathParser; -import com.microsoft.azure.cosmosdb.internal.Paths; -import com.microsoft.azure.cosmosdb.internal.PathsHelper; -import com.microsoft.azure.cosmosdb.internal.QueryCompatibilityMode; -import com.microsoft.azure.cosmosdb.internal.ResourceTokenAuthorizationHelper; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.RuntimeConstants; -import com.microsoft.azure.cosmosdb.internal.SessionContainer; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.Utils; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GatewayServiceConfigurationReader; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.ServerStoreModel; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreClient; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreClientFactory; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyAndResourceTokenPair; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxClientCollectionCache; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxPartitionKeyRangeCache; -import com.microsoft.azure.cosmosdb.rx.internal.directconnectivity.GlobalAddressResolver; -import com.microsoft.azure.cosmosdb.rx.internal.query.DocumentQueryExecutionContextFactory; -import com.microsoft.azure.cosmosdb.rx.internal.query.IDocumentQueryClient; -import com.microsoft.azure.cosmosdb.rx.internal.query.IDocumentQueryExecutionContext; -import com.microsoft.azure.cosmosdb.rx.internal.query.Paginator; -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClientBuilder; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import rx.Observable; -import rx.Single; -import rx.functions.Func1; -import rx.functions.Func2; - -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static com.microsoft.azure.cosmosdb.BridgeInternal.documentFromObject; -import static com.microsoft.azure.cosmosdb.BridgeInternal.getAltLink; -import static com.microsoft.azure.cosmosdb.BridgeInternal.toDatabaseAccount; -import static com.microsoft.azure.cosmosdb.BridgeInternal.toFeedResponsePage; -import static com.microsoft.azure.cosmosdb.BridgeInternal.toResourceResponse; -import static com.microsoft.azure.cosmosdb.BridgeInternal.toStoredProcedureResponse; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - */ -public class RxDocumentClientImpl implements AsyncDocumentClient, IAuthorizationTokenProvider { - private final static ObjectMapper mapper = Utils.getSimpleObjectMapper(); - private final Logger logger = LoggerFactory.getLogger(RxDocumentClientImpl.class); - private final String masterKeyOrResourceToken; - private final URI serviceEndpoint; - private final ConnectionPolicy connectionPolicy; - private final ConsistencyLevel consistencyLevel; - private final BaseAuthorizationTokenProvider authorizationTokenProvider; - private final UserAgentContainer userAgentContainer; - private final boolean hasAuthKeyResourceToken; - private final Configs configs; - private TokenResolver tokenResolver; - private SessionContainer sessionContainer; - private String firstResourceTokenFromPermissionFeed = StringUtils.EMPTY; - private RxClientCollectionCache collectionCache; - private RxStoreModel gatewayProxy; - private RxStoreModel storeModel; - private GlobalAddressResolver addressResolver; - private RxPartitionKeyRangeCache partitionKeyRangeCache; - private Map> resourceTokensMap; - - // RetryPolicy retries a request when it encounters session unavailable (see ClientRetryPolicy). - // Once it exhausts all write regions it clears the session container, then it uses RxClientCollectionCache - // to resolves the request's collection name. If it differs from the session container's resource id it - // explains the session unavailable exception: somebody removed and recreated the collection. In this - // case we retry once again (with empty session token) otherwise we return the error to the client - // (see RenameCollectionAwareClientRetryPolicy) - private IRetryPolicyFactory resetSessionTokenRetryPolicy; - /** - * Compatibility mode: Allows to specify compatibility mode used by client when - * making query requests. Should be removed when application/sql is no longer - * supported. - */ - private final QueryCompatibilityMode queryCompatibilityMode = QueryCompatibilityMode.Default; - private final CompositeHttpClient rxClient; - private final GlobalEndpointManager globalEndpointManager; - private final RetryPolicy retryPolicy; - private volatile boolean useMultipleWriteLocations; - - // creator of TransportClient is responsible for disposing it. - private StoreClientFactory storeClientFactory; - - private GatewayServiceConfigurationReader gatewayConfigurationReader; - - public RxDocumentClientImpl(URI serviceEndpoint, - String masterKeyOrResourceToken, - List permissionFeed, - ConnectionPolicy connectionPolicy, - ConsistencyLevel consistencyLevel, - Configs configs, - TokenResolver tokenResolver) { - this(serviceEndpoint, masterKeyOrResourceToken, permissionFeed, connectionPolicy, consistencyLevel, configs); - this.tokenResolver = tokenResolver; - } - - public RxDocumentClientImpl(URI serviceEndpoint, - String masterKeyOrResourceToken, - List permissionFeed, - ConnectionPolicy connectionPolicy, - ConsistencyLevel consistencyLevel, - Configs configs) { - this(serviceEndpoint, masterKeyOrResourceToken, connectionPolicy, consistencyLevel, configs); - if (permissionFeed != null && permissionFeed.size() > 0) { - this.resourceTokensMap = new HashMap<>(); - for (Permission permission : permissionFeed) { - String[] segments = StringUtils.split(permission.getResourceLink(), - Constants.Properties.PATH_SEPARATOR.charAt(0)); - - if (segments.length <= 0) { - throw new IllegalArgumentException("resourceLink"); - } - - List partitionKeyAndResourceTokenPairs = null; - PathInfo pathInfo = new PathInfo(false, StringUtils.EMPTY, StringUtils.EMPTY, false); - if (!PathsHelper.tryParsePathSegments(permission.getResourceLink(), pathInfo, null)) { - throw new IllegalArgumentException(permission.getResourceLink()); - } - - partitionKeyAndResourceTokenPairs = resourceTokensMap.get(pathInfo.resourceIdOrFullName); - if (partitionKeyAndResourceTokenPairs == null) { - partitionKeyAndResourceTokenPairs = new ArrayList<>(); - this.resourceTokensMap.put(pathInfo.resourceIdOrFullName, partitionKeyAndResourceTokenPairs); - } - - PartitionKey partitionKey = permission.getResourcePartitionKey(); - partitionKeyAndResourceTokenPairs.add(new PartitionKeyAndResourceTokenPair( - partitionKey != null ? partitionKey.getInternalPartitionKey() : PartitionKeyInternal.Empty, - permission.getToken())); - logger.debug("Initializing resource token map , with map key [{}] , partition key [{}] and resource token", - pathInfo.resourceIdOrFullName, partitionKey != null ? partitionKey.toString() : null, permission.getToken()); - - } - - if(this.resourceTokensMap.isEmpty()) { - throw new IllegalArgumentException("permissionFeed"); - } - - String firstToken = permissionFeed.get(0).getToken(); - if(ResourceTokenAuthorizationHelper.isResourceToken(firstToken)) { - this.firstResourceTokenFromPermissionFeed = firstToken; - } - } - } - - public RxDocumentClientImpl(URI serviceEndpoint, String masterKeyOrResourceToken, ConnectionPolicy connectionPolicy, - ConsistencyLevel consistencyLevel, Configs configs) { - - logger.info("Initializing DocumentClient with serviceEndpoint [{}], connectionPolicy [{}], " - + "consistencyLevel [{}], protocol [{}]", serviceEndpoint, connectionPolicy, - consistencyLevel, configs.getProtocol()); - - this.configs = configs; - this.masterKeyOrResourceToken = masterKeyOrResourceToken; - this.serviceEndpoint = serviceEndpoint; - - if (masterKeyOrResourceToken != null && ResourceTokenAuthorizationHelper.isResourceToken(masterKeyOrResourceToken)) { - this.authorizationTokenProvider = null; - hasAuthKeyResourceToken = true; - } else if(masterKeyOrResourceToken != null && !ResourceTokenAuthorizationHelper.isResourceToken(masterKeyOrResourceToken)){ - hasAuthKeyResourceToken = false; - this.authorizationTokenProvider = new BaseAuthorizationTokenProvider(this.masterKeyOrResourceToken); - } else { - hasAuthKeyResourceToken = false; - this.authorizationTokenProvider = null; - } - - if (connectionPolicy != null) { - this.connectionPolicy = connectionPolicy; - } else { - this.connectionPolicy = new ConnectionPolicy(); - } - - this.sessionContainer = new SessionContainer(this.serviceEndpoint.getHost()); - this.consistencyLevel = consistencyLevel; - - this.userAgentContainer = new UserAgentContainer(); - - String userAgentSuffix = this.connectionPolicy.getUserAgentSuffix(); - if (userAgentSuffix != null && userAgentSuffix.length() > 0) { - userAgentContainer.setSuffix(userAgentSuffix); - } - - this.rxClient = httpClientBuilder().build(); - this.globalEndpointManager = new GlobalEndpointManager(asDatabaseAccountManagerInternal(), this.connectionPolicy, /**/configs); - this.retryPolicy = new RetryPolicy(this.globalEndpointManager, this.connectionPolicy); - this.resetSessionTokenRetryPolicy = retryPolicy; - } - - private void initializeGatewayConfigurationReader() { - String resourceToken; - if(this.tokenResolver != null) { - resourceToken = this.tokenResolver.getAuthorizationToken("GET", "", CosmosResourceType.System, null); - } else if(!this.hasAuthKeyResourceToken && this.authorizationTokenProvider == null) { - resourceToken = this.firstResourceTokenFromPermissionFeed; - } else { - assert this.masterKeyOrResourceToken != null; - resourceToken = this.masterKeyOrResourceToken; - } - - this.gatewayConfigurationReader = new GatewayServiceConfigurationReader(this.serviceEndpoint, - this.hasAuthKeyResourceToken, - resourceToken, - this.connectionPolicy, - this.authorizationTokenProvider, - this.rxClient); - - DatabaseAccount databaseAccount = this.gatewayConfigurationReader.initializeReaderAsync().toBlocking().value(); - this.useMultipleWriteLocations = this.connectionPolicy.isUsingMultipleWriteLocations() && BridgeInternal.isEnableMultipleWriteLocations(databaseAccount); - - // TODO: add support for openAsync - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/332589 - this.globalEndpointManager.refreshLocationAsync(databaseAccount).await(); - } - - public void init() { - - // TODO: add support for openAsync - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/332589 - this.gatewayProxy = createRxGatewayProxy(this.sessionContainer, - this.consistencyLevel, - this.queryCompatibilityMode, - this.userAgentContainer, - this.globalEndpointManager, - this.rxClient); - this.globalEndpointManager.init(); - this.initializeGatewayConfigurationReader(); - - this.collectionCache = new RxClientCollectionCache(this.sessionContainer, this.gatewayProxy, this, this.retryPolicy); - this.resetSessionTokenRetryPolicy = new ResetSessionTokenRetryPolicyFactory(this.sessionContainer, this.collectionCache, this.retryPolicy); - - this.partitionKeyRangeCache = new RxPartitionKeyRangeCache(RxDocumentClientImpl.this, - collectionCache); - - if (this.connectionPolicy.getConnectionMode() == ConnectionMode.Gateway) { - this.storeModel = this.gatewayProxy; - } else { - this.initializeDirectConnectivity(); - } - } - - private void initializeDirectConnectivity() { - - this.storeClientFactory = new StoreClientFactory( - this.configs, - this.connectionPolicy.getRequestTimeoutInMillis() / 1000, - // this.maxConcurrentConnectionOpenRequests, - 0, - this.userAgentContainer - ); - - this.addressResolver = new GlobalAddressResolver( - this.rxClient, - this.globalEndpointManager, - this.configs.getProtocol(), - this, - this.collectionCache, - this.partitionKeyRangeCache, - userAgentContainer, - // TODO: Gateway Configuration Reader - // this.gatewayConfigurationReader, - null, - this.connectionPolicy); - - this.createStoreModel(true); - } - - DatabaseAccountManagerInternal asDatabaseAccountManagerInternal() { - return new DatabaseAccountManagerInternal() { - - @Override - public URI getServiceEndpoint() { - return RxDocumentClientImpl.this.getServiceEndpoint(); - } - - @Override - public Observable getDatabaseAccountFromEndpoint(URI endpoint) { - logger.info("Getting database account endpoint from {}", endpoint); - return RxDocumentClientImpl.this.getDatabaseAccountFromEndpoint(endpoint); - } - - @Override - public ConnectionPolicy getConnectionPolicy() { - return RxDocumentClientImpl.this.getConnectionPolicy(); - } - }; - } - - RxGatewayStoreModel createRxGatewayProxy(ISessionContainer sessionContainer, - ConsistencyLevel consistencyLevel, - QueryCompatibilityMode queryCompatibilityMode, - UserAgentContainer userAgentContainer, - GlobalEndpointManager globalEndpointManager, - CompositeHttpClient rxClient) { - return new RxGatewayStoreModel(sessionContainer, - consistencyLevel, - queryCompatibilityMode, - userAgentContainer, - globalEndpointManager, - rxClient); - } - - private CompositeHttpClientBuilder httpClientBuilder() { - - HttpClientFactory factory = new HttpClientFactory(this.configs) - .withMaxIdleConnectionTimeoutInMillis(this.connectionPolicy.getIdleConnectionTimeoutInMillis()) - .withPoolSize(this.connectionPolicy.getMaxPoolSize()) - .withHttpProxy(this.connectionPolicy.getProxy()) - .withRequestTimeoutInMillis(this.connectionPolicy.getRequestTimeoutInMillis()); - - return factory.toHttpClientBuilder(); - } - - private void createStoreModel(boolean subscribeRntbdStatus) { - // EnableReadRequestsFallback, if not explicitly set on the connection policy, - // is false if the account's consistency is bounded staleness, - // and true otherwise. - - StoreClient storeClient = this.storeClientFactory.createStoreClient( - this.addressResolver, - this.sessionContainer, - this.gatewayConfigurationReader, - this, - false - ); - - this.storeModel = new ServerStoreModel(storeClient); - } - - - @Override - public URI getServiceEndpoint() { - return this.serviceEndpoint; - } - - @Override - public URI getWriteEndpoint() { - return globalEndpointManager.getWriteEndpoints().stream().findFirst().map(loc -> { - try { - return loc.toURI(); - } catch (URISyntaxException e) { - throw new IllegalStateException(e); - } - }).orElse(null); - } - - @Override - public URI getReadEndpoint() { - return globalEndpointManager.getReadEndpoints().stream().findFirst().map(loc -> { - try { - return loc.toURI(); - } catch (URISyntaxException e) { - throw new IllegalStateException(e); - } - }).orElse(null); - } - - @Override - public ConnectionPolicy getConnectionPolicy() { - return this.connectionPolicy; - } - - @Override - public Observable> createDatabase(Database database, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> createDatabaseInternal(database, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> createDatabaseInternal(Database database, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - - if (database == null) { - throw new IllegalArgumentException("Database"); - } - - logger.debug("Creating a Database. id: [{}]", database.getId()); - validateResource(database); - - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Create, - ResourceType.Database, Paths.DATABASES_ROOT, database, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - return this.create(request).map(response -> toResourceResponse(response, Database.class)); - } catch (Exception e) { - logger.debug("Failure in creating a database. due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> deleteDatabase(String databaseLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteDatabaseInternal(databaseLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deleteDatabaseInternal(String databaseLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(databaseLink)) { - throw new IllegalArgumentException("databaseLink"); - } - - logger.debug("Deleting a Database. databaseLink: [{}]", databaseLink); - String path = Utils.joinPath(databaseLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.Database, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, Database.class)); - } catch (Exception e) { - logger.debug("Failure in deleting a database. due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readDatabase(String databaseLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readDatabaseInternal(databaseLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readDatabaseInternal(String databaseLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(databaseLink)) { - throw new IllegalArgumentException("databaseLink"); - } - - logger.debug("Reading a Database. databaseLink: [{}]", databaseLink); - String path = Utils.joinPath(databaseLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.Database, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - return this.read(request).map(response -> toResourceResponse(response, Database.class)); - } catch (Exception e) { - logger.debug("Failure in reading a database. due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readDatabases(FeedOptions options) { - return readFeed(options, ResourceType.Database, Database.class, Paths.DATABASES_ROOT); - } - - private String parentResourceLinkToQueryLink(String parentResouceLink, ResourceType resourceTypeEnum) { - switch (resourceTypeEnum) { - case Database: - return Paths.DATABASES_ROOT; - - case DocumentCollection: - return Utils.joinPath(parentResouceLink, Paths.COLLECTIONS_PATH_SEGMENT); - - case Document: - return Utils.joinPath(parentResouceLink, Paths.DOCUMENTS_PATH_SEGMENT); - - case Offer: - return Paths.OFFERS_ROOT; - - case User: - return Utils.joinPath(parentResouceLink, Paths.USERS_PATH_SEGMENT); - - case Permission: - return Utils.joinPath(parentResouceLink, Paths.PERMISSIONS_PATH_SEGMENT); - - case Attachment: - return Utils.joinPath(parentResouceLink, Paths.ATTACHMENTS_PATH_SEGMENT); - - case StoredProcedure: - return Utils.joinPath(parentResouceLink, Paths.STORED_PROCEDURES_PATH_SEGMENT); - - case Trigger: - return Utils.joinPath(parentResouceLink, Paths.TRIGGERS_PATH_SEGMENT); - - case UserDefinedFunction: - return Utils.joinPath(parentResouceLink, Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT); - - default: - throw new IllegalArgumentException("resource type not supported"); - } - } - - private Observable> createQuery( - String parentResourceLink, - SqlQuerySpec sqlQuery, - FeedOptions options, - Class klass, - ResourceType resourceTypeEnum) { - - String queryResourceLink = parentResourceLinkToQueryLink(parentResourceLink, resourceTypeEnum); - - UUID activityId = Utils.randomUUID(); - IDocumentQueryClient queryClient = DocumentQueryClientImpl(RxDocumentClientImpl.this); - Observable> executionContext = - DocumentQueryExecutionContextFactory.createDocumentQueryExecutionContextAsync(queryClient, resourceTypeEnum, klass, sqlQuery , options, queryResourceLink, false, activityId); - return executionContext.single().flatMap(ex -> { - return ex.executeAsync(); - }); - } - - - @Override - public Observable> queryDatabases(String query, FeedOptions options) { - return queryDatabases(new SqlQuerySpec(query), options); - } - - - @Override - public Observable> queryDatabases(SqlQuerySpec querySpec, FeedOptions options) { - return createQuery(Paths.DATABASES_ROOT, querySpec, options, Database.class, ResourceType.Database); - } - - @Override - public Observable> createCollection(String databaseLink, - DocumentCollection collection, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> this.createCollectionInternal(databaseLink, collection, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> createCollectionInternal(String databaseLink, - DocumentCollection collection, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(databaseLink)) { - throw new IllegalArgumentException("databaseLink"); - } - if (collection == null) { - throw new IllegalArgumentException("collection"); - } - - logger.debug("Creating a Collection. databaseLink: [{}], Collection id: [{}]", databaseLink, - collection.getId()); - validateResource(collection); - - String path = Utils.joinPath(databaseLink, Paths.COLLECTIONS_PATH_SEGMENT); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Create, - ResourceType.DocumentCollection, path, collection, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.create(request).map(response -> toResourceResponse(response, DocumentCollection.class)) - .doOnNext(resourceResponse -> { - // set the session token - this.sessionContainer.setSessionToken(resourceResponse.getResource().getResourceId(), - getAltLink(resourceResponse.getResource()), - resourceResponse.getResponseHeaders()); - }); - } catch (Exception e) { - logger.debug("Failure in creating a collection. due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> replaceCollection(DocumentCollection collection, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceCollectionInternal(collection, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> replaceCollectionInternal(DocumentCollection collection, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (collection == null) { - throw new IllegalArgumentException("collection"); - } - - logger.debug("Replacing a Collection. id: [{}]", collection.getId()); - validateResource(collection); - - String path = Utils.joinPath(collection.getSelfLink(), null); - Map requestHeaders = this.getRequestHeaders(options); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.DocumentCollection, path, collection, requestHeaders, options); - - // TODO: .Net has some logic for updating session token which we don't - // have here - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.replace(request).map(response -> toResourceResponse(response, DocumentCollection.class)) - .doOnNext(resourceResponse -> { - if (resourceResponse.getResource() != null) { - // set the session token - this.sessionContainer.setSessionToken(resourceResponse.getResource().getResourceId(), - getAltLink(resourceResponse.getResource()), - resourceResponse.getResponseHeaders()); - } - }); - - } catch (Exception e) { - logger.debug("Failure in replacing a collection. due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> deleteCollection(String collectionLink, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteCollectionInternal(collectionLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deleteCollectionInternal(String collectionLink, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - logger.debug("Deleting a Collection. collectionLink: [{}]", collectionLink); - String path = Utils.joinPath(collectionLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.DocumentCollection, path, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, DocumentCollection.class)); - - } catch (Exception e) { - logger.debug("Failure in deleting a collection, due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - private Observable delete(RxDocumentServiceRequest request) { - populateHeaders(request, HttpConstants.HttpMethods.DELETE); - return getStoreProxy(request).processMessage(request); - } - - private Observable read(RxDocumentServiceRequest request) { - populateHeaders(request, HttpConstants.HttpMethods.GET); - return getStoreProxy(request).processMessage(request); - } - - Observable readFeed(RxDocumentServiceRequest request) { - populateHeaders(request, HttpConstants.HttpMethods.GET); - return gatewayProxy.processMessage(request); - } - - private Observable query(RxDocumentServiceRequest request) { - populateHeaders(request, HttpConstants.HttpMethods.POST); - return this.getStoreProxy(request).processMessage(request) - .map(response -> { - this.captureSessionToken(request, response); - return response; - } - ); - } - - @Override - public Observable> readCollection(String collectionLink, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readCollectionInternal(collectionLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readCollectionInternal(String collectionLink, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - logger.debug("Reading a Collection. collectionLink: [{}]", collectionLink); - String path = Utils.joinPath(collectionLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.DocumentCollection, path, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - return this.read(request).map(response -> toResourceResponse(response, DocumentCollection.class)); - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in reading a collection, due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readCollections(String databaseLink, FeedOptions options) { - - if (StringUtils.isEmpty(databaseLink)) { - throw new IllegalArgumentException("databaseLink"); - } - - return readFeed(options, ResourceType.DocumentCollection, DocumentCollection.class, - Utils.joinPath(databaseLink, Paths.COLLECTIONS_PATH_SEGMENT)); - } - - @Override - public Observable> queryCollections(String databaseLink, String query, - FeedOptions options) { - return createQuery(databaseLink, new SqlQuerySpec(query), options, DocumentCollection.class, ResourceType.DocumentCollection); - } - - @Override - public Observable> queryCollections(String databaseLink, - SqlQuerySpec querySpec, FeedOptions options) { - return createQuery(databaseLink, querySpec, options, DocumentCollection.class, ResourceType.DocumentCollection); - } - - private static String serializeProcedureParams(Object[] objectArray) { - String[] stringArray = new String[objectArray.length]; - - for (int i = 0; i < objectArray.length; ++i) { - Object object = objectArray[i]; - if (object instanceof JsonSerializable) { - stringArray[i] = ((JsonSerializable) object).toJson(); - } else { - - // POJO, ObjectNode, number, String or Boolean - try { - stringArray[i] = mapper.writeValueAsString(object); - } catch (IOException e) { - throw new IllegalArgumentException("Can't serialize the object into the json string", e); - } - } - } - - return String.format("[%s]", StringUtils.join(stringArray, ",")); - } - - private static void validateResource(Resource resource) { - if (!StringUtils.isEmpty(resource.getId())) { - if (resource.getId().indexOf('/') != -1 || resource.getId().indexOf('\\') != -1 || - resource.getId().indexOf('?') != -1 || resource.getId().indexOf('#') != -1) { - throw new IllegalArgumentException("Id contains illegal chars."); - } - - if (resource.getId().endsWith(" ")) { - throw new IllegalArgumentException("Id ends with a space."); - } - } - } - - private Map getRequestHeaders(RequestOptions options) { - Map headers = new HashMap<>(); - - if (this.useMultipleWriteLocations) { - headers.put(HttpConstants.HttpHeaders.ALLOW_TENTATIVE_WRITES, Boolean.TRUE.toString()); - } - - if (consistencyLevel != null) { - headers.put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, consistencyLevel.name()); - } - - if (options == null) { - return headers; - } - - Map customOptions = options.getHeaders(); - if (customOptions != null) { - headers.putAll(customOptions); - } - - if (options.getAccessCondition() != null) { - if (options.getAccessCondition().getType() == AccessConditionType.IfMatch) { - headers.put(HttpConstants.HttpHeaders.IF_MATCH, options.getAccessCondition().getCondition()); - } else { - headers.put(HttpConstants.HttpHeaders.IF_NONE_MATCH, options.getAccessCondition().getCondition()); - } - } - - if (options.getConsistencyLevel() != null) { - headers.put(HttpConstants.HttpHeaders.CONSISTENCY_LEVEL, options.getConsistencyLevel().name()); - } - - if (options.getIndexingDirective() != null) { - headers.put(HttpConstants.HttpHeaders.INDEXING_DIRECTIVE, options.getIndexingDirective().name()); - } - - if (options.getPostTriggerInclude() != null && options.getPostTriggerInclude().size() > 0) { - String postTriggerInclude = StringUtils.join(options.getPostTriggerInclude(), ","); - headers.put(HttpConstants.HttpHeaders.POST_TRIGGER_INCLUDE, postTriggerInclude); - } - - if (options.getPreTriggerInclude() != null && options.getPreTriggerInclude().size() > 0) { - String preTriggerInclude = StringUtils.join(options.getPreTriggerInclude(), ","); - headers.put(HttpConstants.HttpHeaders.PRE_TRIGGER_INCLUDE, preTriggerInclude); - } - - if (!Strings.isNullOrEmpty(options.getSessionToken())) { - headers.put(HttpConstants.HttpHeaders.SESSION_TOKEN, options.getSessionToken()); - } - - if (options.getResourceTokenExpirySeconds() != null) { - headers.put(HttpConstants.HttpHeaders.RESOURCE_TOKEN_EXPIRY, - String.valueOf(options.getResourceTokenExpirySeconds())); - } - - if (options.getOfferThroughput() != null && options.getOfferThroughput() >= 0) { - headers.put(HttpConstants.HttpHeaders.OFFER_THROUGHPUT, options.getOfferThroughput().toString()); - } else if (options.getOfferType() != null) { - headers.put(HttpConstants.HttpHeaders.OFFER_TYPE, options.getOfferType()); - } - - if (options.getPartitionKey() != null) { - headers.put(HttpConstants.HttpHeaders.PARTITION_KEY, options.getPartitionKey().toString()); - } - - if (options.isPopulateQuotaInfo()) { - headers.put(HttpConstants.HttpHeaders.POPULATE_QUOTA_INFO, String.valueOf(true)); - } - - if (options.isScriptLoggingEnabled()) { - headers.put(HttpConstants.HttpHeaders.SCRIPT_ENABLE_LOGGING, String.valueOf(true)); - } - - return headers; - } - - private Map getFeedHeaders(FeedOptionsBase options) { - return BridgeInternal.getFeedHeaders(options); - } - - private Map getMediaHeaders(MediaOptions options) { - Map requestHeaders = new HashMap<>(); - - if (options == null || StringUtils.isEmpty(options.getContentType())) { - requestHeaders.put(HttpConstants.HttpHeaders.CONTENT_TYPE, RuntimeConstants.MediaTypes.OCTET_STREAM); - } - - if (options != null) { - if (!StringUtils.isEmpty(options.getContentType())) { - requestHeaders.put(HttpConstants.HttpHeaders.CONTENT_TYPE, options.getContentType()); - } - - if (!StringUtils.isEmpty(options.getSlug())) { - requestHeaders.put(HttpConstants.HttpHeaders.SLUG, options.getSlug()); - } - } - return requestHeaders; - } - - private Single addPartitionKeyInformation(RxDocumentServiceRequest request, Document document, - RequestOptions options) { - - Single collectionObs = this.collectionCache.resolveCollectionAsync(request); - return collectionObs - .map(collection -> { - addPartitionKeyInformation(request, document, options, collection); - return request; - }); - } - - private Single addPartitionKeyInformation(RxDocumentServiceRequest request, Document document, RequestOptions options, - Single collectionObs) { - - return collectionObs.map(collection -> { - addPartitionKeyInformation(request, document, options, collection); - return request; - }); - } - - private void addPartitionKeyInformation(RxDocumentServiceRequest request, Document document, RequestOptions options, - DocumentCollection collection) { - PartitionKeyDefinition partitionKeyDefinition = collection.getPartitionKey(); - - PartitionKeyInternal partitionKeyInternal = null; - if (options != null && options.getPartitionKey() != null) { - partitionKeyInternal = options.getPartitionKey().getInternalPartitionKey(); - } else if (partitionKeyDefinition == null || partitionKeyDefinition.getPaths().size() == 0) { - // For backward compatibility, if collection doesn't have partition key defined, we assume all documents - // have empty value for it and user doesn't need to specify it explicitly. - partitionKeyInternal = PartitionKeyInternal.getEmpty(); - } else if (document != null) { - partitionKeyInternal = extractPartitionKeyValueFromDocument(document, partitionKeyDefinition); - } else { - throw new UnsupportedOperationException("PartitionKey value must be supplied for this operation."); - } - - request.getHeaders().put(HttpConstants.HttpHeaders.PARTITION_KEY, escapeNonAscii(partitionKeyInternal.toJson())); - } - - private static String escapeNonAscii(String partitionKeyJson) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < partitionKeyJson.length(); i++) { - int val = partitionKeyJson.charAt(i); - if (val > 127) { - sb.append("\\u").append(String.format("%04X", val)); - } else { - sb.append(partitionKeyJson.charAt(i)); - } - } - return sb.toString(); - } - - private static PartitionKeyInternal extractPartitionKeyValueFromDocument( - Document document, - PartitionKeyDefinition partitionKeyDefinition) { - if (partitionKeyDefinition != null) { - String path = partitionKeyDefinition.getPaths().iterator().next(); - List parts = PathParser.getPathParts(path); - if (parts.size() >= 1) { - Object value = document.getObjectByPath(parts); - if (value == null || value.getClass() == ObjectNode.class) { - value = Undefined.Value(); - } - - return PartitionKeyInternal.fromObjectArray(Collections.singletonList(value), false); - } - } - - return null; - } - - private Single getCreateDocumentRequest(String documentCollectionLink, Object document, - RequestOptions options, boolean disableAutomaticIdGeneration, OperationType operationType) { - - if (StringUtils.isEmpty(documentCollectionLink)) { - throw new IllegalArgumentException("documentCollectionLink"); - } - if (document == null) { - throw new IllegalArgumentException("document"); - } - - Document typedDocument = documentFromObject(document, mapper); - - RxDocumentClientImpl.validateResource(typedDocument); - - if (typedDocument.getId() == null && !disableAutomaticIdGeneration) { - // We are supposed to use GUID. Basically UUID is the same as GUID - // when represented as a string. - typedDocument.setId(UUID.randomUUID().toString()); - } - String path = Utils.joinPath(documentCollectionLink, Paths.DOCUMENTS_PATH_SEGMENT); - Map requestHeaders = this.getRequestHeaders(options); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, ResourceType.Document, path, - typedDocument, requestHeaders, options); - - Single collectionObs = this.collectionCache.resolveCollectionAsync(request); - return addPartitionKeyInformation(request, typedDocument, options, collectionObs); - } - - private void populateHeaders(RxDocumentServiceRequest request, String httpMethod) { - if (this.masterKeyOrResourceToken != null) { - request.getHeaders().put(HttpConstants.HttpHeaders.X_DATE, Utils.nowAsRFC1123()); - } - - if (this.masterKeyOrResourceToken != null || this.resourceTokensMap != null || this.tokenResolver != null) { - String resourceName = request.getResourceAddress(); - - String authorization = this.getUserAuthorizationToken( - resourceName, request.getResourceType(), httpMethod, request.getHeaders(), - AuthorizationTokenType.PrimaryMasterKey, request.properties); - try { - authorization = URLEncoder.encode(authorization, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("Failed to encode authtoken.", e); - } - request.getHeaders().put(HttpConstants.HttpHeaders.AUTHORIZATION, authorization); - } - - if ((HttpConstants.HttpMethods.POST.equals(httpMethod) || HttpConstants.HttpMethods.PUT.equals(httpMethod)) - && !request.getHeaders().containsKey(HttpConstants.HttpHeaders.CONTENT_TYPE)) { - request.getHeaders().put(HttpConstants.HttpHeaders.CONTENT_TYPE, RuntimeConstants.MediaTypes.JSON); - } - - if (!request.getHeaders().containsKey(HttpConstants.HttpHeaders.ACCEPT)) { - request.getHeaders().put(HttpConstants.HttpHeaders.ACCEPT, RuntimeConstants.MediaTypes.JSON); - } - } - - @Override - public String getUserAuthorizationToken(String resourceName, - ResourceType resourceType, - String requestVerb, - Map headers, - AuthorizationTokenType tokenType, - Map properties) { - - if (this.tokenResolver != null) { - return this.tokenResolver.getAuthorizationToken(requestVerb, resourceName, this.resolveCosmosResourceType(resourceType), - properties != null ? Collections.unmodifiableMap(properties) : null); - } else if (masterKeyOrResourceToken != null && !hasAuthKeyResourceToken) { - return this.authorizationTokenProvider.generateKeyAuthorizationSignature(requestVerb, resourceName, - resourceType, headers); - } else if (masterKeyOrResourceToken != null && hasAuthKeyResourceToken && resourceTokensMap == null) { - return masterKeyOrResourceToken; - } else { - assert resourceTokensMap != null; - if(resourceType.equals(ResourceType.DatabaseAccount)) { - return this.firstResourceTokenFromPermissionFeed; - } - return ResourceTokenAuthorizationHelper.getAuthorizationTokenUsingResourceTokens(resourceTokensMap, requestVerb, resourceName, headers); - } - } - - private CosmosResourceType resolveCosmosResourceType(ResourceType resourceType) { - try { - return CosmosResourceType.valueOf(resourceType.name()); - } catch (IllegalArgumentException e) { - return CosmosResourceType.System; - } - } - - void captureSessionToken(RxDocumentServiceRequest request, RxDocumentServiceResponse response) { - this.sessionContainer.setSessionToken(request, response.getResponseHeaders()); - } - - private Observable create(RxDocumentServiceRequest request) { - populateHeaders(request, HttpConstants.HttpMethods.POST); - RxStoreModel storeProxy = this.getStoreProxy(request); - return storeProxy.processMessage(request); - } - - private Observable upsert(RxDocumentServiceRequest request) { - - populateHeaders(request, HttpConstants.HttpMethods.POST); - Map headers = request.getHeaders(); - // headers can never be null, since it will be initialized even when no - // request options are specified, - // hence using assertion here instead of exception, being in the private - // method - assert (headers != null); - headers.put(HttpConstants.HttpHeaders.IS_UPSERT, "true"); - - return getStoreProxy(request).processMessage(request) - .map(response -> { - this.captureSessionToken(request, response); - return response; - } - ); - } - - private Observable replace(RxDocumentServiceRequest request) { - populateHeaders(request, HttpConstants.HttpMethods.PUT); - return getStoreProxy(request).processMessage(request); - } - - @Override - public Observable> createDocument(String collectionLink, Object document, - RequestOptions options, boolean disableAutomaticIdGeneration) { - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - if (options == null || options.getPartitionKey() == null) { - requestRetryPolicy = new PartitionKeyMismatchRetryPolicy(collectionCache, requestRetryPolicy, collectionLink, options); - } - - IDocumentClientRetryPolicy finalRetryPolicyInstance = requestRetryPolicy; - return ObservableHelper.inlineIfPossibleAsObs(() -> createDocumentInternal(collectionLink, document, options, disableAutomaticIdGeneration, finalRetryPolicyInstance), requestRetryPolicy); - } - - private Observable> createDocumentInternal(String collectionLink, Object document, - RequestOptions options, final boolean disableAutomaticIdGeneration, IDocumentClientRetryPolicy requestRetryPolicy) { - - try { - logger.debug("Creating a Document. collectionLink: [{}]", collectionLink); - - Single requestObs = getCreateDocumentRequest(collectionLink, document, - options, disableAutomaticIdGeneration, OperationType.Create); - - Observable responseObservable = requestObs - .toObservable() - .flatMap(req -> { - if (requestRetryPolicy != null) { - requestRetryPolicy.onBeforeSendRequest(req); - } - - return create(req); - }); - - Observable> createObservable = - responseObservable - .map(serviceResponse -> { - return toResourceResponse(serviceResponse, Document.class); - }); - - return createObservable; - - } catch (Exception e) { - logger.debug("Failure in creating a document due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> upsertDocument(String collectionLink, Object document, - RequestOptions options, boolean disableAutomaticIdGeneration) { - - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - if (options == null || options.getPartitionKey() == null) { - requestRetryPolicy = new PartitionKeyMismatchRetryPolicy(collectionCache, requestRetryPolicy, collectionLink, options); - } - IDocumentClientRetryPolicy finalRetryPolicyInstance = requestRetryPolicy; - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertDocumentInternal(collectionLink, document, options, disableAutomaticIdGeneration, finalRetryPolicyInstance), requestRetryPolicy); - } - - private Observable> upsertDocumentInternal(String collectionLink, Object document, - RequestOptions options, boolean disableAutomaticIdGeneration, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - logger.debug("Upserting a Document. collectionLink: [{}]", collectionLink); - - Observable reqObs = getCreateDocumentRequest(collectionLink, document, - options, disableAutomaticIdGeneration, OperationType.Upsert).toObservable(); - - Observable responseObservable = reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(req); - } - - return upsert(req);}); - return responseObservable - .map(serviceResponse -> toResourceResponse(serviceResponse, Document.class)); - - } catch (Exception e) { - logger.debug("Failure in upserting a document due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> replaceDocument(String documentLink, Object document, - RequestOptions options) { - - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - if (options == null || options.getPartitionKey() == null) { - String collectionLink = Utils.getCollectionName(documentLink); - requestRetryPolicy = new PartitionKeyMismatchRetryPolicy(collectionCache, requestRetryPolicy, collectionLink, options); - } - IDocumentClientRetryPolicy finalRequestRetryPolicy = requestRetryPolicy; - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceDocumentInternal(documentLink, document, options, finalRequestRetryPolicy), requestRetryPolicy); - } - - private Observable> replaceDocumentInternal(String documentLink, Object document, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(documentLink)) { - throw new IllegalArgumentException("documentLink"); - } - - if (document == null) { - throw new IllegalArgumentException("document"); - } - - Document typedDocument = documentFromObject(document, mapper); - - return this.replaceDocumentInternal(documentLink, typedDocument, options, retryPolicyInstance); - - } catch (Exception e) { - logger.debug("Failure in replacing a document due to [{}]", e.getMessage()); - return Observable.error(e); - } - } - - @Override - public Observable> replaceDocument(Document document, RequestOptions options) { - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - if (options == null || options.getPartitionKey() == null) { - String collectionLink = document.getSelfLink(); - requestRetryPolicy = new PartitionKeyMismatchRetryPolicy(collectionCache, requestRetryPolicy, collectionLink, options); - } - IDocumentClientRetryPolicy finalRequestRetryPolicy = requestRetryPolicy; - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceDocumentInternal(document, options, finalRequestRetryPolicy), requestRetryPolicy); - } - - private Observable> replaceDocumentInternal(Document document, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (document == null) { - throw new IllegalArgumentException("document"); - } - - return this.replaceDocumentInternal(document.getSelfLink(), document, options, retryPolicyInstance); - - } catch (Exception e) { - logger.debug("Failure in replacing a database due to [{}]", e.getMessage()); - return Observable.error(e); - } - } - - private Observable> replaceDocumentInternal(String documentLink, Document document, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - if (document == null) { - throw new IllegalArgumentException("document"); - } - - logger.debug("Replacing a Document. documentLink: [{}]", documentLink); - final String path = Utils.joinPath(documentLink, null); - final Map requestHeaders = getRequestHeaders(options); - final RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.Document, path, document, requestHeaders, options); - - validateResource(document); - - Single collectionObs = collectionCache.resolveCollectionAsync(request); - Single requestObs = addPartitionKeyInformation(request, document, options, collectionObs); - - return requestObs.toObservable().flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - return replace(request) - .map(resp -> toResourceResponse(resp, Document.class));} ); - } - - @Override - public Observable> deleteDocument(String documentLink, RequestOptions options) { - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteDocumentInternal(documentLink, options, requestRetryPolicy), requestRetryPolicy); - } - - private Observable> deleteDocumentInternal(String documentLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(documentLink)) { - throw new IllegalArgumentException("documentLink"); - } - - logger.debug("Deleting a Document. documentLink: [{}]", documentLink); - String path = Utils.joinPath(documentLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.Document, path, requestHeaders, options); - - Single collectionObs = collectionCache.resolveCollectionAsync(request); - - Single requestObs = addPartitionKeyInformation(request, null, options, collectionObs); - - return requestObs.toObservable().flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(req); - } - return this.delete(req) - .map(serviceResponse -> toResourceResponse(serviceResponse, Document.class));}); - - } catch (Exception e) { - logger.debug("Failure in deleting a document due to [{}]", e.getMessage()); - return Observable.error(e); - } - } - - @Override - public Observable> readDocument(String documentLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readDocumentInternal(documentLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readDocumentInternal(String documentLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(documentLink)) { - throw new IllegalArgumentException("documentLink"); - } - - logger.debug("Reading a Document. documentLink: [{}]", documentLink); - String path = Utils.joinPath(documentLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.Document, path, requestHeaders, options); - - Single collectionObs = this.collectionCache.resolveCollectionAsync(request); - - Single requestObs = addPartitionKeyInformation(request, null, options, collectionObs); - - return requestObs.toObservable().flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - return this.read(request).map(serviceResponse -> toResourceResponse(serviceResponse, Document.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in reading a document due to [{}]", e.getMessage()); - return Observable.error(e); - } - } - - @Override - public Observable> readDocuments(String collectionLink, FeedOptions options) { - - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - return queryDocuments(collectionLink, "SELECT * FROM r", options); - } - - @Override - public Observable> queryDocuments(String collectionLink, String query, - FeedOptions options) { - return queryDocuments(collectionLink, new SqlQuerySpec(query), options); - } - - private IDocumentQueryClient DocumentQueryClientImpl(RxDocumentClientImpl rxDocumentClientImpl) { - - return new IDocumentQueryClient () { - - @Override - public RxCollectionCache getCollectionCache() { - return RxDocumentClientImpl.this.collectionCache; - } - - @Override - public RxPartitionKeyRangeCache getPartitionKeyRangeCache() { - return RxDocumentClientImpl.this.partitionKeyRangeCache; - } - - @Override - public IRetryPolicyFactory getResetSessionTokenRetryPolicy() { - return RxDocumentClientImpl.this.resetSessionTokenRetryPolicy; - } - - @Override - public ConsistencyLevel getDefaultConsistencyLevelAsync() { - return RxDocumentClientImpl.this.gatewayConfigurationReader.getDefaultConsistencyLevel(); - } - - @Override - public ConsistencyLevel getDesiredConsistencyLevelAsync() { - // TODO Auto-generated method stub - return RxDocumentClientImpl.this.consistencyLevel; - } - - @Override - public Single executeQueryAsync(RxDocumentServiceRequest request) { - return RxDocumentClientImpl.this.query(request).toSingle(); - } - - @Override - public QueryCompatibilityMode getQueryCompatibilityMode() { - // TODO Auto-generated method stub - return QueryCompatibilityMode.Default; - } - - @Override - public Single readFeedAsync(RxDocumentServiceRequest request) { - // TODO Auto-generated method stub - return null; - } - }; - } - - @Override - public Observable> queryDocuments(String collectionLink, SqlQuerySpec querySpec, - FeedOptions options) { - return createQuery(collectionLink, querySpec, options, Document.class, ResourceType.Document); - } - - @Override - public Observable> queryDocumentChangeFeed(final String collectionLink, - final ChangeFeedOptions changeFeedOptions) { - - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - ChangeFeedQueryImpl changeFeedQueryImpl = new ChangeFeedQueryImpl(this, ResourceType.Document, - Document.class, collectionLink, changeFeedOptions); - - return changeFeedQueryImpl.executeAsync(); - } - - @Override - public Observable> readPartitionKeyRanges(final String collectionLink, - FeedOptions options) { - - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - return readFeed(options, ResourceType.PartitionKeyRange, PartitionKeyRange.class, - Utils.joinPath(collectionLink, Paths.PARTITION_KEY_RANGES_PATH_SEGMENT)); - } - - private RxDocumentServiceRequest getStoredProcedureRequest(String collectionLink, StoredProcedure storedProcedure, - RequestOptions options, OperationType operationType) { - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - if (storedProcedure == null) { - throw new IllegalArgumentException("storedProcedure"); - } - - validateResource(storedProcedure); - - String path = Utils.joinPath(collectionLink, Paths.STORED_PROCEDURES_PATH_SEGMENT); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, ResourceType.StoredProcedure, - path, storedProcedure, requestHeaders, options); - - return request; - } - - private RxDocumentServiceRequest getUserDefinedFunctionRequest(String collectionLink, UserDefinedFunction udf, - RequestOptions options, OperationType operationType) { - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - if (udf == null) { - throw new IllegalArgumentException("udf"); - } - - validateResource(udf); - - String path = Utils.joinPath(collectionLink, Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, - ResourceType.UserDefinedFunction, path, udf, requestHeaders, options); - - return request; - } - - @Override - public Observable> createStoredProcedure(String collectionLink, - StoredProcedure storedProcedure, RequestOptions options) { - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> createStoredProcedureInternal(collectionLink, storedProcedure, options, requestRetryPolicy), requestRetryPolicy); - } - - private Observable> createStoredProcedureInternal(String collectionLink, - StoredProcedure storedProcedure, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - - logger.debug("Creating a StoredProcedure. collectionLink: [{}], storedProcedure id [{}]", - collectionLink, storedProcedure.getId()); - RxDocumentServiceRequest request = getStoredProcedureRequest(collectionLink, storedProcedure, options, - OperationType.Create); - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.create(request).map(response -> toResourceResponse(response, StoredProcedure.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in creating a StoredProcedure due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> upsertStoredProcedure(String collectionLink, - StoredProcedure storedProcedure, RequestOptions options) { - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertStoredProcedureInternal(collectionLink, storedProcedure, options, requestRetryPolicy), requestRetryPolicy); - } - - private Observable> upsertStoredProcedureInternal(String collectionLink, - StoredProcedure storedProcedure, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - - logger.debug("Upserting a StoredProcedure. collectionLink: [{}], storedProcedure id [{}]", - collectionLink, storedProcedure.getId()); - RxDocumentServiceRequest request = getStoredProcedureRequest(collectionLink, storedProcedure, options, - OperationType.Upsert); - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.upsert(request).map(response -> toResourceResponse(response, StoredProcedure.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in upserting a StoredProcedure due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> replaceStoredProcedure(StoredProcedure storedProcedure, - RequestOptions options) { - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceStoredProcedureInternal(storedProcedure, options, requestRetryPolicy), requestRetryPolicy); - } - - private Observable> replaceStoredProcedureInternal(StoredProcedure storedProcedure, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - - if (storedProcedure == null) { - throw new IllegalArgumentException("storedProcedure"); - } - logger.debug("Replacing a StoredProcedure. storedProcedure id [{}]", storedProcedure.getId()); - - RxDocumentClientImpl.validateResource(storedProcedure); - - String path = Utils.joinPath(storedProcedure.getSelfLink(), null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.StoredProcedure, path, storedProcedure, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.replace(request).map(response -> toResourceResponse(response, StoredProcedure.class)); - - } catch (Exception e) { - logger.debug("Failure in replacing a StoredProcedure due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> deleteStoredProcedure(String storedProcedureLink, - RequestOptions options) { - IDocumentClientRetryPolicy requestRetryPolicy = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteStoredProcedureInternal(storedProcedureLink, options, requestRetryPolicy), requestRetryPolicy); - } - - private Observable> deleteStoredProcedureInternal(String storedProcedureLink, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - - if (StringUtils.isEmpty(storedProcedureLink)) { - throw new IllegalArgumentException("storedProcedureLink"); - } - - logger.debug("Deleting a StoredProcedure. storedProcedureLink [{}]", storedProcedureLink); - String path = Utils.joinPath(storedProcedureLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.StoredProcedure, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, StoredProcedure.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in deleting a StoredProcedure due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readStoredProcedure(String storedProcedureLink, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readStoredProcedureInternal(storedProcedureLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readStoredProcedureInternal(String storedProcedureLink, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - - if (StringUtils.isEmpty(storedProcedureLink)) { - throw new IllegalArgumentException("storedProcedureLink"); - } - - logger.debug("Reading a StoredProcedure. storedProcedureLink [{}]", storedProcedureLink); - String path = Utils.joinPath(storedProcedureLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.StoredProcedure, path, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.read(request).map(response -> toResourceResponse(response, StoredProcedure.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in reading a StoredProcedure due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readStoredProcedures(String collectionLink, - FeedOptions options) { - - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - return readFeed(options, ResourceType.StoredProcedure, StoredProcedure.class, - Utils.joinPath(collectionLink, Paths.STORED_PROCEDURES_PATH_SEGMENT)); - } - - @Override - public Observable> queryStoredProcedures(String collectionLink, String query, - FeedOptions options) { - return queryStoredProcedures(collectionLink, new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryStoredProcedures(String collectionLink, - SqlQuerySpec querySpec, FeedOptions options) { - return createQuery(collectionLink, querySpec, options, StoredProcedure.class, ResourceType.StoredProcedure); - } - - @Override - public Observable executeStoredProcedure(String storedProcedureLink, - Object[] procedureParams) { - return this.executeStoredProcedure(storedProcedureLink, null, procedureParams); - } - - @Override - public Observable executeStoredProcedure(String storedProcedureLink, - RequestOptions options, Object[] procedureParams) { - return ObservableHelper.inlineIfPossibleAsObs(() -> executeStoredProcedureInternal(storedProcedureLink, options, procedureParams), this.resetSessionTokenRetryPolicy.getRequestPolicy()); - } - - private Observable executeStoredProcedureInternal(String storedProcedureLink, - RequestOptions options, Object[] procedureParams) { - - try { - logger.debug("Executing a StoredProcedure. storedProcedureLink [{}]", storedProcedureLink); - String path = Utils.joinPath(storedProcedureLink, null); - - Map requestHeaders = getRequestHeaders(options); - requestHeaders.put(HttpConstants.HttpHeaders.ACCEPT, RuntimeConstants.MediaTypes.JSON); - - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.ExecuteJavaScript, - ResourceType.StoredProcedure, path, - procedureParams != null ? RxDocumentClientImpl.serializeProcedureParams(procedureParams) : "", - requestHeaders, options); - - Observable reqObs = addPartitionKeyInformation(request, null, options).toObservable(); - return reqObs.flatMap(req -> create(request) - .map(response -> { - this.captureSessionToken(request, response); - return toStoredProcedureResponse(response); - })); - - } catch (Exception e) { - logger.debug("Failure in executing a StoredProcedure due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> createTrigger(String collectionLink, Trigger trigger, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> createTriggerInternal(collectionLink, trigger, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> createTriggerInternal(String collectionLink, Trigger trigger, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - - logger.debug("Creating a Trigger. collectionLink [{}], trigger id [{}]", collectionLink, - trigger.getId()); - RxDocumentServiceRequest request = getTriggerRequest(collectionLink, trigger, options, - OperationType.Create); - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.create(request).map(response -> toResourceResponse(response, Trigger.class)); - - } catch (Exception e) { - logger.debug("Failure in creating a Trigger due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> upsertTrigger(String collectionLink, Trigger trigger, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertTriggerInternal(collectionLink, trigger, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> upsertTriggerInternal(String collectionLink, Trigger trigger, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - - logger.debug("Upserting a Trigger. collectionLink [{}], trigger id [{}]", collectionLink, - trigger.getId()); - RxDocumentServiceRequest request = getTriggerRequest(collectionLink, trigger, options, - OperationType.Upsert); - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.upsert(request).map(response -> toResourceResponse(response, Trigger.class)); - - } catch (Exception e) { - logger.debug("Failure in upserting a Trigger due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - private RxDocumentServiceRequest getTriggerRequest(String collectionLink, Trigger trigger, RequestOptions options, - OperationType operationType) { - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - if (trigger == null) { - throw new IllegalArgumentException("trigger"); - } - - RxDocumentClientImpl.validateResource(trigger); - - String path = Utils.joinPath(collectionLink, Paths.TRIGGERS_PATH_SEGMENT); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, ResourceType.Trigger, path, - trigger, requestHeaders, options); - - return request; - } - - @Override - public Observable> replaceTrigger(Trigger trigger, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceTriggerInternal(trigger, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> replaceTriggerInternal(Trigger trigger, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (trigger == null) { - throw new IllegalArgumentException("trigger"); - } - - logger.debug("Replacing a Trigger. trigger id [{}]", trigger.getId()); - RxDocumentClientImpl.validateResource(trigger); - - String path = Utils.joinPath(trigger.getSelfLink(), null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.Trigger, path, trigger, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.replace(request).map(response -> toResourceResponse(response, Trigger.class)); - - } catch (Exception e) { - logger.debug("Failure in replacing a Trigger due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> deleteTrigger(String triggerLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteTriggerInternal(triggerLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deleteTriggerInternal(String triggerLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(triggerLink)) { - throw new IllegalArgumentException("triggerLink"); - } - - logger.debug("Deleting a Trigger. triggerLink [{}]", triggerLink); - String path = Utils.joinPath(triggerLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.Trigger, path, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, Trigger.class)); - - } catch (Exception e) { - logger.debug("Failure in deleting a Trigger due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readTrigger(String triggerLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readTriggerInternal(triggerLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readTriggerInternal(String triggerLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(triggerLink)) { - throw new IllegalArgumentException("triggerLink"); - } - - logger.debug("Reading a Trigger. triggerLink [{}]", triggerLink); - String path = Utils.joinPath(triggerLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.Trigger, path, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.read(request).map(response -> toResourceResponse(response, Trigger.class)); - - } catch (Exception e) { - logger.debug("Failure in reading a Trigger due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readTriggers(String collectionLink, FeedOptions options) { - - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - return readFeed(options, ResourceType.Trigger, Trigger.class, - Utils.joinPath(collectionLink, Paths.TRIGGERS_PATH_SEGMENT)); - } - - @Override - public Observable> queryTriggers(String collectionLink, String query, - FeedOptions options) { - return queryTriggers(collectionLink, new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryTriggers(String collectionLink, SqlQuerySpec querySpec, - FeedOptions options) { - return createQuery(collectionLink, querySpec, options, Trigger.class, ResourceType.Trigger); - } - - @Override - public Observable> createUserDefinedFunction(String collectionLink, - UserDefinedFunction udf, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> createUserDefinedFunctionInternal(collectionLink, udf, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> createUserDefinedFunctionInternal(String collectionLink, - UserDefinedFunction udf, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - logger.debug("Creating a UserDefinedFunction. collectionLink [{}], udf id [{}]", collectionLink, - udf.getId()); - RxDocumentServiceRequest request = getUserDefinedFunctionRequest(collectionLink, udf, options, - OperationType.Create); - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.create(request).map(response -> toResourceResponse(response, UserDefinedFunction.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in creating a UserDefinedFunction due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> upsertUserDefinedFunction(String collectionLink, - UserDefinedFunction udf, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertUserDefinedFunctionInternal(collectionLink, udf, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> upsertUserDefinedFunctionInternal(String collectionLink, - UserDefinedFunction udf, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - logger.debug("Upserting a UserDefinedFunction. collectionLink [{}], udf id [{}]", collectionLink, - udf.getId()); - RxDocumentServiceRequest request = getUserDefinedFunctionRequest(collectionLink, udf, options, - OperationType.Upsert); - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.upsert(request).map(response -> toResourceResponse(response, UserDefinedFunction.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in upserting a UserDefinedFunction due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> replaceUserDefinedFunction(UserDefinedFunction udf, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceUserDefinedFunctionInternal(udf, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> replaceUserDefinedFunctionInternal(UserDefinedFunction udf, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - if (udf == null) { - throw new IllegalArgumentException("udf"); - } - - logger.debug("Replacing a UserDefinedFunction. udf id [{}]", udf.getId()); - validateResource(udf); - - String path = Utils.joinPath(udf.getSelfLink(), null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.UserDefinedFunction, path, udf, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.replace(request).map(response -> toResourceResponse(response, UserDefinedFunction.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in replacing a UserDefinedFunction due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> deleteUserDefinedFunction(String udfLink, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteUserDefinedFunctionInternal(udfLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deleteUserDefinedFunctionInternal(String udfLink, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - if (StringUtils.isEmpty(udfLink)) { - throw new IllegalArgumentException("udfLink"); - } - - logger.debug("Deleting a UserDefinedFunction. udfLink [{}]", udfLink); - String path = Utils.joinPath(udfLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.UserDefinedFunction, path, requestHeaders, options); - - if (retryPolicyInstance != null){ - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, UserDefinedFunction.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in deleting a UserDefinedFunction due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readUserDefinedFunction(String udfLink, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readUserDefinedFunctionInternal(udfLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readUserDefinedFunctionInternal(String udfLink, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - // we are using an observable factory here - // observable will be created fresh upon subscription - // this is to ensure we capture most up to date information (e.g., - // session) - try { - if (StringUtils.isEmpty(udfLink)) { - throw new IllegalArgumentException("udfLink"); - } - - logger.debug("Reading a UserDefinedFunction. udfLink [{}]", udfLink); - String path = Utils.joinPath(udfLink, null); - Map requestHeaders = this.getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.UserDefinedFunction, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.read(request).map(response -> toResourceResponse(response, UserDefinedFunction.class)); - - } catch (Exception e) { - // this is only in trace level to capture what's going on - logger.debug("Failure in reading a UserDefinedFunction due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readUserDefinedFunctions(String collectionLink, - FeedOptions options) { - - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - return readFeed(options, ResourceType.UserDefinedFunction, UserDefinedFunction.class, - Utils.joinPath(collectionLink, Paths.USER_DEFINED_FUNCTIONS_PATH_SEGMENT)); - } - - @Override - public Observable> queryUserDefinedFunctions(String collectionLink, - String query, FeedOptions options) { - return queryUserDefinedFunctions(collectionLink, new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryUserDefinedFunctions(String collectionLink, - SqlQuerySpec querySpec, FeedOptions options) { - return createQuery(collectionLink, querySpec, options, UserDefinedFunction.class, ResourceType.UserDefinedFunction); - } - - - @Override - public Observable> createAttachment(String documentLink, Attachment attachment, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> createAttachmentInternal(documentLink, attachment, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> createAttachmentInternal(String documentLink, Attachment attachment, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - logger.debug("Creating a Attachment. documentLink [{}], attachment id [{}]", documentLink, - attachment.getId()); - Observable reqObs = getAttachmentRequest(documentLink, attachment, options, - OperationType.Create).toObservable(); - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(req); - } - - return create(req).map(response -> toResourceResponse(response, Attachment.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in creating a Attachment due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - - @Override - public Observable> upsertAttachment(String documentLink, Attachment attachment, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.retryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertAttachmentInternal(documentLink, attachment, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> upsertAttachmentInternal(String documentLink, Attachment attachment, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - logger.debug("Upserting a Attachment. documentLink [{}], attachment id [{}]", documentLink, - attachment.getId()); - Observable reqObs = getAttachmentRequest(documentLink, attachment, options, - OperationType.Upsert).toObservable(); - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(req); - } - - return upsert(req).map(response -> toResourceResponse(response, Attachment.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in upserting a Attachment due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> replaceAttachment(Attachment attachment, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceAttachmentInternal(attachment, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> replaceAttachmentInternal(Attachment attachment, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (attachment == null) { - throw new IllegalArgumentException("attachment"); - } - - logger.debug("Replacing a Attachment. attachment id [{}]", attachment.getId()); - RxDocumentClientImpl.validateResource(attachment); - - String path = Utils.joinPath(attachment.getSelfLink(), null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.Attachment, path, attachment, requestHeaders, options); - - Observable reqObs = addPartitionKeyInformation(request, null, options).toObservable(); - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return replace(request).map(response -> toResourceResponse(response, Attachment.class)); - }); - } catch (Exception e) { - logger.debug("Failure in replacing a Attachment due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> deleteAttachment(String attachmentLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteAttachmentInternal(attachmentLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deleteAttachmentInternal(String attachmentLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (StringUtils.isEmpty(attachmentLink)) { - throw new IllegalArgumentException("attachmentLink"); - } - - logger.debug("Deleting a Attachment. attachmentLink [{}]", attachmentLink); - String path = Utils.joinPath(attachmentLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.Attachment, path, requestHeaders, options); - - Observable reqObs = addPartitionKeyInformation(request, null, options).toObservable(); - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(req); - } - - return delete(req).map(resp -> toResourceResponse(resp, Attachment.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in deleting a Attachment due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readAttachment(String attachmentLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readAttachmentInternal(attachmentLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readAttachmentInternal(String attachmentLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (StringUtils.isEmpty(attachmentLink)) { - throw new IllegalArgumentException("attachmentLink"); - } - - logger.debug("Reading a Attachment. attachmentLink [{}]", attachmentLink); - String path = Utils.joinPath(attachmentLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.Attachment, path, requestHeaders, options); - - Observable reqObs = addPartitionKeyInformation(request, null, options).toObservable(); - - return reqObs.flatMap(req -> { - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return read(request).map(response -> toResourceResponse(response, Attachment.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in reading a Attachment due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readAttachments(String documentLink, FeedOptions options) { - - if (StringUtils.isEmpty(documentLink)) { - throw new IllegalArgumentException("documentLink"); - } - - return readFeedCollectionChild(options, ResourceType.Attachment, Attachment.class, - Utils.joinPath(documentLink, Paths.ATTACHMENTS_PATH_SEGMENT)); - } - - @Override - public Observable readMedia(String mediaLink) { - if (StringUtils.isEmpty(mediaLink)) { - throw new IllegalArgumentException("mediaLink"); - } - - String targetPath = Utils.joinPath(mediaLink, null); - return ObservableHelper.inlineIfPossibleAsObs(() -> readMediaInternal(targetPath), this.resetSessionTokenRetryPolicy.getRequestPolicy()); - } - - private Observable readMediaInternal(String mediaLink) { - logger.debug("Reading a Media. mediaLink [{}]", mediaLink); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, ResourceType.Media, mediaLink, (Map) null, null); - request.setIsMedia(true); - // Media is strong consistent always -> no need of session handling - populateHeaders(request, HttpConstants.HttpMethods.GET); - return gatewayProxy.processMessage(request).map(response -> - BridgeInternal.toMediaResponse(response, this.connectionPolicy.getMediaReadMode() == MediaReadMode.Buffered)); - } - - @Override - public Observable updateMedia(String mediaLink, InputStream mediaStream, MediaOptions options) { - if (StringUtils.isEmpty(mediaLink)) { - throw new IllegalArgumentException("mediaLink"); - } - if (mediaStream == null) { - throw new IllegalArgumentException("mediaStream"); - } - - String targetPath = Utils.joinPath(mediaLink, null); - return ObservableHelper.inlineIfPossibleAsObs(() -> updateMediaInternal(targetPath, mediaStream, options), this.resetSessionTokenRetryPolicy.getRequestPolicy()); - } - - private Observable updateMediaInternal(String mediaLink, InputStream mediaStream, MediaOptions options) { - logger.debug("Updating a Media. mediaLink [{}]", mediaLink); - Map requestHeaders = this.getMediaHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, ResourceType.Media, - mediaLink, - mediaStream, - requestHeaders); - request.setIsMedia(true); - - // Media is strong consistent always -> need of session handling - populateHeaders(request, HttpConstants.HttpMethods.PUT); - return gatewayProxy.processMessage(request).map(response -> - BridgeInternal.toMediaResponse(response, this.connectionPolicy.getMediaReadMode() == MediaReadMode.Buffered)); - } - - @Override - public Observable> queryAttachments(String documentLink, String query, - FeedOptions options) { - return queryAttachments(documentLink, new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryAttachments(String documentLink, SqlQuerySpec querySpec, - FeedOptions options) { - return createQuery(documentLink, querySpec, options, Attachment.class, ResourceType.Attachment); - } - - private Single getAttachmentRequest(String documentLink, Attachment attachment, - RequestOptions options, OperationType operationType) { - if (StringUtils.isEmpty(documentLink)) { - throw new IllegalArgumentException("documentLink"); - } - if (attachment == null) { - throw new IllegalArgumentException("attachment"); - } - - RxDocumentClientImpl.validateResource(attachment); - - String path = Utils.joinPath(documentLink, Paths.ATTACHMENTS_PATH_SEGMENT); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, ResourceType.Attachment, path, - attachment, requestHeaders, options); - - return addPartitionKeyInformation(request, null, options); - } - - @Override - public Observable> createAttachment(String documentLink, InputStream mediaStream, - MediaOptions options, RequestOptions requestOptions) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> createAttachmentInternal(documentLink, mediaStream, options, requestOptions, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> createAttachmentInternal(String documentLink, InputStream mediaStream, - MediaOptions options, RequestOptions requestOptions, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - logger.debug("Creating a Attachment. attachmentLink [{}]", documentLink); - Observable reqObs = getAttachmentRequest(documentLink, mediaStream, options, - requestOptions, OperationType.Create).toObservable(); - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(req); - } - - return create(req).map(response -> toResourceResponse(response, Attachment.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in creating a Attachment due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> upsertAttachment(String documentLink, InputStream mediaStream, - MediaOptions options, RequestOptions requestOptions) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertAttachmentInternal(documentLink, mediaStream, options, requestOptions, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> upsertAttachmentInternal(String documentLink, InputStream mediaStream, - MediaOptions options, RequestOptions requestOptions, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - logger.debug("Upserting a Attachment. attachmentLink [{}]", documentLink); - Observable reqObs = getAttachmentRequest(documentLink, mediaStream, options, - requestOptions, OperationType.Upsert).toObservable(); - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(req); - } - - return upsert(req).map(response -> toResourceResponse(response, Attachment.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in upserting a Attachment due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - private Single getAttachmentRequest(String documentLink, InputStream mediaStream, - MediaOptions options, RequestOptions requestOptions, OperationType operationType) { - if (StringUtils.isEmpty(documentLink)) { - throw new IllegalArgumentException("documentLink"); - } - if (mediaStream == null) { - throw new IllegalArgumentException("mediaStream"); - } - String path = Utils.joinPath(documentLink, Paths.ATTACHMENTS_PATH_SEGMENT); - Map requestHeaders = this.getMediaHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, ResourceType.Attachment, path, - mediaStream, requestHeaders); - request.setIsMedia(true); - return addPartitionKeyInformation(request, null, requestOptions); - } - - @Override - public Observable> readConflict(String conflictLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readConflictInternal(conflictLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readConflictInternal(String conflictLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (StringUtils.isEmpty(conflictLink)) { - throw new IllegalArgumentException("conflictLink"); - } - - logger.debug("Reading a Conflict. conflictLink [{}]", conflictLink); - String path = Utils.joinPath(conflictLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.Conflict, path, requestHeaders, options); - - Observable reqObs = addPartitionKeyInformation(request, null, options).toObservable(); - - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - return this.read(request).map(response -> toResourceResponse(response, Conflict.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in reading a Conflict due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readConflicts(String collectionLink, FeedOptions options) { - - if (StringUtils.isEmpty(collectionLink)) { - throw new IllegalArgumentException("collectionLink"); - } - - return readFeed(options, ResourceType.Conflict, Conflict.class, - Utils.joinPath(collectionLink, Paths.CONFLICTS_PATH_SEGMENT)); - } - - @Override - public Observable> queryConflicts(String collectionLink, String query, - FeedOptions options) { - return queryConflicts(collectionLink, new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryConflicts(String collectionLink, SqlQuerySpec querySpec, - FeedOptions options) { - return createQuery(collectionLink, querySpec, options, Conflict.class, ResourceType.Conflict); - } - - @Override - public Observable> deleteConflict(String conflictLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteConflictInternal(conflictLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deleteConflictInternal(String conflictLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (StringUtils.isEmpty(conflictLink)) { - throw new IllegalArgumentException("conflictLink"); - } - - logger.debug("Deleting a Conflict. conflictLink [{}]", conflictLink); - String path = Utils.joinPath(conflictLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.Conflict, path, requestHeaders, options); - - Observable reqObs = addPartitionKeyInformation(request, null, options).toObservable(); - return reqObs.flatMap(req -> { - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, Conflict.class)); - }); - - } catch (Exception e) { - logger.debug("Failure in deleting a Conflict due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> createUser(String databaseLink, User user, RequestOptions options) { - return ObservableHelper.inlineIfPossibleAsObs(() -> createUserInternal(databaseLink, user, options), this.resetSessionTokenRetryPolicy.getRequestPolicy()); - } - - private Observable> createUserInternal(String databaseLink, User user, RequestOptions options) { - try { - logger.debug("Creating a User. databaseLink [{}], user id [{}]", databaseLink, user.getId()); - RxDocumentServiceRequest request = getUserRequest(databaseLink, user, options, OperationType.Create); - return this.create(request).map(response -> toResourceResponse(response, User.class)); - - } catch (Exception e) { - logger.debug("Failure in creating a User due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> upsertUser(String databaseLink, User user, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertUserInternal(databaseLink, user, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> upsertUserInternal(String databaseLink, User user, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - try { - logger.debug("Upserting a User. databaseLink [{}], user id [{}]", databaseLink, user.getId()); - RxDocumentServiceRequest request = getUserRequest(databaseLink, user, options, OperationType.Upsert); - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.upsert(request).map(response -> toResourceResponse(response, User.class)); - - } catch (Exception e) { - logger.debug("Failure in upserting a User due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - private RxDocumentServiceRequest getUserRequest(String databaseLink, User user, RequestOptions options, - OperationType operationType) { - if (StringUtils.isEmpty(databaseLink)) { - throw new IllegalArgumentException("databaseLink"); - } - if (user == null) { - throw new IllegalArgumentException("user"); - } - - RxDocumentClientImpl.validateResource(user); - - String path = Utils.joinPath(databaseLink, Paths.USERS_PATH_SEGMENT); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, ResourceType.User, path, user, - requestHeaders, options); - - return request; - } - - @Override - public Observable> replaceUser(User user, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceUserInternal(user, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> replaceUserInternal(User user, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (user == null) { - throw new IllegalArgumentException("user"); - } - logger.debug("Replacing a User. user id [{}]", user.getId()); - RxDocumentClientImpl.validateResource(user); - - String path = Utils.joinPath(user.getSelfLink(), null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.User, path, user, requestHeaders, options); - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.replace(request).map(response -> toResourceResponse(response, User.class)); - - } catch (Exception e) { - logger.debug("Failure in replacing a User due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - - public Observable> deleteUser(String userLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deleteUserInternal(userLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deleteUserInternal(String userLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (StringUtils.isEmpty(userLink)) { - throw new IllegalArgumentException("userLink"); - } - logger.debug("Deleting a User. userLink [{}]", userLink); - String path = Utils.joinPath(userLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.User, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, User.class)); - - } catch (Exception e) { - logger.debug("Failure in deleting a User due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - @Override - public Observable> readUser(String userLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readUserInternal(userLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readUserInternal(String userLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(userLink)) { - throw new IllegalArgumentException("userLink"); - } - logger.debug("Reading a User. userLink [{}]", userLink); - String path = Utils.joinPath(userLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.User, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - return this.read(request).map(response -> toResourceResponse(response, User.class)); - - } catch (Exception e) { - logger.debug("Failure in reading a User due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readUsers(String databaseLink, FeedOptions options) { - - if (StringUtils.isEmpty(databaseLink)) { - throw new IllegalArgumentException("databaseLink"); - } - - return readFeed(options, ResourceType.User, User.class, - Utils.joinPath(databaseLink, Paths.USERS_PATH_SEGMENT)); - } - - @Override - public Observable> queryUsers(String databaseLink, String query, FeedOptions options) { - return queryUsers(databaseLink, new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryUsers(String databaseLink, SqlQuerySpec querySpec, - FeedOptions options) { - return createQuery(databaseLink, querySpec, options, User.class, ResourceType.User); - } - - @Override - public Observable> createPermission(String userLink, Permission permission, - RequestOptions options) { - return ObservableHelper.inlineIfPossibleAsObs(() -> createPermissionInternal(userLink, permission, options), this.resetSessionTokenRetryPolicy.getRequestPolicy()); - } - - private Observable> createPermissionInternal(String userLink, Permission permission, - RequestOptions options) { - - try { - logger.debug("Creating a Permission. userLink [{}], permission id [{}]", userLink, permission.getId()); - RxDocumentServiceRequest request = getPermissionRequest(userLink, permission, options, - OperationType.Create); - return this.create(request).map(response -> toResourceResponse(response, Permission.class)); - - } catch (Exception e) { - logger.debug("Failure in creating a Permission due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> upsertPermission(String userLink, Permission permission, - RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> upsertPermissionInternal(userLink, permission, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> upsertPermissionInternal(String userLink, Permission permission, - RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - logger.debug("Upserting a Permission. userLink [{}], permission id [{}]", userLink, permission.getId()); - RxDocumentServiceRequest request = getPermissionRequest(userLink, permission, options, - OperationType.Upsert); - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.upsert(request).map(response -> toResourceResponse(response, Permission.class)); - - } catch (Exception e) { - logger.debug("Failure in upserting a Permission due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - private RxDocumentServiceRequest getPermissionRequest(String userLink, Permission permission, - RequestOptions options, OperationType operationType) { - if (StringUtils.isEmpty(userLink)) { - throw new IllegalArgumentException("userLink"); - } - if (permission == null) { - throw new IllegalArgumentException("permission"); - } - - RxDocumentClientImpl.validateResource(permission); - - String path = Utils.joinPath(userLink, Paths.PERMISSIONS_PATH_SEGMENT); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(operationType, ResourceType.Permission, path, - permission, requestHeaders, options); - - return request; - } - - @Override - public Observable> replacePermission(Permission permission, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> replacePermissionInternal(permission, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> replacePermissionInternal(Permission permission, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (permission == null) { - throw new IllegalArgumentException("permission"); - } - logger.debug("Replacing a Permission. permission id [{}]", permission.getId()); - RxDocumentClientImpl.validateResource(permission); - - String path = Utils.joinPath(permission.getSelfLink(), null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.Permission, path, permission, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.replace(request).map(response -> toResourceResponse(response, Permission.class)); - - } catch (Exception e) { - logger.debug("Failure in replacing a Permission due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> deletePermission(String permissionLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> deletePermissionInternal(permissionLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> deletePermissionInternal(String permissionLink, RequestOptions options, - IDocumentClientRetryPolicy retryPolicyInstance) { - - try { - if (StringUtils.isEmpty(permissionLink)) { - throw new IllegalArgumentException("permissionLink"); - } - logger.debug("Deleting a Permission. permissionLink [{}]", permissionLink); - String path = Utils.joinPath(permissionLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Delete, - ResourceType.Permission, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.delete(request).map(response -> toResourceResponse(response, Permission.class)); - - } catch (Exception e) { - logger.debug("Failure in deleting a Permission due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readPermission(String permissionLink, RequestOptions options) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readPermissionInternal(permissionLink, options, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readPermissionInternal(String permissionLink, RequestOptions options, IDocumentClientRetryPolicy retryPolicyInstance ) { - try { - if (StringUtils.isEmpty(permissionLink)) { - throw new IllegalArgumentException("permissionLink"); - } - logger.debug("Reading a Permission. permissionLink [{}]", permissionLink); - String path = Utils.joinPath(permissionLink, null); - Map requestHeaders = getRequestHeaders(options); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.Permission, path, requestHeaders, options); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - return this.read(request).map(response -> toResourceResponse(response, Permission.class)); - - } catch (Exception e) { - logger.debug("Failure in reading a Permission due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readPermissions(String userLink, FeedOptions options) { - - if (StringUtils.isEmpty(userLink)) { - throw new IllegalArgumentException("userLink"); - } - - return readFeed(options, ResourceType.Permission, Permission.class, - Utils.joinPath(userLink, Paths.PERMISSIONS_PATH_SEGMENT)); - } - - @Override - public Observable> queryPermissions(String userLink, String query, - FeedOptions options) { - return queryPermissions(userLink, new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryPermissions(String userLink, SqlQuerySpec querySpec, - FeedOptions options) { - return createQuery(userLink, querySpec, options, Permission.class, ResourceType.Permission); - } - - @Override - public Observable> replaceOffer(Offer offer) { - return ObservableHelper.inlineIfPossibleAsObs(() -> replaceOfferInternal(offer), this.resetSessionTokenRetryPolicy.getRequestPolicy()); - } - - private Observable> replaceOfferInternal(Offer offer) { - try { - if (offer == null) { - throw new IllegalArgumentException("offer"); - } - logger.debug("Replacing an Offer. offer id [{}]", offer.getId()); - RxDocumentClientImpl.validateResource(offer); - - String path = Utils.joinPath(offer.getSelfLink(), null); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Replace, - ResourceType.Offer, path, offer, null, null); - return this.replace(request).map(response -> toResourceResponse(response, Offer.class)); - - } catch (Exception e) { - logger.debug("Failure in replacing an Offer due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readOffer(String offerLink) { - IDocumentClientRetryPolicy retryPolicyInstance = this.resetSessionTokenRetryPolicy.getRequestPolicy(); - return ObservableHelper.inlineIfPossibleAsObs(() -> readOfferInternal(offerLink, retryPolicyInstance), retryPolicyInstance); - } - - private Observable> readOfferInternal(String offerLink, IDocumentClientRetryPolicy retryPolicyInstance) { - try { - if (StringUtils.isEmpty(offerLink)) { - throw new IllegalArgumentException("offerLink"); - } - logger.debug("Reading an Offer. offerLink [{}]", offerLink); - String path = Utils.joinPath(offerLink, null); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.Offer, path, (HashMap)null, null); - - if (retryPolicyInstance != null) { - retryPolicyInstance.onBeforeSendRequest(request); - } - - return this.read(request).map(response -> toResourceResponse(response, Offer.class)); - - } catch (Exception e) { - logger.debug("Failure in reading an Offer due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - @Override - public Observable> readOffers(FeedOptions options) { - return readFeed(options, ResourceType.Offer, Offer.class, - Utils.joinPath(Paths.OFFERS_PATH_SEGMENT, null)); - } - - private Observable> readFeedCollectionChild(FeedOptions options, ResourceType resourceType, - Class klass, String resourceLink) { - if (options == null) { - options = new FeedOptions(); - } - - int maxPageSize = options.getMaxItemCount() != null ? options.getMaxItemCount() : -1; - - final FeedOptions finalFeedOptions = options; - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(options.getPartitionKey()); - Func2 createRequestFunc = (continuationToken, pageSize) -> { - Map requestHeaders = new HashMap<>(); - if (continuationToken != null) { - requestHeaders.put(HttpConstants.HttpHeaders.CONTINUATION, continuationToken); - } - requestHeaders.put(HttpConstants.HttpHeaders.PAGE_SIZE, Integer.toString(pageSize)); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.ReadFeed, - resourceType, resourceLink, requestHeaders, finalFeedOptions); - return request; - }; - - Func1>> executeFunc = request -> { - return ObservableHelper.inlineIfPossibleAsObs(() -> { - Single collectionObs = this.collectionCache.resolveCollectionAsync(request); - Single requestObs = this.addPartitionKeyInformation(request, null, requestOptions, collectionObs); - - return requestObs.toObservable().flatMap(req -> this.readFeed(req) - .map(response -> toFeedResponsePage(response, klass))); - }, this.resetSessionTokenRetryPolicy.getRequestPolicy()); - }; - - return Paginator.getPaginatedQueryResultAsObservable(options, createRequestFunc, executeFunc, klass, maxPageSize); - } - - private Observable> readFeed(FeedOptions options, ResourceType resourceType, Class klass, String resourceLink) { - if (options == null) { - options = new FeedOptions(); - } - - int maxPageSize = options.getMaxItemCount() != null ? options.getMaxItemCount() : -1; - final FeedOptions finalFeedOptions = options; - Func2 createRequestFunc = (continuationToken, pageSize) -> { - Map requestHeaders = new HashMap<>(); - if (continuationToken != null) { - requestHeaders.put(HttpConstants.HttpHeaders.CONTINUATION, continuationToken); - } - requestHeaders.put(HttpConstants.HttpHeaders.PAGE_SIZE, Integer.toString(pageSize)); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.ReadFeed, - resourceType, resourceLink, requestHeaders, finalFeedOptions); - return request; - }; - - Func1>> executeFunc = request -> { - return ObservableHelper.inlineIfPossibleAsObs(() -> readFeed(request).map(response -> toFeedResponsePage(response, klass)), - this.resetSessionTokenRetryPolicy.getRequestPolicy()); - }; - - return Paginator.getPaginatedQueryResultAsObservable(options, createRequestFunc, executeFunc, klass, maxPageSize); - } - - @Override - public Observable> queryOffers(String query, FeedOptions options) { - return queryOffers(new SqlQuerySpec(query), options); - } - - @Override - public Observable> queryOffers(SqlQuerySpec querySpec, FeedOptions options) { - return createQuery(null, querySpec, options, Offer.class, ResourceType.Offer); - } - - @Override - public Observable getDatabaseAccount() { - return ObservableHelper.inlineIfPossibleAsObs(() -> getDatabaseAccountInternal(), this.resetSessionTokenRetryPolicy.getRequestPolicy()); - } - - private Observable getDatabaseAccountInternal() { - try { - logger.debug("Getting Database Account"); - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.DatabaseAccount, "", // path - (HashMap) null, - null); - return this.read(request).map(response -> toDatabaseAccount(response)); - - } catch (Exception e) { - logger.debug("Failure in getting Database Account due to [{}]", e.getMessage(), e); - return Observable.error(e); - } - } - - public Object getSession() { - return this.sessionContainer; - } - - public void setSession(Object sessionContainer) { - this.sessionContainer = (SessionContainer) sessionContainer; - } - - public RxPartitionKeyRangeCache getPartitionKeyRangeCache() { - return partitionKeyRangeCache; - } - - public Observable getDatabaseAccountFromEndpoint(URI endpoint) { - return Observable.defer(() -> { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create(OperationType.Read, - ResourceType.DatabaseAccount, "", (HashMap) null, (Object) null); - this.populateHeaders(request, HttpConstants.HttpMethods.GET); - - request.setEndpointOverride(endpoint); - return this.gatewayProxy.processMessage(request).doOnError(e -> { - String message = String.format("Failed to retrieve database account information. %s", - e.getCause() != null - ? e.getCause().toString() - : e.toString()); - logger.warn(message); - }).map(rsp -> rsp.getResource(DatabaseAccount.class)) - .doOnNext(databaseAccount -> { - this.useMultipleWriteLocations = this.connectionPolicy.isUsingMultipleWriteLocations() - && BridgeInternal.isEnableMultipleWriteLocations(databaseAccount); - }); - }); - } - - /** - * Certain requests must be routed through gateway even when the client connectivity mode is direct. - * - * @param request - * @return RxStoreModel - */ - private RxStoreModel getStoreProxy(RxDocumentServiceRequest request) { - // If a request is configured to always use Gateway mode(in some cases when targeting .NET Core) - // we return the Gateway store model - if (request.UseGatewayMode) { - return this.gatewayProxy; - } - - ResourceType resourceType = request.getResourceType(); - OperationType operationType = request.getOperationType(); - - if (resourceType == ResourceType.Offer || - resourceType.isScript() && operationType != OperationType.ExecuteJavaScript || - resourceType == ResourceType.PartitionKeyRange) { - return this.gatewayProxy; - } - - if (operationType == OperationType.Create - || operationType == OperationType.Upsert) { - if (resourceType == ResourceType.Database || - resourceType == ResourceType.User || - resourceType == ResourceType.DocumentCollection || - resourceType == ResourceType.Permission) { - return this.gatewayProxy; - } else { - return this.storeModel; - } - } else if (operationType == OperationType.Delete) { - if (resourceType == ResourceType.Database || - resourceType == ResourceType.User || - resourceType == ResourceType.DocumentCollection) { - return this.gatewayProxy; - } else { - return this.storeModel; - } - } else if (operationType == OperationType.Replace) { - if (resourceType == ResourceType.DocumentCollection) { - return this.gatewayProxy; - } else { - return this.storeModel; - } - } else if (operationType == OperationType.Read) { - if (resourceType == ResourceType.DocumentCollection) { - return this.gatewayProxy; - } else { - return this.storeModel; - } - } else { - if ((request.getOperationType() == OperationType.Query || request.getOperationType() == OperationType.SqlQuery) && - Utils.isCollectionChild(request.getResourceType())) { - if (request.getPartitionKeyRangeIdentity() == null) { - return this.gatewayProxy; - } - } - - return this.storeModel; - } - } - - @Override - public void close() { - logger.info("Shutting down ..."); - LifeCycleUtils.closeQuietly(this.globalEndpointManager); - LifeCycleUtils.closeQuietly(this.storeClientFactory); - - try { - this.rxClient.shutdown(); - } catch (Exception e) { - logger.warn("Failure in shutting down rxClient", e); - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxPartitionKeyRangeCache.java b/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxPartitionKeyRangeCache.java deleted file mode 100644 index 1636b7ccd29f..000000000000 --- a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/caches/RxPartitionKeyRangeCache.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.caches; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.internal.routing.IServerIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.NotFoundException; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.InMemoryCollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.internal.Exceptions; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.Utils; - -import rx.Observable; -import rx.Single; - -/** - * While this class is public, but it is not part of our published public APIs. - * This is meant to be internally used only by our sdk. - **/ -public class RxPartitionKeyRangeCache implements IPartitionKeyRangeCache { - private final Logger logger = LoggerFactory.getLogger(RxPartitionKeyRangeCache.class); - - private final AsyncCache routingMapCache; - private final AsyncDocumentClient client; - private final RxCollectionCache collectionCache; - - public RxPartitionKeyRangeCache(AsyncDocumentClient client, RxCollectionCache collectionCache) { - this.routingMapCache = new AsyncCache<>(); - this.client = client; - this.collectionCache = collectionCache; - } - - /* (non-Javadoc) - * @see com.microsoft.azure.cosmosdb.rx.internal.caches.IPartitionKeyRangeCache#tryLookupAsync(java.lang.String, com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap) - */ - @Override - public Single tryLookupAsync(String collectionRid, CollectionRoutingMap previousValue, Map properties) { - return routingMapCache.getAsync( - collectionRid, - previousValue, - () -> getRoutingMapForCollectionAsync(collectionRid, previousValue, properties)) - .onErrorResumeNext(err -> { - logger.debug("tryLookupAsync on collectionRid {} encountered failure", collectionRid, err); - DocumentClientException dce = Utils.as(err, DocumentClientException.class); - if (dce != null && Exceptions.isStatusCode(dce, HttpConstants.StatusCodes.NOTFOUND)) { - return Single.just(null); - } - - return Single.error(err); - }); - } - - @Override - public Single tryLookupAsync(String collectionRid, CollectionRoutingMap previousValue, boolean forceRefreshCollectionRoutingMap, - Map properties) { - return tryLookupAsync(collectionRid, previousValue, properties); - } - - /* (non-Javadoc) - * @see com.microsoft.azure.cosmosdb.rx.internal.caches.IPartitionKeyRangeCache#tryGetOverlappingRangesAsync(java.lang.String, com.microsoft.azure.cosmosdb.internal.routing.Range, boolean) - */ - @Override - public Single> tryGetOverlappingRangesAsync(String collectionRid, Range range, boolean forceRefresh, - Map properties) { - - Single routingMapObs = tryLookupAsync(collectionRid, null, properties); - - return routingMapObs.flatMap(routingMap -> { - if (forceRefresh && routingMap != null) { - logger.debug("tryGetOverlappingRangesAsync with forceRefresh on collectionRid {}", collectionRid); - return tryLookupAsync(collectionRid, routingMap, properties); - } - - return Single.just(routingMap); - - }).map(routingMap -> { - if (routingMap != null) { - // TODO: the routingMap.getOverlappingRanges(range) returns Collection - // maybe we should consider changing to ArrayList to avoid conversion - return new ArrayList<>(routingMap.getOverlappingRanges(range)); - } else { - logger.debug("Routing Map Null for collection: {} for range: {}, forceRefresh:{}", collectionRid, range.toString(), forceRefresh); - return null; - } - }); - } - - /* (non-Javadoc) - * @see com.microsoft.azure.cosmosdb.rx.internal.caches.IPartitionKeyRangeCache#tryGetPartitionKeyRangeByIdAsync(java.lang.String, java.lang.String, boolean) - */ - @Override - public Single tryGetPartitionKeyRangeByIdAsync(String collectionResourceId, String partitionKeyRangeId, - boolean forceRefresh, Map properties) { - - Single routingMapObs = tryLookupAsync(collectionResourceId, null, properties); - - return routingMapObs.flatMap(routingMap -> { - if (forceRefresh && routingMap != null) { - return tryLookupAsync(collectionResourceId, routingMap, properties); - } - - return Single.just(routingMap); - - }).map(routingMap -> { - if (routingMap != null) { - return routingMap.getRangeByPartitionKeyRangeId(partitionKeyRangeId); - } else { - logger.debug("Routing Map Null for collection: {}, PartitionKeyRangeId: {}, forceRefresh:{}", collectionResourceId, partitionKeyRangeId, forceRefresh); - return null; - } - }); - } - - /* (non-Javadoc) - * @see com.microsoft.azure.cosmosdb.rx.internal.caches.IPartitionKeyRangeCache#tryGetRangeByPartitionKeyRangeId(java.lang.String, java.lang.String) - */ - @Override - public Single tryGetRangeByPartitionKeyRangeId(String collectionRid, String partitionKeyRangeId, Map properties) { - Single routingMapObs = routingMapCache.getAsync( - collectionRid, - null, - () -> getRoutingMapForCollectionAsync(collectionRid, null, properties)); - - return routingMapObs.map(routingMap -> routingMap.getRangeByPartitionKeyRangeId(partitionKeyRangeId)) - .onErrorResumeNext(err -> { - DocumentClientException dce = Utils.as(err, DocumentClientException.class); - logger.debug("tryGetRangeByPartitionKeyRangeId on collectionRid {} and partitionKeyRangeId {} encountered failure", - collectionRid, partitionKeyRangeId, err); - - if (dce != null && Exceptions.isStatusCode(dce, HttpConstants.StatusCodes.NOTFOUND)) { - return Single.just(null); - } - - return Single.error(dce); - }); - } - - private Single getRoutingMapForCollectionAsync( - String collectionRid, - CollectionRoutingMap previousRoutingMap, - Map properties) { - - // TODO: NOTE: main java code doesn't do anything in regard to the previous routing map - // .Net code instead of using DocumentClient controls sending request and receiving requests here - - // here we stick to what main java sdk does, investigate later. - - Single> rangesObs = getPartitionKeyRange(collectionRid, false, properties); - - return rangesObs.flatMap(ranges -> { - - List> rangesTuples = - ranges.stream().map(range -> new ImmutablePair<>(range, (IServerIdentity) null)).collect(Collectors.toList()); - - - CollectionRoutingMap routingMap; - if (previousRoutingMap == null) - { - // Splits could have happened during change feed query and we might have a mix of gone and new ranges. - Set goneRanges = new HashSet<>(ranges.stream().flatMap(range -> CollectionUtils.emptyIfNull(range.getParents()).stream()).collect(Collectors.toSet())); - - routingMap = InMemoryCollectionRoutingMap.tryCreateCompleteRoutingMap( - rangesTuples.stream().filter(tuple -> !goneRanges.contains(tuple.left.getId())).collect(Collectors.toList()), - collectionRid); - } - else - { - routingMap = previousRoutingMap.tryCombine(rangesTuples); - } - - if (routingMap == null) - { - // Range information either doesn't exist or is not complete. - return Single.error(new NotFoundException(String.format("GetRoutingMapForCollectionAsync(collectionRid: {%s}), Range information either doesn't exist or is not complete.", collectionRid))); - } - - return Single.just(routingMap); - }); - } - - private Single> getPartitionKeyRange(String collectionRid, boolean forceRefresh, Map properties) { - RxDocumentServiceRequest request = RxDocumentServiceRequest.create( - OperationType.ReadFeed, - collectionRid, - ResourceType.PartitionKeyRange, - null - ); //this request doesn't actually go to server - - request.requestContext.resolvedCollectionRid = collectionRid; - Single collectionObs = collectionCache.resolveCollectionAsync(request); - - return collectionObs.flatMap(coll -> { - - FeedOptions feedOptions = new FeedOptions(); - if (properties != null) { - feedOptions.setProperties(properties); - } - Observable> rs = client.readPartitionKeyRanges(coll.getSelfLink(), feedOptions) - // maxConcurrent = 1 to makes it in the right order - .flatMap(p -> Observable.from(p.getResults()), 1).toList(); - return rs.toSingle(); - }); - } -} - diff --git a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/GlobalAddressResolver.java b/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/GlobalAddressResolver.java deleted file mode 100644 index 2299c4a04d31..000000000000 --- a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/GlobalAddressResolver.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.directconnectivity; - - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.AddressInformation; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.AddressResolver; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GatewayAddressCache; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GatewayServiceConfigurationReader; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.IAddressResolver; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.GlobalEndpointManager; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxPartitionKeyRangeCache; -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import rx.Completable; -import rx.Single; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Queue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -public class GlobalAddressResolver implements IAddressResolver { - private final static int MaxBackupReadRegions = 3; - private final GlobalEndpointManager endpointManager; - private final Protocol protocol; - private final IAuthorizationTokenProvider tokenProvider; - private final UserAgentContainer userAgentContainer; - private final RxCollectionCache collectionCache; - private final RxPartitionKeyRangeCache routingMapProvider; - private final int maxEndpoints; - private final GatewayServiceConfigurationReader serviceConfigReader; - final Map addressCacheByEndpoint; - - private GatewayAddressCache gatewayAddressCache; - private AddressResolver addressResolver; - private CompositeHttpClient httpClient; - - public GlobalAddressResolver( - CompositeHttpClient httpClient, - GlobalEndpointManager endpointManager, - Protocol protocol, - IAuthorizationTokenProvider tokenProvider, - RxCollectionCache collectionCache, - RxPartitionKeyRangeCache routingMapProvider, - UserAgentContainer userAgentContainer, - GatewayServiceConfigurationReader serviceConfigReader, - ConnectionPolicy connectionPolicy) { - - this.httpClient = httpClient; - this.endpointManager = endpointManager; - this.protocol = protocol; - this.tokenProvider = tokenProvider; - this.userAgentContainer = userAgentContainer; - this.collectionCache = collectionCache; - this.routingMapProvider = routingMapProvider; - this.serviceConfigReader = serviceConfigReader; - - int maxBackupReadEndpoints = (connectionPolicy.isEnableReadRequestsFallback() == null || connectionPolicy.isEnableReadRequestsFallback()) ? GlobalAddressResolver.MaxBackupReadRegions : 0; - this.maxEndpoints = maxBackupReadEndpoints + 2; // for write and alternate write endpoint (during failover) - this.addressCacheByEndpoint = new ConcurrentHashMap<>(); - - for (URL endpoint : endpointManager.getWriteEndpoints()) { - this.getOrAddEndpoint(endpoint); - } - for (URL endpoint : endpointManager.getReadEndpoints()) { - this.getOrAddEndpoint(endpoint); - } - } - - Completable openAsync(DocumentCollection collection) { - Single routingMap = this.routingMapProvider.tryLookupAsync(collection.getId(), null, null); - return routingMap.flatMapCompletable(collectionRoutingMap -> { - if (collectionRoutingMap == null) { - return Completable.complete(); - } - - List ranges = ((List)collectionRoutingMap.getOrderedPartitionKeyRanges()).stream().map(range -> - new PartitionKeyRangeIdentity(collection.getResourceId(), range.getId())).collect(Collectors.toList()); - List tasks = new ArrayList<>(); - for (EndpointCache endpointCache : this.addressCacheByEndpoint.values()) { - tasks.add(endpointCache.addressCache.openAsync(collection, ranges)); - } - return Completable.mergeDelayError(tasks); - }); - } - - @Override - public Single resolveAsync(RxDocumentServiceRequest request, boolean forceRefresh) { - IAddressResolver resolver = this.getAddressResolver(request); - return resolver.resolveAsync(request, forceRefresh); - } - - public void dispose() { - for (EndpointCache endpointCache : this.addressCacheByEndpoint.values()) { - endpointCache.addressCache.dispose(); - } - } - - private IAddressResolver getAddressResolver(RxDocumentServiceRequest rxDocumentServiceRequest) { - URL endpoint = this.endpointManager.resolveServiceEndpoint(rxDocumentServiceRequest); - return this.getOrAddEndpoint(endpoint).addressResolver; - } - - private EndpointCache getOrAddEndpoint(URL endpoint) { - EndpointCache endpointCache = this.addressCacheByEndpoint.computeIfAbsent(endpoint , key -> { - GatewayAddressCache gatewayAddressCache = new GatewayAddressCache(endpoint, protocol, this.tokenProvider, this.userAgentContainer, this.httpClient); - AddressResolver addressResolver = new AddressResolver(); - addressResolver.initializeCaches(this.collectionCache, this.routingMapProvider, gatewayAddressCache); - EndpointCache cache = new EndpointCache(); - cache.addressCache = gatewayAddressCache; - cache.addressResolver = addressResolver; - return cache; - }); - - if (this.addressCacheByEndpoint.size() > this.maxEndpoints) { - List allEndpoints = new ArrayList(this.endpointManager.getWriteEndpoints()); - allEndpoints.addAll(this.endpointManager.getReadEndpoints()); - Collections.reverse(allEndpoints); - Queue endpoints = new LinkedList<>(allEndpoints); - while (this.addressCacheByEndpoint.size() > this.maxEndpoints) { - if (endpoints.size() > 0) { - URL dequeueEnpoint = ((LinkedList) endpoints).pop(); - if (this.addressCacheByEndpoint.get(dequeueEnpoint) != null) { - this.addressCacheByEndpoint.remove(dequeueEnpoint); - } - } else { - break; - } - } - } - return endpointCache; - } - - static class EndpointCache { - GatewayAddressCache addressCache; - AddressResolver addressResolver; - } -} diff --git a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/package-info.java b/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/package-info.java deleted file mode 100644 index 2a008122642e..000000000000 --- a/cosmosdb/data-plane/sdk/src/main/java/com/microsoft/azure/cosmosdb/rx/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -/** - * This package provides Rx interfaces for interacting with Azure Cosmos DB. - */ -package com.microsoft.azure.cosmosdb.rx; \ No newline at end of file diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressValidator.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressValidator.java deleted file mode 100644 index bb19bcfbe40b..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/AddressValidator.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import org.assertj.core.api.Condition; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This is a helper class for validating a partition address for tests. - */ -public interface AddressValidator { - - void validate(Address address); - - class Builder { - private List validators = new ArrayList<>(); - - public AddressValidator build() { - return new AddressValidator() { - - @Override - public void validate(Address address) { - for (AddressValidator validator : validators) { - validator.validate(address); - } - } - }; - } - - public Builder withId(final String resourceId) { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - assertThat(address.getId()).as("check Resource Id").isEqualTo(resourceId); - } - }); - return this; - } - - - - public Builder withProperty(String propertyName, Condition validatingCondition) { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - assertThat(address.get(propertyName)).is(validatingCondition); - - } - }); - return this; - } - - public Builder withProperty(String propertyName, Object value) { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - assertThat(address.get(propertyName)).isEqualTo(value); - - } - }); - return this; - } - - public Builder isPrimary(boolean isPrimary) { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - assertThat(address.IsPrimary()).isTrue(); - } - }); - return this; - } - - public Builder httpsProtocol() { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - assertThat(address.getProtocolScheme()).isEqualTo("https"); - } - }); - return this; - } - - public Builder protocol(Protocol protocol) { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - if (protocol == Protocol.Https) { - assertThat(address.getProtocolScheme()).isEqualTo("https"); - } else if (protocol == Protocol.Tcp){ - assertThat(address.getProtocolScheme()).isEqualTo("rntbd"); - } - } - }); - return this; - } - - public Builder withRid(String rid) { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - assertThat(address.getResourceId()).isEqualTo(rid); - } - }); - return this; - } - - public Builder withPartitionKeyRangeId(String partitionKeyRangeId) { - validators.add(new AddressValidator() { - - @Override - public void validate(Address address) { - assertThat(address.getParitionKeyRangeId()).isEqualTo(partitionKeyRangeId); - } - }); - return this; - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/BarrierRequestHelperTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/BarrierRequestHelperTest.java deleted file mode 100644 index 57f6a4f79d0e..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/BarrierRequestHelperTest.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientImpl; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import java.util.Map; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Fail.fail; - -public class BarrierRequestHelperTest { - @Test(groups = "direct") - public void barrierBasic() { - IAuthorizationTokenProvider authTokenProvider = getIAuthorizationTokenProvider(); - - for (ResourceType resourceType : ResourceType.values()) { - - for (OperationType operationType : OperationType.values()) { - Document randomResource = new Document(); - randomResource.setId(UUID.randomUUID().toString()); - RxDocumentServiceRequest request = - RxDocumentServiceRequest.create(operationType, resourceType, "/dbs/7mVFAA==/colls/7mVFAP1jpeU=", randomResource, (Map) null); - - BarrierRequestHelper.createAsync(request, authTokenProvider, 10l, 10l).toCompletable().await(); - request = - RxDocumentServiceRequest.create(operationType, resourceType, "/dbs/7mVFAA==", randomResource, null); - - request.setResourceId("3"); - try { - BarrierRequestHelper.createAsync(request, authTokenProvider, 10l, 10l).toCompletable().await(); - } catch (Exception e) { - if (!BarrierRequestHelper.isCollectionHeadBarrierRequest(resourceType, operationType)) { - fail("Should not fail for non-collection head combinations"); - } - } - } - } - } - - @Test(groups = "direct") - public void barrierDBFeed() { - IAuthorizationTokenProvider authTokenProvider = getIAuthorizationTokenProvider(); - - ResourceType resourceType = ResourceType.DocumentCollection; - OperationType operationType = OperationType.Query; - - Document randomResource = new Document(); - randomResource.setId(UUID.randomUUID().toString()); - RxDocumentServiceRequest request = - RxDocumentServiceRequest.create(operationType, resourceType, "/dbs/7mVFAA==/colls/7mVFAP1jpeU=", randomResource, (Map) null); - - RxDocumentServiceRequest barrierRequest = BarrierRequestHelper.createAsync(request, authTokenProvider, 11l, 10l).toBlocking().value(); - - assertThat(barrierRequest.getOperationType()).isEqualTo(OperationType.HeadFeed); - assertThat(barrierRequest.getResourceType()).isEqualTo(ResourceType.Database); - - - assertThat(getTargetGlobalLsn(barrierRequest)).isEqualTo(10l); - assertThat(getTargetLsn(barrierRequest)).isEqualTo(11l); - } - - @Test(groups = "direct") - public void barrierDocumentQueryNameBasedRequest() { - IAuthorizationTokenProvider authTokenProvider = getIAuthorizationTokenProvider(); - - ResourceType resourceType = ResourceType.Document; - OperationType operationType = OperationType.Query; - - Document randomResource = new Document(); - randomResource.setId(UUID.randomUUID().toString()); - RxDocumentServiceRequest request = - RxDocumentServiceRequest.create(operationType, resourceType, "/dbs/dbname/colls/collname", randomResource, (Map) null); - - RxDocumentServiceRequest barrierRequest = BarrierRequestHelper.createAsync(request, authTokenProvider, 11l, 10l).toBlocking().value(); - - assertThat(barrierRequest.getOperationType()).isEqualTo(OperationType.Head); - assertThat(barrierRequest.getResourceType()).isEqualTo(ResourceType.DocumentCollection); - assertThat(barrierRequest.getResourceAddress()).isEqualTo("dbs/dbname/colls/collname"); - - assertThat(getTargetGlobalLsn(barrierRequest)).isEqualTo(10l); - assertThat(getTargetLsn(barrierRequest)).isEqualTo(11l); - } - - @Test(groups = "direct") - public void barrierDocumentReadNameBasedRequest() { - IAuthorizationTokenProvider authTokenProvider = getIAuthorizationTokenProvider(); - - ResourceType resourceType = ResourceType.Document; - OperationType operationType = OperationType.Read; - - Document randomResource = new Document(); - randomResource.setId(UUID.randomUUID().toString()); - RxDocumentServiceRequest request = - RxDocumentServiceRequest.create(operationType, resourceType, "/dbs/dbname/colls/collname", randomResource, (Map) null); - - RxDocumentServiceRequest barrierRequest = BarrierRequestHelper.createAsync(request, authTokenProvider, 11l, 10l).toBlocking().value(); - - assertThat(barrierRequest.getOperationType()).isEqualTo(OperationType.Head); - assertThat(barrierRequest.getResourceType()).isEqualTo(ResourceType.DocumentCollection); - assertThat(barrierRequest.getResourceAddress()).isEqualTo("dbs/dbname/colls/collname"); - - assertThat(getTargetGlobalLsn(barrierRequest)).isEqualTo(10l); - assertThat(getTargetLsn(barrierRequest)).isEqualTo(11l); - assertThat(barrierRequest.getIsNameBased()).isEqualTo(true); - - } - - @Test(groups = "direct") - public void barrierDocumentReadRidBasedRequest() { - IAuthorizationTokenProvider authTokenProvider = getIAuthorizationTokenProvider(); - - ResourceType resourceType = ResourceType.Document; - OperationType operationType = OperationType.Read; - - Document randomResource = new Document(); - randomResource.setId(UUID.randomUUID().toString()); - RxDocumentServiceRequest request = - RxDocumentServiceRequest.create(operationType, "7mVFAA==", resourceType, (Map) null); - - RxDocumentServiceRequest barrierRequest = BarrierRequestHelper.createAsync(request, authTokenProvider, 11l, 10l).toBlocking().value(); - - assertThat(barrierRequest.getOperationType()).isEqualTo(OperationType.Head); - assertThat(barrierRequest.getResourceType()).isEqualTo(ResourceType.DocumentCollection); - assertThat(barrierRequest.getResourceAddress()).isEqualTo("7mVFAA=="); - - assertThat(getTargetGlobalLsn(barrierRequest)).isEqualTo(10l); - assertThat(getTargetLsn(barrierRequest)).isEqualTo(11l); - assertThat(barrierRequest.getIsNameBased()).isEqualTo(false); - } - - @DataProvider(name = "isCollectionHeadBarrierRequestArgProvider") - public Object[][] isCollectionHeadBarrierRequestArgProvider() { - return new Object[][]{ - // resourceType, operationType, isCollectionHeadBarrierRequest - - {ResourceType.Attachment, null, true}, - {ResourceType.Document, null, true}, - {ResourceType.Conflict, null, true}, - {ResourceType.StoredProcedure, null, true}, - {ResourceType.Attachment, null, true}, - {ResourceType.Trigger, null, true}, - - {ResourceType.DocumentCollection, OperationType.ReadFeed, false}, - {ResourceType.DocumentCollection, OperationType.Query, false}, - {ResourceType.DocumentCollection, OperationType.SqlQuery, false}, - - {ResourceType.DocumentCollection, OperationType.Create, true}, - {ResourceType.DocumentCollection, OperationType.Read, true}, - {ResourceType.DocumentCollection, OperationType.Replace, true}, - {ResourceType.DocumentCollection, OperationType.ExecuteJavaScript, true}, - - {ResourceType.PartitionKeyRange, null, false}, - }; - } - - @Test(groups = "direct", dataProvider = "isCollectionHeadBarrierRequestArgProvider") - public void isCollectionHeadBarrierRequest(ResourceType resourceType, - OperationType operationType, - boolean expectedResult) { - if (operationType != null) { - boolean actual = BarrierRequestHelper.isCollectionHeadBarrierRequest(resourceType, operationType); - assertThat(actual).isEqualTo(expectedResult); - } else { - for (OperationType type : OperationType.values()) { - boolean actual = BarrierRequestHelper.isCollectionHeadBarrierRequest(resourceType, type); - assertThat(actual).isEqualTo(expectedResult); - } - } - } - - private IAuthorizationTokenProvider getIAuthorizationTokenProvider() { - return (RxDocumentClientImpl) - new AsyncDocumentClient.Builder() - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withServiceEndpoint(TestConfigurations.HOST) - .build(); - } - - private String getHeaderValue(RxDocumentServiceRequest req, String name) { - return req.getHeaders().get(name); - } - - private String getPartitionKey(RxDocumentServiceRequest req) { - return getHeaderValue(req, HttpConstants.HttpHeaders.PARTITION_KEY); - } - - private String getCollectionRid(RxDocumentServiceRequest req) { - return getHeaderValue(req, WFConstants.BackendHeaders.COLLECTION_RID); - } - - private PartitionKeyRangeIdentity getPartitionKeyRangeIdentity(RxDocumentServiceRequest req) { - return req.getPartitionKeyRangeIdentity(); - } - - private Long getTargetLsn(RxDocumentServiceRequest req) { - return Long.parseLong(getHeaderValue(req, HttpConstants.HttpHeaders.TARGET_LSN)); - } - - private Long getTargetGlobalLsn(RxDocumentServiceRequest req) { - return Long.parseLong(getHeaderValue(req, HttpConstants.HttpHeaders.TARGET_GLOBAL_COMMITTED_LSN)); - } -} - diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayAddressCacheTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayAddressCacheTest.java deleted file mode 100644 index 54d581f42615..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayAddressCacheTest.java +++ /dev/null @@ -1,880 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.microsoft.azure.cosmosdb.ConfigsBuilder; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.HttpClientFactory; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientImpl; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Single; -import rx.observers.TestSubscriber; - -import java.net.URL; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -public class GatewayAddressCacheTest extends TestSuiteBase { - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public GatewayAddressCacheTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @DataProvider(name = "targetPartitionsKeyRangeListAndCollectionLinkParams") - public Object[][] partitionsKeyRangeListAndCollectionLinkParams() { - return new Object[][] { - // target partition key range ids, collection link - { ImmutableList.of("0"), getNameBasedCollectionLink(), Protocol.Tcp }, - { ImmutableList.of("0"), getNameBasedCollectionLink(), Protocol.Https }, - - { ImmutableList.of("1"), getNameBasedCollectionLink(), Protocol.Https }, - { ImmutableList.of("1"), getCollectionSelfLink(), Protocol.Https }, - { ImmutableList.of("3"), getNameBasedCollectionLink(), Protocol.Https }, - - { ImmutableList.of("0", "1"), getNameBasedCollectionLink(), Protocol.Https }, - { ImmutableList.of("1", "3"), getNameBasedCollectionLink(), Protocol.Https }, - }; - } - - @DataProvider(name = "protocolProvider") - public Object[][] protocolProvider() { - return new Object[][]{ - { Protocol.Https }, - { Protocol.Tcp }, - }; - } - - @Test(groups = { "direct" }, dataProvider = "targetPartitionsKeyRangeListAndCollectionLinkParams", timeOut = TIMEOUT) - public void getServerAddressesViaGateway(List partitionKeyRangeIds, - String collectionLink, - Protocol protocol) throws Exception { - Configs configs = ConfigsBuilder.instance().withProtocol(protocol).build(); - // ask gateway for the addresses - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - protocol, - authorizationTokenProvider, - null, - getCompositeHttpClient(configs)); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document, - collectionLink + "/docs/", - getDocumentDefinition(), new HashMap<>()); - - Single> addresses = cache.getServerAddressesViaGatewayAsync( - req, createdCollection.getResourceId(), partitionKeyRangeIds, false); - - PartitionReplicasAddressesValidator validator = new PartitionReplicasAddressesValidator.Builder() - .withProtocol(protocol) - .replicasOfPartitions(partitionKeyRangeIds) - .build(); - - validateSuccess(addresses, validator, TIMEOUT); - } - - @Test(groups = { "direct" }, dataProvider = "protocolProvider", timeOut = TIMEOUT) - public void getMasterAddressesViaGatewayAsync(Protocol protocol) throws Exception { - Configs configs = ConfigsBuilder.instance().withProtocol(protocol).build(); - // ask gateway for the addresses - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - protocol, - authorizationTokenProvider, - null, - getCompositeHttpClient(configs)); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Database, - "/dbs", - new Database(), new HashMap<>()); - - Single> addresses = cache.getMasterAddressesViaGatewayAsync(req, ResourceType.Database, - null, "/dbs/", false, false, null); - - PartitionReplicasAddressesValidator validator = new PartitionReplicasAddressesValidator.Builder() - .withProtocol(protocol) - .replicasOfSamePartition() - .build(); - - validateSuccess(addresses, validator, TIMEOUT); - } - - @DataProvider(name = "targetPartitionsKeyRangeAndCollectionLinkParams") - public Object[][] partitionsKeyRangeAndCollectionLinkParams() { - return new Object[][] { - // target partition key range ids, collection link, protocol - { "0", getNameBasedCollectionLink(), Protocol.Tcp }, - { "0", getNameBasedCollectionLink(), Protocol.Https }, - - { "1", getNameBasedCollectionLink(), Protocol.Https} , - { "1", getCollectionSelfLink(), Protocol.Https }, - { "3", getNameBasedCollectionLink(), Protocol.Https }, - }; - } - - @Test(groups = { "direct" }, dataProvider = "targetPartitionsKeyRangeAndCollectionLinkParams", timeOut = TIMEOUT) - public void tryGetAddresses_ForDataPartitions(String partitionKeyRangeId, String collectionLink, Protocol protocol) throws Exception { - Configs configs = ConfigsBuilder.instance().withProtocol(protocol).build(); - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - protocol, - authorizationTokenProvider, - null, - getCompositeHttpClient(configs)); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document, - collectionLink, - new Database(), new HashMap<>()); - - String collectionRid = createdCollection.getResourceId(); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity(collectionRid, partitionKeyRangeId); - boolean forceRefreshPartitionAddresses = false; - Single addressesInfosFromCacheObs = cache.tryGetAddresses(req, partitionKeyRangeIdentity, forceRefreshPartitionAddresses); - - ArrayList addressInfosFromCache = Lists.newArrayList(getSuccessResult(addressesInfosFromCacheObs, TIMEOUT)); - - Single> masterAddressFromGatewayObs = cache.getServerAddressesViaGatewayAsync(req, - collectionRid, ImmutableList.of(partitionKeyRangeId), false); - List
expectedAddresses = getSuccessResult(masterAddressFromGatewayObs, TIMEOUT); - - assertSameAs(addressInfosFromCache, expectedAddresses); - } - - @DataProvider(name = "openAsyncTargetAndTargetPartitionsKeyRangeAndCollectionLinkParams") - public Object[][] openAsyncTargetAndPartitionsKeyRangeTargetAndCollectionLinkParams() { - return new Object[][] { - // openAsync target partition key range ids, target partition key range id, collection link - { ImmutableList.of("0", "1"), "0", getNameBasedCollectionLink() }, - { ImmutableList.of("0", "1"), "1", getNameBasedCollectionLink() }, - { ImmutableList.of("0", "1"), "1", getCollectionSelfLink() }, - }; - } - - @Test(groups = { "direct" }, - dataProvider = "openAsyncTargetAndTargetPartitionsKeyRangeAndCollectionLinkParams", - timeOut = TIMEOUT) - public void tryGetAddresses_ForDataPartitions_AddressCachedByOpenAsync_NoHttpRequest( - List allPartitionKeyRangeIds, - String partitionKeyRangeId, String collectionLink) throws Exception { - Configs configs = new Configs(); - HttpClientUnderTestWrapper httpClientWrapper = getHttpClientUnderTestWrapper(configs); - - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - Protocol.Https, - authorizationTokenProvider, - null, - httpClientWrapper.getSpyHttpClient()); - - String collectionRid = createdCollection.getResourceId(); - - List pkriList = allPartitionKeyRangeIds.stream().map( - pkri -> new PartitionKeyRangeIdentity(collectionRid, pkri)).collect(Collectors.toList()); - - cache.openAsync(createdCollection, pkriList).await(); - - assertThat(httpClientWrapper.capturedRequest).asList().hasSize(1); - httpClientWrapper.capturedRequest.clear(); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document, - collectionLink, - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity(collectionRid, partitionKeyRangeId); - boolean forceRefreshPartitionAddresses = false; - Single addressesInfosFromCacheObs = cache.tryGetAddresses(req, partitionKeyRangeIdentity, forceRefreshPartitionAddresses); - ArrayList addressInfosFromCache = Lists.newArrayList(getSuccessResult(addressesInfosFromCacheObs, TIMEOUT)); - - // no new request is made - assertThat(httpClientWrapper.capturedRequest) - .describedAs("no http request: addresses already cached by openAsync") - .asList().hasSize(0); - - Single> masterAddressFromGatewayObs = cache.getServerAddressesViaGatewayAsync(req, - collectionRid, ImmutableList.of(partitionKeyRangeId), false); - List
expectedAddresses = getSuccessResult(masterAddressFromGatewayObs, TIMEOUT); - - assertThat(httpClientWrapper.capturedRequest) - .describedAs("getServerAddressesViaGatewayAsync will read addresses from gateway") - .asList().hasSize(1); - - assertSameAs(addressInfosFromCache, expectedAddresses); - } - - @Test(groups = { "direct" }, - dataProvider = "openAsyncTargetAndTargetPartitionsKeyRangeAndCollectionLinkParams", - timeOut = TIMEOUT) - public void tryGetAddresses_ForDataPartitions_ForceRefresh( - List allPartitionKeyRangeIds, - String partitionKeyRangeId, - String collectionLink) throws Exception { - Configs configs = new Configs(); - HttpClientUnderTestWrapper httpClientWrapper = getHttpClientUnderTestWrapper(configs); - - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - Protocol.Https, - authorizationTokenProvider, - null, - httpClientWrapper.getSpyHttpClient()); - - String collectionRid = createdCollection.getResourceId(); - - List pkriList = allPartitionKeyRangeIds.stream().map( - pkri -> new PartitionKeyRangeIdentity(collectionRid, pkri)).collect(Collectors.toList()); - - cache.openAsync(createdCollection, pkriList).await(); - - assertThat(httpClientWrapper.capturedRequest).asList().hasSize(1); - httpClientWrapper.capturedRequest.clear(); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document, - collectionLink, - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity(collectionRid, partitionKeyRangeId); - Single addressesInfosFromCacheObs = cache.tryGetAddresses(req, partitionKeyRangeIdentity, true); - ArrayList addressInfosFromCache = Lists.newArrayList(getSuccessResult(addressesInfosFromCacheObs, TIMEOUT)); - - // no new request is made - assertThat(httpClientWrapper.capturedRequest) - .describedAs("force refresh fetched from gateway") - .asList().hasSize(1); - - Single> masterAddressFromGatewayObs = cache.getServerAddressesViaGatewayAsync(req, - collectionRid, ImmutableList.of(partitionKeyRangeId), false); - List
expectedAddresses = getSuccessResult(masterAddressFromGatewayObs, TIMEOUT); - - assertThat(httpClientWrapper.capturedRequest) - .describedAs("getServerAddressesViaGatewayAsync will read addresses from gateway") - .asList().hasSize(2); - - assertSameAs(addressInfosFromCache, expectedAddresses); - } - - @Test(groups = { "direct" }, - dataProvider = "openAsyncTargetAndTargetPartitionsKeyRangeAndCollectionLinkParams", - timeOut = TIMEOUT) - public void tryGetAddresses_ForDataPartitions_Suboptimal_Refresh( - List allPartitionKeyRangeIds, - String partitionKeyRangeId, - String collectionLink) throws Exception { - Configs configs = new Configs(); - HttpClientUnderTestWrapper httpClientWrapper = getHttpClientUnderTestWrapper(configs); - - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - int suboptimalRefreshTime = 2; - - GatewayAddressCache origCache = new GatewayAddressCache(serviceEndpoint, - Protocol.Https, - authorizationTokenProvider, - null, - httpClientWrapper.getSpyHttpClient(), - suboptimalRefreshTime); - - String collectionRid = createdCollection.getResourceId(); - - List pkriList = allPartitionKeyRangeIds.stream().map( - pkri -> new PartitionKeyRangeIdentity(collectionRid, pkri)).collect(Collectors.toList()); - - origCache.openAsync(createdCollection, pkriList).await(); - - assertThat(httpClientWrapper.capturedRequest).asList().hasSize(1); - httpClientWrapper.capturedRequest.clear(); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Document, - collectionLink, - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity(collectionRid, partitionKeyRangeId); - Single addressesInfosFromCacheObs = origCache.tryGetAddresses(req, partitionKeyRangeIdentity, true); - ArrayList addressInfosFromCache = Lists.newArrayList(getSuccessResult(addressesInfosFromCacheObs, TIMEOUT)); - - // no new request is made - assertThat(httpClientWrapper.capturedRequest) - .describedAs("force refresh fetched from gateway") - .asList().hasSize(1); - - GatewayAddressCache spyCache = Mockito.spy(origCache); - - final AtomicInteger fetchCounter = new AtomicInteger(0); - Mockito.doAnswer(new Answer() { - @Override - public Single> answer(InvocationOnMock invocationOnMock) throws Throwable { - - RxDocumentServiceRequest req = invocationOnMock.getArgumentAt(0, RxDocumentServiceRequest.class); - String collectionRid = invocationOnMock.getArgumentAt(1, String.class); - List partitionKeyRangeIds = invocationOnMock.getArgumentAt(2, List.class); - boolean forceRefresh = invocationOnMock.getArgumentAt(3, Boolean.class); - - int cnt = fetchCounter.getAndIncrement(); - - if (cnt == 0) { - Single> res = origCache.getServerAddressesViaGatewayAsync(req, - collectionRid, - partitionKeyRangeIds, - forceRefresh); - - // remove one replica - return res.map(list -> removeOneReplica(list)); - } - - return origCache.getServerAddressesViaGatewayAsync(req, - collectionRid, - partitionKeyRangeIds, - forceRefresh); - } - }).when(spyCache).getServerAddressesViaGatewayAsync(Matchers.any(RxDocumentServiceRequest.class), Matchers.anyString(), - Matchers.anyList(), Matchers.anyBoolean()); - - httpClientWrapper.capturedRequest.clear(); - - // force refresh to replace existing with sub-optimal addresses - addressesInfosFromCacheObs = spyCache.tryGetAddresses(req, partitionKeyRangeIdentity, true); - AddressInformation[] suboptimalAddresses = getSuccessResult(addressesInfosFromCacheObs, TIMEOUT); - assertThat(httpClientWrapper.capturedRequest) - .describedAs("getServerAddressesViaGatewayAsync will read addresses from gateway") - .asList().hasSize(1); - httpClientWrapper.capturedRequest.clear(); - assertThat(suboptimalAddresses).hasSize(ServiceConfig.SystemReplicationPolicy.MaxReplicaSetSize - 1); - assertThat(fetchCounter.get()).isEqualTo(1); - - // no refresh, use cache - addressesInfosFromCacheObs = spyCache.tryGetAddresses(req, partitionKeyRangeIdentity, false); - suboptimalAddresses = getSuccessResult(addressesInfosFromCacheObs, TIMEOUT); - assertThat(httpClientWrapper.capturedRequest) - .describedAs("getServerAddressesViaGatewayAsync will read addresses from gateway") - .asList().hasSize(0); - assertThat(suboptimalAddresses).hasSize(ServiceConfig.SystemReplicationPolicy.MaxReplicaSetSize - 1); - assertThat(fetchCounter.get()).isEqualTo(1); - - // wait for refresh time - TimeUnit.SECONDS.sleep(suboptimalRefreshTime + 1); - - addressesInfosFromCacheObs = spyCache.tryGetAddresses(req, partitionKeyRangeIdentity, false); - AddressInformation[] addresses = getSuccessResult(addressesInfosFromCacheObs, TIMEOUT); - assertThat(addresses).hasSize(ServiceConfig.SystemReplicationPolicy.MaxReplicaSetSize); - assertThat(httpClientWrapper.capturedRequest) - .describedAs("getServerAddressesViaGatewayAsync will read addresses from gateway") - .asList().hasSize(1); - assertThat(fetchCounter.get()).isEqualTo(2); - } - - @Test(groups = { "direct" }, dataProvider = "protocolProvider",timeOut = TIMEOUT) - public void tryGetAddresses_ForMasterPartition(Protocol protocol) throws Exception { - Configs configs = ConfigsBuilder.instance().withProtocol(protocol).build(); - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - protocol, - authorizationTokenProvider, - null, - getCompositeHttpClient(configs)); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Database, - "/dbs", - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity("M"); - boolean forceRefreshPartitionAddresses = false; - Single addressesInfosFromCacheObs = cache.tryGetAddresses(req, partitionKeyRangeIdentity, forceRefreshPartitionAddresses); - - ArrayList addressInfosFromCache = Lists.newArrayList(getSuccessResult(addressesInfosFromCacheObs, TIMEOUT)); - - Single> masterAddressFromGatewayObs = cache.getMasterAddressesViaGatewayAsync(req, ResourceType.Database, - null, "/dbs/", false, false, null); - List
expectedAddresses = getSuccessResult(masterAddressFromGatewayObs, TIMEOUT); - - assertSameAs(addressInfosFromCache, expectedAddresses); - } - - @DataProvider(name = "refreshTime") - public Object[][] refreshTime() { - return new Object[][] { - // refresh time, wait before doing tryGetAddresses - { 60, 1 }, - { 1, 2 }, - }; - } - - @Test(groups = { "direct" }, timeOut = TIMEOUT, dataProvider = "refreshTime") - public void tryGetAddresses_ForMasterPartition_MasterPartitionAddressAlreadyCached_NoNewHttpRequest( - int suboptimalPartitionForceRefreshIntervalInSeconds, - int waitTimeInBetweenAttemptsInSeconds - ) throws Exception { - Configs configs = new Configs(); - HttpClientUnderTestWrapper clientWrapper = getHttpClientUnderTestWrapper(configs); - - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - Protocol.Https, - authorizationTokenProvider, - null, - clientWrapper.getSpyHttpClient(), - suboptimalPartitionForceRefreshIntervalInSeconds); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Database, - "/dbs", - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity("M"); - boolean forceRefreshPartitionAddresses = false; - - // request master partition info to ensure it is cached. - AddressInformation[] expectedAddresses = cache.tryGetAddresses(req, - partitionKeyRangeIdentity, - forceRefreshPartitionAddresses) - .toBlocking().value(); - - assertThat(clientWrapper.capturedRequest).asList().hasSize(1); - clientWrapper.capturedRequest.clear(); - - - TimeUnit.SECONDS.sleep(waitTimeInBetweenAttemptsInSeconds); - - Single addressesObs = cache.tryGetAddresses(req, - partitionKeyRangeIdentity, - forceRefreshPartitionAddresses); - - AddressInformation[] actualAddresses = getSuccessResult(addressesObs, TIMEOUT); - - assertExactlyEqual(actualAddresses, expectedAddresses); - - // the cache address is used. no new http request is sent - assertThat(clientWrapper.capturedRequest).asList().hasSize(0); - } - - @Test(groups = { "direct" }, timeOut = TIMEOUT) - public void tryGetAddresses_ForMasterPartition_ForceRefresh() throws Exception { - Configs configs = new Configs(); - HttpClientUnderTestWrapper clientWrapper = getHttpClientUnderTestWrapper(configs); - - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - GatewayAddressCache cache = new GatewayAddressCache(serviceEndpoint, - Protocol.Https, - authorizationTokenProvider, - null, - clientWrapper.getSpyHttpClient()); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Database, - "/dbs", - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity("M"); - - // request master partition info to ensure it is cached. - AddressInformation[] expectedAddresses = cache.tryGetAddresses(req, - partitionKeyRangeIdentity, - false) - .toBlocking().value(); - - assertThat(clientWrapper.capturedRequest).asList().hasSize(1); - clientWrapper.capturedRequest.clear(); - - Single addressesObs = cache.tryGetAddresses(req, - partitionKeyRangeIdentity, - true); - - AddressInformation[] actualAddresses = getSuccessResult(addressesObs, TIMEOUT); - - assertExactlyEqual(actualAddresses, expectedAddresses); - - // the cache address is used. no new http request is sent - assertThat(clientWrapper.capturedRequest).asList().hasSize(1); - } - - private static List
removeOneReplica(List
addresses) { - addresses.remove(0); - return addresses; - } - - @Test(groups = { "direct" }, timeOut = TIMEOUT) - public void tryGetAddresses_SuboptimalMasterPartition_NotStaleEnough_NoRefresh() throws Exception { - Configs configs = new Configs(); - Instant start = Instant.now(); - HttpClientUnderTestWrapper clientWrapper = getHttpClientUnderTestWrapper(configs); - - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - int refreshPeriodInSeconds = 10; - - GatewayAddressCache origCache = new GatewayAddressCache(serviceEndpoint, - Protocol.Https, - authorizationTokenProvider, - null, - clientWrapper.getSpyHttpClient(), refreshPeriodInSeconds); - - GatewayAddressCache spyCache = Mockito.spy(origCache); - - final AtomicInteger getMasterAddressesViaGatewayAsyncInvocation = new AtomicInteger(0); - Mockito.doAnswer(new Answer() { - @Override - public Single> answer(InvocationOnMock invocationOnMock) throws Throwable { - - RxDocumentServiceRequest request = invocationOnMock.getArgumentAt(0, RxDocumentServiceRequest.class); - ResourceType resourceType = invocationOnMock.getArgumentAt(1, ResourceType.class); - String resourceAddress = invocationOnMock.getArgumentAt(2, String.class); - String entryUrl = invocationOnMock.getArgumentAt(3, String.class); - boolean forceRefresh = invocationOnMock.getArgumentAt(4, Boolean.class); - boolean useMasterCollectionResolver = invocationOnMock.getArgumentAt(5, Boolean.class); - - int cnt = getMasterAddressesViaGatewayAsyncInvocation.getAndIncrement(); - - if (cnt == 0) { - Single> res = origCache.getMasterAddressesViaGatewayAsync( - request, - resourceType, - resourceAddress, - entryUrl, - forceRefresh, - useMasterCollectionResolver, - null); - - // remove one replica - return res.map(list -> removeOneReplica(list)); - } - - return origCache.getMasterAddressesViaGatewayAsync( - request, - resourceType, - resourceAddress, - entryUrl, - forceRefresh, - useMasterCollectionResolver, - null); - } - }).when(spyCache).getMasterAddressesViaGatewayAsync(Matchers.any(RxDocumentServiceRequest.class), Matchers.any(ResourceType.class), Matchers.anyString(), - Matchers.anyString(), Matchers.anyBoolean(), Matchers.anyBoolean(), Matchers.anyMap()); - - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Database, - "/dbs", - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity("M"); - - // request master partition info to ensure it is cached. - AddressInformation[] expectedAddresses = spyCache.tryGetAddresses(req, - partitionKeyRangeIdentity, - false) - .toBlocking().value(); - - assertThat(clientWrapper.capturedRequest).asList().hasSize(1); - clientWrapper.capturedRequest.clear(); - - Single addressesObs = spyCache.tryGetAddresses(req, - partitionKeyRangeIdentity, - false); - - AddressInformation[] actualAddresses = getSuccessResult(addressesObs, TIMEOUT); - - assertExactlyEqual(actualAddresses, expectedAddresses); - - // the cache address is used. no new http request is sent - assertThat(clientWrapper.capturedRequest).asList().hasSize(0); - - Instant end = Instant.now(); - assertThat(end.minusSeconds(refreshPeriodInSeconds)).isBefore(start); - } - - @Test(groups = { "direct" }, timeOut = TIMEOUT) - public void tryGetAddresses_SuboptimalMasterPartition_Stale_DoRefresh() throws Exception { - Configs configs = new Configs(); - HttpClientUnderTestWrapper clientWrapper = getHttpClientUnderTestWrapper(configs); - - URL serviceEndpoint = new URL(TestConfigurations.HOST); - IAuthorizationTokenProvider authorizationTokenProvider = (RxDocumentClientImpl) client; - - int refreshPeriodInSeconds = 1; - - GatewayAddressCache origCache = new GatewayAddressCache(serviceEndpoint, - Protocol.Https, - authorizationTokenProvider, - null, - clientWrapper.getSpyHttpClient(), refreshPeriodInSeconds); - - GatewayAddressCache spyCache = Mockito.spy(origCache); - - final AtomicInteger getMasterAddressesViaGatewayAsyncInvocation = new AtomicInteger(0); - Mockito.doAnswer(new Answer() { - @Override - public Single> answer(InvocationOnMock invocationOnMock) throws Throwable { - - System.out.print("fetch"); - - RxDocumentServiceRequest request = invocationOnMock.getArgumentAt(0, RxDocumentServiceRequest.class); - ResourceType resourceType = invocationOnMock.getArgumentAt(1, ResourceType.class); - String resourceAddress = invocationOnMock.getArgumentAt(2, String.class); - String entryUrl = invocationOnMock.getArgumentAt(3, String.class); - boolean forceRefresh = invocationOnMock.getArgumentAt(4, Boolean.class); - boolean useMasterCollectionResolver = invocationOnMock.getArgumentAt(5, Boolean.class); - - int cnt = getMasterAddressesViaGatewayAsyncInvocation.getAndIncrement(); - - if (cnt == 0) { - Single> res = origCache.getMasterAddressesViaGatewayAsync( - request, - resourceType, - resourceAddress, - entryUrl, - forceRefresh, - useMasterCollectionResolver, - null); - - // remove one replica - return res.map(list -> removeOneReplica(list)); - } - - return origCache.getMasterAddressesViaGatewayAsync( - request, - resourceType, - resourceAddress, - entryUrl, - forceRefresh, - useMasterCollectionResolver, - null); - } - }).when(spyCache).getMasterAddressesViaGatewayAsync(Matchers.any(RxDocumentServiceRequest.class), Matchers.any(ResourceType.class), Matchers.anyString(), - Matchers.anyString(), Matchers.anyBoolean(), Matchers.anyBoolean(), Matchers.anyMap()); - - RxDocumentServiceRequest req = - RxDocumentServiceRequest.create(OperationType.Create, ResourceType.Database, - "/dbs", - new Database(), new HashMap<>()); - - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity("M"); - - // request master partition info to ensure it is cached. - AddressInformation[] subOptimalAddresses = spyCache.tryGetAddresses(req, - partitionKeyRangeIdentity, - false) - .toBlocking().value(); - - assertThat(getMasterAddressesViaGatewayAsyncInvocation.get()).isEqualTo(1); - assertThat(subOptimalAddresses).hasSize(ServiceConfig.SystemReplicationPolicy.MaxReplicaSetSize - 1); - - Instant start = Instant.now(); - TimeUnit.SECONDS.sleep(refreshPeriodInSeconds + 1); - Instant end = Instant.now(); - assertThat(end.minusSeconds(refreshPeriodInSeconds)).isAfter(start); - - assertThat(clientWrapper.capturedRequest).asList().hasSize(1); - clientWrapper.capturedRequest.clear(); - - Single addressesObs = spyCache.tryGetAddresses(req, - partitionKeyRangeIdentity, - false); - - - AddressInformation[] actualAddresses = getSuccessResult(addressesObs, TIMEOUT); - // the cache address is used. no new http request is sent - assertThat(clientWrapper.capturedRequest).asList().hasSize(1); - assertThat(getMasterAddressesViaGatewayAsyncInvocation.get()).isEqualTo(2); - assertThat(actualAddresses).hasSize(ServiceConfig.SystemReplicationPolicy.MaxReplicaSetSize); - - List
fetchedAddresses = origCache.getMasterAddressesViaGatewayAsync(req, ResourceType.Database, - null, "/dbs/", false, false, null).toBlocking().value(); - - assertSameAs(ImmutableList.copyOf(actualAddresses), fetchedAddresses); - } - - public static void assertSameAs(List actual, List
expected) { - assertThat(actual).asList().hasSize(expected.size()); - for(int i = 0; i < expected.size(); i++) { - assertEqual(actual.get(i), expected.get(i)); - } - } - - private static void assertEqual(AddressInformation actual, Address expected) { - assertThat(actual.getPhysicalUri()).isEqualTo(expected.getPhyicalUri()); - assertThat(actual.getProtocolScheme()).isEqualTo(expected.getProtocolScheme().toLowerCase()); - assertThat(actual.isPrimary()).isEqualTo(expected.IsPrimary()); - } - - private static void assertEqual(AddressInformation actual, AddressInformation expected) { - assertThat(actual.getPhysicalUri()).isEqualTo(expected.getPhysicalUri()); - assertThat(actual.getProtocolName()).isEqualTo(expected.getProtocolName()); - assertThat(actual.isPrimary()).isEqualTo(expected.isPrimary()); - assertThat(actual.isPublic()).isEqualTo(expected.isPublic()); - } - - public static void assertExactlyEqual(AddressInformation[] actual, AddressInformation[] expected) { - assertExactlyEqual(Arrays.asList(actual), Arrays.asList(expected)); - } - - public static void assertExactlyEqual(List actual, List expected) { - assertThat(actual).asList().hasSize(expected.size()); - for(int i = 0; i < expected.size(); i++) { - assertEqual(actual.get(i), expected.get(i)); - } - } - - public static T getSuccessResult(Single observable, long timeout) { - TestSubscriber testSubscriber = new TestSubscriber<>(); - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - return testSubscriber.getOnNextEvents().get(0); - } - - public static void validateSuccess(Single> observable, - PartitionReplicasAddressesValidator validator, long timeout) { - TestSubscriber> testSubscriber = new TestSubscriber<>(); - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - @BeforeClass(groups = { "direct" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(30000); - createdCollection = createCollection(client, createdDatabase.getId(), getCollectionDefinition(), options); - } - - @AfterClass(groups = { "direct" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteCollection(client, createdCollection); - safeClose(client); - } - - static protected DocumentCollection getCollectionDefinition() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList<>(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId("mycol"); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } - - private CompositeHttpClient getCompositeHttpClient(Configs configs) { - CompositeHttpClient httpClient = new HttpClientFactory(configs) - .toHttpClientBuilder().build(); - return httpClient; - } - - private HttpClientUnderTestWrapper getHttpClientUnderTestWrapper(Configs configs) { - CompositeHttpClient origHttpClient = getCompositeHttpClient(configs); - return new HttpClientUnderTestWrapper(origHttpClient); - } - - public String getNameBasedCollectionLink() { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(); - } - - public String getCollectionSelfLink() { - return createdCollection.getSelfLink(); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfigurationReaderTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfigurationReaderTest.java deleted file mode 100644 index 691139545995..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/GatewayServiceConfigurationReaderTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.net.URI; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.io.IOUtils; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.DatabaseAccount; -import com.microsoft.azure.cosmosdb.internal.BaseAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; -import com.microsoft.azure.cosmosdb.rx.internal.SpyClientUnderTestFactory; -import com.microsoft.azure.cosmosdb.rx.internal.SpyClientUnderTestFactory.ClientUnderTest; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.ByteBufUtil; -import io.netty.handler.codec.http.DefaultHttpHeaders; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import rx.Observable; -import rx.Single; -import rx.observers.TestSubscriber; - -public class GatewayServiceConfigurationReaderTest extends TestSuiteBase { - - private static final int TIMEOUT = 8000; - private CompositeHttpClient mockHttpClient; - private CompositeHttpClient httpClient; - private BaseAuthorizationTokenProvider baseAuthorizationTokenProvider; - private ConnectionPolicy connectionPolicy; - private GatewayServiceConfigurationReader mockGatewayServiceConfigurationReader; - private GatewayServiceConfigurationReader gatewayServiceConfigurationReader; - private AsyncDocumentClient client; - private String databaseAccountJson; - private DatabaseAccount expectedDatabaseAccount; - - @Factory(dataProvider = "clientBuilders") - public GatewayServiceConfigurationReaderTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @BeforeClass(groups = "simple") - public void setup() throws Exception { - client = clientBuilder.build(); - mockHttpClient = (CompositeHttpClient) Mockito.mock(CompositeHttpClient.class); - - ClientUnderTest clientUnderTest = SpyClientUnderTestFactory.createClientUnderTest(this.clientBuilder); - httpClient = clientUnderTest.getSpyHttpClient(); - baseAuthorizationTokenProvider = new BaseAuthorizationTokenProvider(TestConfigurations.MASTER_KEY); - connectionPolicy = ConnectionPolicy.GetDefault(); - mockGatewayServiceConfigurationReader = new GatewayServiceConfigurationReader(new URI(TestConfigurations.HOST), - false, TestConfigurations.MASTER_KEY, connectionPolicy, baseAuthorizationTokenProvider, mockHttpClient); - - gatewayServiceConfigurationReader = new GatewayServiceConfigurationReader(new URI(TestConfigurations.HOST), - false, - TestConfigurations.MASTER_KEY, - connectionPolicy, - baseAuthorizationTokenProvider, - httpClient); - databaseAccountJson = IOUtils - .toString(getClass().getClassLoader().getResourceAsStream("databaseAccount.json"), "UTF-8"); - expectedDatabaseAccount = new DatabaseAccount(databaseAccountJson); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - @Test(groups = "simple") - public void mockInitializeReaderAsync() throws Exception { - - HttpClientResponse mockedResponse = getMockResponse(databaseAccountJson); - - Mockito.when(mockHttpClient.submit(Matchers.any(RxClient.ServerInfo.class), Matchers.any())) - .thenReturn(Observable.just(mockedResponse)); - - Single databaseAccount = mockGatewayServiceConfigurationReader.initializeReaderAsync(); - validateSuccess(databaseAccount, expectedDatabaseAccount); - } - - @Test(groups = "simple") - public void mockInitializeReaderAsyncWithResourceToken() throws Exception { - mockGatewayServiceConfigurationReader = new GatewayServiceConfigurationReader(new URI(TestConfigurations.HOST), - true, "SampleResourceToken", connectionPolicy, baseAuthorizationTokenProvider, mockHttpClient); - - HttpClientResponse mockedResponse = getMockResponse(databaseAccountJson); - - Mockito.when(mockHttpClient.submit(Matchers.any(RxClient.ServerInfo.class), Matchers.any())) - .thenReturn(Observable.just(mockedResponse)); - - Single databaseAccount = mockGatewayServiceConfigurationReader.initializeReaderAsync(); - validateSuccess(databaseAccount, expectedDatabaseAccount); - } - - @Test(groups = "simple") - public void initializeReaderAsync() { - Single databaseAccount = gatewayServiceConfigurationReader.initializeReaderAsync(); - validateSuccess(databaseAccount); - } - - public static void validateSuccess(Single observable) { - TestSubscriber testSubscriber = new TestSubscriber(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(TIMEOUT, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - assertThat(BridgeInternal.getQueryEngineConfiuration(testSubscriber.getOnNextEvents().get(0)).size() > 0).isTrue(); - assertThat(BridgeInternal.getReplicationPolicy(testSubscriber.getOnNextEvents().get(0))).isNotNull(); - assertThat(BridgeInternal.getSystemReplicationPolicy(testSubscriber.getOnNextEvents().get(0))).isNotNull(); - } - - public static void validateSuccess(Single observable, DatabaseAccount expectedDatabaseAccount) - throws InterruptedException { - TestSubscriber testSubscriber = new TestSubscriber(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(TIMEOUT, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - assertThat(testSubscriber.getOnNextEvents().get(0).getId()).isEqualTo(expectedDatabaseAccount.getId()); - assertThat(testSubscriber.getOnNextEvents().get(0).getAddressesLink()) - .isEqualTo(expectedDatabaseAccount.getAddressesLink()); - assertThat(testSubscriber.getOnNextEvents().get(0).getWritableLocations().iterator().next().getEndpoint()) - .isEqualTo(expectedDatabaseAccount.getWritableLocations().iterator().next().getEndpoint()); - assertThat(BridgeInternal.getSystemReplicationPolicy(testSubscriber.getOnNextEvents().get(0)).getMaxReplicaSetSize()) - .isEqualTo(BridgeInternal.getSystemReplicationPolicy(expectedDatabaseAccount).getMaxReplicaSetSize()); - assertThat(BridgeInternal.getSystemReplicationPolicy(testSubscriber.getOnNextEvents().get(0)).getMaxReplicaSetSize()) - .isEqualTo(BridgeInternal.getSystemReplicationPolicy(expectedDatabaseAccount).getMaxReplicaSetSize()); - assertThat(BridgeInternal.getQueryEngineConfiuration(testSubscriber.getOnNextEvents().get(0))) - .isEqualTo(BridgeInternal.getQueryEngineConfiuration(expectedDatabaseAccount)); - } - - private HttpClientResponse getMockResponse(String databaseAccountJson) { - HttpClientResponse resp = Mockito.mock(HttpClientResponse.class); - Mockito.doReturn(HttpResponseStatus.valueOf(200)).when(resp).getStatus(); - Mockito.doReturn(Observable.just(ByteBufUtil.writeUtf8(ByteBufAllocator.DEFAULT, databaseAccountJson))) - .when(resp).getContent(); - - HttpHeaders httpHeaders = new DefaultHttpHeaders(); - DefaultHttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, - HttpResponseStatus.valueOf(200), httpHeaders); - - try { - Constructor constructor = HttpResponseHeaders.class - .getDeclaredConstructor(HttpResponse.class); - constructor.setAccessible(true); - HttpResponseHeaders httpResponseHeaders = constructor.newInstance(httpResponse); - Mockito.doReturn(httpResponseHeaders).when(resp).getHeaders(); - - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException e) { - throw new IllegalStateException("Failed to instantiate class object.", e); - } - return resp; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionReplicasAddressesValidator.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionReplicasAddressesValidator.java deleted file mode 100644 index fbd37eb5da7d..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/internal/directconnectivity/PartitionReplicasAddressesValidator.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.internal.directconnectivity; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This is a helper class for validating partition replicas' addresses for tests. - */ -public interface PartitionReplicasAddressesValidator { - - int MAX_REPLICA_SIZE = 4; - - void validate(Collection
addresses); - - class Builder { - private List validators = new ArrayList<>(); - - public PartitionReplicasAddressesValidator build() { - return new PartitionReplicasAddressesValidator() { - - public void validate(Collection
addresses) { - for (PartitionReplicasAddressesValidator validator : validators) { - validator.validate(addresses); - } - } - }; - } - - public Builder size(final int expectedCount) { - - validators.add(new PartitionReplicasAddressesValidator() { - @Override - public void validate(Collection
addresses) { - assertThat(addresses).hasSize(expectedCount); - } - }); - return this; - } - - public Builder forEach(AddressValidator validator) { - - validators.add(new PartitionReplicasAddressesValidator() { - @Override - public void validate(Collection
addresses) { - - for (Address address : addresses) { - validator.validate(address); - } - - } - }); - return this; - } - - public Builder httpsProtocol() { - this.forEach(new AddressValidator.Builder().httpsProtocol().build()); - return this; - } - - public Builder withProtocol(Protocol protocol) { - this.forEach(new AddressValidator.Builder().protocol(protocol).build()); - return this; - } - - public Builder replicasOfPartition(String partitionKeyRangeId) { - validators.add(new PartitionReplicasAddressesValidator() { - @Override - public void validate(Collection
addresses) { - - // if running against prod due to upgrade etc, we may have occasionally 3 or 4 replicas. - assertThat(addresses).size().isGreaterThanOrEqualTo(MAX_REPLICA_SIZE - 1).isLessThanOrEqualTo(MAX_REPLICA_SIZE); - assertThat(addresses.stream().filter(a -> a.IsPrimary()).count()).isEqualTo(1); - - Address a = addresses.iterator().next(); - - AddressValidator validator = new AddressValidator.Builder() - .withPartitionKeyRangeId(partitionKeyRangeId) - .withRid(a.getResourceId()) - .build(); - - for (Address address : addresses) { - validator.validate(address); - } - } - }); - return this; - } - - public Builder replicasOfSamePartition() { - validators.add(new PartitionReplicasAddressesValidator() { - @Override - public void validate(Collection
addresses) { - - // if running against prod due to upgrade etc, we may have occasionally 3 or 4 replicas. - assertThat(addresses).size().isGreaterThanOrEqualTo(MAX_REPLICA_SIZE - 1).isLessThanOrEqualTo(MAX_REPLICA_SIZE); - assertThat(addresses.stream().filter(a -> a.IsPrimary()).count()).isEqualTo(1); - - Address a = addresses.iterator().next(); - - AddressValidator validator = new AddressValidator.Builder() - .withPartitionKeyRangeId(a.getParitionKeyRangeId()) - .withRid(a.getResourceId()) - .build(); - - for (Address address : addresses) { - validator.validate(address); - } - } - }); - return this; - } - - public Builder replicasOfPartitions(Collection partitionKeyRangeIds) { - validators.add(new PartitionReplicasAddressesValidator() { - @Override - public void validate(Collection
addresses) { - - for (String pki : partitionKeyRangeIds) { - List
partitionReplicas = addresses.stream() - .filter(a -> pki.equals(a.getParitionKeyRangeId())) - .collect(Collectors.toList()); - - PartitionReplicasAddressesValidator v = new Builder().replicasOfPartition(pki).build(); - v.validate(partitionReplicas); - } - } - }); - return this; - } - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AggregateQueryTests.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AggregateQueryTests.java deleted file mode 100644 index 3a0fb11fb207..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AggregateQueryTests.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -public class AggregateQueryTests extends TestSuiteBase { - - public static class QueryConfig { - String testName; - String query; - Object expected; - - public QueryConfig (String testName, String query, Object expected) { - this.testName = testName; - this.query = query; - this.expected = expected; - } - } - - public static class AggregateConfig { - String operator; - Object expected; - String condition; - - public AggregateConfig(String operator, Object expected, String condition) { - this.operator = operator; - this.expected = expected; - this.condition = condition; - } - } - - private Database createdDatabase; - private DocumentCollection createdCollection; - private ArrayList docs = new ArrayList(); - private ArrayList queryConfigs = new ArrayList(); - - private String partitionKey = "mypk"; - private String uniquePartitionKey = "uniquePartitionKey"; - private String field = "field"; - private int sum; - private int numberOfDocuments = 800; - private int numberOfDocumentsWithNumericId; - private int numberOfDocsWithSamePartitionKey = 400; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public AggregateQueryTests(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // Links: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - // Notes: - // I've seen this test time out in my development environment. I test against a debug instance of the public - // emulator and so what I'm seeing could be the result of a public emulator performance issue. Of course, it - // might also be the result of a Tcp protocol performance problem. - - @Test(groups = { "simple" }, timeOut = 2 * TIMEOUT, dataProvider = "queryMetricsArgProvider") - public void queryDocumentsWithAggregates(boolean qmEnabled) throws Exception { - - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setPopulateQueryMetrics(qmEnabled); - options.setMaxDegreeOfParallelism(2); - - for (QueryConfig queryConfig : queryConfigs) { - - Observable> queryObservable = client - .queryDocuments(createdCollection.getSelfLink(), queryConfig.query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .withAggregateValue(queryConfig.expected) - .numberOfPages(1) - .hasValidQueryMetrics(qmEnabled) - .build(); - - try { - validateQuerySuccess(queryObservable, validator); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - } - - public void bulkInsert(AsyncDocumentClient client) { - generateTestData(); - - ArrayList>> result = new ArrayList>>(); - for (int i = 0; i < docs.size(); i++) { - result.add(client.createDocument("dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(), docs.get(i), null, false)); - } - - Observable.merge(result, 100).toList().toBlocking().single(); - } - - public void generateTestData() { - - Object[] values = new Object[]{null, false, true, "abc", "cdfg", "opqrs", "ttttttt", "xyz", "oo", "ppp"}; - for (int i = 0; i < values.length; i++) { - Document d = new Document(); - d.set(partitionKey, values[i]); - docs.add(d); - } - - for (int i = 0; i < numberOfDocsWithSamePartitionKey; i++) { - Document d = new Document(); - d.set(partitionKey, uniquePartitionKey); - d.set("resourceId", Integer.toString(i)); - d.set(field, i + 1); - docs.add(d); - } - - numberOfDocumentsWithNumericId = numberOfDocuments - values.length - numberOfDocsWithSamePartitionKey; - for (int i = 0; i < numberOfDocumentsWithNumericId; i++) { - Document d = new Document(); - d.set(partitionKey, i + 1); - docs.add(d); - } - - sum = (int) (numberOfDocumentsWithNumericId * (numberOfDocumentsWithNumericId + 1) / 2.0); - - } - - public void generateTestConfigs() { - - String aggregateQueryFormat = "SELECT VALUE %s(r.%s) FROM r WHERE %s"; - AggregateConfig[] aggregateConfigs = new AggregateConfig[] { - new AggregateConfig("AVG", sum / numberOfDocumentsWithNumericId, String.format("IS_NUMBER(r.%s)", partitionKey)), - new AggregateConfig("AVG", null, "true"), - new AggregateConfig("COUNT", numberOfDocuments, "true"), - new AggregateConfig("MAX","xyz","true"), - new AggregateConfig("MIN", null, "true"), - new AggregateConfig("SUM", sum, String.format("IS_NUMBER(r.%s)", partitionKey)), - new AggregateConfig("SUM", null, "true") - }; - - for (AggregateConfig config: aggregateConfigs) { - String query = String.format(aggregateQueryFormat, config.operator, partitionKey, config.condition); - String testName = String.format("%s %s", config.operator, config.condition); - queryConfigs.add(new QueryConfig(testName, query, config.expected)); - } - - String aggregateSinglePartitionQueryFormat = "SELECT VALUE %s(r.%s) FROM r WHERE r.%s = '%s'"; - String aggregateSinglePartitionQueryFormatSelect = "SELECT %s(r.%s) FROM r WHERE r.%s = '%s'"; - double samePartitionSum = numberOfDocsWithSamePartitionKey * (numberOfDocsWithSamePartitionKey + 1) / 2.0; - - AggregateConfig[] aggregateSinglePartitionConfigs = new AggregateConfig[] { - new AggregateConfig("AVG", samePartitionSum / numberOfDocsWithSamePartitionKey, null), - new AggregateConfig("COUNT", numberOfDocsWithSamePartitionKey, null), - new AggregateConfig("MAX", numberOfDocsWithSamePartitionKey, null), - new AggregateConfig("MIN", 1, null), - new AggregateConfig("SUM", samePartitionSum, null) - }; - - for (AggregateConfig config: aggregateSinglePartitionConfigs) { - String query = String.format(aggregateSinglePartitionQueryFormat, config.operator, field, partitionKey, uniquePartitionKey); - String testName = String.format("%s SinglePartition %s", config.operator, "SELECT VALUE"); - queryConfigs.add(new QueryConfig(testName, query, config.expected)); - - query = String.format(aggregateSinglePartitionQueryFormatSelect, config.operator, field, partitionKey, uniquePartitionKey); - testName = String.format("%s SinglePartition %s", config.operator, "SELECT"); - queryConfigs.add(new QueryConfig(testName, query, new Document("{'$1':" + removeTrailingZerosIfInteger(config.expected) + "}"))); - } - } - - private Object removeTrailingZerosIfInteger(Object obj) { - if (obj instanceof Number) { - Number num = (Number) obj; - if (num.doubleValue() == num.intValue()) { - return num.intValue(); - } - } - return obj; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - truncateCollection(SHARED_MULTI_PARTITION_COLLECTION); - - bulkInsert(client); - generateTestConfigs(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AttachmentCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AttachmentCrudTest.java deleted file mode 100644 index a229e251a2a5..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AttachmentCrudTest.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class AttachmentCrudTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private Document createdDocument; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirectHttps") // Direct TCP mode does not support attachments - public AttachmentCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createAttachment() throws Exception { - // create an Attachment - String uuid = UUID.randomUUID().toString(); - Attachment attachment = getAttachmentDefinition(uuid, "application/text"); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(createdDocument.getId())); - Observable> createObservable = client.createAttachment(getDocumentLink(), attachment, options); - - // validate attachment creation - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(attachment.getId()) - .withContentType("application/text") - .notNullEtag() - .build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void readAttachment() throws Exception { - // create an Attachment - String uuid = UUID.randomUUID().toString(); - Attachment attachment = getAttachmentDefinition(uuid, "application/text"); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(createdDocument.getId())); - Attachment readBackAttachment = client.createAttachment(getDocumentLink(), attachment, options).toBlocking().single().getResource(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - - // read attachment - Observable> readObservable = client.readAttachment(readBackAttachment.getSelfLink(), options); - - // validate attachment read - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(attachment.getId()) - .withContentType("application/text") - .notNullEtag() - .build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void deleteAttachment() throws Exception { - // create an Attachment - String uuid = UUID.randomUUID().toString(); - Attachment attachment = getAttachmentDefinition(uuid, "application/text"); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(createdDocument.getId())); - Attachment readBackAttachment = client.createAttachment(getDocumentLink(), attachment, options).toBlocking().single().getResource(); - - // delete attachment - Observable> deleteObservable = client.deleteAttachment(readBackAttachment.getSelfLink(), options); - - // validate attachment delete - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource() - .build(); - validateSuccess(deleteObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void upsertAttachment() throws Exception { - // create an Attachment - String uuid = UUID.randomUUID().toString(); - Attachment attachment = getAttachmentDefinition(uuid, "application/text"); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(createdDocument.getId())); - Attachment readBackAttachment = client.upsertAttachment(getDocumentLink(), attachment, options).toBlocking().single().getResource(); - - // read attachment - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readAttachment(readBackAttachment.getSelfLink(), options); - - // validate attachment read - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(attachment.getId()) - .withContentType("application/text") - .notNullEtag() - .build(); - validateSuccess(readObservable, validator); - - //update attachment - readBackAttachment.setContentType("application/json"); - - Observable> updateObservable = client.upsertAttachment(getDocumentLink(), readBackAttachment, options); - - // validate attachment update - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackAttachment.getId()) - .withContentType("application/json") - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void replaceAttachment() throws Exception { - // create an Attachment - String uuid = UUID.randomUUID().toString(); - Attachment attachment = getAttachmentDefinition(uuid, "application/text"); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(createdDocument.getId())); - Attachment readBackAttachment = client.createAttachment(getDocumentLink(), attachment, options).toBlocking().single().getResource(); - - - // read attachment - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readAttachment(readBackAttachment.getSelfLink(), options); - - // validate attachment read - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(attachment.getId()) - .withContentType("application/text") - .notNullEtag() - .build(); - validateSuccess(readObservable, validator); - - //update attachment - readBackAttachment.setContentType("application/json"); - - Observable> updateObservable = client.replaceAttachment(readBackAttachment, options); - - // validate attachment update - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackAttachment.getId()) - .withContentType("application/json") - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - createdDocument = createDocument(client, createdDatabase.getId(), createdCollection.getId(), getDocumentDefinition()); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getDocumentLink() { - return createdDocument.getSelfLink(); - } - - private static Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - private static Attachment getAttachmentDefinition(String uuid, String type) { - return new Attachment(String.format( - "{" + - " 'id': '%s'," + - " 'media': 'http://xstore.'," + - " 'MediaType': 'Book'," + - " 'Author': 'My Book Author'," + - " 'Title': 'My Book Title'," + - " 'contentType': '%s'" + - "}", uuid, type)); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AttachmentQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AttachmentQueryTest.java deleted file mode 100644 index 1a353241e4b9..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/AttachmentQueryTest.java +++ /dev/null @@ -1,199 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -public class AttachmentQueryTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdAttachments = new ArrayList<>(); - - private Document createdDocument; - - private AsyncDocumentClient client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - public String getDocumentLink() { - return createdDocument.getSelfLink(); - } - - @Factory(dataProvider = "clientBuilders") - public AttachmentQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryWithFilter() throws Exception { - - String filterId = createdAttachments.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - Observable> queryObservable = client - .queryAttachments(getDocumentLink(), query, options); - - List expectedDocs = createdAttachments.stream().filter(sp -> filterId.equals(sp.getId()) ).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void query_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - Observable> queryObservable = client - .queryAttachments(getDocumentLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAll() throws Exception { - - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryAttachments(getDocumentLink(), query, options); - - List expectedDocs = createdAttachments; - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .exactlyContainsInAnyOrder(expectedDocs - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void invalidQuerySytax() throws Exception { - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .notNullActivityId() - .build(); - validateQueryFailure(queryObservable, validator); - } - - public Attachment createAttachment(AsyncDocumentClient client) { - Attachment attachment = getAttachmentDefinition(); - return client.createAttachment(getDocumentLink(), attachment, null).toBlocking().single().getResource(); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - Document docDef = new Document(); - docDef.setId(UUID.randomUUID().toString()); - - createdDocument = createDocument(client, createdDatabase.getId(), createdCollection.getId(), docDef); - - for(int i = 0; i < 5; i++) { - createdAttachments.add(createAttachment(client)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - private static Attachment getAttachmentDefinition() { - return new Attachment(String.format( - "{" + - " 'id': '%s'," + - " 'media': 'http://xstore.'," + - " 'MediaType': 'Book'," + - " 'Author': 'My Book Author'," + - " 'Title': 'My Book Title'," + - " 'contentType': '%s'" + - "}", UUID.randomUUID().toString(), "application/text")); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/BackPressureCrossPartitionTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/BackPressureCrossPartitionTest.java deleted file mode 100644 index 2a40e985d409..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/BackPressureCrossPartitionTest.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientUnderTest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; -import rx.internal.util.RxRingBuffer; -import rx.observers.TestSubscriber; -import rx.schedulers.Schedulers; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; - -public class BackPressureCrossPartitionTest extends TestSuiteBase { - private final Logger log = LoggerFactory.getLogger(BackPressureCrossPartitionTest.class); - - private static final int TIMEOUT = 1800000; - private static final int SETUP_TIMEOUT = 60000; - - private int numberOfDocs = 4000; - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdDocuments; - - private RxDocumentClientUnderTest client; - private int numberOfPartitions; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - static protected DocumentCollection getCollectionDefinition() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList<>(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection includedPaths = new ArrayList<>(); - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath("/*"); - Collection indexes = new ArrayList<>(); - Index stringIndex = Index.Range(DataType.String); - stringIndex.set("precision", -1); - indexes.add(stringIndex); - - Index numberIndex = Index.Range(DataType.Number); - numberIndex.set("precision", -1); - indexes.add(numberIndex); - includedPath.setIndexes(indexes); - includedPaths.add(includedPath); - indexingPolicy.setIncludedPaths(includedPaths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - collectionDefinition.setIndexingPolicy(indexingPolicy); - - return collectionDefinition; - } - - @Factory(dataProvider = "simpleClientBuildersWithDirectHttps") - public BackPressureCrossPartitionTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - private void warmUp() { - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - // ensure collection is cached - client.queryDocuments(getCollectionLink(), "SELECT * FROM r", options).first().toBlocking().single(); - } - - @DataProvider(name = "queryProvider") - public Object[][] queryProvider() { - return new Object[][] { - // query, maxItemCount, max expected back pressure buffered, total number of expected query results - { "SELECT * FROM r", 1, 2 * RxRingBuffer.SIZE, numberOfDocs}, - { "SELECT * FROM r", 100, 2 * RxRingBuffer.SIZE, numberOfDocs}, - { "SELECT * FROM r ORDER BY r.prop", 100, 2 * RxRingBuffer.SIZE + 3 * numberOfPartitions, numberOfDocs}, - { "SELECT TOP 1000 * FROM r", 1, 2 * RxRingBuffer.SIZE, 1000}, - { "SELECT TOP 1000 * FROM r", 100, 2 * RxRingBuffer.SIZE, 1000}, - { "SELECT TOP 1000 * FROM r ORDER BY r.prop", 100, 2 * RxRingBuffer.SIZE + 3 * numberOfPartitions , 1000}, - }; - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // Links: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - - @Test(groups = { "long" }, dataProvider = "queryProvider", timeOut = 2 * TIMEOUT) - public void query(String query, int maxItemCount, int maxExpectedBufferedCountForBackPressure, int expectedNumberOfResults) throws Exception { - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(maxItemCount); - options.setMaxDegreeOfParallelism(2); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - client.httpRequests.clear(); - - log.info("instantiating subscriber ..."); - TestSubscriber> subscriber = new TestSubscriber<>(1); - queryObservable.observeOn(Schedulers.io(), 1).subscribe(subscriber); - int sleepTimeInMillis = 40000; - int i = 0; - - // use a test subscriber and request for more result and sleep in between - try { - while(subscriber.getCompletions() == 0 && subscriber.getOnErrorEvents().isEmpty()) { - log.debug("loop " + i); - - TimeUnit.MILLISECONDS.sleep(sleepTimeInMillis); - sleepTimeInMillis /= 2; - - if (sleepTimeInMillis > 4000) { - // validate that only one item is returned to subscriber in each iteration - assertThat(subscriber.getValueCount() - i).isEqualTo(1); - } - - log.debug("subscriber.getValueCount(): " + subscriber.getValueCount()); - log.debug("client.httpRequests.size(): " + client.httpRequests.size()); - // validate that the difference between the number of requests to backend - // and the number of returned results is always less than a fixed threshold - - assertThat(client.httpRequests.size() - subscriber.getValueCount()) - .isLessThanOrEqualTo(maxExpectedBufferedCountForBackPressure); - - log.debug("requesting more"); - subscriber.requestMore(1); - i++; - } - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - - try { - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - assertThat(subscriber.getOnNextEvents().stream().mapToInt(p -> p.getResults().size()).sum()).isEqualTo(expectedNumberOfResults); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @BeforeClass(groups = { "long" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(20000); - createdDatabase = SHARED_DATABASE; - createdCollection = createCollection(createdDatabase.getId(), getCollectionDefinition(), options); - - client = new ClientUnderTestBuilder(clientBuilder).build(); - - ArrayList docDefList = new ArrayList<>(); - for(int i = 0; i < numberOfDocs; i++) { - docDefList.add(getDocumentDefinition(i)); - } - - Observable> documentBulkInsertObs = bulkInsert( - client, - getCollectionLink(), - docDefList, - 1000); - - createdDocuments = documentBulkInsertObs.map(ResourceResponse::getResource).toList().toBlocking().single(); - - numberOfPartitions = client.readPartitionKeyRanges(getCollectionLink(), null) - .flatMap(p -> Observable.from(p.getResults())).toList().toBlocking().single().size(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - warmUp(); - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // Links: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - - @AfterClass(groups = { "long" }, timeOut = 2 * SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteCollection(client, createdCollection); - safeClose(client); - } - - private static Document getDocumentDefinition(int cnt) { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"prop\" : %d, " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, cnt, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/BackPressureTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/BackPressureTest.java deleted file mode 100644 index c22fc3a4da06..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/BackPressureTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientUnderTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; -import rx.internal.util.RxRingBuffer; -import rx.observers.TestSubscriber; -import rx.schedulers.Schedulers; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; - -public class BackPressureTest extends TestSuiteBase { - - private static final int TIMEOUT = 200000; - private static final int SETUP_TIMEOUT = 60000; - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdDocuments; - - private RxDocumentClientUnderTest client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - private static DocumentCollection getSinglePartitionCollectionDefinition() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - return collectionDefinition; - } - - @Factory(dataProvider = "simpleClientBuildersWithDirectHttps") - public BackPressureTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "long" }, timeOut = TIMEOUT) - public void readFeed() throws Exception { - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(1); - Observable> queryObservable = client - .readDocuments(getCollectionLink(), options); - - client.httpRequests.clear(); - - TestSubscriber subscriber = new TestSubscriber(1); - queryObservable.observeOn(Schedulers.io(), 1).subscribe(subscriber); - int sleepTimeInMillis = 10000; // 10 seconds - - int i = 0; - // use a test subscriber and request for more result and sleep in between - while (subscriber.getCompletions() == 0 && subscriber.getOnErrorEvents().isEmpty()) { - TimeUnit.MILLISECONDS.sleep(sleepTimeInMillis); - sleepTimeInMillis /= 2; - - if (sleepTimeInMillis > 1000) { - // validate that only one item is returned to subscriber in each iteration - assertThat(subscriber.getValueCount() - i).isEqualTo(1); - } - // validate that only one item is returned to subscriber in each iteration - // validate that the difference between the number of requests to backend - // and the number of returned results is always less than a fixed threshold - assertThat(client.httpRequests.size() - subscriber.getOnNextEvents().size()) - .isLessThanOrEqualTo(RxRingBuffer.SIZE); - - subscriber.requestMore(1); - i++; - } - - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - assertThat(subscriber.getOnNextEvents()).hasSize(createdDocuments.size()); - } - - @Test(groups = { "long" }, timeOut = TIMEOUT) - public void query() throws Exception { - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(1); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), "SELECT * from r", options); - - client.httpRequests.clear(); - - TestSubscriber subscriber = new TestSubscriber(1); - queryObservable.observeOn(Schedulers.io(), 1).subscribe(subscriber); - int sleepTimeInMillis = 10000; - - int i = 0; - // use a test subscriber and request for more result and sleep in between - while(subscriber.getCompletions() == 0 && subscriber.getOnErrorEvents().isEmpty()) { - TimeUnit.MILLISECONDS.sleep(sleepTimeInMillis); - sleepTimeInMillis /= 2; - - if (sleepTimeInMillis > 1000) { - // validate that only one item is returned to subscriber in each iteration - assertThat(subscriber.getValueCount() - i).isEqualTo(1); - } - // validate that the difference between the number of requests to backend - // and the number of returned results is always less than a fixed threshold - assertThat(client.httpRequests.size() - subscriber.getValueCount()) - .isLessThanOrEqualTo(RxRingBuffer.SIZE); - - subscriber.requestMore(1); - i++; - } - - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - - assertThat(subscriber.getOnNextEvents()).hasSize(createdDocuments.size()); - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // NOTE: This method requires multiple SHUTDOWN_TIMEOUT intervals - // SEE: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - - @BeforeClass(groups = { "long" }, timeOut = 2 * SETUP_TIMEOUT) - public void beforeClass() throws Exception { - - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(1000); - createdDatabase = SHARED_DATABASE; - createdCollection = createCollection(createdDatabase.getId(), getSinglePartitionCollectionDefinition(), options); - - client = new ClientUnderTestBuilder(clientBuilder).build(); - - // increase throughput to max for a single partition collection to avoid throttling - // for bulk insert and later queries. - Offer offer = client.queryOffers( - String.format("SELECT * FROM r WHERE r.offerResourceId = '%s'", - createdCollection.getResourceId()) - , null).first().map(FeedResponse::getResults).toBlocking().single().get(0); - offer.setThroughput(6000); - offer = client.replaceOffer(offer).toBlocking().single().getResource(); - assertThat(offer.getThroughput()).isEqualTo(6000); - - ArrayList docDefList = new ArrayList<>(); - for(int i = 0; i < 1000; i++) { - docDefList.add(getDocumentDefinition(i)); - } - - Observable> documentBulkInsertObs = bulkInsert( - client, - getCollectionLink(), - docDefList, - 200); - - createdDocuments = documentBulkInsertObs.map(ResourceResponse::getResource).toList().toBlocking().single(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - warmUp(); - } - - private void warmUp() { - // ensure collection is cached - client.queryDocuments(getCollectionLink(), "SELECT * from r", null).first().toBlocking().single(); - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // NOTE: This method requires multiple SHUTDOWN_TIMEOUT intervals - // SEE: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - - @AfterClass(groups = { "long" }, timeOut = 2 * SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteCollection(client, createdCollection); - safeClose(client); - } - - private static Document getDocumentDefinition(int cnt) { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"prop\" : %d, " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, cnt, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ChangeFeedTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ChangeFeedTest.java deleted file mode 100644 index b2446f333019..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ChangeFeedTest.java +++ /dev/null @@ -1,315 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.time.ZonedDateTime; -import java.util.List; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -public class ChangeFeedTest extends TestSuiteBase { - - private static final int SETUP_TIMEOUT = 40000; - private static final int TIMEOUT = 30000; - private static final String PartitionKeyFieldName = "mypk"; - private Database createdDatabase; - private DocumentCollection createdCollection; - private Multimap partitionKeyToDocuments = ArrayListMultimap.create(); - - private AsyncDocumentClient client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - static protected DocumentCollection getCollectionDefinition() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/" + PartitionKeyFieldName); - partitionKeyDef.setPaths(paths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } - - public ChangeFeedTest() { - clientBuilder = createGatewayRxDocumentClient(); - subscriberValidationTimeout = TIMEOUT; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void changeFeed_fromBeginning() throws Exception { - String partitionKey = partitionKeyToDocuments.keySet().iterator().next(); - Collection expectedDocuments = partitionKeyToDocuments.get(partitionKey); - - ChangeFeedOptions changeFeedOption = new ChangeFeedOptions(); - changeFeedOption.setMaxItemCount(3); - changeFeedOption.setPartitionKey(new PartitionKey(partitionKey)); - changeFeedOption.setStartFromBeginning(true); - - List> changeFeedResultList = client.queryDocumentChangeFeed(getCollectionLink(), changeFeedOption) - .toList().toBlocking().single(); - - int count = 0; - for(int i = 0; i < changeFeedResultList.size(); i++) { - FeedResponse changeFeedPage = changeFeedResultList.get(i); - assertThat(changeFeedPage.getResponseContinuation()).as("Response continuation should not be null").isNotNull(); - - count += changeFeedPage.getResults().size(); - assertThat(changeFeedPage.getResults().size()) - .as("change feed should contain all the previously created documents") - .isLessThanOrEqualTo(changeFeedOption.getMaxItemCount()); - } - assertThat(count).as("the number of changes").isEqualTo(expectedDocuments.size()); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void changesFromPartitionKeyRangeId_FromBeginning() throws Exception { - List partitionKeyRangeIds = client.readPartitionKeyRanges(getCollectionLink(), null) - .flatMap(p -> Observable.from(p.getResults()), 1) - .map(pkr -> pkr.getId()) - .toList() - .toBlocking() - .single(); - - assertThat(partitionKeyRangeIds.size()).isGreaterThan(1); - - String pkRangeId = partitionKeyRangeIds.get(0); - - ChangeFeedOptions changeFeedOption = new ChangeFeedOptions(); - changeFeedOption.setMaxItemCount(3); - changeFeedOption.setPartitionKeyRangeId(pkRangeId); - changeFeedOption.setStartFromBeginning(true); - List> changeFeedResultList = client.queryDocumentChangeFeed(getCollectionLink(), changeFeedOption) - .toList().toBlocking().single(); - - int count = 0; - for(int i = 0; i < changeFeedResultList.size(); i++) { - FeedResponse changeFeedPage = changeFeedResultList.get(i); - assertThat(changeFeedPage.getResponseContinuation()).as("Response continuation should not be null").isNotNull(); - - count += changeFeedPage.getResults().size(); - assertThat(changeFeedPage.getResults().size()) - .as("change feed should contain all the previously created documents") - .isLessThanOrEqualTo(changeFeedOption.getMaxItemCount()); - - assertThat(changeFeedPage.getResponseContinuation()).as("Response continuation should not be null").isNotNull(); - assertThat(changeFeedPage.getResponseContinuation()).as("Response continuation should not be empty").isNotEmpty(); - } - assertThat(changeFeedResultList.size()).as("has at least one page").isGreaterThanOrEqualTo(1); - assertThat(count).as("the number of changes").isGreaterThan(0); - assertThat(count).as("the number of changes").isLessThan(partitionKeyToDocuments.size()); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void changeFeed_fromNow() throws Exception { - // Read change feed from current. - ChangeFeedOptions changeFeedOption = new ChangeFeedOptions(); - String partitionKey = partitionKeyToDocuments.keySet().iterator().next(); - changeFeedOption.setPartitionKey(new PartitionKey(partitionKey)); - - List> changeFeedResultsList = client.queryDocumentChangeFeed(getCollectionLink(), changeFeedOption) - .toList() - .toBlocking().single(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder().totalSize(0).build(); - validator.validate(changeFeedResultsList); - assertThat(changeFeedResultsList.get(changeFeedResultsList.size() -1 ). - getResponseContinuation()).as("Response continuation should not be null").isNotNull(); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void changeFeed_fromStartDate() throws Exception { - - //setStartDateTime is not currently supported in multimaster mode. So skipping the test - if(BridgeInternal.isEnableMultipleWriteLocations(client.getDatabaseAccount().toBlocking().single())){ - throw new SkipException("StartTime/IfModifiedSince is not currently supported when EnableMultipleWriteLocations is set"); - } - - // Read change feed from current. - ChangeFeedOptions changeFeedOption = new ChangeFeedOptions(); - String partitionKey = partitionKeyToDocuments.keySet().iterator().next(); - - changeFeedOption.setPartitionKey(new PartitionKey(partitionKey)); - ZonedDateTime befTime = ZonedDateTime.now(); - // Waiting for at-least a second to ensure that new document is created after we took the time stamp - waitAtleastASecond(befTime); - - ZonedDateTime dateTimeBeforeCreatingDoc = ZonedDateTime.now(); - changeFeedOption.setStartDateTime(dateTimeBeforeCreatingDoc); - - // Waiting for at-least a second to ensure that new document is created after we took the time stamp - waitAtleastASecond(dateTimeBeforeCreatingDoc); - client.createDocument(getCollectionLink(), getDocumentDefinition(partitionKey), null, true).toBlocking().single().getResource(); - - List> changeFeedResultList = client.queryDocumentChangeFeed(getCollectionLink(), - changeFeedOption).toList() - .toBlocking().single(); - - int count = 0; - for(int i = 0; i < changeFeedResultList.size(); i++) { - FeedResponse changeFeedPage = changeFeedResultList.get(i); - count += changeFeedPage.getResults().size(); - assertThat(changeFeedPage.getResponseContinuation()).as("Response continuation should not be null").isNotNull(); - } - assertThat(count).as("Change feed should have one newly created document").isEqualTo(1); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void changesFromPartitionKey_AfterInsertingNewDocuments() throws Exception { - ChangeFeedOptions changeFeedOption = new ChangeFeedOptions(); - changeFeedOption.setMaxItemCount(3); - String partitionKey = partitionKeyToDocuments.keySet().iterator().next(); - changeFeedOption.setPartitionKey(new PartitionKey(partitionKey)); - - List> changeFeedResultsList = client.queryDocumentChangeFeed(getCollectionLink(), changeFeedOption) - .toList().toBlocking().single(); - - assertThat(changeFeedResultsList).as("only one page").hasSize(1); - assertThat(changeFeedResultsList.get(0).getResults()).as("no recent changes").isEmpty(); - - String changeFeedContinuation = changeFeedResultsList.get(changeFeedResultsList.size()-1).getResponseContinuation(); - assertThat(changeFeedContinuation).as("continuation token is not null").isNotNull(); - assertThat(changeFeedContinuation).as("continuation token is not empty").isNotEmpty(); - - // create some documents - client.createDocument(getCollectionLink(), getDocumentDefinition(partitionKey), null, true).toBlocking().single(); - client.createDocument(getCollectionLink(), getDocumentDefinition(partitionKey), null, true).toBlocking().single(); - - // Read change feed from continuation - changeFeedOption.setRequestContinuation(changeFeedContinuation); - - - FeedResponse changeFeedResults2 = client.queryDocumentChangeFeed(getCollectionLink(), changeFeedOption) - .toBlocking().first(); - - assertThat(changeFeedResults2.getResults()).as("change feed should contain newly inserted docs.").hasSize(2); - assertThat(changeFeedResults2.getResponseContinuation()).as("Response continuation should not be null").isNotNull(); - } - - public void createDocument(AsyncDocumentClient client, String partitionKey) { - Document docDefinition = getDocumentDefinition(partitionKey); - - Document createdDocument = client - .createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource(); - partitionKeyToDocuments.put(partitionKey, createdDocument); - } - - public List bulkInsert(AsyncDocumentClient client, List docs) { - ArrayList>> result = new ArrayList>>(); - for (int i = 0; i < docs.size(); i++) { - result.add(client.createDocument("dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(), docs.get(i), null, false)); - } - - return Observable.merge(result, 100).map(r -> r.getResource()).toList().toBlocking().single(); - } - - @AfterMethod(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void removeCollection() { - if (createdCollection != null) { - deleteCollection(client, getCollectionLink()); - } - } - - @BeforeMethod(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void populateDocuments(Method method) { - super.beforeMethod(method); - partitionKeyToDocuments.clear(); - - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(10100); - createdCollection = createCollection(client, createdDatabase.getId(), getCollectionDefinition(), options); - - List docs = new ArrayList<>(); - - for (int i = 0; i < 200; i++) { - String partitionKey = UUID.randomUUID().toString(); - for(int j = 0; j < 7; j++) { - docs.add(getDocumentDefinition(partitionKey)); - } - } - - List insertedDocs = bulkInsert(client, docs); - for(Document doc: insertedDocs) { - partitionKeyToDocuments.put(doc.getString(PartitionKeyFieldName), doc); - } - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - // set up the client - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static Document getDocumentDefinition(String partitionKey) { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(); - doc.setId(uuid); - doc.set("mypk", partitionKey); - doc.set("prop", uuid); - return doc; - } - - private static void waitAtleastASecond(ZonedDateTime befTime) throws InterruptedException { - while (befTime.plusSeconds(1).isAfter(ZonedDateTime.now())) { - Thread.sleep(100); - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ClientUnderTestBuilder.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ClientUnderTestBuilder.java deleted file mode 100644 index 914014c2bb2c..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ClientUnderTestBuilder.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientUnderTest; - -public class ClientUnderTestBuilder extends Builder { - - public ClientUnderTestBuilder(Builder builder) { - this.configs = builder.configs; - this.connectionPolicy = builder.connectionPolicy; - this.desiredConsistencyLevel = builder.desiredConsistencyLevel; - this.masterKeyOrResourceToken = builder.masterKeyOrResourceToken; - this.serviceEndpoint = builder.serviceEndpoint; - } - - @Override - public RxDocumentClientUnderTest build() { - return new RxDocumentClientUnderTest( - this.serviceEndpoint, - this.masterKeyOrResourceToken, - this.connectionPolicy, - this.desiredConsistencyLevel, - this.configs); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/CollectionCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/CollectionCrudTest.java deleted file mode 100644 index 3aa4b54519cf..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/CollectionCrudTest.java +++ /dev/null @@ -1,335 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.CompositePath; -import com.microsoft.azure.cosmosdb.CompositePathSortOrder; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.IndexingMode; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.SpatialSpec; -import com.microsoft.azure.cosmosdb.SpatialType; - -import rx.Observable; - -public class CollectionCrudTest extends TestSuiteBase { - private static final int TIMEOUT = 30000; - private static final int SETUP_TIMEOUT = 20000; - private static final int SHUTDOWN_TIMEOUT = 20000; - private final String databaseId = DatabaseForTest.generateId(); - - private AsyncDocumentClient client; - private Database database; - - @Factory(dataProvider = "clientBuildersWithDirect") - public CollectionCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - this.subscriberValidationTimeout = TIMEOUT; - } - - @DataProvider(name = "collectionCrudArgProvider") - public Object[][] collectionCrudArgProvider() { - return new Object[][] { - // collection name, is name base - {UUID.randomUUID().toString(), false } , - {UUID.randomUUID().toString(), true } , - - // with special characters in the name. - {"+ -_,:.|~" + UUID.randomUUID().toString() + " +-_,:.|~", true } , - }; - } - - private DocumentCollection getCollectionDefinition(String collectionName) { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(collectionName); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider") - public void createCollection(String collectionName, boolean isNameBased) { - DocumentCollection collectionDefinition = getCollectionDefinition(collectionName); - - Observable> createObservable = client - .createCollection(getDatabaseLink(database, isNameBased), collectionDefinition, null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(collectionDefinition.getId()).build(); - - validateSuccess(createObservable, validator); - safeDeleteAllCollections(client, database); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void createCollectionWithCompositeIndexAndSpatialSpec() { - DocumentCollection collection = new DocumentCollection(); - - IndexingPolicy indexingPolicy = new IndexingPolicy(); - CompositePath compositePath1 = new CompositePath(); - compositePath1.setPath("/path1"); - compositePath1.setOrder(CompositePathSortOrder.Ascending); - CompositePath compositePath2 = new CompositePath(); - compositePath2.setPath("/path2"); - compositePath2.setOrder(CompositePathSortOrder.Descending); - CompositePath compositePath3 = new CompositePath(); - compositePath3.setPath("/path3"); - CompositePath compositePath4 = new CompositePath(); - compositePath4.setPath("/path4"); - compositePath4.setOrder(CompositePathSortOrder.Ascending); - CompositePath compositePath5 = new CompositePath(); - compositePath5.setPath("/path5"); - compositePath5.setOrder(CompositePathSortOrder.Descending); - CompositePath compositePath6 = new CompositePath(); - compositePath6.setPath("/path6"); - - ArrayList compositeIndex1 = new ArrayList(); - compositeIndex1.add(compositePath1); - compositeIndex1.add(compositePath2); - compositeIndex1.add(compositePath3); - - ArrayList compositeIndex2 = new ArrayList(); - compositeIndex2.add(compositePath4); - compositeIndex2.add(compositePath5); - compositeIndex2.add(compositePath6); - - Collection> compositeIndexes = new ArrayList>(); - compositeIndexes.add(compositeIndex1); - compositeIndexes.add(compositeIndex2); - indexingPolicy.setCompositeIndexes(compositeIndexes); - - SpatialType[] spatialTypes = new SpatialType[] { - SpatialType.Point, - SpatialType.LineString, - SpatialType.Polygon, - SpatialType.MultiPolygon - }; - Collection spatialIndexes = new ArrayList(); - for (int index = 0; index < 2; index++) { - Collection collectionOfSpatialTypes = new ArrayList(); - - SpatialSpec spec = new SpatialSpec(); - spec.setPath("/path" + index + "/*"); - - for (int i = index; i < index + 3; i++) { - collectionOfSpatialTypes.add(spatialTypes[i]); - } - spec.setSpatialTypes(collectionOfSpatialTypes); - spatialIndexes.add(spec); - } - - indexingPolicy.setSpatialIndexes(spatialIndexes); - - collection.setId(UUID.randomUUID().toString()); - collection.setIndexingPolicy(indexingPolicy); - - Observable> createObservable = client - .createCollection(database.getSelfLink(), collection, null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(collection.getId()) - .withCompositeIndexes(compositeIndexes) - .withSpatialIndexes(spatialIndexes) - .build(); - - validateSuccess(createObservable, validator); - safeDeleteAllCollections(client, database); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider") - public void readCollection(String collectionName, boolean isNameBased) { - DocumentCollection collectionDefinition = getCollectionDefinition(collectionName); - - Observable> createObservable = client.createCollection(getDatabaseLink(database, isNameBased), collectionDefinition, - null); - DocumentCollection collection = createObservable.toBlocking().single().getResource(); - - Observable> readObservable = client.readCollection(getCollectionLink(database, collection, isNameBased), null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(collection.getId()).build(); - validateSuccess(readObservable, validator); - safeDeleteAllCollections(client, database); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider") - public void readCollection_NameBase(String collectionName, boolean isNameBased) { - DocumentCollection collectionDefinition = getCollectionDefinition(collectionName); - - Observable> createObservable = client.createCollection(getDatabaseLink(database, isNameBased), collectionDefinition, - null); - DocumentCollection collection = createObservable.toBlocking().single().getResource(); - - Observable> readObservable = client.readCollection( - getCollectionLink(database, collection, isNameBased), null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(collection.getId()).build(); - validateSuccess(readObservable, validator); - safeDeleteAllCollections(client, database); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider") - public void readCollection_DoesntExist(String collectionName, boolean isNameBased) throws Exception { - - Observable> readObservable = client - .readCollection(Utils.getCollectionNameLink(database.getId(), "I don't exist"), null); - - FailureValidator validator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider") - public void deleteCollection(String collectionName, boolean isNameBased) { - DocumentCollection collectionDefinition = getCollectionDefinition(collectionName); - - Observable> createObservable = client.createCollection(getDatabaseLink(database, isNameBased), collectionDefinition, null); - DocumentCollection collection = createObservable.toBlocking().single().getResource(); - - Observable> deleteObservable = client.deleteCollection(getCollectionLink(database, collection, isNameBased), - null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource().build(); - validateSuccess(deleteObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT, dataProvider = "collectionCrudArgProvider") - public void replaceCollection(String collectionName, boolean isNameBased) { - // create a collection - DocumentCollection collectionDefinition = getCollectionDefinition(collectionName); - Observable> createObservable = client.createCollection(getDatabaseLink(database, isNameBased), collectionDefinition, null); - DocumentCollection collection = createObservable.toBlocking().single().getResource(); - // sanity check - assertThat(collection.getIndexingPolicy().getIndexingMode()).isEqualTo(IndexingMode.Consistent); - - // replace indexing mode - IndexingPolicy indexingMode = new IndexingPolicy(); - indexingMode.setIndexingMode(IndexingMode.Lazy); - collection.setIndexingPolicy(indexingMode); - Observable> readObservable = client.replaceCollection(collection, null); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .indexingMode(IndexingMode.Lazy).build(); - validateSuccess(readObservable, validator); - safeDeleteAllCollections(client, database); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void sessionTokenConsistencyCollectionDeleteCreateSameName() { - AsyncDocumentClient client1 = clientBuilder.build(); - AsyncDocumentClient client2 = clientBuilder.build(); - - String dbId = "db"; - String collectionId = "coll"; - try { - Database databaseDefinition = new Database(); - databaseDefinition.setId(dbId); - createDatabase(client1, dbId); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(collectionId); - DocumentCollection collection = createCollection(client1, dbId, collectionDefinition); - - Document document = new Document(); - document.setId("doc"); - document.set("name", "New Document"); - createDocument(client1, dbId, collectionId, document); - ResourceResponse readDocumentResponse = client1.readDocument(Utils.getDocumentNameLink(dbId, collectionId, document.getId()), null).toBlocking().single(); - logger.info("Client 1 Read Document Client Side Request Statistics {}", readDocumentResponse.getRequestDiagnosticsString()); - logger.info("Client 1 Read Document Latency {}", readDocumentResponse.getRequestLatency()); - - document.set("name", "New Updated Document"); - ResourceResponse upsertDocumentResponse = client1.upsertDocument(collection.getSelfLink(), document, null, - true).toBlocking().single(); - logger.info("Client 1 Upsert Document Client Side Request Statistics {}", upsertDocumentResponse.getRequestDiagnosticsString()); - logger.info("Client 1 Upsert Document Latency {}", upsertDocumentResponse.getRequestLatency()); - - // Delete the existing collection - deleteCollection(client2, Utils.getCollectionNameLink(dbId, collectionId)); - // Recreate the collection with the same name but with different client - createCollection(client2, dbId, collectionDefinition); - - Document newDocument = new Document(); - newDocument.setId("doc"); - newDocument.set("name", "New Created Document"); - createDocument(client2, dbId, collectionId, newDocument); - - readDocumentResponse = client1.readDocument(Utils.getDocumentNameLink(dbId, collectionId, newDocument.getId()), null).toBlocking().single(); - logger.info("Client 2 Read Document Client Side Request Statistics {}", readDocumentResponse.getRequestDiagnosticsString()); - logger.info("Client 2 Read Document Latency {}", readDocumentResponse.getRequestLatency()); - - Document readDocument = readDocumentResponse.getResource(); - - assertThat(readDocument.getId().equals(newDocument.getId())).isTrue(); - assertThat(readDocument.get("name").equals(newDocument.get("name"))).isTrue(); - } finally { - safeDeleteDatabase(client1, dbId); - safeClose(client1); - safeClose(client2); - } - } - - @BeforeClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - database = createDatabase(client, databaseId); - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId); - safeClose(client); - } - - private static String getDatabaseLink(Database db, boolean isNameLink) { - return isNameLink ? "dbs/" + db.getId() : db.getSelfLink(); - } - - private static String getCollectionLink(Database db, DocumentCollection documentCollection, boolean isNameLink) { - return isNameLink ? "dbs/" + db.getId() + "/colls/" + documentCollection.getId() : documentCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/CollectionQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/CollectionQueryTest.java deleted file mode 100644 index 0a4500c9d6a7..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/CollectionQueryTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.apache.commons.lang3.StringUtils; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -public class CollectionQueryTest extends TestSuiteBase { - private final static int TIMEOUT = 30000; - private final String databaseId = DatabaseForTest.generateId(); - private List createdCollections = new ArrayList<>(); - private AsyncDocumentClient client; - - private String getDatabaseLink() { - return Utils.getDatabaseNameLink(databaseId); - } - - @Factory(dataProvider = "clientBuilders") - public CollectionQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - this.subscriberValidationTimeout = TIMEOUT; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryCollectionsWithFilter() throws Exception { - - String filterCollectionId = createdCollections.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterCollectionId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - Observable> queryObservable = client.queryCollections(getDatabaseLink(), query, options); - - List expectedCollections = createdCollections.stream() - .filter(c -> StringUtils.equals(filterCollectionId, c.getId()) ).collect(Collectors.toList()); - - assertThat(expectedCollections).isNotEmpty(); - - int expectedPageSize = (expectedCollections.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedCollections.size()) - .exactlyContainsInAnyOrder(expectedCollections.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAllCollections() throws Exception { - - String query = "SELECT * from c"; - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - String databaseLink = Utils.getDatabaseNameLink(databaseId); - Observable> queryObservable = client.queryCollections(databaseLink, query, options); - - List expectedCollections = createdCollections; - - assertThat(expectedCollections).isNotEmpty(); - - int expectedPageSize = (expectedCollections.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedCollections.size()) - .exactlyContainsInAnyOrder(expectedCollections.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryCollections_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client.queryCollections(getDatabaseLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createDatabase(client, databaseId); - - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - createdCollections.add(createCollection(client, databaseId, collection)); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId); - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DCDocumentCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DCDocumentCrudTest.java deleted file mode 100644 index fc8b79637e95..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DCDocumentCrudTest.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.StoredProcedureResponse; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.SpyClientUnderTestFactory; -import org.mockito.stubbing.Answer; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.spy; - -/** - * The purpose of the tests in this class is to ensure the request are routed through direct connectivity stack. - * The tests in other test classes validate the actual behaviour and different scenarios. - */ -public class DCDocumentCrudTest extends TestSuiteBase { - private final static int QUERY_TIMEOUT = 30000; - private final static String PARTITION_KEY_FIELD_NAME = "mypk"; - - private static Database createdDatabase; - private static DocumentCollection createdCollection; - - private SpyClientUnderTestFactory.ClientWithGatewaySpy client; - - @DataProvider - public static Object[][] directClientBuilder() { - return new Object[][] { { createDCBuilder(Protocol.Https) }, { createDCBuilder(Protocol.Tcp) } }; - } - - static Builder createDCBuilder(Protocol protocol) { - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - - Configs configs = spy(new Configs()); - doAnswer((Answer) invocation -> protocol).when(configs).getProtocol(); - - return new Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConfigs(configs) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY); - } - - @Factory(dataProvider = "directClientBuilder") - public DCDocumentCrudTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "direct" }, timeOut = TIMEOUT) - public void executeStoredProc() { - StoredProcedure storedProcedure = new StoredProcedure(); - storedProcedure.setId(UUID.randomUUID().toString()); - storedProcedure.setBody("function() {var x = 10;}"); - - Observable> createObservable = client - .createStoredProcedure(getCollectionLink(), storedProcedure, null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(storedProcedure.getId()) - .build(); - - validateSuccess(createObservable, validator, TIMEOUT); - - // creating a stored proc will go through gateway so clearing captured requests - - client.getCapturedRequests().clear(); - - // execute the created storedProc and ensure it goes through direct connectivity stack - String storedProcLink = "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId() + "/sprocs/" + storedProcedure.getId(); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey("dummy")); - StoredProcedureResponse storedProcedureResponse = client - .executeStoredProcedure(storedProcLink, options, null).toBlocking().single(); - - assertThat(storedProcedureResponse.getStatusCode()).isEqualTo(200); - - // validate the request routed through direct stack - validateNoStoredProcExecutionOperationThroughGateway(); - } - - /** - * Tests document creation through direct mode - */ - @Test(groups = { "direct" }, timeOut = TIMEOUT) - public void create() { - final Document docDefinition = getDocumentDefinition(); - - Observable> createObservable = client.createDocument( - this.getCollectionLink(), docDefinition, null, false); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - - validateSuccess(createObservable, validator, TIMEOUT); - validateNoDocumentOperationThroughGateway(); - } - - /** - * Tests document read through direct https. - * @throws Exception - */ - @Test(groups = { "direct" }, timeOut = TIMEOUT) - public void read() throws Exception { - Document docDefinition = this.getDocumentDefinition(); - Document document = client.createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource(); - - // give times to replicas to catch up after a write - waitIfNeededForReplicasToCatchUp(clientBuilder); - - String pkValue = document.getString(PARTITION_KEY_FIELD_NAME); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(pkValue)); - - String docLink = - String.format("dbs/%s/colls/%s/docs/%s", createdDatabase.getId(), createdCollection.getId(), document.getId()); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - - validateSuccess(client.readDocument(docLink, options), validator, TIMEOUT); - - validateNoDocumentOperationThroughGateway(); - } - - /** - * Tests document upsert through direct https. - * @throws Exception - */ - @Test(groups = { "direct" }, timeOut = TIMEOUT) - public void upsert() throws Exception { - - final Document docDefinition = getDocumentDefinition(); - - final Document document = client.createDocument(getCollectionLink(), docDefinition, null, false) - .toBlocking() - .single() - .getResource(); - - // give times to replicas to catch up after a write - waitIfNeededForReplicasToCatchUp(clientBuilder); - - String pkValue = document.getString(PARTITION_KEY_FIELD_NAME); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(pkValue)); - - String propName = "newProp"; - String propValue = "hello"; - document.set(propName, propValue); - - ResourceResponseValidator validator = ResourceResponseValidator.builder() - .withProperty(propName, propValue) - .build(); - validateSuccess(client.upsertDocument(getCollectionLink(), document, options, false), validator, TIMEOUT); - - validateNoDocumentOperationThroughGateway(); - } - - @Test(groups = { "direct" }, timeOut = QUERY_TIMEOUT) - public void crossPartitionQuery() { - - truncateCollection(createdCollection); - waitIfNeededForReplicasToCatchUp(clientBuilder); - - client.getCapturedRequests().clear(); - - int cnt = 1000; - List documentList = new ArrayList<>(); - for(int i = 0; i < cnt; i++) { - Document docDefinition = getDocumentDefinition(); - documentList.add(docDefinition); - } - - documentList = bulkInsert(client, getCollectionLink(), documentList).map(ResourceResponse::getResource).toList().toBlocking().single(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setMaxDegreeOfParallelism(-1); - options.setMaxItemCount(100); - Observable> results = client.queryDocuments(getCollectionLink(), "SELECT * FROM r", options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(documentList.size()) - .exactlyContainsInAnyOrder(documentList.stream().map(Document::getResourceId).collect(Collectors.toList())).build(); - - try { - validateQuerySuccess(results, validator, QUERY_TIMEOUT); - validateNoDocumentQueryOperationThroughGateway(); - // validates only the first query for fetching query plan goes to gateway. - assertThat(client.getCapturedRequests().stream().filter(r -> r.getResourceType() == ResourceType.Document)).hasSize(1); - } catch (Throwable error) { - if (clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - } - } - - private void validateNoStoredProcExecutionOperationThroughGateway() { - // this validates that Document related requests don't go through gateway - DocumentServiceRequestValidator validateResourceTypesSentToGateway = DocumentServiceRequestValidator.builder() - .resourceTypeIn(ResourceType.DatabaseAccount, - ResourceType.Database, - ResourceType.DocumentCollection, - ResourceType.PartitionKeyRange) - .build(); - - // validate that all gateway captured requests are non document resources - for(RxDocumentServiceRequest request: client.getCapturedRequests()) { - validateResourceTypesSentToGateway.validate(request); - } - } - - private void validateNoDocumentOperationThroughGateway() { - // this validates that Document related requests don't go through gateway - DocumentServiceRequestValidator validateResourceTypesSentToGateway = DocumentServiceRequestValidator.builder() - .resourceTypeIn(ResourceType.DatabaseAccount, - ResourceType.Database, - ResourceType.DocumentCollection, - ResourceType.PartitionKeyRange) - .build(); - - // validate that all gateway captured requests are non document resources - for(RxDocumentServiceRequest request: client.getCapturedRequests()) { - validateResourceTypesSentToGateway.validate(request); - } - } - - private void validateNoDocumentQueryOperationThroughGateway() { - // this validates that Document related requests don't go through gateway - DocumentServiceRequestValidator validateResourceTypesSentToGateway = DocumentServiceRequestValidator.builder() - .resourceTypeIn(ResourceType.DatabaseAccount, - ResourceType.Database, - ResourceType.DocumentCollection, - ResourceType.PartitionKeyRange) - .build(); - - // validate that all gateway captured requests are non document resources - for(RxDocumentServiceRequest request: client.getCapturedRequests()) { - if (request.getOperationType() == OperationType.Query) { - assertThat(request.getPartitionKeyRangeIdentity()).isNull(); - } else { - validateResourceTypesSentToGateway.validate(request); - } - } - } - - @BeforeClass(groups = { "direct" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(10100); - createdDatabase = SHARED_DATABASE; - createdCollection = createCollection(createdDatabase.getId(), getCollectionDefinition(), options); - client = SpyClientUnderTestFactory.createClientWithGatewaySpy(clientBuilder); - - assertThat(client.getCapturedRequests()).isNotEmpty(); - } - - @AfterClass(groups = { "direct" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - @BeforeMethod(groups = { "direct" }) - public void beforeMethod(Method method) { - super.beforeMethod(method); - client.getCapturedRequests().clear(); - } - - private String getCollectionLink() { - return String.format("/dbs/%s/colls/%s", createdDatabase.getId(), createdCollection.getId()); - } - - private Document getDocumentDefinition() { - Document doc = new Document(); - doc.setId(UUID.randomUUID().toString()); - doc.set(PARTITION_KEY_FIELD_NAME, UUID.randomUUID().toString()); - doc.set("name", "Hafez"); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DatabaseCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DatabaseCrudTest.java deleted file mode 100644 index 3df99491e5b2..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DatabaseCrudTest.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -import java.util.ArrayList; -import java.util.List; - -public class DatabaseCrudTest extends TestSuiteBase { - private final String preExistingDatabaseId = DatabaseForTest.generateId(); - private final List databases = new ArrayList<>(); - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public DatabaseCrudTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void createDatabase() throws Exception { - Database databaseDefinition = new Database(); - databaseDefinition.setId(DatabaseForTest.generateId()); - databases.add(databaseDefinition.getId()); - - // create the database - Observable> createObservable = client.createDatabase(databaseDefinition, null); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(databaseDefinition.getId()).build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void createDatabase_AlreadyExists() throws Exception { - Database databaseDefinition = new Database(); - databaseDefinition.setId(DatabaseForTest.generateId()); - databases.add(databaseDefinition.getId()); - - client.createDatabase(databaseDefinition, null).toBlocking().single(); - - // attempt to create the database - Observable> createObservable = client.createDatabase(databaseDefinition, null); - - // validate - FailureValidator validator = new FailureValidator.Builder().resourceAlreadyExists().build(); - validateFailure(createObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void readDatabase() throws Exception { - // read database - Observable> readObservable = client - .readDatabase(Utils.getDatabaseNameLink(preExistingDatabaseId), null); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(preExistingDatabaseId).build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void readDatabase_DoesntExist() throws Exception { - // read database - Observable> readObservable = client - .readDatabase(Utils.getDatabaseNameLink("I don't exist"), null); - - // validate - FailureValidator validator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, validator); - } - - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void deleteDatabase() throws Exception { - // create the database - Database databaseDefinition = new Database(); - databaseDefinition.setId(DatabaseForTest.generateId()); - databases.add(databaseDefinition.getId()); - client.createDatabase(databaseDefinition, null).toCompletable().await(); - - // delete the database - Observable> deleteObservable = client - .deleteDatabase(Utils.getDatabaseNameLink(databaseDefinition.getId()), null); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource().build(); - validateSuccess(deleteObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void deleteDatabase_DoesntExist() throws Exception { - // delete the database - Observable> deleteObservable = client - .deleteDatabase(Utils.getDatabaseNameLink("I don't exist"), null); - - // validate - FailureValidator validator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(deleteObservable, validator); - } - - @BeforeClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createDatabase(client, preExistingDatabaseId); - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, preExistingDatabaseId); - for(String dbId: databases) { - safeDeleteDatabase(client, dbId); - } - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DatabaseQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DatabaseQueryTest.java deleted file mode 100644 index 832e8fe62ea8..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DatabaseQueryTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.apache.commons.lang3.StringUtils; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -public class DatabaseQueryTest extends TestSuiteBase { - - public final String databaseId1 = DatabaseForTest.generateId(); - public final String databaseId2 = DatabaseForTest.generateId(); - - private List createdDatabases = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public DatabaseQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDatabaseWithFilter() throws Exception { - String query = String.format("SELECT * from c where c.id = '%s'", databaseId1); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - Observable> queryObservable = client.queryDatabases(query, options); - - List expectedDatabases = createdDatabases.stream() - .filter(d -> StringUtils.equals(databaseId1, d.getId()) ).collect(Collectors.toList()); - - assertThat(expectedDatabases).isNotEmpty(); - - int expectedPageSize = (expectedDatabases.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDatabases.size()) - .exactlyContainsInAnyOrder(expectedDatabases.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAllDatabase() throws Exception { - - String query = String.format("SELECT * from c where c.id in ('%s', '%s')", - databaseId1, - databaseId2); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - Observable> queryObservable = client.queryDatabases(query, options); - - List expectedDatabases = createdDatabases; - - assertThat(expectedDatabases).isNotEmpty(); - - int expectedPageSize = (expectedDatabases.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDatabases.size()) - .exactlyContainsInAnyOrder(expectedDatabases.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDatabases_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client.queryDatabases(query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - - Database d1 = new Database(); - d1.setId(databaseId1); - createdDatabases.add(createDatabase(client, d1)); - - Database d2 = new Database(); - d2.setId(databaseId2); - createdDatabases.add(createDatabase(client, d2)); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId1); - safeDeleteDatabase(client, databaseId2); - - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DocumentClientResourceLeakTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DocumentClientResourceLeakTest.java deleted file mode 100644 index e3a1df72d70a..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DocumentClientResourceLeakTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import org.testng.SkipException; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import static org.apache.commons.io.FileUtils.ONE_MB; -import static org.assertj.core.api.Assertions.assertThat; - -public class DocumentClientResourceLeakTest extends TestSuiteBase { - private static final int TIMEOUT = 240000; - private static final int MAX_NUMBER = 1000; - private Builder clientBuilder; - private AsyncDocumentClient client; - - private Database createdDatabase; - private DocumentCollection createdCollection; - - @Factory(dataProvider = "simpleClientBuildersWithDirect") - public DocumentClientResourceLeakTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = {"emulator"}, timeOut = TIMEOUT) - public void resourceLeak() throws Exception { - //TODO FIXME DANOBLE this test doesn't pass on RNTBD - if (clientBuilder.configs.getProtocol() == Protocol.Tcp) { - throw new SkipException("RNTBD"); - } - System.gc(); - TimeUnit.SECONDS.sleep(10); - long usedMemoryInBytesBefore = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); - - - for (int i = 0; i < MAX_NUMBER; i++) { - logger.info("client {}", i); - client = clientBuilder.build(); - try { - logger.info("creating doc..."); - createDocument(client, createdDatabase.getId(), createdCollection.getId(), getDocumentDefinition()); - } finally { - logger.info("closing client..."); - client.close(); - } - } - System.gc(); - TimeUnit.SECONDS.sleep(10); - long usedMemoryInBytesAfter = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()); - - assertThat(usedMemoryInBytesAfter - usedMemoryInBytesBefore).isLessThan(200 * ONE_MB); - } - - @BeforeClass(groups = {"emulator"}, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DocumentCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DocumentCrudTest.java deleted file mode 100644 index 2c13e78df1ef..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/DocumentCrudTest.java +++ /dev/null @@ -1,435 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.apache.commons.lang3.StringUtils; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import java.util.Date; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import static org.apache.commons.io.FileUtils.ONE_MB; -import static org.assertj.core.api.Assertions.assertThat; - -public class DocumentCrudTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public DocumentCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @DataProvider(name = "documentCrudArgProvider") - public Object[][] documentCrudArgProvider() { - return new Object[][] { - // collection name, is name base - {UUID.randomUUID().toString(), false } , - {UUID.randomUUID().toString(), true } , - - // with special characters in the name. - {"+ -_,:.|~" + UUID.randomUUID().toString() + " +-_,:.|~", true } , - }; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void createDocument(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - Observable> createObservable = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void createLargeDocument(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - //Keep size as ~ 1.5MB to account for size of other props - int size = (int) (ONE_MB * 1.5); - docDefinition.set("largeString", StringUtils.repeat("x", size)); - - Observable> createObservable = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void createDocumentWithVeryLargePartitionKey(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - StringBuilder sb = new StringBuilder(); - for(int i = 0; i < 100; i++) { - sb.append(i).append("x"); - } - docDefinition.set("mypk", sb.toString()); - - Observable> createObservable = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .withProperty("mypk", sb.toString()) - .build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void readDocumentWithVeryLargePartitionKey(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - StringBuilder sb = new StringBuilder(); - for(int i = 0; i < 100; i++) { - sb.append(i).append("x"); - } - docDefinition.set("mypk", sb.toString()); - - Document createdDocument = TestSuiteBase.createDocument(client, createdDatabase.getId(), createdCollection.getId(), docDefinition); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(sb.toString())); - Observable> readObservable = client.readDocument(getDocumentLink(createdDocument, isNameBased), options); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .withProperty("mypk", sb.toString()) - .build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void createDocument_AlreadyExists(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - client.createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - Observable> createObservable = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false); - - FailureValidator validator = new FailureValidator.Builder().resourceAlreadyExists().build(); - validateFailure(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void createDocumentTimeout(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - Observable> createObservable = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false) - .timeout(1, TimeUnit.MILLISECONDS); - - FailureValidator validator = new FailureValidator.Builder().instanceOf(TimeoutException.class).build(); - - validateFailure(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void readDocument(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(document.get("mypk"))); - Observable> readObservable = client.readDocument(getDocumentLink(document, isNameBased), options); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(document.getId()) - .build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void timestamp(String documentId, boolean isNameBased) throws Exception { - Date before = new Date(); - Document docDefinition = getDocumentDefinition(documentId); - Thread.sleep(1000); - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(document.get("mypk"))); - Observable> readObservable = client.readDocument(getDocumentLink(document, isNameBased), options); - Document readDocument = readObservable.toBlocking().single().getResource(); - Thread.sleep(1000); - Date after = new Date(); - - assertThat(readDocument.getTimestamp()).isAfterOrEqualsTo(before); - assertThat(readDocument.getTimestamp()).isBeforeOrEqualsTo(after); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void readDocument_DoesntExist(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(document.get("mypk"))); - client.deleteDocument(getDocumentLink(document, isNameBased), options).toBlocking().first(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - - options.setPartitionKey(new PartitionKey("looloo")); - Observable> readObservable = client.readDocument(getDocumentLink(document, isNameBased), options); - - FailureValidator validator = new FailureValidator.Builder().instanceOf(DocumentClientException.class) - .statusCode(404).build(); - validateFailure(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void deleteDocument(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(document.get("mypk"))); - Observable> deleteObservable = client.deleteDocument(getDocumentLink(document, isNameBased), options); - - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource().build(); - validateSuccess(deleteObservable, validator); - - // attempt to read document which was deleted - waitIfNeededForReplicasToCatchUp(clientBuilder); - - Observable> readObservable = client.readDocument(getDocumentLink(document, isNameBased), options); - FailureValidator notFoundValidator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, notFoundValidator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void deleteDocument_undefinedPK(String documentId, boolean isNameBased) { - Document docDefinition = new Document(); - docDefinition.setId(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(Undefined.Value())); - Observable> deleteObservable = client.deleteDocument(getDocumentLink(document, isNameBased), options); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource().build(); - validateSuccess(deleteObservable, validator); - - // attempt to read document which was deleted - waitIfNeededForReplicasToCatchUp(clientBuilder); - - Observable> readObservable = client.readDocument(getDocumentLink(document, isNameBased), options); - FailureValidator notFoundValidator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, notFoundValidator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void deleteDocument_DoesntExist(String documentId, boolean isNameBased) { - Document docDefinition = getDocumentDefinition(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(document.get("mypk"))); - client.deleteDocument(getDocumentLink(document, isNameBased), options).toBlocking().single(); - - // delete again - Observable> deleteObservable = client.deleteDocument(getDocumentLink(document, isNameBased), options); - - FailureValidator validator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(deleteObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void replaceDocument(String documentId, boolean isNameBased) { - // create a document - Document docDefinition = getDocumentDefinition(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - String newPropValue = UUID.randomUUID().toString(); - document.set("newProp", newPropValue); - - // replace document - Observable> readObservable = client.replaceDocument(document, null); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withProperty("newProp", newPropValue).build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void replaceDocument_UsingDocumentLink(String documentId, boolean isNameBased) { - // create a document - Document docDefinition = getDocumentDefinition(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - String newPropValue = UUID.randomUUID().toString(); - document.set("newProp", newPropValue); - - // replace document - Observable> readObservable = client.replaceDocument(getDocumentLink(document, isNameBased), document, null); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withProperty("newProp", newPropValue).build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void upsertDocument_CreateDocument(String documentId, boolean isNameBased) { - // create a document - Document docDefinition = getDocumentDefinition(documentId); - - - // replace document - Observable> upsertObservable = client.upsertDocument(getCollectionLink(isNameBased), - docDefinition, null, false); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()).build(); - try { - validateSuccess(upsertObservable, validator); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "documentCrudArgProvider") - public void upsertDocument_ReplaceDocument(String documentId, boolean isNameBased) { - // create a document - Document docDefinition = getDocumentDefinition(documentId); - - Document document = client - .createDocument(getCollectionLink(isNameBased), docDefinition, null, false).toBlocking().single().getResource(); - - String newPropValue = UUID.randomUUID().toString(); - document.set("newProp", newPropValue); - - // replace document - Observable> readObservable = client.upsertDocument - (getCollectionLink(isNameBased), document, null, true); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withProperty("newProp", newPropValue).build(); - try { - validateSuccess(readObservable, validator); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - @BeforeMethod(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeMethod() { - safeClose(client); - client = clientBuilder.build(); - } - - private String getCollectionLink(boolean isNameBased) { - return isNameBased ? "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId() : createdCollection.getSelfLink(); - } - - private String getDocumentLink(Document doc, boolean isNameBased) { - return isNameBased ? "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId() + "/docs/" + doc.getId() : - "dbs/" + createdDatabase.getResourceId() + "/colls/" + createdCollection.getResourceId() + "/docs/" + doc.getResourceId(); - } - - private Document getDocumentDefinition(String documentId) { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , documentId, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/LogLevelTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/LogLevelTest.java deleted file mode 100644 index c2ace6ab6596..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/LogLevelTest.java +++ /dev/null @@ -1,308 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx; - -import java.io.StringWriter; -import java.lang.reflect.Method; -import java.util.UUID; - -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.PropertyConfigurator; -import org.apache.log4j.WriterAppender; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -import static org.assertj.core.api.Assertions.assertThat; - -public class LogLevelTest extends TestSuiteBase { - public final static String COSMOS_DB_LOGGING_CATEGORY = "com.microsoft.azure.cosmosdb"; - public final static String NETWORK_LOGGING_CATEGORY = "com.microsoft.azure.cosmosdb.netty-network"; - public final static String LOG_PATTERN_1 = "HTTP/1.1 200 Ok."; - public final static String LOG_PATTERN_2 = "| 0 1 2 3 4 5 6 7 8 9 a b c d e f |"; - public final static String LOG_PATTERN_3 = "USER_EVENT: SslHandshakeCompletionEvent(SUCCESS)"; - public final static String LOG_PATTERN_4 = "CONNECT: "; - - private static Database createdDatabase; - private static DocumentCollection createdCollection; - - public LogLevelTest() { - this.clientBuilder = createGatewayRxDocumentClient(); - } - - @BeforeClass(groups = {"simple"}, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - } - - /** - * This test will try to create document with netty wire DEBUG logging and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithDebugLevel() throws Exception { - LogManager.getLogger(NETWORK_LOGGING_CATEGORY).setLevel(Level.DEBUG); - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - LogManager.getLogger(NETWORK_LOGGING_CATEGORY).addAppender(appender); - - AsyncDocumentClient client = clientBuilder.build(); - try { - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).isEmpty(); - - } finally { - safeClose(client); - } - } - - /** - * This test will try to create document with netty wire WARN logging and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithWarningLevel() throws Exception { - LogManager.getRootLogger().setLevel(Level.INFO); - LogManager.getLogger(NETWORK_LOGGING_CATEGORY).setLevel(Level.WARN); - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - Logger.getLogger(NETWORK_LOGGING_CATEGORY).addAppender(appender); - - AsyncDocumentClient client = clientBuilder.build(); - try { - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).isEmpty(); - } finally { - safeClose(client); - } - } - - /** - * This test will try to create document with netty wire TRACE logging and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithTraceLevel() throws Exception { - LogManager.getRootLogger().setLevel(Level.INFO); - LogManager.getLogger(NETWORK_LOGGING_CATEGORY).setLevel(Level.TRACE); - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - Logger.getLogger(NETWORK_LOGGING_CATEGORY).addAppender(appender); - - AsyncDocumentClient client = clientBuilder.build(); - try { - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1); - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2); - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3); - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4); - - } finally { - safeClose(client); - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithTraceLevelAtRoot() throws Exception { - LogManager.getRootLogger().setLevel(Level.INFO); - LogManager.getLogger(COSMOS_DB_LOGGING_CATEGORY).setLevel(Level.TRACE); - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - Logger.getLogger(NETWORK_LOGGING_CATEGORY).addAppender(appender); - - AsyncDocumentClient client = clientBuilder.build(); - try { - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_1); - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_2); - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_3); - assertThat(consoleWriter.toString()).contains(LOG_PATTERN_4); - } finally { - safeClose(client); - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithDebugLevelAtRoot() throws Exception { - LogManager.getRootLogger().setLevel(Level.INFO); - LogManager.getLogger(COSMOS_DB_LOGGING_CATEGORY).setLevel(Level.DEBUG); - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - Logger.getLogger(NETWORK_LOGGING_CATEGORY).addAppender(appender); - - AsyncDocumentClient client = clientBuilder.build(); - try { - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).isEmpty(); - } finally { - safeClose(client); - } - } - - /** - * This test will try to create document with netty wire ERROR logging and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithErrorClient() throws Exception { - LogManager.getRootLogger().setLevel(Level.INFO); - LogManager.getLogger(NETWORK_LOGGING_CATEGORY).setLevel(Level.ERROR); - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - Logger.getLogger(NETWORK_LOGGING_CATEGORY).addAppender(appender); - - AsyncDocumentClient client = clientBuilder.build(); - try { - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).isEmpty(); - } finally { - safeClose(client); - } - } - - /** - * This test will try to create document with netty wire INFO logging and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithInfoLevel() throws Exception { - LogManager.getRootLogger().setLevel(Level.INFO); - LogManager.getLogger(NETWORK_LOGGING_CATEGORY).setLevel(Level.INFO); - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - Logger.getLogger(NETWORK_LOGGING_CATEGORY).addAppender(appender); - - AsyncDocumentClient client = clientBuilder.build(); - try { - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).isEmpty(); - } finally { - safeClose(client); - } - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - @BeforeMethod(groups = { "simple"}) - public void beforeMethod(Method method) { - super.beforeMethod(method); - LogManager.resetConfiguration(); - PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("log4j.properties")); - } - - @AfterMethod(groups = { "simple" }) - public void afterMethod() { - LogManager.resetConfiguration(); - PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("log4j.properties")); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT) - public void afterClass() { - LogManager.resetConfiguration(); - PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("log4j.properties")); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/MultiMasterConflictResolutionTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/MultiMasterConflictResolutionTest.java deleted file mode 100644 index 05ce9cee9b9f..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/MultiMasterConflictResolutionTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.BridgeUtils; -import com.microsoft.azure.cosmosdb.ConflictResolutionMode; -import com.microsoft.azure.cosmosdb.ConflictResolutionPolicy; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import javax.net.ssl.SSLException; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -// assumes multi master is enabled in endpoint -public class MultiMasterConflictResolutionTest extends TestSuiteBase { - private static final int TIMEOUT = 40000; - - private final String databaseId = DatabaseForTest.generateId(); - - private AsyncDocumentClient client; - private Database database; - - @Factory(dataProvider = "clientBuilders") - public MultiMasterConflictResolutionTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = "multi-master", timeOut = TIMEOUT) - public void conflictResolutionPolicyCRUD() { - - // default last writer wins, path _ts - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - collection = getResource(client.createCollection(getDatabaseLink(database), collection, null)); - - assertThat(collection.getConflictResolutionPolicy().getConflictResolutionMode()).isEqualTo(ConflictResolutionMode.LastWriterWins); - - // LWW without path specified, should default to _ts - collection.setConflictResolutionPolicy(ConflictResolutionPolicy.createLastWriterWinsPolicy()); - collection = getResource(client.replaceCollection(collection, null)); - - - assertThat(collection.getConflictResolutionPolicy().getConflictResolutionMode()).isEqualTo(ConflictResolutionMode.LastWriterWins); - assertThat(collection.getConflictResolutionPolicy().getConflictResolutionPath()).isEqualTo("/_ts"); - - // Tests the following scenarios - // 1. LWW with valid path - // 2. LWW with null path, should default to _ts - // 3. LWW with empty path, should default to _ts - testConflictResolutionPolicyRequiringPath(ConflictResolutionMode.LastWriterWins, - new String[] { "/a", null, "" }, new String[] { "/a", "/_ts", "/_ts" }); - - // LWW invalid path - collection.setConflictResolutionPolicy(ConflictResolutionPolicy.createLastWriterWinsPolicy("/a/b")); - - try { - collection = getResource(client.replaceCollection(collection, null)); - fail("Expected exception on invalid path."); - } catch (Exception e) { - - // when (e.StatusCode == HttpStatusCode.BadRequest) - DocumentClientException dce = com.microsoft.azure.cosmosdb.rx.internal.Utils.as(e.getCause(), DocumentClientException.class); - if (dce != null && dce.getStatusCode() == 400) { - assertThat(dce.getMessage()).contains("Invalid path '\\/a\\/b' for last writer wins conflict resolution"); - } else { - throw e; - } - } - - // LWW invalid path - - collection.setConflictResolutionPolicy(ConflictResolutionPolicy.createLastWriterWinsPolicy("someText")); - - try { - collection = getResource(client.replaceCollection(collection, null)); - fail("Expected exception on invalid path."); - } catch (Exception e) { - // when (e.StatusCode == HttpStatusCode.BadRequest) - DocumentClientException dce = com.microsoft.azure.cosmosdb.rx.internal.Utils.as(e.getCause(), DocumentClientException.class); - if (dce != null && dce.getStatusCode() == 400) { - assertThat(dce.getMessage()).contains("Invalid path 'someText' for last writer wins conflict resolution"); - } else { - throw e; - } - } - - // Tests the following scenarios - // 1. Custom with valid sprocLink - // 2. Custom with null sprocLink, should default to empty string - // 3. Custom with empty sprocLink, should default to empty string - testConflictResolutionPolicyRequiringPath(ConflictResolutionMode.Custom, - new String[] { "randomSprocName", null, "" }, new String[] { "randomSprocName", "", "" }); - } - - private void testConflictResolutionPolicyRequiringPath(ConflictResolutionMode conflictResolutionMode, - String[] paths, String[] expectedPaths) { - for (int i = 0; i < paths.length; i++) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - - if (conflictResolutionMode == ConflictResolutionMode.LastWriterWins) { - collection.setConflictResolutionPolicy(ConflictResolutionPolicy.createLastWriterWinsPolicy(paths[i])); - } else { - collection.setConflictResolutionPolicy(ConflictResolutionPolicy.createCustomPolicy(paths[i])); - } - collection = getResource(client.createCollection("dbs/" + database.getId(), collection, null)); - assertThat(collection.getConflictResolutionPolicy().getConflictResolutionMode()).isEqualTo(conflictResolutionMode); - - if (conflictResolutionMode == ConflictResolutionMode.LastWriterWins) { - assertThat(collection.getConflictResolutionPolicy().getConflictResolutionPath()).isEqualTo(expectedPaths[i]); - } else { - assertThat(collection.getConflictResolutionPolicy().getConflictResolutionProcedure()).isEqualTo(expectedPaths[i]); - } - } - } - - @Test(groups = "multi-master", timeOut = TIMEOUT) - public void invalidConflictResolutionPolicy_LastWriterWinsWithStoredProc() throws Exception { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - - // LWW without path specified, should default to _ts - ConflictResolutionPolicy policy = BridgeUtils.createConflictResolutionPolicy(); - BridgeUtils.setMode(policy, ConflictResolutionMode.LastWriterWins); - BridgeUtils.setStoredProc(policy,"randomSprocName"); - collection.setConflictResolutionPolicy(policy); - - Observable> createObservable = client.createCollection( - getDatabaseLink(database), - collection, - null); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .errorMessageContains("LastWriterWins conflict resolution mode should not have conflict resolution procedure set.") - .build(); - validateFailure(createObservable, validator); - } - - @Test(groups = "multi-master", timeOut = TIMEOUT) - public void invalidConflictResolutionPolicy_CustomWithPath() throws Exception { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - - // LWW without path specified, should default to _ts - ConflictResolutionPolicy policy = BridgeUtils.createConflictResolutionPolicy(); - BridgeUtils.setMode(policy, ConflictResolutionMode.Custom); - BridgeUtils.setPath(policy,"/mypath"); - collection.setConflictResolutionPolicy(policy); - - Observable> createObservable = client.createCollection( - getDatabaseLink(database), - collection, - null); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .errorMessageContains("Custom conflict resolution mode should not have conflict resolution path set.") - .build(); - validateFailure(createObservable, validator); - } - - @BeforeClass(groups = {"multi-master"}, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - // set up the client - - client = clientBuilder.build(); - database = createDatabase(client, databaseId); - } - - private T getResource(Observable> obs) { - return obs.toBlocking().single().getResource(); - } - - @AfterClass(groups = {"multi-master"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, database); - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/MultiOrderByQueryTests.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/MultiOrderByQueryTests.java deleted file mode 100644 index 9734948d38e3..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/MultiOrderByQueryTests.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.Random; -import java.util.UUID; - -import org.apache.commons.collections4.ComparatorUtils; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.azure.cosmosdb.CompositePath; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.CompositePathSortOrder; -import com.microsoft.azure.cosmosdb.Document; - -public class MultiOrderByQueryTests extends TestSuiteBase { - - private static final int TIMEOUT = 35000; - private static final String NUMBER_FIELD = "numberField"; - private static final String STRING_FIELD = "stringField"; - private static final String NUMBER_FIELD_2 = "numberField2"; - private static final String STRING_FIELD_2 = "stringField2"; - private static final String BOOL_FIELD = "boolField"; - private static final String NULL_FIELD = "nullField"; - private static final String OBJECT_FIELD = "objectField"; - private static final String ARRAY_FIELD = "arrayField"; - private static final String SHORT_STRING_FIELD = "shortStringField"; - private static final String MEDIUM_STRING_FIELD = "mediumStringField"; - private static final String LONG_STRING_FIELD = "longStringField"; - private static final String PARTITION_KEY = "pk"; - private ArrayList documents = new ArrayList(); - private DocumentCollection documentCollection; - private Builder clientBuilder; - private AsyncDocumentClient client; - - class CustomComparator implements Comparator { - String path; - CompositePathSortOrder order; - boolean isNumericPath = false; - boolean isStringPath = false; - boolean isBooleanPath = false; - boolean isNullPath = false; - - public CustomComparator(String path, CompositePathSortOrder order) { - this.path = path; - this.order = order; - if (this.path.contains("number")) { - isNumericPath = true; - } else if (this.path.toLowerCase().contains("string")) { - isStringPath = true; - } else if (this.path.contains("bool")) { - isBooleanPath = true; - } else if (this.path.contains("null")) { - isNullPath = true; - } - } - - @Override - public int compare(Document doc1, Document doc2) { - boolean isAsc = order == CompositePathSortOrder.Ascending; - if (isNumericPath) { - if (doc1.getInt(path) < doc2.getInt(path)) - return isAsc ? -1 : 1; - else if (doc1.getInt(path) > doc2.getInt(path)) - return isAsc ? 1 : -1; - else - return 0; - } else if (isStringPath) { - if (!isAsc) { - Document temp = doc1; - doc1 = doc2; - doc2 = temp; - } - return doc1.getString(path).compareTo(doc2.getString(path)); - } else if (isBooleanPath) { - if (doc1.getBoolean(path) == false && doc2.getBoolean(path) == true) - return isAsc ? -1 : 1; - else if (doc1.getBoolean(path) == true && doc2.getBoolean(path) == false) - return isAsc ? 1 : -1; - else - return 0; - } else if (isNullPath) { - // all nulls are equal - return 0; - } else { - throw new IllegalStateException("data type not handled by comparator!"); - } - } - } - - @Factory(dataProvider = "clientBuilders") - public MultiOrderByQueryTests(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - documentCollection = SHARED_MULTI_PARTITION_COLLECTION_WITH_COMPOSITE_AND_SPATIAL_INDEXES; - truncateCollection(SHARED_MULTI_PARTITION_COLLECTION_WITH_COMPOSITE_AND_SPATIAL_INDEXES); - - int numberOfDocuments = 4; - - Random random = new Random(); - for (int i = 0; i < numberOfDocuments; ++i) { - Document multiOrderByDocument = generateMultiOrderByDocument(); - String multiOrderByDocumentString = multiOrderByDocument.toJson(); - int numberOfDuplicates = 5; - - for (int j = 0; j < numberOfDuplicates; j++) { - // Add the document itself for exact duplicates - Document initialDocument = new Document(multiOrderByDocumentString); - initialDocument.setId(UUID.randomUUID().toString()); - this.documents.add(initialDocument); - - // Permute all the fields so that there are duplicates with tie breaks - Document numberClone = new Document(multiOrderByDocumentString); - numberClone.set(NUMBER_FIELD, random.nextInt(5)); - numberClone.setId(UUID.randomUUID().toString()); - this.documents.add(numberClone); - - Document stringClone = new Document(multiOrderByDocumentString); - stringClone.set(STRING_FIELD, Integer.toString(random.nextInt(5))); - stringClone.setId(UUID.randomUUID().toString()); - this.documents.add(stringClone); - - Document boolClone = new Document(multiOrderByDocumentString); - boolClone.set(BOOL_FIELD, random.nextInt(2) % 2 == 0); - boolClone.setId(UUID.randomUUID().toString()); - this.documents.add(boolClone); - - // Also fuzz what partition it goes to - Document partitionClone = new Document(multiOrderByDocumentString); - partitionClone.set(PARTITION_KEY, random.nextInt(5)); - partitionClone.setId(UUID.randomUUID().toString()); - this.documents.add(partitionClone); - } - } - - bulkInsertBlocking(client, documentCollection.getSelfLink(), documents); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - private Document generateMultiOrderByDocument() { - Random random = new Random(); - Document document = new Document(); - document.setId(UUID.randomUUID().toString()); - document.set(NUMBER_FIELD, random.nextInt(5)); - document.set(NUMBER_FIELD_2, random.nextInt(5)); - document.set(BOOL_FIELD, (random.nextInt() % 2) == 0); - document.set(STRING_FIELD, Integer.toString(random.nextInt(5))); - document.set(STRING_FIELD_2, Integer.toString(random.nextInt(5))); - document.set(NULL_FIELD, null); - document.set(OBJECT_FIELD, ""); - document.set(ARRAY_FIELD, (new ObjectMapper()).createArrayNode()); - document.set(SHORT_STRING_FIELD, "a" + random.nextInt(100)); - document.set(MEDIUM_STRING_FIELD, "a" + random.nextInt(128) + 100); - document.set(LONG_STRING_FIELD, "a" + random.nextInt(255) + 128); - document.set(PARTITION_KEY, random.nextInt(5)); - return document; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDocumentsWithMultiOrder() throws DocumentClientException, InterruptedException { - FeedOptions feedOptions = new FeedOptions(); - feedOptions.setEnableCrossPartitionQuery(true); - - boolean[] booleanValues = new boolean[] {true, false}; - Iterator> compositeIndexesIterator = documentCollection.getIndexingPolicy().getCompositeIndexes().iterator(); - while (compositeIndexesIterator.hasNext()) { - ArrayList compositeIndex = compositeIndexesIterator.next(); - // for every order - for (boolean invert : booleanValues) { - // for normal and inverted order - for (boolean hasTop : booleanValues) { - // with and without top - for (boolean hasFilter : booleanValues) { - // with and without filter - // Generate a multi order by from that index - List orderByItems = new ArrayList(); - List selectItems = new ArrayList(); - boolean isDesc; - Iterator compositeIndexiterator = compositeIndex.iterator(); - while (compositeIndexiterator.hasNext()) { - CompositePath compositePath = compositeIndexiterator.next(); - isDesc = compositePath.getOrder() == CompositePathSortOrder.Descending ? true : false; - if (invert) { - isDesc = !isDesc; - } - - String isDescString = isDesc ? "DESC" : "ASC"; - String compositePathName = compositePath.getPath().replaceAll("/", ""); - String orderByItemsString = "root." + compositePathName + " " + isDescString; - String selectItemsString = "root." + compositePathName; - orderByItems.add(orderByItemsString); - selectItems.add(selectItemsString); - } - - int topCount = 10; - StringBuilder selectItemStringBuilder = new StringBuilder(); - for (String selectItem: selectItems) { - selectItemStringBuilder.append(selectItem); - selectItemStringBuilder.append(","); - } - selectItemStringBuilder.deleteCharAt(selectItemStringBuilder.length() - 1); - StringBuilder orderByItemStringBuilder = new StringBuilder(); - for (String orderByItem : orderByItems) { - orderByItemStringBuilder.append(orderByItem); - orderByItemStringBuilder.append(","); - } - orderByItemStringBuilder.deleteCharAt(orderByItemStringBuilder.length() - 1); - - String topString = hasTop ? "TOP " + topCount : ""; - String whereString = hasFilter ? "WHERE root." + NUMBER_FIELD + " % 2 = 0" : ""; - String query = "SELECT " + topString + " [" + selectItemStringBuilder.toString() + "] " + - "FROM root " + whereString + " " + - "ORDER BY " + orderByItemStringBuilder.toString(); - - ArrayList expectedOrderedList = top(sort(filter(this.documents, hasFilter), compositeIndex, invert), hasTop, topCount) ; - - Observable> queryObservable = client - .queryDocuments(documentCollection.getSelfLink(), query, feedOptions); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .withOrderedResults(expectedOrderedList, compositeIndex) - .build(); - - validateQuerySuccess(queryObservable, validator); - } - } - } - } - - // Create document with numberField not set. - // This query would then be invalid. - Document documentWithEmptyField = generateMultiOrderByDocument(); - documentWithEmptyField.remove(NUMBER_FIELD); - client.createDocument(documentCollection.getSelfLink(), documentWithEmptyField, null, false).toBlocking().single(); - String query = "SELECT [root." + NUMBER_FIELD + ",root." + STRING_FIELD + "] FROM root ORDER BY root." + NUMBER_FIELD + " ASC ,root." + STRING_FIELD + " DESC"; - Observable> queryObservable = client - .queryDocuments(documentCollection.getSelfLink(), query, feedOptions); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(UnsupportedOperationException.class) - .build(); - - validateQueryFailure(queryObservable, validator); - } - - private ArrayList top(ArrayList documents, boolean hasTop, int topCount) { - ArrayList result = new ArrayList(); - int counter = 0; - if (hasTop) { - while (counter < topCount && counter < documents.size()) { - result.add(documents.get(counter)); - counter++; - } - } else { - result.addAll(documents); - } - return result; - } - - private ArrayList sort(ArrayList documents, ArrayList compositeIndex, - boolean invert) { - Collection> comparators = new ArrayList>(); - Iterator compositeIndexIterator = compositeIndex.iterator(); - while (compositeIndexIterator.hasNext()) { - CompositePath compositePath = compositeIndexIterator.next(); - CompositePathSortOrder order = compositePath.getOrder(); - if (invert) { - if (order == CompositePathSortOrder.Descending) { - order = CompositePathSortOrder.Ascending; - } else { - order = CompositePathSortOrder.Descending; - } - } - String path = compositePath.getPath().replace("/", ""); - comparators.add(new CustomComparator(path, order)); - } - Collections.sort(documents, ComparatorUtils.chainedComparator(comparators)); - return documents; - } - - private ArrayList filter(ArrayList documents, boolean hasFilter) { - ArrayList result = new ArrayList(); - if (hasFilter) { - for (Document document : documents) { - if (document.getInt(NUMBER_FIELD) % 2 == 0) { - result.add(document); - } - } - } else { - result.addAll(documents); - } - return result; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferQueryTest.java deleted file mode 100644 index 5554c8c1ee7a..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferQueryTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.assertj.core.util.Strings; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -public class OfferQueryTest extends TestSuiteBase { - - public final static int SETUP_TIMEOUT = 40000; - public final String databaseId = DatabaseForTest.generateId(); - - private List createdCollections = new ArrayList<>(); - - private AsyncDocumentClient client; - - private String getDatabaseLink() { - return Utils.getDatabaseNameLink(databaseId); - } - - @Factory(dataProvider = "clientBuilders") - public OfferQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void queryOffersWithFilter() throws Exception { - String collectionResourceId = createdCollections.get(0).getResourceId(); - String query = String.format("SELECT * from c where c.offerResourceId = '%s'", collectionResourceId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - Observable> queryObservable = client.queryOffers(query, null); - - List allOffers = client.readOffers(null).flatMap(f -> Observable.from(f.getResults())).toList().toBlocking().single(); - List expectedOffers = allOffers.stream().filter(o -> collectionResourceId.equals(o.getString("offerResourceId"))).collect(Collectors.toList()); - - assertThat(expectedOffers).isNotEmpty(); - - int expectedPageSize = (expectedOffers.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedOffers.size()) - .exactlyContainsInAnyOrder(expectedOffers.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT * 100) - public void queryOffersFilterMorePages() throws Exception { - - List collectionResourceIds = createdCollections.stream().map(c -> c.getResourceId()).collect(Collectors.toList()); - String query = String.format("SELECT * from c where c.offerResourceId in (%s)", - Strings.join(collectionResourceIds.stream().map(s -> "'" + s + "'").collect(Collectors.toList())).with(",")); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(1); - Observable> queryObservable = client.queryOffers(query, options); - - List expectedOffers = client.readOffers(null).flatMap(f -> Observable.from(f.getResults())).toList().toBlocking().single() - .stream().filter(o -> collectionResourceIds.contains(o.getOfferResourceId())) - .collect(Collectors.toList()); - - assertThat(expectedOffers).hasSize(createdCollections.size()); - - int expectedPageSize = (expectedOffers.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedOffers.size()) - .exactlyContainsInAnyOrder(expectedOffers.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void queryCollections_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - Observable> queryObservable = client.queryCollections(getDatabaseLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @BeforeClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - - Database d1 = new Database(); - d1.setId(databaseId); - createDatabase(client, d1); - - for(int i = 0; i < 3; i++) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - createdCollections.add(createCollection(client, databaseId, collection)); - } - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId); - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferReadReplaceTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferReadReplaceTest.java deleted file mode 100644 index 6a5d9e9fdfd0..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OfferReadReplaceTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.List; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.Offer; -import com.microsoft.azure.cosmosdb.ResourceResponse; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class OfferReadReplaceTest extends TestSuiteBase { - - public final String databaseId = DatabaseForTest.generateId(); - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public OfferReadReplaceTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void readAndReplaceOffer() { - - client.readOffers(null).toBlocking().subscribe((offersFeed) -> { - try { - int i; - List offers = offersFeed.getResults(); - for (i = 0; i < offers.size(); i++) { - if (offers.get(i).getOfferResourceId().equals(createdCollection.getResourceId())) { - break; - } - } - - Offer rOffer = client.readOffer(offers.get(i).getSelfLink()).toBlocking().single().getResource(); - int oldThroughput = rOffer.getThroughput(); - - Observable> readObservable = client.readOffer(offers.get(i).getSelfLink()); - - // validate offer read - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withOfferThroughput(oldThroughput) - .notNullEtag() - .build(); - - validateSuccess(readObservable, validatorForRead); - - // update offer - int newThroughput = oldThroughput + 100; - offers.get(i).setThroughput(newThroughput); - Observable> replaceObservable = client.replaceOffer(offers.get(i)); - - // validate offer replace - ResourceResponseValidator validatorForReplace = new ResourceResponseValidator.Builder() - .withOfferThroughput(newThroughput) - .notNullEtag() - .build(); - - validateSuccess(replaceObservable, validatorForReplace); - - } catch (Exception e) { - e.printStackTrace(); - } - - }); - } - - @BeforeClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = createDatabase(client, databaseId); - createdCollection = createCollection(client, createdDatabase.getId(), - getCollectionDefinition()); - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, createdDatabase); - safeClose(client); - } - -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OrderbyDocumentQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OrderbyDocumentQueryTest.java deleted file mode 100644 index cca649efba67..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/OrderbyDocumentQueryTest.java +++ /dev/null @@ -1,589 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; - -import com.fasterxml.jackson.core.JsonProcessingException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; -import com.microsoft.azure.cosmosdb.rx.internal.query.CompositeContinuationToken; -import com.microsoft.azure.cosmosdb.rx.internal.query.OrderByContinuationToken; - -import rx.Observable; -import rx.observers.TestSubscriber; - -public class OrderbyDocumentQueryTest extends TestSuiteBase { - private final double minQueryRequestChargePerPartition = 2.0; - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdDocuments = new ArrayList<>(); - - private AsyncDocumentClient client; - - private int numberOfPartitions; - - @Factory(dataProvider = "clientBuildersWithDirect") - public OrderbyDocumentQueryTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "queryMetricsArgProvider") - public void queryDocumentsValidateContent(boolean qmEnabled) throws Exception { - Document expectedDocument = createdDocuments.get(0); - - String query = String.format("SELECT * from root r where r.propStr = '%s'" - + " ORDER BY r.propInt" - , expectedDocument.getString("propStr")); - - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setPopulateQueryMetrics(qmEnabled); - - Observable> queryObservable = client.queryDocuments(getCollectionLink(), query, options); - - List expectedResourceIds = new ArrayList<>(); - expectedResourceIds.add(expectedDocument.getResourceId()); - - Map> resourceIDToValidator = new HashMap<>(); - - resourceIDToValidator.put(expectedDocument.getResourceId(), - new ResourceValidator.Builder().areEqual(expectedDocument).build()); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .numberOfPages(1) - .containsExactly(expectedResourceIds) - .validateAllResources(resourceIDToValidator) - .totalRequestChargeIsAtLeast(numberOfPartitions * minQueryRequestChargePerPartition) - .allPagesSatisfy(new FeedResponseValidator.Builder().hasRequestChargeHeader().build()) - .hasValidQueryMetrics(qmEnabled) - .build(); - - try { - validateQuerySuccess(queryObservable, validator); - } catch (Throwable error) { - // TODO: DANOBLE: report this detailed information in all failures produced by TestSuiteBase classes - // work item: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/370015 - String message = String.format("%s %s mode with %s consistency test failure", - this.clientBuilder.connectionPolicy.getConnectionMode(), - this.clientBuilder.configs.getProtocol(), - this.clientBuilder.desiredConsistencyLevel); - throw new AssertionError(message, error); - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDocuments_NoResults() throws Exception { - String query = "SELECT * from root r where r.id = '2' ORDER BY r.propInt"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .totalRequestChargeIsAtLeast(numberOfPartitions * minQueryRequestChargePerPartition) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .hasRequestChargeHeader().build()) - .build(); - - validateQuerySuccess(queryObservable, validator); - } - - @DataProvider(name = "sortOrder") - public Object[][] sortOrder() { - return new Object[][] { { "ASC" }, {"DESC"} }; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "sortOrder") - public void queryOrderBy(String sortOrder) throws Exception { - String query = String.format("SELECT * FROM r ORDER BY r.propInt %s", sortOrder); - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - int pageSize = 3; - options.setMaxItemCount(pageSize); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - Comparator validatorComparator = Comparator.nullsFirst(Comparator.naturalOrder()); - - List expectedResourceIds = sortDocumentsAndCollectResourceIds("propInt", d -> d.getInt("propInt"), validatorComparator); - if ("DESC".equals(sortOrder)) { - Collections.reverse(expectedResourceIds); - } - - int expectedPageSize = expectedNumberOfPages(expectedResourceIds.size(), pageSize); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(expectedResourceIds) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .hasRequestChargeHeader().build()) - .totalRequestChargeIsAtLeast(numberOfPartitions * minQueryRequestChargePerPartition) - .build(); - - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryOrderByInt() throws Exception { - String query = "SELECT * FROM r ORDER BY r.propInt"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - int pageSize = 3; - options.setMaxItemCount(pageSize); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - Comparator validatorComparator = Comparator.nullsFirst(Comparator.naturalOrder()); - List expectedResourceIds = sortDocumentsAndCollectResourceIds("propInt", d -> d.getInt("propInt"), validatorComparator); - int expectedPageSize = expectedNumberOfPages(expectedResourceIds.size(), pageSize); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(expectedResourceIds) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .hasRequestChargeHeader().build()) - .totalRequestChargeIsAtLeast(numberOfPartitions * minQueryRequestChargePerPartition) - .build(); - - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryOrderByString() throws Exception { - String query = "SELECT * FROM r ORDER BY r.propStr"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - int pageSize = 3; - options.setMaxItemCount(pageSize); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - Comparator validatorComparator = Comparator.nullsFirst(Comparator.naturalOrder()); - List expectedResourceIds = sortDocumentsAndCollectResourceIds("propStr", d -> d.getString("propStr"), validatorComparator); - int expectedPageSize = expectedNumberOfPages(expectedResourceIds.size(), pageSize); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(expectedResourceIds) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .hasRequestChargeHeader().build()) - .totalRequestChargeIsAtLeast(numberOfPartitions * minQueryRequestChargePerPartition) - .build(); - - validateQuerySuccess(queryObservable, validator); - } - - @DataProvider(name = "topValue") - public Object[][] topValueParameter() { - return new Object[][] { { 0 }, { 1 }, { 5 }, { createdDocuments.size() - 1 }, { createdDocuments.size() }, - { createdDocuments.size() + 1 }, { 2 * createdDocuments.size() } }; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "topValue") - public void queryOrderWithTop(int topValue) throws Exception { - String query = String.format("SELECT TOP %d * FROM r ORDER BY r.propInt", topValue); - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - int pageSize = 3; - options.setMaxItemCount(pageSize); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - Comparator validatorComparator = Comparator.nullsFirst(Comparator.naturalOrder()); - - List expectedResourceIds = - sortDocumentsAndCollectResourceIds("propInt", d -> d.getInt("propInt"), validatorComparator) - .stream().limit(topValue).collect(Collectors.toList()); - - int expectedPageSize = expectedNumberOfPages(expectedResourceIds.size(), pageSize); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(expectedResourceIds) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .hasRequestChargeHeader().build()) - .totalRequestChargeIsAtLeast(numberOfPartitions * (topValue > 0 ? minQueryRequestChargePerPartition : 1)) - .build(); - - validateQuerySuccess(queryObservable, validator); - } - - private List sortDocumentsAndCollectResourceIds(String propName, Function extractProp, Comparator comparer) { - return createdDocuments.stream() - .filter(d -> d.getHashMap().containsKey(propName)) // removes undefined - .sorted((d1, d2) -> comparer.compare(extractProp.apply(d1), extractProp.apply(d2))) - .map(d -> d.getResourceId()).collect(Collectors.toList()); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void crossPartitionQueryNotEnabled() throws Exception { - String query = "SELECT * FROM r ORDER BY r.propInt"; - FeedOptions options = new FeedOptions(); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .build(); - validateQueryFailure(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryScopedToSinglePartition_StartWithContinuationToken() throws Exception { - String query = "SELECT * FROM r ORDER BY r.propScopedPartitionInt ASC"; - FeedOptions options = new FeedOptions(); - options.setPartitionKey(new PartitionKey("duplicateParitionKeyValue")); - options.setMaxItemCount(3); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - - TestSubscriber> subscriber = new TestSubscriber<>(); - queryObservable.first().subscribe(subscriber); - - subscriber.awaitTerminalEvent(); - subscriber.assertCompleted(); - subscriber.assertNoErrors(); - assertThat(subscriber.getValueCount()).isEqualTo(1); - FeedResponse page = subscriber.getOnNextEvents().get(0); - assertThat(page.getResults()).hasSize(3); - - assertThat(page.getResponseContinuation()).isNotEmpty(); - - - options.setRequestContinuation(page.getResponseContinuation()); - queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - - List expectedDocs = createdDocuments.stream() - .filter(d -> (StringUtils.equals("duplicateParitionKeyValue", d.getString("mypk")))) - .filter(d -> (d.getInt("propScopedPartitionInt") > 2)).collect(Collectors.toList()); - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - assertThat(expectedDocs).hasSize(10 - 3); - - FeedResponseListValidator validator = null; - - validator = new FeedResponseListValidator.Builder() - .containsExactly(expectedDocs.stream() - .sorted((e1, e2) -> Integer.compare(e1.getInt("propScopedPartitionInt"), e2.getInt("propScopedPartitionInt"))) - .map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void orderByContinuationTokenRoundTrip() throws Exception { - { - // Positive - OrderByContinuationToken orderByContinuationToken = new OrderByContinuationToken( - new CompositeContinuationToken( - "asdf", - new Range("A", "D", false, true)), - new QueryItem[] {new QueryItem("{\"item\" : 42}")}, - "rid", - false); - String serialized = orderByContinuationToken.toString(); - ValueHolder outOrderByContinuationToken = new ValueHolder(); - - assertThat(OrderByContinuationToken.tryParse(serialized, outOrderByContinuationToken)).isTrue(); - OrderByContinuationToken deserialized = outOrderByContinuationToken.v; - CompositeContinuationToken compositeContinuationToken = deserialized.getCompositeContinuationToken(); - String token = compositeContinuationToken.getToken(); - Range range = compositeContinuationToken.getRange(); - assertThat(token).isEqualTo("asdf"); - assertThat(range.getMin()).isEqualTo("A"); - assertThat(range.getMax()).isEqualTo("D"); - assertThat(range.isMinInclusive()).isEqualTo(false); - assertThat(range.isMaxInclusive()).isEqualTo(true); - - QueryItem[] orderByItems = deserialized.getOrderByItems(); - assertThat(orderByItems).isNotNull(); - assertThat(orderByItems.length).isEqualTo(1); - assertThat(orderByItems[0].getItem()).isEqualTo(42); - - String rid = deserialized.getRid(); - assertThat(rid).isEqualTo("rid"); - - boolean inclusive = deserialized.getInclusive(); - assertThat(inclusive).isEqualTo(false); - } - - { - // Negative - ValueHolder outOrderByContinuationToken = new ValueHolder(); - assertThat(OrderByContinuationToken.tryParse("{\"property\" : \"Not a valid Order By Token\"}", outOrderByContinuationToken)).isFalse(); - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT * 10, dataProvider = "sortOrder") - public void queryDocumentsWithOrderByContinuationTokensInteger(String sortOrder) throws Exception { - // Get Actual - String query = String.format("SELECT * FROM c ORDER BY c.propInt %s", sortOrder); - - // Get Expected - Comparator order = sortOrder.equals("ASC")?Comparator.naturalOrder():Comparator.reverseOrder(); - Comparator validatorComparator = Comparator.nullsFirst(order); - - List expectedResourceIds = sortDocumentsAndCollectResourceIds("propInt", d -> d.getInt("propInt"), validatorComparator); - this.queryWithContinuationTokensAndPageSizes(query, new int[] { 1, 5, 10, 100}, expectedResourceIds); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT * 10, dataProvider = "sortOrder") - public void queryDocumentsWithOrderByContinuationTokensString(String sortOrder) throws Exception { - // Get Actual - String query = String.format("SELECT * FROM c ORDER BY c.id %s", sortOrder); - - // Get Expected - Comparator order = sortOrder.equals("ASC")?Comparator.naturalOrder():Comparator.reverseOrder(); - Comparator validatorComparator = Comparator.nullsFirst(order); - - List expectedResourceIds = sortDocumentsAndCollectResourceIds("id", d -> d.getString("id"), validatorComparator); - this.queryWithContinuationTokensAndPageSizes(query, new int[] { 1, 5, 10, 100 }, expectedResourceIds); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT * 10, dataProvider = "sortOrder") - public void queryDocumentsWithInvalidOrderByContinuationTokensString(String sortOrder) throws Exception { - // Get Actual - String query = String.format("SELECT * FROM c ORDER BY c.id %s", sortOrder); - - // Get Expected - Comparator validatorComparator; - if(sortOrder.equals("ASC")) { - validatorComparator = Comparator.nullsFirst(Comparator.naturalOrder()); - }else{ - validatorComparator = Comparator.nullsFirst(Comparator.reverseOrder()); - } - List expectedResourceIds = sortDocumentsAndCollectResourceIds("id", d -> d.getString("id"), validatorComparator); - this.assertInvalidContinuationToken(query, new int[] { 1, 5, 10, 100 }, expectedResourceIds); - } - - public Document createDocument(AsyncDocumentClient client, Map keyValueProps) - throws DocumentClientException { - Document docDefinition = getDocumentDefinition(keyValueProps); - return client.createDocument(getCollectionLink(), docDefinition, null, false) - .toBlocking().single() - .getResource(); - } - - public List bulkInsert(AsyncDocumentClient client, List> keyValuePropsList) { - - ArrayList>> result = new ArrayList>>(); - - for(Map keyValueProps: keyValuePropsList) { - Document docDefinition = getDocumentDefinition(keyValueProps); - Observable> obs = client.createDocument(getCollectionLink(), docDefinition, null, false); - result.add(obs); - } - - return Observable.merge(result, 100). - map(resp -> resp.getResource()) - .toList().toBlocking().single(); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - truncateCollection(SHARED_MULTI_PARTITION_COLLECTION); - - List> keyValuePropsList = new ArrayList<>(); - Map props; - - for(int i = 0; i < 30; i++) { - props = new HashMap<>(); - props.put("propInt", i); - props.put("propStr", String.valueOf(i)); - keyValuePropsList.add(props); - } - - //undefined values - props = new HashMap<>(); - keyValuePropsList.add(props); - - createdDocuments = bulkInsert(client, keyValuePropsList); - - for(int i = 0; i < 10; i++) { - Map p = new HashMap<>(); - p.put("propScopedPartitionInt", i); - Document doc = getDocumentDefinition("duplicateParitionKeyValue", UUID.randomUUID().toString(), p); - createdDocuments.add(client.createDocument(getCollectionLink(), doc, null, false).toBlocking().single().getResource()); - - } - numberOfPartitions = client - .readPartitionKeyRanges(getCollectionLink(), null) - .flatMap(p -> Observable.from(p.getResults())).toList().toBlocking().single().size(); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private void assertInvalidContinuationToken(String query, int[] pageSize, List expectedIds) { - String requestContinuation = null; - do { - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(1); - options.setEnableCrossPartitionQuery(true); - options.setMaxDegreeOfParallelism(2); - OrderByContinuationToken orderByContinuationToken = new OrderByContinuationToken( - new CompositeContinuationToken( - "asdf", - new Range("A", "D", false, true)), - new QueryItem[] {new QueryItem("{\"item\" : 42}")}, - "rid", - false); - options.setRequestContinuation(orderByContinuationToken.toString()); - Observable> queryObservable = client.queryDocuments(getCollectionLink(), query, - options); - - Observable> firstPageObservable = queryObservable.first(); - TestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - firstPageObservable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(TIMEOUT, TimeUnit.MILLISECONDS); - testSubscriber.assertError(DocumentClientException.class); - } while (requestContinuation != null); - } - - private void queryWithContinuationTokensAndPageSizes(String query, int[] pageSizes, List expectedIds) { - for (int pageSize : pageSizes) { - List receivedDocuments = this.queryWithContinuationTokens(query, pageSize); - List actualIds = new ArrayList(); - for (Document document : receivedDocuments) { - actualIds.add(document.getResourceId()); - } - - assertThat(actualIds).containsExactlyElementsOf(expectedIds); - } - } - - private List queryWithContinuationTokens(String query, int pageSize) { - String requestContinuation = null; - List continuationTokens = new ArrayList(); - List receivedDocuments = new ArrayList(); - do { - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(pageSize); - options.setEnableCrossPartitionQuery(true); - options.setMaxDegreeOfParallelism(2); - options.setRequestContinuation(requestContinuation); - Observable> queryObservable = client.queryDocuments(getCollectionLink(), query, - options); - - Observable> firstPageObservable = queryObservable.first(); - TestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - firstPageObservable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(TIMEOUT, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - - FeedResponse firstPage = testSubscriber.getOnNextEvents().get(0); - requestContinuation = firstPage.getResponseContinuation(); - receivedDocuments.addAll(firstPage.getResults()); - continuationTokens.add(requestContinuation); - } while (requestContinuation != null); - - return receivedDocuments; - } - - private static Document getDocumentDefinition(String partitionKey, String id, Map keyValuePair) { - StringBuilder sb = new StringBuilder(); - sb.append("{\n"); - - for(String key: keyValuePair.keySet()) { - Object val = keyValuePair.get(key); - sb.append(" "); - sb.append("\"").append(key).append("\"").append(" :" ); - if (val == null) { - sb.append("null"); - } else { - sb.append(toJson(val)); - } - sb.append(",\n"); - } - - sb.append(String.format(" \"id\": \"%s\",\n", id)); - sb.append(String.format(" \"mypk\": \"%s\"\n", partitionKey)); - sb.append("}"); - - return new Document(sb.toString()); - } - - private static Document getDocumentDefinition(Map keyValuePair) { - String uuid = UUID.randomUUID().toString(); - return getDocumentDefinition(uuid, uuid, keyValuePair); - } - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - private static String toJson(Object object){ - try { - return com.microsoft.azure.cosmosdb.internal.Utils.getSimpleObjectMapper().writeValueAsString(object); - } catch (JsonProcessingException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ParallelDocumentQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ParallelDocumentQueryTest.java deleted file mode 100644 index 14aacf69af53..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ParallelDocumentQueryTest.java +++ /dev/null @@ -1,438 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.QueryMetrics; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; - -import org.testng.SkipException; -import org.testng.annotations.DataProvider; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; -import com.microsoft.azure.cosmosdb.rx.internal.query.CompositeContinuationToken; - -import rx.Observable; -import rx.observers.TestSubscriber; - -import java.util.Map; - -public class ParallelDocumentQueryTest extends TestSuiteBase { - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdDocuments; - - private AsyncDocumentClient client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - @Factory(dataProvider = "clientBuildersWithDirect") - public ParallelDocumentQueryTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @DataProvider(name = "queryMetricsArgProvider") - public Object[][] queryMetricsArgProvider() { - return new Object[][]{ - {true}, - {false}, - }; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "queryMetricsArgProvider") - public void queryDocuments(boolean qmEnabled) { - String query = "SELECT * from c where c.prop = 99"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - options.setEnableCrossPartitionQuery(true); - options.setPopulateQueryMetrics(qmEnabled); - options.setMaxDegreeOfParallelism(2); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - List expectedDocs = createdDocuments.stream().filter(d -> 99 == d.getInt("prop") ).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .hasValidQueryMetrics(qmEnabled) - .build(); - - try { - validateQuerySuccess(queryObservable, validator, TIMEOUT); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format(String.format("Direct TCP test failure: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel)); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryMetricEquality() throws Exception { - String query = "SELECT * from c where c.prop = 99"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - options.setEnableCrossPartitionQuery(true); - options.setPopulateQueryMetrics(true); - options.setMaxDegreeOfParallelism(0); - - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - List> resultList1 = queryObservable.toList().toBlocking().single(); - - options.setMaxDegreeOfParallelism(4); - Observable> threadedQueryObs = client.queryDocuments(getCollectionLink(), query, - options); - List> resultList2 = threadedQueryObs.toList().toBlocking().single(); - - assertThat(resultList1.size()).isEqualTo(resultList2.size()); - for(int i = 0; i < resultList1.size(); i++){ - compareQueryMetrics(resultList1.get(i).getQueryMetrics(), resultList2.get(i).getQueryMetrics()); - } - } - - private void compareQueryMetrics(Map qm1, Map qm2) { - assertThat(qm1.keySet().size()).isEqualTo(qm2.keySet().size()); - QueryMetrics queryMetrics1 = BridgeInternal.createQueryMetricsFromCollection(qm1.values()); - QueryMetrics queryMetrics2 = BridgeInternal.createQueryMetricsFromCollection(qm2.values()); - assertThat(queryMetrics1.getRetrievedDocumentSize()).isEqualTo(queryMetrics2.getRetrievedDocumentSize()); - assertThat(queryMetrics1.getRetrievedDocumentCount()).isEqualTo(queryMetrics2.getRetrievedDocumentCount()); - assertThat(queryMetrics1.getIndexHitDocumentCount()).isEqualTo(queryMetrics2.getIndexHitDocumentCount()); - assertThat(queryMetrics1.getOutputDocumentCount()).isEqualTo(queryMetrics2.getOutputDocumentCount()); - assertThat(queryMetrics1.getOutputDocumentSize()).isEqualTo(queryMetrics2.getOutputDocumentSize()); - assertThat(BridgeInternal.getClientSideMetrics(queryMetrics1).getRequestCharge()) - .isEqualTo(BridgeInternal.getClientSideMetrics(queryMetrics1).getRequestCharge()); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDocuments_NoResults() { - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPagesIsGreaterThanOrEqualTo(1) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .pageSizeIsLessThanOrEqualTo(0) - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // See: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - - @Test(groups = { "simple" }, timeOut = 2 * TIMEOUT) - public void queryDocumentsWithPageSize() { - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - int pageSize = 3; - options.setMaxItemCount(pageSize); - options.setMaxDegreeOfParallelism(-1); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - List expectedDocs = createdDocuments; - assertThat(expectedDocs).isNotEmpty(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .exactlyContainsInAnyOrder(expectedDocs - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPagesIsGreaterThanOrEqualTo((expectedDocs.size() + 1) / 3) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0) - .pageSizeIsLessThanOrEqualTo(pageSize) - .build()) - .build(); - try { - validateQuerySuccess(queryObservable, validator, 2 * subscriberValidationTimeout); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void invalidQuerySyntax() { - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .notNullActivityId() - .build(); - validateQueryFailure(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void crossPartitionQueryNotEnabled() { - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .build(); - validateQueryFailure(queryObservable, validator); - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // Links: - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - - @Test(groups = { "simple" }, timeOut = 2 * TIMEOUT) - public void partitionKeyRangeId() { - int sum = 0; - try { - for (String partitionKeyRangeId : client.readPartitionKeyRanges(getCollectionLink(), null) - .flatMap(p -> Observable.from(p.getResults())) - .map(pkr -> pkr.getId()).toList().toBlocking().single()) { - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - options.setPartitionKeyRangeIdInternal(partitionKeyRangeId); - int queryResultCount = client - .queryDocuments(getCollectionLink(), query, options) - .flatMap(p -> Observable.from(p.getResults())) - .toList().toBlocking().single().size(); - - sum += queryResultCount; - } - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - - assertThat(sum).isEqualTo(createdDocuments.size()); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void compositeContinuationTokenRoundTrip() throws Exception { - { - // Positive - CompositeContinuationToken compositeContinuationToken = new CompositeContinuationToken("asdf", - new Range("A", "D", false, true)); - String serialized = compositeContinuationToken.toString(); - ValueHolder outCompositeContinuationToken = new ValueHolder(); - boolean succeeed = CompositeContinuationToken.tryParse(serialized, outCompositeContinuationToken); - assertThat(succeeed).isTrue(); - CompositeContinuationToken deserialized = outCompositeContinuationToken.v; - String token = deserialized.getToken(); - Range range = deserialized.getRange(); - assertThat(token).isEqualTo("asdf"); - assertThat(range.getMin()).isEqualTo("A"); - assertThat(range.getMax()).isEqualTo("D"); - assertThat(range.isMinInclusive()).isEqualTo(false); - assertThat(range.isMaxInclusive()).isEqualTo(true); - } - - { - // Negative - ValueHolder outCompositeContinuationToken = new ValueHolder(); - boolean succeeed = CompositeContinuationToken.tryParse("{\"property\" : \"not a valid composite continuation token\"}", outCompositeContinuationToken); - assertThat(succeeed).isFalse(); - } - - { - // Negative - Gateway composite continuation token - ValueHolder outCompositeContinuationToken = new ValueHolder(); - boolean succeeed = CompositeContinuationToken.tryParse("{\"token\":\"-RID:tZFQAImzNLQLAAAAAAAAAA==#RT:1#TRC:10\",\"range\":{\"min\":\"\",\"max\":\"FF\"}}", outCompositeContinuationToken); - assertThat(succeeed).isFalse(); - } - } - - // TODO: This test has been timing out on build, related work item - https://msdata.visualstudio.com/CosmosDB/_workitems/edit/402438/ - @Test(groups = { "non-emulator" }, timeOut = TIMEOUT * 10) - public void queryDocumentsWithCompositeContinuationTokens() throws Exception { - String query = "SELECT * FROM c"; - - // Get Expected - List expectedDocs = createdDocuments - .stream() - .collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - this.queryWithContinuationTokensAndPageSizes(query, new int[] {1, 10, 100}, expectedDocs); - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // Links: - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - // Notes: - // When I've watch this method execute in the debugger and seen that the code sometimes pauses for quite a while in - // the middle of the second group of 21 documents. I test against a debug instance of the public emulator and so - // what I'm seeing could be the result of a public emulator performance issue. Of course, it might also be the - // result of a Tcp protocol performance problem. - - @BeforeClass(groups = { "simple", "non-emulator" }, timeOut = 2 * SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - truncateCollection(SHARED_MULTI_PARTITION_COLLECTION); - List docDefList = new ArrayList<>(); - for(int i = 0; i < 13; i++) { - docDefList.add(getDocumentDefinition(i)); - } - - for(int i = 0; i < 21; i++) { - docDefList.add(getDocumentDefinition(99)); - } - - createdDocuments = bulkInsertBlocking(client, getCollectionLink(), docDefList); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple", "non-emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static Document getDocumentDefinition(int cnt) { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"prop\" : %d, " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, cnt, uuid)); - return doc; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, enabled = false) - public void invalidQuerySytax() throws Exception { - - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client.queryDocuments(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder().instanceOf(DocumentClientException.class) - .statusCode(400).notNullActivityId().build(); - validateQueryFailure(queryObservable, validator); - } - - public Document createDocument(AsyncDocumentClient client, int cnt) throws DocumentClientException { - - Document docDefinition = getDocumentDefinition(cnt); - - return client.createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single() - .getResource(); - } - - private void queryWithContinuationTokensAndPageSizes(String query, int[] pageSizes, List expectedDocs) { - for (int pageSize : pageSizes) { - List receivedDocuments = this.queryWithContinuationTokens(query, pageSize); - List actualIds = new ArrayList(); - for (Document document : receivedDocuments) { - actualIds.add(document.getResourceId()); - } - - List expectedIds = new ArrayList(); - for (Document document : expectedDocs) { - expectedIds.add(document.getResourceId()); - } - - assertThat(actualIds).containsOnlyElementsOf(expectedIds); - } - } - - private List queryWithContinuationTokens(String query, int pageSize) { - String requestContinuation = null; - List continuationTokens = new ArrayList(); - List receivedDocuments = new ArrayList(); - do { - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(pageSize); - options.setEnableCrossPartitionQuery(true); - options.setMaxDegreeOfParallelism(2); - options.setRequestContinuation(requestContinuation); - Observable> queryObservable = client.queryDocuments(getCollectionLink(), query, - options); - - Observable> firstPageObservable = queryObservable.first(); - TestSubscriber> testSubscriber = new TestSubscriber<>(); - firstPageObservable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(TIMEOUT, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - - FeedResponse firstPage = testSubscriber.getOnNextEvents().get(0); - requestContinuation = firstPage.getResponseContinuation(); - receivedDocuments.addAll(firstPage.getResults()); - continuationTokens.add(requestContinuation); - } while (requestContinuation != null); - - return receivedDocuments; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/PermissionCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/PermissionCrudTest.java deleted file mode 100644 index 45c5132499c7..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/PermissionCrudTest.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.Document; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.PermissionMode; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class PermissionCrudTest extends TestSuiteBase { - - private Database createdDatabase; - private User createdUser; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public PermissionCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createPermission() throws Exception { - - createdUser = safeCreateUser(client, createdDatabase.getId(), getUserDefinition()); - //create permission - Permission permission = new Permission(); - permission.setId(UUID.randomUUID().toString()); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc="); - - - Observable> createObservable = client.createPermission(getUserLink(), permission, null); - - // validate permission creation - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(permission.getId()) - .withPermissionMode(PermissionMode.Read) - .withPermissionResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc=") - .notNullEtag() - .build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void readPermission() throws Exception { - createdUser = safeCreateUser(client, createdDatabase.getId(), getUserDefinition()); - - // create permission - Permission permission = new Permission(); - permission.setId(UUID.randomUUID().toString()); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc="); - Permission readBackPermission = client.createPermission(getUserLink(), permission, null).toBlocking().single().getResource(); - - // read Permission - Observable> readObservable = client.readPermission(readBackPermission.getSelfLink(), null); - - // validate permission read - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(permission.getId()) - .withPermissionMode(PermissionMode.Read) - .withPermissionResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc=") - .notNullEtag() - .build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void deletePermission() throws Exception { - - createdUser = safeCreateUser(client, createdDatabase.getId(), getUserDefinition()); - - // create permission - Permission permission = new Permission(); - permission.setId(UUID.randomUUID().toString()); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc="); - Permission readBackPermission = client.createPermission(getUserLink(), permission, null).toBlocking().single().getResource(); - - // delete - Observable> deleteObservable = client.deletePermission(readBackPermission.getSelfLink(), null); - - // validate delete permission - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource() - .build(); - validateSuccess(deleteObservable, validator); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - - // attempt to read the permission which was deleted - Observable> readObservable = client.readPermission(readBackPermission.getSelfLink(), null); - FailureValidator notFoundValidator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, notFoundValidator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void upsertPermission() throws Exception { - - createdUser = safeCreateUser(client, createdDatabase.getId(), getUserDefinition()); - - // create permission - Permission permission = new Permission(); - permission.setId(UUID.randomUUID().toString()); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc="); - Permission readBackPermission = client.upsertPermission(getUserLink(), permission, null).toBlocking().single().getResource(); - - // read Permission - Observable> readObservable = client.readPermission(readBackPermission.getSelfLink(), null); - - // validate permission creation - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackPermission.getId()) - .withPermissionMode(PermissionMode.Read) - .withPermissionResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc=") - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update permission - readBackPermission.setPermissionMode(PermissionMode.All); - - Observable> updateObservable = client.upsertPermission(getUserLink(), readBackPermission, null); - - // validate permission update - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackPermission.getId()) - .withPermissionMode(PermissionMode.All) - .withPermissionResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc=") - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void replacePermission() throws Exception { - - createdUser = safeCreateUser(client, createdDatabase.getId(), getUserDefinition()); - - // create permission - Permission permission = new Permission(); - permission.setId(UUID.randomUUID().toString()); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc="); - Permission readBackPermission = client.createPermission(getUserLink(), permission, null).toBlocking().single().getResource(); - - // read Permission - Observable> readObservable = client.readPermission(readBackPermission.getSelfLink(), null); - - // validate permission creation - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackPermission.getId()) - .withPermissionMode(PermissionMode.Read) - .withPermissionResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc=") - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update permission - readBackPermission.setPermissionMode(PermissionMode.All); - - Observable> updateObservable = client.replacePermission(readBackPermission, null); - - // validate permission replace - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackPermission.getId()) - .withPermissionMode(PermissionMode.All) - .withPermissionResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgTc=") - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static User getUserDefinition() { - User user = new User(); - user.setId(UUID.randomUUID().toString()); - return user; - } - - private String getUserLink() { - return createdUser.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/PermissionQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/PermissionQueryTest.java deleted file mode 100644 index f53e7da02ede..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/PermissionQueryTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.PermissionMode; -import com.microsoft.azure.cosmosdb.User; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class PermissionQueryTest extends TestSuiteBase { - - public final String databaseId = DatabaseForTest.generateId(); - - private Database createdDatabase; - private User createdUser; - private List createdPermissions = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public PermissionQueryTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryWithFilter() throws Exception { - - String filterId = createdPermissions.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - Observable> queryObservable = client - .queryPermissions(getUserLink(), query, options); - - List expectedDocs = createdPermissions.stream().filter(sp -> filterId.equals(sp.getId()) ).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator, TIMEOUT); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void query_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryPermissions(getUserLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAll() throws Exception { - - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(3); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryPermissions(getUserLink(), query, options); - - int expectedPageSize = (createdPermissions.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .exactlyContainsInAnyOrder(createdPermissions - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void invalidQuerySytax() throws Exception { - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryPermissions(getUserLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .notNullActivityId() - .build(); - validateQueryFailure(queryObservable, validator); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - Database d = new Database(); - d.setId(databaseId); - createdDatabase = createDatabase(client, d); - createdUser = safeCreateUser(client, createdDatabase.getId(), getUserDefinition()); - - for(int i = 0; i < 5; i++) { - createdPermissions.add(createPermissions(client, i)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, createdDatabase); - safeClose(client); - } - - private static User getUserDefinition() { - User user = new User(); - user.setId(UUID.randomUUID().toString()); - return user; - } - - public Permission createPermissions(AsyncDocumentClient client, int index) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - - Permission permission = new Permission(); - permission.setId(UUID.randomUUID().toString()); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgT" + Integer.toString(index) + "="); - - return client.createPermission(getUserLink(), permission, null).toBlocking().single().getResource(); - } - - private String getUserLink() { - return "dbs/" + getDatabaseId() + "/users/" + getUserId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } - - private String getUserId() { - return createdUser.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ProxyHostTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ProxyHostTest.java deleted file mode 100644 index f982df926d24..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ProxyHostTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.io.StringWriter; -import java.lang.reflect.Method; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.PropertyConfigurator; -import org.apache.log4j.WriterAppender; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.rx.proxy.HttpProxyServer; - -import io.netty.handler.logging.LogLevel; -import io.netty.handler.logging.LoggingHandler; - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * This class help to test proxy host feature scenarios where user can provide proxy - * host server during AsyncDocumentClient initialization and all its request will - * go through that particular host. - * - */ -public class ProxyHostTest extends TestSuiteBase { - - private static Database createdDatabase; - private static DocumentCollection createdCollection; - - private AsyncDocumentClient client; - private final String PROXY_HOST = "localhost"; - private final int PROXY_PORT = 8080; - private HttpProxyServer httpProxyServer; - - public ProxyHostTest() { - this.clientBuilder = createGatewayRxDocumentClient(); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION; - httpProxyServer = new HttpProxyServer(); - httpProxyServer.start(); - // wait for proxy server to be ready - TimeUnit.SECONDS.sleep(1); - } - - /** - * This test will try to create document via http proxy server and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithValidHttpProxy() throws Exception { - AsyncDocumentClient clientWithRightProxy = null; - try { - ConnectionPolicy connectionPolicy =new ConnectionPolicy(); - connectionPolicy.setProxy(PROXY_HOST, PROXY_PORT); - clientWithRightProxy = new Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = clientWithRightProxy - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - } finally { - safeClose(clientWithRightProxy); - } - } - - /** - * This test will try to create document via http proxy server with netty wire logging and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocumentWithValidHttpProxyWithNettyWireLogging() throws Exception { - LogManager.getRootLogger().setLevel(Level.INFO); - LogManager.getLogger(LogLevelTest.NETWORK_LOGGING_CATEGORY).setLevel(Level.TRACE); - AsyncDocumentClient clientWithRightProxy = null; - try { - StringWriter consoleWriter = new StringWriter(); - WriterAppender appender = new WriterAppender(new PatternLayout(), consoleWriter); - Logger.getLogger(LogLevelTest.NETWORK_LOGGING_CATEGORY).addAppender(appender); - - ConnectionPolicy connectionPolicy =new ConnectionPolicy(); - connectionPolicy.setProxy(PROXY_HOST, PROXY_PORT); - clientWithRightProxy = new Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - Document docDefinition = getDocumentDefinition(); - Observable> createObservable = clientWithRightProxy - .createDocument(getCollectionLink(), docDefinition, null, false); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - validateSuccess(createObservable, validator); - - assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_1); - assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_2); - assertThat(consoleWriter.toString()).contains(LogLevelTest.LOG_PATTERN_3); - } finally { - safeClose(clientWithRightProxy); - } - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() throws Exception { - safeClose(client); - httpProxyServer.shutDown(); - // wait for proxy server to be shutdown - TimeUnit.SECONDS.sleep(1); - - LogManager.resetConfiguration(); - PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("log4j.properties")); - } - - @BeforeMethod(groups = { "simple"}) - public void beforeMethod() { - LogManager.resetConfiguration(); - PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("log4j.properties")); - } - - @AfterMethod(groups = { "simple" }) - public void afterMethod(Method method) { - super.beforeMethod(method); - LogManager.resetConfiguration(); - PropertyConfigurator.configure(this.getClass().getClassLoader().getResource("log4j.properties")); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedAttachmentsTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedAttachmentsTest.java deleted file mode 100644 index bf61c7d7414a..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedAttachmentsTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.apache.commons.io.IOUtils; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Attachment; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.MediaOptions; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; - -import rx.Observable; -import rx.observers.TestSubscriber; - -import javax.net.ssl.SSLException; - -public class ReadFeedAttachmentsTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private Document createdDocument; - - private AsyncDocumentClient client; - - private PartitionKey pk; - @Factory(dataProvider = "clientBuildersWithDirect") - public ReadFeedAttachmentsTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = 30000000) - public void readExternalAttachments() throws Exception { - createdDocument = createDocument(client, createdDatabase.getId(), - createdCollection.getId(), getDocumentDefinition()); - - List createdAttachments = new ArrayList<>(); - for(int i = 0; i < 5; i++) { - createdAttachments.add(createAttachments(client)); - } - waitIfNeededForReplicasToCatchUp(clientBuilder); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - options.setPartitionKey(pk); - - Observable> feedObservable = client.readAttachments(getDocumentLink(), options); - - int expectedPageSize = (createdAttachments.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .totalSize(createdAttachments.size()) - .exactlyContainsInAnyOrder(createdAttachments - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - //@Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readAndUpdateEmbededAttachments() throws Exception { - createdDocument = createDocument(client, createdDatabase.getId(), - createdCollection.getId(), getDocumentDefinition()); - - FeedOptions feedOptions = new FeedOptions(); - feedOptions.setMaxItemCount(1); - feedOptions.setPartitionKey(pk); - String documentLink = "dbs/" + getDatabaseId() + "/colls/" + getCollectionId() + "/docs/" + getDocumentId(); - - MediaOptions options = new MediaOptions(); - options.setContentType("application/octet-stream"); - - RequestOptions reqOptions = new RequestOptions(); - reqOptions.setPartitionKey(pk); - - - try(InputStream ipStream = getMedia1Stream()) { - TestSubscriber> subscriber = new TestSubscriber<>(); - client.createAttachment(documentLink, ipStream, options, reqOptions) - .toBlocking() - .subscribe(subscriber); - subscriber.assertNoErrors(); - } - - try(InputStream ipStream = getMedia1Stream()) { - validateReadEmbededAttachment(documentLink, ipStream, feedOptions); - } - - validateUpdateEmbededAttachment(documentLink, options, feedOptions); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private void validateUpdateEmbededAttachment(String documentLink, MediaOptions mediaOptions, FeedOptions feedOptions) throws Exception { - String mediaLink = client.readAttachments(documentLink, feedOptions) - .map( response -> response.getResults().iterator().next().getMediaLink()) - .toBlocking() - .first(); - - try (InputStream ipStream = getMedia2Stream()) { - client.updateMedia(mediaLink, ipStream, mediaOptions) - .toBlocking().first(); - } - - try (InputStream ipStream = getMedia2Stream()) { - validateReadEmbededAttachment(documentLink, ipStream, feedOptions); - } - } - - private void validateReadEmbededAttachment(String documentLink, InputStream ipStream, FeedOptions feedOptions) { - TestSubscriber subscriber = new TestSubscriber<>(); - client.readAttachments(documentLink, feedOptions) - .map( response -> response.getResults().iterator().next().getMediaLink()) - .flatMap(mediaLink -> client.readMedia(mediaLink)) - .map(mediaResponse -> { - - try(InputStream responseMediaStream = mediaResponse.getMedia()) { - return IOUtils.contentEquals(ipStream, responseMediaStream); - } catch (IOException e) { - return false; - } - }) - .filter(x -> x) // Filter only right extractions back - .toBlocking() - .subscribe(subscriber); - - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - subscriber.assertValueCount(1); - } - - private InputStream getMedia1Stream() - { - return this.getClass().getResourceAsStream("/cosmosdb-1.png"); - } - - private InputStream getMedia2Stream() - { - return this.getClass().getResourceAsStream("/Microsoft.jpg"); - } - - private String getCollectionId() { - return createdCollection.getId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } - - private String getDocumentId() { - return createdDocument.getId(); - } - - public Attachment createAttachments(AsyncDocumentClient client) { - Attachment attachment = getAttachmentDefinition(); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(pk); - return client.createAttachment(getDocumentLink(), attachment, options).toBlocking().single().getResource(); - } - - public String getDocumentLink() { - return "dbs/" + getDatabaseId() + "/colls/" + getCollectionId() + "/docs/" + getDocumentId(); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - pk = new PartitionKey(uuid); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - private static Attachment getAttachmentDefinition() { - String uuid = UUID.randomUUID().toString(); - String type = "application/text"; - return new Attachment(String.format( - "{" + - " 'id': '%s'," + - " 'media': 'http://xstore.'," + - " 'MediaType': 'Book'," + - " 'Author': 'My Book Author'," + - " 'Title': 'My Book Title'," + - " 'contentType': '%s'" + - "}", uuid, type)); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedCollectionsTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedCollectionsTest.java deleted file mode 100644 index fb3c735ea867..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedCollectionsTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class ReadFeedCollectionsTest extends TestSuiteBase { - - protected static final int FEED_TIMEOUT = 60000; - protected static final int SETUP_TIMEOUT = 60000; - protected static final int SHUTDOWN_TIMEOUT = 20000; - - public final String databaseId = DatabaseForTest.generateId(); - - private Database createdDatabase; - private List createdCollections = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public ReadFeedCollectionsTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readCollections() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readCollections(getDatabaseLink(), options); - - int expectedPageSize = (createdCollections.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(createdCollections.size()) - .exactlyContainsInAnyOrder(createdCollections.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = createDatabase(client, databaseId); - - for(int i = 0; i < 3; i++) { - createdCollections.add(createCollections(client)); - } - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, createdDatabase); - safeClose(client); - } - - public DocumentCollection createCollections(AsyncDocumentClient client) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - return client.createCollection(getDatabaseLink(), collection, null).toBlocking().single().getResource(); - } - - private String getDatabaseLink() { - return "dbs/" + createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedDatabasesTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedDatabasesTest.java deleted file mode 100644 index 823118868ec5..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedDatabasesTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class ReadFeedDatabasesTest extends TestSuiteBase { - - private List createdDatabases = new ArrayList<>(); - private List allDatabases = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public ReadFeedDatabasesTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readDatabases() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readDatabases(options); - - int expectedPageSize = (allDatabases.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(allDatabases.size()) - .exactlyContainsInAnyOrder(allDatabases.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws URISyntaxException { - client = clientBuilder.build(); - allDatabases = client.readDatabases(null) - .map(frp -> frp.getResults()) - .toList() - .map(list -> list.stream().flatMap(x -> x.stream()).collect(Collectors.toList())) - .toBlocking() - .single(); - for(int i = 0; i < 5; i++) { - createdDatabases.add(createDatabase(client)); - } - allDatabases.addAll(createdDatabases); - } - - public Database createDatabase(AsyncDocumentClient client) { - Database db = new Database(); - db.setId(UUID.randomUUID().toString()); - return client.createDatabase(db, null).toBlocking().single().getResource(); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - for (int i = 0; i < 5; i ++) { - safeDeleteDatabase(client, createdDatabases.get(i).getId()); - } - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedDocumentsTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedDocumentsTest.java deleted file mode 100644 index fd59b372ffe6..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedDocumentsTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -public class ReadFeedDocumentsTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdDocuments; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public ReadFeedDocumentsTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readDocuments() { - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readDocuments(getCollectionLink(), options); - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(createdDocuments.size()) - .numberOfPagesIsGreaterThanOrEqualTo(1) - .exactlyContainsInAnyOrder(createdDocuments.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0) - .pageSizeIsLessThanOrEqualTo(options.getMaxItemCount()) - .build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readDocuments_withoutEnableCrossPartitionQuery() { - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readDocuments(getCollectionLink(), options); - FailureValidator validator = FailureValidator.builder().instanceOf(DocumentClientException.class) - .statusCode(400) - .errorMessageContains("Cross partition query is required but disabled." + - " Please set x-ms-documentdb-query-enablecrosspartition to true," + - " specify x-ms-documentdb-partitionkey," + - " or revise your query to avoid this exception.") - .build(); - validateQueryFailure(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT, alwaysRun = true) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - - truncateCollection(SHARED_MULTI_PARTITION_COLLECTION); - List docDefList = new ArrayList<>(); - - for(int i = 0; i < 100; i++) { - docDefList.add(getDocumentDefinition()); - } - - createdDocuments = bulkInsertBlocking(client, getCollectionLink(), docDefList); - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - public String getCollectionLink() { - return "dbs/" + getDatabaseId() + "/colls/" + getCollectionId(); - } - - private String getCollectionId() { - return createdCollection.getId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedExceptionHandlingTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedExceptionHandlingTest.java deleted file mode 100644 index 044d2a6e9910..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedExceptionHandlingTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.concurrent.CountDownLatch; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import org.mockito.Mockito; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.BridgeUtils; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedResponse; - -import rx.Observable; -import rx.Subscriber; - - -public class ReadFeedExceptionHandlingTest extends TestSuiteBase { - - public class ExceptionSubscriber extends Subscriber> { - - public int onNextCount; - CountDownLatch latch = new CountDownLatch(1); - public ExceptionSubscriber() { - onNextCount = 0; - } - - @Override - public void onCompleted() { - latch.countDown(); - } - - @Override - public void onError(Throwable e) { - DocumentClientException exception = (DocumentClientException) e; - assertThat(exception).isNotNull(); - assertThat(exception.getStatusCode()).isEqualTo(0); - latch.countDown(); - } - - @Override - public void onNext(FeedResponse page) { - assertThat(page.getResults().size()).isEqualTo(2); - onNextCount ++; - } - } - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public ReadFeedExceptionHandlingTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void readFeedException() throws Exception { - - ArrayList dbs = new ArrayList(); - dbs.add(new Database()); - dbs.add(new Database()); - - ArrayList> frps = new ArrayList>(); - frps.add(BridgeInternal.createFeedResponse(dbs, null)); - frps.add(BridgeInternal.createFeedResponse(dbs, null)); - - Observable> response = Observable.from(frps) - .concatWith(Observable.error(new DocumentClientException(0))) - .concatWith(Observable.from(frps)); - - final AsyncDocumentClient mockClient = Mockito.spy(client); - Mockito.when(mockClient.readDatabases(null)).thenReturn(response); - ExceptionSubscriber subscriber = new ExceptionSubscriber(); - mockClient.readDatabases(null).subscribe(subscriber); - subscriber.latch.await(); - assertThat(subscriber.onNextCount).isEqualTo(2); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(this.client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedOffersTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedOffersTest.java deleted file mode 100644 index 7b7e46d9dd01..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedOffersTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Offer; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class ReadFeedOffersTest extends TestSuiteBase { - - protected static final int FEED_TIMEOUT = 60000; - protected static final int SETUP_TIMEOUT = 60000; - protected static final int SHUTDOWN_TIMEOUT = 20000; - - public final String databaseId = DatabaseForTest.generateId(); - - private Database createdDatabase; - private List allOffers = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public ReadFeedOffersTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "emulator" }, timeOut = FEED_TIMEOUT) - public void readOffers() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readOffers(options); - - int expectedPageSize = (allOffers.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(allOffers.size()) - .exactlyContainsInAnyOrder(allOffers.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = createDatabase(client, databaseId); - - for(int i = 0; i < 3; i++) { - createCollections(client); - } - - allOffers = client.readOffers(null) - .map(frp -> frp.getResults()) - .toList() - .map(list -> list.stream().flatMap(x -> x.stream()).collect(Collectors.toList())) - .toBlocking() - .single(); - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, createdDatabase); - safeClose(client); - } - - public DocumentCollection createCollections(AsyncDocumentClient client) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - return client.createCollection(getDatabaseLink(), collection, null).toBlocking().single().getResource(); - } - - private String getDatabaseLink() { - return "dbs/" + createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedPermissionsTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedPermissionsTest.java deleted file mode 100644 index 6959a305bd5c..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedPermissionsTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.PermissionMode; -import com.microsoft.azure.cosmosdb.User; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class ReadFeedPermissionsTest extends TestSuiteBase { - - public final String databaseId = DatabaseForTest.generateId(); - - private Database createdDatabase; - private User createdUser; - private List createdPermissions = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public ReadFeedPermissionsTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readPermissions() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readPermissions(getUserLink(), options); - - int expectedPageSize = (createdPermissions.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(createdPermissions.size()) - .numberOfPages(expectedPageSize) - .exactlyContainsInAnyOrder(createdPermissions.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - Database d = new Database(); - d.setId(databaseId); - createdDatabase = createDatabase(client, d); - createdUser = safeCreateUser(client, createdDatabase.getId(), getUserDefinition()); - - for(int i = 0; i < 5; i++) { - createdPermissions.add(createPermissions(client, i)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId); - safeClose(client); - } - - private static User getUserDefinition() { - User user = new User(); - user.setId(UUID.randomUUID().toString()); - return user; - } - - public Permission createPermissions(AsyncDocumentClient client, int index) { - DocumentCollection collection = new DocumentCollection(); - collection.setId(UUID.randomUUID().toString()); - Permission permission = new Permission(); - permission.setId(UUID.randomUUID().toString()); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink("dbs/AQAAAA==/colls/AQAAAJ0fgT" + Integer.toString(index) + "="); - return client.createPermission(getUserLink(), permission, null).toBlocking().single().getResource(); - } - - private String getUserLink() { - return "dbs/" + getDatabaseId() + "/users/" + getUserId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } - - private String getUserId() { - return createdUser.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedPkrTests.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedPkrTests.java deleted file mode 100644 index 6fbd5e74ad5a..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedPkrTests.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import javax.net.ssl.SSLException; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; - -import rx.Observable; - -public class ReadFeedPkrTests extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public ReadFeedPkrTests(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "emulator" }, timeOut = FEED_TIMEOUT) - public void readPartitionKeyRanges() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readPartitionKeyRanges(getCollectionLink(), options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(1) - .numberOfPages(1) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - createdDatabase = SHARED_DATABASE; - createdCollection = createCollection(createdDatabase.getId(), - getCollectionDefinition(), - null); - client = clientBuilder.build(); - } - - @AfterClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteCollection(client, createdCollection); - safeClose(client); - } - - private String getCollectionLink() { - return "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedStoredProceduresTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedStoredProceduresTest.java deleted file mode 100644 index 0f7d2aa156ea..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedStoredProceduresTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.StoredProcedure; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class ReadFeedStoredProceduresTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdStoredProcedures = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public ReadFeedStoredProceduresTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readStoredProcedures() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readStoredProcedures(getCollectionLink(), options); - - int expectedPageSize = (createdStoredProcedures.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .totalSize(createdStoredProcedures.size()) - .exactlyContainsInAnyOrder(createdStoredProcedures - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - for(int i = 0; i < 5; i++) { - createdStoredProcedures.add(createStoredProcedures(client)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - public StoredProcedure createStoredProcedures(AsyncDocumentClient client) { - StoredProcedure sproc = new StoredProcedure(); - sproc.setId(UUID.randomUUID().toString()); - sproc.setBody("function() {var x = 10;}"); - return client.createStoredProcedure(getCollectionLink(), sproc, null).toBlocking().single().getResource(); - } - - private String getCollectionLink() { - return "dbs/" + getDatabaseId() + "/colls/" + getCollectionId(); - } - - private String getCollectionId() { - return createdCollection.getId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedTriggersTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedTriggersTest.java deleted file mode 100644 index 2b2c40780718..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedTriggersTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.TriggerOperation; -import com.microsoft.azure.cosmosdb.TriggerType; - -import rx.Observable; - -public class ReadFeedTriggersTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdTriggers = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public ReadFeedTriggersTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readTriggers() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readTriggers(getCollectionLink(), options); - - int expectedPageSize = (createdTriggers.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .totalSize(createdTriggers.size()) - .exactlyContainsInAnyOrder(createdTriggers - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - - this.client = clientBuilder.build(); - this.createdDatabase = SHARED_DATABASE; - this.createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - this.truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - for(int i = 0; i < 5; i++) { - this.createdTriggers.add(this.createTriggers(client)); - } - - this.waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - public Trigger createTriggers(AsyncDocumentClient client) { - Trigger trigger = new Trigger(); - trigger.setId(UUID.randomUUID().toString()); - trigger.setBody("function() {var x = 10;}"); - trigger.setTriggerOperation(TriggerOperation.Create); - trigger.setTriggerType(TriggerType.Pre); - return client.createTrigger(getCollectionLink(), trigger, null).toBlocking().single().getResource(); - } - - private String getCollectionLink() { - return "dbs/" + getDatabaseId() + "/colls/" + getCollectionId(); - } - - private String getCollectionId() { - return createdCollection.getId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedUdfsTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedUdfsTest.java deleted file mode 100644 index 4bd2ccbbbfde..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedUdfsTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class ReadFeedUdfsTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdUserDefinedFunctions = new ArrayList<>(); - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public ReadFeedUdfsTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readUserDefinedFunctions() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readUserDefinedFunctions(getCollectionLink(), options); - - int expectedPageSize = (createdUserDefinedFunctions.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .totalSize(createdUserDefinedFunctions.size()) - .exactlyContainsInAnyOrder(createdUserDefinedFunctions - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - for(int i = 0; i < 5; i++) { - createdUserDefinedFunctions.add(createUserDefinedFunctions(client)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - public UserDefinedFunction createUserDefinedFunctions(AsyncDocumentClient client) { - UserDefinedFunction udf = new UserDefinedFunction(); - udf.setId(UUID.randomUUID().toString()); - udf.setBody("function() {var x = 10;}"); - return client.createUserDefinedFunction(getCollectionLink(), udf, null).toBlocking().single().getResource(); - } - - private String getCollectionLink() { - return "dbs/" + getDatabaseId() + "/colls/" + getCollectionId(); - } - - private String getCollectionId() { - return createdCollection.getId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedUsersTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedUsersTest.java deleted file mode 100644 index 68186ec977d5..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ReadFeedUsersTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.User; - -import rx.Observable; - -import javax.net.ssl.SSLException; - -public class ReadFeedUsersTest extends TestSuiteBase { - - public final String databaseId = DatabaseForTest.generateId(); - private Database createdDatabase; - - private AsyncDocumentClient client; - private List createdUsers = new ArrayList<>(); - - @Factory(dataProvider = "clientBuilders") - public ReadFeedUsersTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readUsers() throws Exception { - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - - Observable> feedObservable = client.readUsers(getDatabaseLink(), options); - - int expectedPageSize = (createdUsers.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(createdUsers.size()) - .exactlyContainsInAnyOrder(createdUsers.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - Database d = new Database(); - d.setId(databaseId); - createdDatabase = createDatabase(client, d); - - for(int i = 0; i < 5; i++) { - createdUsers.add(createUsers(client)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, createdDatabase.getId()); - safeClose(client); - } - - public User createUsers(AsyncDocumentClient client) { - User user = new User(); - user.setId(UUID.randomUUID().toString()); - return client.createUser(getDatabaseLink(), user, null).toBlocking().single().getResource(); - } - - private String getDatabaseLink() { - return "dbs/" + createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ResourceTokenTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ResourceTokenTest.java deleted file mode 100644 index c5587f7b7482..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/ResourceTokenTest.java +++ /dev/null @@ -1,547 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.apache.commons.lang3.StringUtils; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.PermissionMode; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.User; - -import rx.Observable; - -/** - * This class try to test different scenario related to fetching various - * resources from resource token directly or via permission feed . - * - */ -public class ResourceTokenTest extends TestSuiteBase { - public final String databaseId = DatabaseForTest.generateId(); - - private Database createdDatabase; - private DocumentCollection createdCollection; - private DocumentCollection createdCollectionWithPartitionKey; - private Document createdDocument; - private Document createdDocumentWithPartitionKey; - private Document createdDocumentWithPartitionKey2; - private User createdUser; - private Permission createdCollPermission; - private Permission createdCollPermissionWithName; - private Permission createdDocPermission; - private Permission createdDocPermissionWithName; - private Permission createdDocPermissionWithPartitionKey; - private Permission createdDocPermissionWithPartitionKeyWithName; - private Permission createdDocPermissionWithPartitionKey2; - private Permission createdDocPermissionWithPartitionKey2WithName; - private Permission createdColPermissionWithPartitionKey; - private Permission createdColPermissionWithPartitionKeyWithName; - private Permission createdColPermissionWithPartitionKey2; - private Permission createdColPermissionWithPartitionKey2WithName; - - private AsyncDocumentClient client; - - // All static string used in below test cases - private final static String DOCUMENT_DEFINITION = "{ 'id': 'doc%d', 'counter': '%d'}"; - private final static String DOCUMENT_DEFINITION_WITH_PERMISSION_KEY = "{ " + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" + "}"; - private final static String PARTITION_KEY_PATH = "/mypk"; - - private static final String PARTITION_KEY_VALUE = "1"; - private static final String PARTITION_KEY_VALUE_2 = "2"; - private static final String PERMISSION_DEFINITION = "{" + " 'id': 'PermissionForDocWithPartitionKey'," - + " 'permissionMode': 'read'," + " 'resource': '%s'," + " 'resourcePartitionKey': ['%s']" + "}"; - private static final String COLLECTION_PERMISSION_DEFINITION = "{" + " 'id': 'PermissionForColWithPartitionKey'," - + " 'permissionMode': 'read'," + " 'resource': '%s'," + " 'resourcePartitionKey': ['%s']" + "}"; - private static final String USER_NAME = "TestUser"; - private static final String PERMISSION_FOR_COLL = "PermissionForColl"; - private static final String PERMISSION_FOR_COLL_WITH_NAME = "PermissionForCollWithName"; - private static final String PERMISSION_FOR_DOC = "PermissionForDoc"; - private static final String PERMISSION_FOR_DOC_WITH_NAME = "PermissionForDocWithName"; - - @Factory(dataProvider = "clientBuilders") - public ResourceTokenTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - Database d = new Database(); - d.setId(databaseId); - createdDatabase = createDatabase(client, d); - // Create collection - createdCollection = createCollection(client, createdDatabase.getId(), getCollectionDefinition()); - // Create document - createdDocument = createDocument(client, createdDatabase.getId(),createdCollection.getId(), getDocument()); - // Create collection with partition key - createdCollectionWithPartitionKey = createCollection(client, createdDatabase.getId(), getCollectionDefinitionWithPartitionKey()); - // Create document with partition key - createdDocumentWithPartitionKey = createDocument(client, createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), - getDocumentDefinitionWithPartitionKey()); - // Create second document with partition key - createdDocumentWithPartitionKey2 = createDocument(client, createdDatabase.getId(),createdCollectionWithPartitionKey.getId(), - getDocumentDefinitionWithPartitionKey2()); - // Create user - createdUser = createUser(client, createdDatabase.getId(), getUserDefinition()); - // Create permission for collection - createdCollPermission = client.createPermission(getUserLink(), getCollPermission(), null).toBlocking().single() - .getResource(); - createdCollPermissionWithName = client.createPermission(getUserLink(), getCollPermissionWithName(), null).toBlocking().single() - .getResource(); - // Create permission for document - createdDocPermission = client.createPermission(getUserLink(), getDocPermission(), null).toBlocking().single() - .getResource(); - createdDocPermissionWithName = client.createPermission(getUserLink(), getDocPermissionWithName(), null).toBlocking().single() - .getResource(); - // Create permission for document with partition key - createdDocPermissionWithPartitionKey = client - .createPermission(getUserLink(), getDocPermissionWithPartitionKey(), null).toBlocking().single() - .getResource(); - createdDocPermissionWithPartitionKeyWithName = client - .createPermission(getUserLink(), getDocPermissionWithPartitionKeyWithName(), null).toBlocking().single() - .getResource(); - // Create permission for document with partition key 2 - createdDocPermissionWithPartitionKey2 = client - .createPermission(getUserLink(), getDocPermissionWithPartitionKey2(), null).toBlocking().single() - .getResource(); - createdDocPermissionWithPartitionKey2WithName = client - .createPermission(getUserLink(), getDocPermissionWithPartitionKey2WithName(), null).toBlocking().single() - .getResource(); - // Create permission for collection with partition key - createdColPermissionWithPartitionKey = client - .createPermission(getUserLink(), getColPermissionWithPartitionKey(), null).toBlocking().single() - .getResource(); - createdColPermissionWithPartitionKeyWithName = client - .createPermission(getUserLink(), getColPermissionWithPartitionKeyWithName(), null).toBlocking().single() - .getResource(); - // Create permission for collection with partition key - createdColPermissionWithPartitionKey2 = client - .createPermission(getUserLink(), getColPermissionWithPartitionKey2(), null).toBlocking().single() - .getResource(); - createdColPermissionWithPartitionKey2WithName = client - .createPermission(getUserLink(), getColPermissionWithPartitionKey2WithName(), null).toBlocking().single() - .getResource(); - } - - @DataProvider(name = "collectionAndPermissionData") - public Object[][] collectionAndPermissionData() { - return new Object[][]{ - //This test will try to read collection from its own permission and validate it, both with request Id and name. - {createdCollection.getSelfLink(), createdCollPermission}, - {Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()), createdDocPermissionWithName}, - }; - } - - @DataProvider(name = "documentAndPermissionData") - public Object[][] documentAndPermissionData() { - return new Object[][]{ - //These tests will try to read document from its own permission and validate it, both with request Id and name. - {createdDocument.getSelfLink(), createdDocPermission, createdDocument.getId(), null}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollection.getId(), createdDocument.getId()), createdDocPermissionWithName, createdDocument.getId(), null}, - - //These tests will try to read document from its permission having partition key 1 and validate it, both with request Id and name. - {createdDocumentWithPartitionKey.getSelfLink(), createdDocPermissionWithPartitionKey, createdDocumentWithPartitionKey.getId(), PARTITION_KEY_VALUE}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey.getId()), createdDocPermissionWithPartitionKeyWithName - , createdDocumentWithPartitionKey.getId(), PARTITION_KEY_VALUE}, - - //These tests will try to read document from its permission having partition key 2 and validate it, both with request Id and name. - {createdDocumentWithPartitionKey2.getSelfLink(), createdDocPermissionWithPartitionKey2, createdDocumentWithPartitionKey2.getId(), PARTITION_KEY_VALUE_2}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey2.getId()), - createdDocPermissionWithPartitionKey2WithName, createdDocumentWithPartitionKey2.getId(), PARTITION_KEY_VALUE_2}, - - // These tests will try to read document from its parent collection permission and validate it, both with request Id and name. - {createdDocument.getSelfLink(), createdCollPermission, createdDocument.getId(), null}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollection.getId(), createdDocument.getId()), createdCollPermissionWithName, createdDocument.getId(), null}, - - //This test will try to read document from collection permission having partition key 1 and validate it, both with request Id and name. - {createdDocumentWithPartitionKey.getSelfLink(), createdColPermissionWithPartitionKey, createdDocumentWithPartitionKey.getId(), PARTITION_KEY_VALUE}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey.getId()), createdColPermissionWithPartitionKeyWithName, createdDocumentWithPartitionKey.getId(), PARTITION_KEY_VALUE}, - - //This test will try to read document from collection permission having partition key 2 and validate it, both with request Id and name. - {createdDocumentWithPartitionKey2.getSelfLink(), createdColPermissionWithPartitionKey2, createdDocumentWithPartitionKey2.getId(), PARTITION_KEY_VALUE_2}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey2.getId()), createdColPermissionWithPartitionKey2WithName, createdDocumentWithPartitionKey2.getId(), PARTITION_KEY_VALUE_2} - - }; - } - - @DataProvider(name = "documentAndPermissionDataForResourceNotFound") - public Object[][] documentAndPermissionDataForResourceNotFound() { - return new Object[][]{ - //This test will try to read document from its resource token directly and validate it. - {createdDocumentWithPartitionKey2.getSelfLink(), createdColPermissionWithPartitionKey, PARTITION_KEY_VALUE}, - //This test will try to read document from its parent collection resource token directly and validate it. - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey2.getId()), - createdColPermissionWithPartitionKeyWithName, PARTITION_KEY_VALUE} - }; - } - - @DataProvider(name = "documentAndMultipleCollPermissionData") - public Object[][] documentAndMultipleCollPermissionData() { - return new Object[][]{ - //These tests will try to read document from partition 1 with two collection permissions having different partition keys and validate it, both with request Id and name. - {createdDocumentWithPartitionKey.getSelfLink(), createdColPermissionWithPartitionKey, createdColPermissionWithPartitionKey2, createdDocumentWithPartitionKey.getId(), - PARTITION_KEY_VALUE}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey.getId()), createdColPermissionWithPartitionKeyWithName - , createdColPermissionWithPartitionKey2WithName, createdDocumentWithPartitionKey.getId(), PARTITION_KEY_VALUE}, - - //These tests will try to read document from partition 1 with two collection permissions having different partition keys and validate it, both with request Id and name. - {createdDocumentWithPartitionKey2.getSelfLink(), createdColPermissionWithPartitionKey, createdColPermissionWithPartitionKey2, createdDocumentWithPartitionKey2.getId(), - PARTITION_KEY_VALUE_2}, - {Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey2.getId()), createdColPermissionWithPartitionKeyWithName - , createdColPermissionWithPartitionKey2WithName, createdDocumentWithPartitionKey2.getId(), PARTITION_KEY_VALUE_2} - }; - } - - @DataProvider(name = "resourceToken") - public Object[][] resourceToken() { - return new Object[][]{ - //This test will try to read document from its resource token directly and validate it. - {createdDocPermission.getToken()}, - //This test will try to read document from its parent collection resource token directly and validate it. - {createdCollPermission.getToken()} - }; - } - - /** - * This test will try to read collection from permission and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, dataProvider = "collectionAndPermissionData", timeOut = TIMEOUT) - public void readCollectionFromPermissionFeed(String collectionUrl, Permission permission) throws Exception { - AsyncDocumentClient asyncClientResourceToken = null ; - try { - List permissionFeed = new ArrayList<>(); - permissionFeed.add(permission); - asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withPermissionFeed(permissionFeed).withConnectionPolicy(ConnectionPolicy.GetDefault()) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - Observable> readObservable = asyncClientResourceToken - .readCollection(collectionUrl, null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(createdCollection.getId()).build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientResourceToken); - } - } - - /** - * This test will try to read document from permission and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, dataProvider = "documentAndPermissionData", timeOut = TIMEOUT) - public void readDocumentFromPermissionFeed(String documentUrl, Permission permission, String documentId, String partitionKey) throws Exception { - AsyncDocumentClient asyncClientResourceToken = null; - try { - List permissionFeed = new ArrayList<>(); - permissionFeed.add(permission); - asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withPermissionFeed(permissionFeed).withConnectionPolicy(ConnectionPolicy.GetDefault()) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - RequestOptions options = null; - if(StringUtils.isNotEmpty(partitionKey)) { - options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(partitionKey)); - } - Observable> readObservable = asyncClientResourceToken - .readDocument(documentUrl, options); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(documentId).build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientResourceToken); - } - } - - /** - * This test will try to read document from resource token directly and validate it. - * - * @throws Exception - */ - @Test(groups = { "simple" }, dataProvider = "resourceToken", timeOut = TIMEOUT) - public void readDocumentFromResouceToken(String resourceToken) throws Exception { - AsyncDocumentClient asyncClientResourceToken = null; - try { - asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(resourceToken) - .withConnectionPolicy(ConnectionPolicy.GetDefault()).withConsistencyLevel(ConsistencyLevel.Session) - .build(); - Observable> readObservable = asyncClientResourceToken - .readDocument(createdDocument.getSelfLink(), null); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(createdDocument.getId()).build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientResourceToken); - } - } - - /** - * This test will try to read document from multiple collection permissions having different keys and validate it. - * - * @throws Exception - */ - @Test(groups = {"simple"}, dataProvider = "documentAndMultipleCollPermissionData", timeOut = TIMEOUT) - public void readDocumentOfParKeyFromTwoCollPermissionWithDiffPartitionKeys(String documentUrl, Permission collPermission1, Permission collPermission2, String documentId, String partitionKey) throws Exception { - AsyncDocumentClient asyncClientResourceToken = null; - try { - List permissionFeed = new ArrayList<>(); - permissionFeed.add(collPermission1); - permissionFeed.add(collPermission2); - asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withPermissionFeed(permissionFeed).withConnectionPolicy(ConnectionPolicy.GetDefault()) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(partitionKey)); - Observable> readObservable = asyncClientResourceToken - .readDocument(documentUrl, options); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(documentId).build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientResourceToken); - } - } - - /** - * This test will try to read document with wrong collection permission hence - * expecting resource not found failure. - * - * @throws Exception - */ - @Test(groups = { "simple" },dataProvider = "documentAndPermissionDataForResourceNotFound", timeOut = TIMEOUT) - public void readDocumentFromCollPermissionWithDiffPartitionKey_ResourceNotFound(String documentUrl, Permission permission, String partitionKey) throws Exception { - AsyncDocumentClient asyncClientResourceToken = null; - try { - List permissionFeed = new ArrayList<>(); - permissionFeed.add(permission); - asyncClientResourceToken = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withPermissionFeed(permissionFeed).withConnectionPolicy(ConnectionPolicy.GetDefault()) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(partitionKey)); - Observable> readObservable = asyncClientResourceToken - .readDocument(documentUrl, options); - FailureValidator validator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, validator); - } finally { - safeClose(asyncClientResourceToken); - } - } - - /** - * This test will try to read document with collection permissions and passing wrong partitionkey - * in request options hence expecting exception. - * - * @throws Exception - */ - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void readDocumentFromCollPermissionWithDiffPartitionKey_WithException() throws Exception { - AsyncDocumentClient asyncClientResourceToken = null; - try { - List permissionFeed = new ArrayList<>(); - permissionFeed.add(createdColPermissionWithPartitionKey); - asyncClientResourceToken = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(ConnectionPolicy.GetDefault()) - .withConsistencyLevel(ConsistencyLevel.Session) - .withPermissionFeed(permissionFeed) - .build(); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(PARTITION_KEY_VALUE_2)); - Observable> readObservable = asyncClientResourceToken - .readDocument(createdDocumentWithPartitionKey.getSelfLink(), options); - FailureValidator validator = new FailureValidator.Builder().resourceTokenNotFound().build(); - validateFailure(readObservable, validator); - } finally { - safeClose(asyncClientResourceToken); - } - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId); - safeClose(client); - } - - private static User getUserDefinition() { - User user = new User(); - user.setId(USER_NAME); - return user; - } - - private static Document getDocument() { - Document doc = new Document(String.format(DOCUMENT_DEFINITION, 1, 1)); - return doc; - } - - private Permission getCollPermission() { - Permission permission = new Permission(); - permission.setId(PERMISSION_FOR_COLL); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink(createdCollection.getSelfLink()); - return permission; - } - - private Permission getCollPermissionWithName() { - Permission permission = new Permission(); - permission.setId(PERMISSION_FOR_COLL_WITH_NAME); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink(Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId())); - return permission; - } - - private Permission getDocPermission() { - Permission permission = new Permission(); - permission.setId(PERMISSION_FOR_DOC); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink(createdDocument.getSelfLink()); - return permission; - } - private Permission getDocPermissionWithName() { - Permission permission = new Permission(); - permission.setId(PERMISSION_FOR_DOC_WITH_NAME); - permission.setPermissionMode(PermissionMode.Read); - permission.setResourceLink(Utils.getDocumentNameLink(createdDatabase.getId(),createdCollection.getId(),createdDocument.getId())); - return permission; - } - - private Permission getDocPermissionWithPartitionKey() { - String permissionStr = String.format(PERMISSION_DEFINITION, createdDocumentWithPartitionKey.getSelfLink(), - PARTITION_KEY_VALUE); - Permission permission = new Permission(permissionStr); - return permission; - } - - private Permission getDocPermissionWithPartitionKeyWithName() { - String permissionStr = String.format(PERMISSION_DEFINITION, Utils.getDocumentNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId(), createdDocumentWithPartitionKey.getId()), - PARTITION_KEY_VALUE); - Permission permission = new Permission(permissionStr); - permission.setId("PermissionForDocWithPartitionKeyWithName"); - return permission; - } - - private Permission getDocPermissionWithPartitionKey2() { - String permissionStr = String.format(PERMISSION_DEFINITION, createdDocumentWithPartitionKey2.getSelfLink(), - PARTITION_KEY_VALUE_2); - Permission permission = new Permission(permissionStr); - permission.setId("PermissionForDocWithPartitionKey2"); - return permission; - } - - private Permission getDocPermissionWithPartitionKey2WithName() { - String permissionStr = String.format(PERMISSION_DEFINITION, Utils.getDocumentNameLink(createdDatabase.getId(),createdCollectionWithPartitionKey.getId(),createdDocumentWithPartitionKey2.getId()), - PARTITION_KEY_VALUE_2); - Permission permission = new Permission(permissionStr); - permission.setId("PermissionForDocWithPartitionKey2WithName"); - return permission; - } - - private Permission getColPermissionWithPartitionKey() { - String permissionStr = String.format(COLLECTION_PERMISSION_DEFINITION, createdCollectionWithPartitionKey.getSelfLink(), - PARTITION_KEY_VALUE); - Permission permission = new Permission(permissionStr); - return permission; - } - - private Permission getColPermissionWithPartitionKeyWithName() { - String permissionStr = String.format(COLLECTION_PERMISSION_DEFINITION, Utils.getCollectionNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId()), - PARTITION_KEY_VALUE); - Permission permission = new Permission(permissionStr); - permission.setId("PermissionForColWithPartitionKeyWithName"); - return permission; - } - - private Permission getColPermissionWithPartitionKey2() { - String permissionStr = String.format(COLLECTION_PERMISSION_DEFINITION, createdCollectionWithPartitionKey.getSelfLink(), - PARTITION_KEY_VALUE_2); - Permission permission = new Permission(permissionStr); - permission.setId("PermissionForColWithPartitionKey2"); - return permission; - } - - private Permission getColPermissionWithPartitionKey2WithName() { - String permissionStr = String.format(COLLECTION_PERMISSION_DEFINITION, Utils.getCollectionNameLink(createdDatabase.getId(), createdCollectionWithPartitionKey.getId()), - PARTITION_KEY_VALUE_2); - Permission permission = new Permission(permissionStr); - permission.setId("PermissionForColWithPartitionKey2WithName"); - return permission; - } - - private String getUserLink() { - return createdUser.getSelfLink(); - } - - static protected DocumentCollection getCollectionDefinition() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - return collectionDefinition; - } - - private Document getDocumentDefinitionWithPartitionKey() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format(DOCUMENT_DEFINITION_WITH_PERMISSION_KEY, uuid, PARTITION_KEY_VALUE)); - return doc; - } - private Document getDocumentDefinitionWithPartitionKey2() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format(DOCUMENT_DEFINITION_WITH_PERMISSION_KEY, uuid, PARTITION_KEY_VALUE_2)); - return doc; - } - - private DocumentCollection getCollectionDefinitionWithPartitionKey() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add(PARTITION_KEY_PATH); - partitionKeyDef.setPaths(paths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SimpleSerializationTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SimpleSerializationTest.java deleted file mode 100644 index 338f5b7004c7..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SimpleSerializationTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import org.apache.commons.lang3.NotImplementedException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import java.io.IOException; -import java.time.Instant; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SimpleSerializationTest extends TestSuiteBase { - - private DocumentCollection createdCollection; - private AsyncDocumentClient client; - - private static class TestObject { - public static class BadSerializer extends JsonSerializer { - @Override - public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) { - throw new NotImplementedException("bad"); - } - } - - @JsonProperty("mypk") - private String mypk; - - @JsonProperty("id") - private String id; - - @JsonProperty("prop") - @JsonSerialize(using = BadSerializer.class) - private String prop; - } - - @Factory(dataProvider = "clientBuildersWithDirect") - public SimpleSerializationTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = {"simple"}, timeOut = TIMEOUT) - public void createDocument() { - TestObject testObject = new TestObject(); - testObject.id = UUID.randomUUID().toString(); - testObject.mypk = UUID.randomUUID().toString(); - testObject.prop = UUID.randomUUID().toString(); - - Observable> createObservable = client - .createDocument(getCollectionLink(), testObject, null, false); - - FailureValidator failureValidator = FailureValidator.builder().instanceOf(IllegalArgumentException.class) - .causeOfCauseInstanceOf(NotImplementedException.class) - .errorMessageContains("Can't serialize the object into the json string").build(); - - validateFailure(createObservable, failureValidator); - } - - @BeforeClass(groups = {"simple"}, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - client = clientBuilder.build(); - } - - @AfterClass(groups = {"simple"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SinglePartitionDocumentQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SinglePartitionDocumentQueryTest.java deleted file mode 100644 index fdca1855021f..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SinglePartitionDocumentQueryTest.java +++ /dev/null @@ -1,370 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.SqlParameter; -import com.microsoft.azure.cosmosdb.SqlParameterCollection; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; -import rx.observers.TestSubscriber; - - -public class SinglePartitionDocumentQueryTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdDocuments = new ArrayList<>(); - - private AsyncDocumentClient client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - @Factory(dataProvider = "clientBuildersWithDirect") - public SinglePartitionDocumentQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "queryMetricsArgProvider") - public void queryDocuments(boolean queryMetricsEnabled) throws Exception { - - String query = "SELECT * from c where c.prop = 99"; - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - options.setPopulateQueryMetrics(queryMetricsEnabled); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - List expectedDocs = createdDocuments.stream().filter(d -> 99 == d.getInt("prop") ).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .hasValidQueryMetrics(queryMetricsEnabled) - .build(); - - try { - validateQuerySuccess(queryObservable, validator, 10000); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDocuments_ParameterizedQueryWithInClause() throws Exception { - String query = "SELECT * from c where c.prop IN (@param1, @param2)"; - SqlParameterCollection params = new SqlParameterCollection(new SqlParameter("@param1", 3), new SqlParameter("@param2", 4)); - SqlQuerySpec sqs = new SqlQuerySpec(query, params); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), sqs, options); - - List expectedDocs = createdDocuments.stream().filter(d -> (3 == d.getInt("prop") || 4 == d.getInt("prop"))).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - try { - validateQuerySuccess(queryObservable, validator, 10000); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDocuments_ParameterizedQuery() throws Exception { - String query = "SELECT * from c where c.prop = @param"; - SqlParameterCollection params = new SqlParameterCollection(new SqlParameter("@param", 3)); - SqlQuerySpec sqs = new SqlQuerySpec(query, params); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), sqs, options); - - List expectedDocs = createdDocuments.stream().filter(d -> 3 == d.getInt("prop")).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - try { - validateQuerySuccess(queryObservable, validator, 10000); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDocuments_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryDocumentsWithPageSize() throws Exception { - - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(3); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - List expectedDocs = createdDocuments; - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .exactlyContainsInAnyOrder(createdDocuments - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - try { - validateQuerySuccess(queryObservable, validator); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryOrderBy() throws Exception { - - String query = "SELECT * FROM r ORDER BY r.prop ASC"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(3); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - List expectedDocs = createdDocuments; - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(createdDocuments.stream() - .sorted((e1, e2) -> Integer.compare(e1.getInt("prop"), e2.getInt("prop"))) - .map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - try { - validateQuerySuccess(queryObservable, validator); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT * 1000) - public void continuationToken() throws Exception { - String query = "SELECT * FROM r ORDER BY r.prop ASC"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(3); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - - TestSubscriber> subscriber = new TestSubscriber<>(); - queryObservable.first().subscribe(subscriber); - - subscriber.awaitTerminalEvent(); - subscriber.assertCompleted(); - subscriber.assertNoErrors(); - assertThat(subscriber.getValueCount()).isEqualTo(1); - FeedResponse page = subscriber.getOnNextEvents().get(0); - assertThat(page.getResults()).hasSize(3); - - assertThat(page.getResponseContinuation()).isNotEmpty(); - - - options.setRequestContinuation(page.getResponseContinuation()); - queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - - List expectedDocs = createdDocuments.stream().filter(d -> (d.getInt("prop") > 2)).collect(Collectors.toList()); - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - assertThat(expectedDocs).hasSize(createdDocuments.size() -3); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(expectedDocs.stream() - .sorted((e1, e2) -> Integer.compare(e1.getInt("prop"), e2.getInt("prop"))) - .map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void invalidQuerySytax() throws Exception { - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryDocuments(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .notNullActivityId() - .build(); - validateQueryFailure(queryObservable, validator); - } - - public Document createDocument(AsyncDocumentClient client, int cnt) { - Document docDefinition = getDocumentDefinition(cnt); - return client.createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource(); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - for(int i = 0; i < 5; i++) { - createdDocuments.add(createDocument(client, i)); - } - - for(int i = 0; i < 8; i++) { - createdDocuments.add(createDocument(client, 99)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static Document getDocumentDefinition(int cnt) { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"prop\" : %d, " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, cnt, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SinglePartitionReadFeedDocumentsTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SinglePartitionReadFeedDocumentsTest.java deleted file mode 100644 index 6ea1db1f0c3b..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SinglePartitionReadFeedDocumentsTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -public class SinglePartitionReadFeedDocumentsTest extends TestSuiteBase { - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdDocuments; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public SinglePartitionReadFeedDocumentsTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = FEED_TIMEOUT) - public void readDocuments() { - final FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - final Observable> feedObservable = client.readDocuments(getCollectionLink(), options); - final int expectedPageSize = (createdDocuments.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(createdDocuments.size()) - .numberOfPages(expectedPageSize) - .exactlyContainsInAnyOrder(createdDocuments.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(feedObservable, validator, FEED_TIMEOUT); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - List docDefList = new ArrayList<>(); - - for(int i = 0; i < 5; i++) { - docDefList.add(getDocumentDefinition()); - } - - createdDocuments = bulkInsertBlocking(client, getCollectionLink(), docDefList); - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - public String getCollectionLink() { - return "dbs/" + getDatabaseId() + "/colls/" + getCollectionId(); - } - - private String getCollectionId() { - return createdCollection.getId(); - } - - private String getDatabaseId() { - return createdDatabase.getId(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SpyClientBuilder.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SpyClientBuilder.java deleted file mode 100644 index 7e575659681e..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/SpyClientBuilder.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.rx.internal.SpyClientUnderTestFactory; - -public class SpyClientBuilder extends AsyncDocumentClient.Builder { - - public SpyClientBuilder(AsyncDocumentClient.Builder builder) { - super(); - super.configs = builder.configs; - super.connectionPolicy = builder.connectionPolicy; - super.desiredConsistencyLevel = builder.desiredConsistencyLevel; - super.masterKeyOrResourceToken = builder.masterKeyOrResourceToken; - super.serviceEndpoint = builder.serviceEndpoint; - } - - public SpyClientUnderTestFactory.ClientUnderTest build() { - return SpyClientUnderTestFactory.createClientUnderTest( - serviceEndpoint, - masterKeyOrResourceToken, - connectionPolicy, - desiredConsistencyLevel, - configs); - } - - public SpyClientUnderTestFactory.ClientWithGatewaySpy buildWithGatewaySpy() { - return SpyClientUnderTestFactory.createClientWithGatewaySpy( - serviceEndpoint, - masterKeyOrResourceToken, - connectionPolicy, - desiredConsistencyLevel, - configs); - } - - public SpyClientUnderTestFactory.DirectHttpsClientUnderTest buildWithDirectHttps() { - return SpyClientUnderTestFactory.createDirectHttpsClientUnderTest( - serviceEndpoint, - masterKeyOrResourceToken, - connectionPolicy, - desiredConsistencyLevel); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureCrudTest.java deleted file mode 100644 index e963d5322d5a..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureCrudTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.UUID; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.StoredProcedure; - -import rx.Observable; - - -public class StoredProcedureCrudTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public StoredProcedureCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createStoredProcedure() throws Exception { - - // create a stored procedure - StoredProcedure storedProcedureDef = new StoredProcedure(); - storedProcedureDef.setId(UUID.randomUUID().toString()); - storedProcedureDef.setBody("function() {var x = 10;}"); - - Observable> createObservable = client.createStoredProcedure(getCollectionLink(), storedProcedureDef, null); - - // validate stored procedure creation - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(storedProcedureDef.getId()) - .withStoredProcedureBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void readStoredProcedure() throws Exception { - // create a stored procedure - StoredProcedure storedProcedureDef = new StoredProcedure(); - storedProcedureDef.setId(UUID.randomUUID().toString()); - storedProcedureDef.setBody("function() {var x = 10;}"); - StoredProcedure storedProcedure = client.createStoredProcedure(getCollectionLink(), storedProcedureDef, null).toBlocking().single().getResource(); - - // read stored procedure - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readStoredProcedure(storedProcedure.getSelfLink(), null); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(storedProcedureDef.getId()) - .withStoredProcedureBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void deleteStoredProcedure() throws Exception { - // create a stored procedure - StoredProcedure storedProcedureDef = new StoredProcedure(); - storedProcedureDef.setId(UUID.randomUUID().toString()); - storedProcedureDef.setBody("function() {var x = 10;}"); - StoredProcedure storedProcedure = client.createStoredProcedure(getCollectionLink(), storedProcedureDef, null).toBlocking().single().getResource(); - - // delete - Observable> deleteObservable = client.deleteStoredProcedure(storedProcedure.getSelfLink(), null); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource() - .build(); - validateSuccess(deleteObservable, validator); - - // attempt to read stored procedure which was deleted - waitIfNeededForReplicasToCatchUp(clientBuilder); - - Observable> readObservable = client.readStoredProcedure(storedProcedure.getSelfLink(), null); - FailureValidator notFoundValidator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, notFoundValidator); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureQueryTest.java deleted file mode 100644 index c10eb81aaf6e..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureQueryTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - - -public class StoredProcedureQueryTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdStoredProcs = new ArrayList<>(); - - private AsyncDocumentClient client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - @Factory(dataProvider = "clientBuildersWithDirect") - public StoredProcedureQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryWithFilter() throws Exception { - - String filterId = createdStoredProcs.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - Observable> queryObservable = client - .queryStoredProcedures(getCollectionLink(), query, options); - - List expectedDocs = createdStoredProcs.stream().filter(sp -> filterId.equals(sp.getId()) ).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - try { - validateQuerySuccess(queryObservable, validator, 10000); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void query_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryStoredProcedures(getCollectionLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAll() throws Exception { - - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(3); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryStoredProcedures(getCollectionLink(), query, options); - - List expectedDocs = createdStoredProcs; - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .exactlyContainsInAnyOrder(expectedDocs - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - try { - validateQuerySuccess(queryObservable, validator); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void invalidQuerySytax() throws Exception { - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryStoredProcedures(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .notNullActivityId() - .build(); - validateQueryFailure(queryObservable, validator); - } - - public StoredProcedure createStoredProc(AsyncDocumentClient client) { - StoredProcedure storedProcedure = getStoredProcedureDef(); - return client.createStoredProcedure(getCollectionLink(), storedProcedure, null).toBlocking().single().getResource(); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - for(int i = 0; i < 5; i++) { - createdStoredProcs.add(createStoredProc(client)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static StoredProcedure getStoredProcedureDef() { - StoredProcedure storedProcedureDef = new StoredProcedure(); - storedProcedureDef.setId(UUID.randomUUID().toString()); - storedProcedureDef.setBody("function() {var x = 10;}"); - return storedProcedureDef; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureUpsertReplaceTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureUpsertReplaceTest.java deleted file mode 100644 index 62870762d1b3..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/StoredProcedureUpsertReplaceTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -import rx.Observable; - -import javax.net.ssl.SSLException; - - -public class StoredProcedureUpsertReplaceTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public StoredProcedureUpsertReplaceTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void upsertStoredProcedure() throws Exception { - - // create a stored procedure - StoredProcedure storedProcedureDef = new StoredProcedure(); - storedProcedureDef.setId(UUID.randomUUID().toString()); - storedProcedureDef.setBody("function() {var x = 10;}"); - StoredProcedure readBackSp = client.upsertStoredProcedure(getCollectionLink(), storedProcedureDef, null).toBlocking().single().getResource(); - - //read back stored procedure - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readStoredProcedure(readBackSp.getSelfLink(), null); - - // validate stored procedure creation - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackSp.getId()) - .withStoredProcedureBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update stored procedure - readBackSp.setBody("function() {var x = 11;}"); - - Observable> updateObservable = client.upsertStoredProcedure(getCollectionLink(), readBackSp, null); - - // validate stored procedure update - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackSp.getId()) - .withStoredProcedureBody("function() {var x = 11;}") - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void replaceStoredProcedure() throws Exception { - - // create a stored procedure - StoredProcedure storedProcedureDef = new StoredProcedure(); - storedProcedureDef.setId(UUID.randomUUID().toString()); - storedProcedureDef.setBody("function() {var x = 10;}"); - StoredProcedure readBackSp = client.createStoredProcedure(getCollectionLink(), storedProcedureDef, null).toBlocking().single().getResource(); - - // read stored procedure to validate creation - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readStoredProcedure(readBackSp.getSelfLink(), null); - - // validate stored procedure creation - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackSp.getId()) - .withStoredProcedureBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update stored procedure - readBackSp.setBody("function() {var x = 11;}"); - - Observable> replaceObservable = client.replaceStoredProcedure(readBackSp, null); - - //validate stored procedure replace - ResourceResponseValidator validatorForReplace = new ResourceResponseValidator.Builder() - .withId(readBackSp.getId()) - .withStoredProcedureBody("function() {var x = 11;}") - .notNullEtag() - .build(); - validateSuccess(replaceObservable, validatorForReplace); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void executeStoredProcedure() throws Exception { - // create a stored procedure - StoredProcedure storedProcedureDef = new StoredProcedure( - "{" + - " 'id': '" +UUID.randomUUID().toString() + "'," + - " 'body':" + - " 'function () {" + - " for (var i = 0; i < 10; i++) {" + - " getContext().getResponse().appendValue(\"Body\", i);" + - " }" + - " }'" + - "}"); - - StoredProcedure storedProcedure = null; - - try { - storedProcedure = client.createStoredProcedure(getCollectionLink(), storedProcedureDef, null).toBlocking().single().getResource(); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - - String result = null; - - try { - result = client.executeStoredProcedure(storedProcedure.getSelfLink(), null).toBlocking().single().getResponseAsString(); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - - assertThat(result).isEqualTo("\"0123456789\""); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestSuiteBase.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestSuiteBase.java deleted file mode 100644 index d77fd497ccd4..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TestSuiteBase.java +++ /dev/null @@ -1,1010 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.spy; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.RetryOptions; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.internal.PathParser; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.internal.Configs; -import org.apache.commons.lang3.StringUtils; -import org.mockito.stubbing.Answer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.AfterSuite; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.DataProvider; - -import com.microsoft.azure.cosmosdb.CompositePath; -import com.microsoft.azure.cosmosdb.CompositePathSortOrder; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import org.testng.annotations.Test; -import rx.Observable; -import rx.observers.TestSubscriber; - -public class TestSuiteBase { - private static final int DEFAULT_BULK_INSERT_CONCURRENCY_LEVEL = 500; - private static final ObjectMapper objectMapper = new ObjectMapper(); - protected static Logger logger = LoggerFactory.getLogger(TestSuiteBase.class.getSimpleName()); - protected static final int TIMEOUT = 8000; - protected static final int FEED_TIMEOUT = 12000; - protected static final int SETUP_TIMEOUT = 30000; - protected static final int SHUTDOWN_TIMEOUT = 12000; - - protected static final int SUITE_SETUP_TIMEOUT = 120000; - protected static final int SUITE_SHUTDOWN_TIMEOUT = 60000; - - protected static final int WAIT_REPLICA_CATCH_UP_IN_MILLIS = 4000; - - protected int subscriberValidationTimeout = TIMEOUT; - - protected static ConsistencyLevel accountConsistency; - - protected Builder clientBuilder; - - protected static Database SHARED_DATABASE; - protected static DocumentCollection SHARED_MULTI_PARTITION_COLLECTION; - protected static DocumentCollection SHARED_SINGLE_PARTITION_COLLECTION; - protected static DocumentCollection SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - protected static DocumentCollection SHARED_MULTI_PARTITION_COLLECTION_WITH_COMPOSITE_AND_SPATIAL_INDEXES; - - - protected TestSuiteBase() { - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA, true); - objectMapper.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true); - logger.debug("Initializing {} ...", this.getClass().getSimpleName()); - } - - @BeforeMethod(groups = { "simple", "long", "direct", "multi-master", "emulator", "non-emulator" }) - public void beforeMethod(Method method) { - if (this.clientBuilder != null) { - logger.info("Starting {}::{} using {} {} mode with {} consistency", - method.getDeclaringClass().getSimpleName(), method.getName(), - this.clientBuilder.connectionPolicy.getConnectionMode(), - this.clientBuilder.configs.getProtocol(), - this.clientBuilder.desiredConsistencyLevel); - return; - } - logger.info("Starting {}::{}", method.getDeclaringClass().getSimpleName(), method.getName()); - } - - @AfterMethod(groups = { "simple", "long", "direct", "multi-master", "emulator", "non-emulator" }) - public void afterMethod(Method m) { - Test t = m.getAnnotation(Test.class); - logger.info("Finished {}:{}.", m.getDeclaringClass().getSimpleName(), m.getName()); - } - - private static class DatabaseManagerImpl implements DatabaseForTest.DatabaseManager { - public static DatabaseManagerImpl getInstance(AsyncDocumentClient client) { - return new DatabaseManagerImpl(client); - } - - private final AsyncDocumentClient client; - - private DatabaseManagerImpl(AsyncDocumentClient client) { - this.client = client; - } - - @Override - public Observable> queryDatabases(SqlQuerySpec query) { - return client.queryDatabases(query, null); - } - - @Override - public Observable> createDatabase(Database databaseDefinition) { - return client.createDatabase(databaseDefinition, null); - } - - @Override - public Observable> deleteDatabase(String id) { - - return client.deleteDatabase("dbs/" + id, null); - } - } - - @BeforeSuite(groups = { "simple", "long", "direct", "multi-master", "emulator", "non-emulator" }, timeOut = SUITE_SETUP_TIMEOUT) - public static void beforeSuite() { - logger.info("beforeSuite Started"); - AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build(); - try { - DatabaseForTest dbForTest = DatabaseForTest.create(DatabaseManagerImpl.getInstance(houseKeepingClient)); - SHARED_DATABASE = dbForTest.createdDatabase; - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(10100); - SHARED_MULTI_PARTITION_COLLECTION = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinitionWithRangeRangeIndex(), options); - SHARED_SINGLE_PARTITION_COLLECTION = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinition(), null); - SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinitionSinglePartitionWithoutPartitionKey()); - SHARED_MULTI_PARTITION_COLLECTION_WITH_COMPOSITE_AND_SPATIAL_INDEXES = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinitionMultiPartitionWithCompositeAndSpatialIndexes(), options); - } finally { - houseKeepingClient.close(); - } - } - - @AfterSuite(groups = { "simple", "long", "direct", "multi-master", "emulator", "non-emulator" }, timeOut = SUITE_SHUTDOWN_TIMEOUT) - public static void afterSuite() { - logger.info("afterSuite Started"); - AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build(); - try { - safeDeleteDatabase(houseKeepingClient, SHARED_DATABASE); - DatabaseForTest.cleanupStaleTestDatabases(DatabaseManagerImpl.getInstance(houseKeepingClient)); - } finally { - safeClose(houseKeepingClient); - } - } - - protected static void truncateCollection(DocumentCollection collection) { - logger.info("Truncating collection {} ...", collection.getId()); - AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build(); - try { - List paths = collection.getPartitionKey().getPaths(); - - FeedOptions options = new FeedOptions(); - options.setMaxDegreeOfParallelism(-1); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(100); - - logger.info("Truncating collection {} documents ...", collection.getId()); - - houseKeepingClient.queryDocuments(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(doc -> { - RequestOptions requestOptions = new RequestOptions(); - - if (paths != null && !paths.isEmpty()) { - List pkPath = PathParser.getPathParts(paths.get(0)); - Object propertyValue = doc.getObjectByPath(pkPath); - if (propertyValue == null) { - propertyValue = Undefined.Value(); - } - - requestOptions.setPartitionKey(new PartitionKey(propertyValue)); - } - - return houseKeepingClient.deleteDocument(doc.getSelfLink(), requestOptions); - }).toCompletable().await(); - - logger.info("Truncating collection {} triggers ...", collection.getId()); - - houseKeepingClient.queryTriggers(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(trigger -> { - RequestOptions requestOptions = new RequestOptions(); - -// if (paths != null && !paths.isEmpty()) { -// Object propertyValue = trigger.getObjectByPath(PathParser.getPathParts(paths.get(0))); -// requestOptions.setPartitionKey(new PartitionKey(propertyValue)); -// } - - return houseKeepingClient.deleteTrigger(trigger.getSelfLink(), requestOptions); - }).toCompletable().await(); - - logger.info("Truncating collection {} storedProcedures ...", collection.getId()); - - houseKeepingClient.queryStoredProcedures(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(storedProcedure -> { - RequestOptions requestOptions = new RequestOptions(); - -// if (paths != null && !paths.isEmpty()) { -// Object propertyValue = storedProcedure.getObjectByPath(PathParser.getPathParts(paths.get(0))); -// requestOptions.setPartitionKey(new PartitionKey(propertyValue)); -// } - - return houseKeepingClient.deleteStoredProcedure(storedProcedure.getSelfLink(), requestOptions); - }).toCompletable().await(); - - logger.info("Truncating collection {} udfs ...", collection.getId()); - - houseKeepingClient.queryUserDefinedFunctions(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(udf -> { - RequestOptions requestOptions = new RequestOptions(); - -// if (paths != null && !paths.isEmpty()) { -// Object propertyValue = udf.getObjectByPath(PathParser.getPathParts(paths.get(0))); -// requestOptions.setPartitionKey(new PartitionKey(propertyValue)); -// } - - return houseKeepingClient.deleteUserDefinedFunction(udf.getSelfLink(), requestOptions); - }).toCompletable().await(); - - } finally { - houseKeepingClient.close(); - } - - logger.info("Finished truncating collection {}.", collection.getId()); - } - - protected static void waitIfNeededForReplicasToCatchUp(Builder clientBuilder) { - switch (clientBuilder.desiredConsistencyLevel) { - case Eventual: - case ConsistentPrefix: - logger.info(" additional wait in Eventual mode so the replica catch up"); - // give times to replicas to catch up after a write - try { - TimeUnit.MILLISECONDS.sleep(WAIT_REPLICA_CATCH_UP_IN_MILLIS); - } catch (Exception e) { - logger.error("unexpected failure", e); - } - - case Session: - case BoundedStaleness: - case Strong: - default: - break; - } - } - - private static DocumentCollection getCollectionDefinitionSinglePartitionWithoutPartitionKey() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - return collectionDefinition; - } - - - public static DocumentCollection createCollection(String databaseId, - DocumentCollection collection, - RequestOptions options) { - AsyncDocumentClient client = createGatewayHouseKeepingDocumentClient().build(); - try { - return client.createCollection("dbs/" + databaseId, collection, options).toBlocking().single().getResource(); - } finally { - client.close(); - } - } - - public static DocumentCollection createCollection(AsyncDocumentClient client, String databaseId, - DocumentCollection collection, RequestOptions options) { - return client.createCollection("dbs/" + databaseId, collection, options).toBlocking().single().getResource(); - } - - public static DocumentCollection createCollection(AsyncDocumentClient client, String databaseId, - DocumentCollection collection) { - return client.createCollection("dbs/" + databaseId, collection, null).toBlocking().single().getResource(); - } - - private static DocumentCollection getCollectionDefinitionMultiPartitionWithCompositeAndSpatialIndexes() { - final String NUMBER_FIELD = "numberField"; - final String STRING_FIELD = "stringField"; - final String NUMBER_FIELD_2 = "numberField2"; - final String STRING_FIELD_2 = "stringField2"; - final String BOOL_FIELD = "boolField"; - final String NULL_FIELD = "nullField"; - final String OBJECT_FIELD = "objectField"; - final String ARRAY_FIELD = "arrayField"; - final String SHORT_STRING_FIELD = "shortStringField"; - final String MEDIUM_STRING_FIELD = "mediumStringField"; - final String LONG_STRING_FIELD = "longStringField"; - final String PARTITION_KEY = "pk"; - - DocumentCollection documentCollection = new DocumentCollection(); - - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection> compositeIndexes = new ArrayList>(); - - //Simple - ArrayList compositeIndexSimple = new ArrayList(); - CompositePath compositePath1 = new CompositePath(); - compositePath1.setPath("/" + NUMBER_FIELD); - compositePath1.setOrder(CompositePathSortOrder.Ascending); - - CompositePath compositePath2 = new CompositePath(); - compositePath2.setPath("/" + STRING_FIELD); - compositePath2.setOrder(CompositePathSortOrder.Descending); - - compositeIndexSimple.add(compositePath1); - compositeIndexSimple.add(compositePath2); - - //Max Columns - ArrayList compositeIndexMaxColumns = new ArrayList(); - CompositePath compositePath3 = new CompositePath(); - compositePath3.setPath("/" + NUMBER_FIELD); - compositePath3.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath4 = new CompositePath(); - compositePath4.setPath("/" + STRING_FIELD); - compositePath4.setOrder(CompositePathSortOrder.Ascending); - - CompositePath compositePath5 = new CompositePath(); - compositePath5.setPath("/" + NUMBER_FIELD_2); - compositePath5.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath6 = new CompositePath(); - compositePath6.setPath("/" + STRING_FIELD_2); - compositePath6.setOrder(CompositePathSortOrder.Ascending); - - compositeIndexMaxColumns.add(compositePath3); - compositeIndexMaxColumns.add(compositePath4); - compositeIndexMaxColumns.add(compositePath5); - compositeIndexMaxColumns.add(compositePath6); - - //Primitive Values - ArrayList compositeIndexPrimitiveValues = new ArrayList(); - CompositePath compositePath7 = new CompositePath(); - compositePath7.setPath("/" + NUMBER_FIELD); - compositePath7.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath8 = new CompositePath(); - compositePath8.setPath("/" + STRING_FIELD); - compositePath8.setOrder(CompositePathSortOrder.Ascending); - - CompositePath compositePath9 = new CompositePath(); - compositePath9.setPath("/" + BOOL_FIELD); - compositePath9.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath10 = new CompositePath(); - compositePath10.setPath("/" + NULL_FIELD); - compositePath10.setOrder(CompositePathSortOrder.Ascending); - - compositeIndexPrimitiveValues.add(compositePath7); - compositeIndexPrimitiveValues.add(compositePath8); - compositeIndexPrimitiveValues.add(compositePath9); - compositeIndexPrimitiveValues.add(compositePath10); - - //Long Strings - ArrayList compositeIndexLongStrings = new ArrayList(); - CompositePath compositePath11 = new CompositePath(); - compositePath11.setPath("/" + STRING_FIELD); - - CompositePath compositePath12 = new CompositePath(); - compositePath12.setPath("/" + SHORT_STRING_FIELD); - - CompositePath compositePath13 = new CompositePath(); - compositePath13.setPath("/" + MEDIUM_STRING_FIELD); - - CompositePath compositePath14 = new CompositePath(); - compositePath14.setPath("/" + LONG_STRING_FIELD); - - compositeIndexLongStrings.add(compositePath11); - compositeIndexLongStrings.add(compositePath12); - compositeIndexLongStrings.add(compositePath13); - compositeIndexLongStrings.add(compositePath14); - - compositeIndexes.add(compositeIndexSimple); - compositeIndexes.add(compositeIndexMaxColumns); - compositeIndexes.add(compositeIndexPrimitiveValues); - compositeIndexes.add(compositeIndexLongStrings); - - indexingPolicy.setCompositeIndexes(compositeIndexes); - documentCollection.setIndexingPolicy(indexingPolicy); - - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - ArrayList partitionKeyPaths = new ArrayList(); - partitionKeyPaths.add("/" + PARTITION_KEY); - partitionKeyDefinition.setPaths(partitionKeyPaths); - documentCollection.setPartitionKey(partitionKeyDefinition); - - documentCollection.setId(UUID.randomUUID().toString()); - - return documentCollection; - } - - public static Document createDocument(AsyncDocumentClient client, String databaseId, String collectionId, Document document) { - return createDocument(client, databaseId, collectionId, document, null); - } - - public static Document createDocument(AsyncDocumentClient client, String databaseId, String collectionId, Document document, RequestOptions options) { - return client.createDocument(Utils.getCollectionNameLink(databaseId, collectionId), document, options, false).toBlocking().single().getResource(); - } - - public Observable> bulkInsert(AsyncDocumentClient client, - String collectionLink, - List documentDefinitionList, - int concurrencyLevel) { - ArrayList>> result = new ArrayList>>(documentDefinitionList.size()); - for (Document docDef : documentDefinitionList) { - result.add(client.createDocument(collectionLink, docDef, null, false)); - } - - return Observable.merge(result, concurrencyLevel); - } - - public Observable> bulkInsert(AsyncDocumentClient client, - String collectionLink, - List documentDefinitionList) { - return bulkInsert(client, collectionLink, documentDefinitionList, DEFAULT_BULK_INSERT_CONCURRENCY_LEVEL); - } - - public List bulkInsertBlocking(AsyncDocumentClient client, - String collectionLink, - List documentDefinitionList) { - return bulkInsert(client, collectionLink, documentDefinitionList, DEFAULT_BULK_INSERT_CONCURRENCY_LEVEL) - .map(ResourceResponse::getResource) - .toList() - .toBlocking() - .single(); - } - - public static ConsistencyLevel getAccountDefaultConsistencyLevel(AsyncDocumentClient client) { - return client.getDatabaseAccount().toBlocking().single().getConsistencyPolicy().getDefaultConsistencyLevel(); - } - - public static User createUser(AsyncDocumentClient client, String databaseId, User user) { - return client.createUser("dbs/" + databaseId, user, null).toBlocking().single().getResource(); - } - - public static User safeCreateUser(AsyncDocumentClient client, String databaseId, User user) { - deleteUserIfExists(client, databaseId, user.getId()); - return createUser(client, databaseId, user); - } - - private static DocumentCollection safeCreateCollection(AsyncDocumentClient client, String databaseId, DocumentCollection collection, RequestOptions options) { - deleteCollectionIfExists(client, databaseId, collection.getId()); - return createCollection(client, databaseId, collection, options); - } - - public static String getCollectionLink(DocumentCollection collection) { - return collection.getSelfLink(); - } - - static protected DocumentCollection getCollectionDefinition() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } - - static protected DocumentCollection getCollectionDefinitionWithRangeRangeIndex() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList<>(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection includedPaths = new ArrayList<>(); - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath("/*"); - Collection indexes = new ArrayList<>(); - Index stringIndex = Index.Range(DataType.String); - stringIndex.set("precision", -1); - indexes.add(stringIndex); - - Index numberIndex = Index.Range(DataType.Number); - numberIndex.set("precision", -1); - indexes.add(numberIndex); - includedPath.setIndexes(indexes); - includedPaths.add(includedPath); - indexingPolicy.setIncludedPaths(includedPaths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setIndexingPolicy(indexingPolicy); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } - - public static void deleteCollectionIfExists(AsyncDocumentClient client, String databaseId, String collectionId) { - List res = client.queryCollections("dbs/" + databaseId, - String.format("SELECT * FROM root r where r.id = '%s'", collectionId), null).toBlocking().single() - .getResults(); - if (!res.isEmpty()) { - deleteCollection(client, Utils.getCollectionNameLink(databaseId, collectionId)); - } - } - - public static void deleteCollection(AsyncDocumentClient client, String collectionLink) { - client.deleteCollection(collectionLink, null).toBlocking().single(); - } - - public static void deleteDocumentIfExists(AsyncDocumentClient client, String databaseId, String collectionId, String docId) { - FeedOptions options = new FeedOptions(); - options.setPartitionKey(new PartitionKey(docId)); - List res = client - .queryDocuments(Utils.getCollectionNameLink(databaseId, collectionId), String.format("SELECT * FROM root r where r.id = '%s'", docId), options) - .toBlocking().single().getResults(); - if (!res.isEmpty()) { - deleteDocument(client, Utils.getDocumentNameLink(databaseId, collectionId, docId)); - } - } - - public static void safeDeleteDocument(AsyncDocumentClient client, String documentLink, RequestOptions options) { - if (client != null && documentLink != null) { - try { - client.deleteDocument(documentLink, options).toBlocking().single(); - } catch (Exception e) { - DocumentClientException dce = com.microsoft.azure.cosmosdb.rx.internal.Utils.as(e, DocumentClientException.class); - if (dce == null || dce.getStatusCode() != 404) { - throw e; - } - } - } - } - - public static void deleteDocument(AsyncDocumentClient client, String documentLink) { - client.deleteDocument(documentLink, null).toBlocking().single(); - } - - public static void deleteUserIfExists(AsyncDocumentClient client, String databaseId, String userId) { - List res = client - .queryUsers("dbs/" + databaseId, String.format("SELECT * FROM root r where r.id = '%s'", userId), null) - .toBlocking().single().getResults(); - if (!res.isEmpty()) { - deleteUser(client, Utils.getUserNameLink(databaseId, userId)); - } - } - - public static void deleteUser(AsyncDocumentClient client, String userLink) { - client.deleteUser(userLink, null).toBlocking().single(); - } - - public static String getDatabaseLink(Database database) { - return database.getSelfLink(); - } - - static private Database safeCreateDatabase(AsyncDocumentClient client, Database database) { - safeDeleteDatabase(client, database.getId()); - return createDatabase(client, database); - } - - static protected Database createDatabase(AsyncDocumentClient client, Database database) { - Observable> databaseObservable = client.createDatabase(database, null); - return databaseObservable.toBlocking().single().getResource(); - } - - static protected Database createDatabase(AsyncDocumentClient client, String databaseId) { - Database databaseDefinition = new Database(); - databaseDefinition.setId(databaseId); - return createDatabase(client, databaseDefinition); - } - - static protected Database createDatabaseIfNotExists(AsyncDocumentClient client, String databaseId) { - return client.queryDatabases(String.format("SELECT * FROM r where r.id = '%s'", databaseId), null).flatMap(p -> Observable.from(p.getResults())).switchIfEmpty( - Observable.defer(() -> { - - Database databaseDefinition = new Database(); - databaseDefinition.setId(databaseId); - - return client.createDatabase(databaseDefinition, null).map(ResourceResponse::getResource); - }) - ).toBlocking().single(); - } - - static protected void safeDeleteDatabase(AsyncDocumentClient client, Database database) { - if (database != null) { - safeDeleteDatabase(client, database.getId()); - } - } - - static protected void safeDeleteDatabase(AsyncDocumentClient client, String databaseId) { - if (client != null) { - try { - client.deleteDatabase(Utils.getDatabaseNameLink(databaseId), null).toBlocking().single(); - } catch (Exception e) { - } - } - } - - static protected void safeDeleteAllCollections(AsyncDocumentClient client, Database database) { - if (database != null) { - List collections = client.readCollections(database.getSelfLink(), null) - .flatMap(p -> Observable.from(p.getResults())) - .toList() - .toBlocking() - .single(); - - for(DocumentCollection collection: collections) { - client.deleteCollection(collection.getSelfLink(), null).toBlocking().single().getResource(); - } - } - } - - static protected void safeDeleteCollection(AsyncDocumentClient client, DocumentCollection collection) { - if (client != null && collection != null) { - try { - client.deleteCollection(collection.getSelfLink(), null).toBlocking().single(); - } catch (Exception e) { - } - } - } - - static protected void safeDeleteCollection(AsyncDocumentClient client, String databaseId, String collectionId) { - if (client != null && databaseId != null && collectionId != null) { - try { - client.deleteCollection("/dbs/" + databaseId + "/colls/" + collectionId, null).toBlocking().single(); - } catch (Exception e) { - } - } - } - - static protected void safeClose(AsyncDocumentClient client) { - if (client != null) { - try { - client.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - public void validateSuccess(Observable> observable, - ResourceResponseValidator validator) { - validateSuccess(observable, validator, subscriberValidationTimeout); - } - - public static void validateSuccess(Observable> observable, - ResourceResponseValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public void validateFailure(Observable> observable, - FailureValidator validator) { - validateFailure(observable, validator, subscriberValidationTimeout); - } - - public static void validateFailure(Observable> observable, - FailureValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - public void validateQuerySuccess(Observable> observable, - FeedResponseListValidator validator) { - validateQuerySuccess(observable, validator, subscriberValidationTimeout); - } - - public static void validateQuerySuccess(Observable> observable, - FeedResponseListValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - validator.validate(testSubscriber.getOnNextEvents()); - } - - public void validateQueryFailure(Observable> observable, - FailureValidator validator) { - validateQueryFailure(observable, validator, subscriberValidationTimeout); - } - - public static void validateQueryFailure(Observable> observable, - FailureValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - @DataProvider - public static Object[][] clientBuilders() { - return new Object[][] { { createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null) } }; - } - - @DataProvider - public static Object[][] clientBuildersWithSessionConsistency() { - return new Object[][] { - { createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null) }, - { createDirectRxDocumentClient(ConsistencyLevel.Session, Protocol.Https, false, null) }, - { createDirectRxDocumentClient(ConsistencyLevel.Session, Protocol.Tcp, false, null) } - }; - } - - private static ConsistencyLevel parseConsistency(String consistency) { - if (consistency != null) { - for (ConsistencyLevel consistencyLevel : ConsistencyLevel.values()) { - if (consistencyLevel.name().toLowerCase().equals(consistency.toLowerCase())) { - return consistencyLevel; - } - } - } - - logger.error("Invalid configured test consistency [{}].", consistency); - throw new IllegalStateException("Invalid configured test consistency " + consistency); - } - - private static List parsePreferredLocation(String preferredLocations) { - if (StringUtils.isEmpty(preferredLocations)) { - return null; - } - - try { - return objectMapper.readValue(preferredLocations, new TypeReference>(){}); - } catch (Exception e) { - logger.error("Invalid configured test preferredLocations [{}].", preferredLocations); - throw new IllegalStateException("Invalid configured test preferredLocations " + preferredLocations); - } - } - - @DataProvider - public static Object[][] simpleClientBuildersWithDirect() { - return simpleClientBuildersWithDirect(Protocol.Https, Protocol.Tcp); - } - - @DataProvider - public static Object[][] simpleClientBuildersWithDirectHttps() { - return simpleClientBuildersWithDirect(Protocol.Https); - } - - @DataProvider - public static Object[][] simpleClientBuildersWithDirectTcp() { - return simpleClientBuildersWithDirect(Protocol.Tcp); - } - - private static Object[][] simpleClientBuildersWithDirect(Protocol... protocols) { - - accountConsistency = parseConsistency(TestConfigurations.CONSISTENCY); - logger.info("Max test consistency to use is [{}]", accountConsistency); - List testConsistencies = new ArrayList<>(); - - switch (accountConsistency) { - case Strong: - case BoundedStaleness: - case Session: - case ConsistentPrefix: - case Eventual: - testConsistencies.add(ConsistencyLevel.Eventual); - break; - default: - throw new IllegalStateException("Invalid configured test consistency " + accountConsistency); - } - - List preferredLocation = parsePreferredLocation(TestConfigurations.PREFERRED_LOCATIONS); - boolean isMultiMasterEnabled = preferredLocation != null && accountConsistency == ConsistencyLevel.Session; - - List builders = new ArrayList<>(); - builders.add(createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null)); - - for (Protocol protocol : protocols) { - testConsistencies.forEach(consistencyLevel -> builders.add(createDirectRxDocumentClient(consistencyLevel, - protocol, - isMultiMasterEnabled, - preferredLocation))); - } - - builders.forEach(b -> logger.info("Will Use ConnectionMode [{}], Consistency [{}], Protocol [{}]", - b.connectionPolicy.getConnectionMode(), - b.desiredConsistencyLevel, - b.configs.getProtocol() - )); - - return builders.stream().map(b -> new Object[]{b}).collect(Collectors.toList()).toArray(new Object[0][]); - } - - @DataProvider - public static Object[][] clientBuildersWithDirect() { - return clientBuildersWithDirectAllConsistencies(Protocol.Https, Protocol.Tcp); - } - - @DataProvider - public static Object[][] clientBuildersWithDirectHttps() { - return clientBuildersWithDirectAllConsistencies(Protocol.Https); - } - - @DataProvider - public static Object[][] clientBuildersWithDirectTcp() { - return clientBuildersWithDirectAllConsistencies(Protocol.Tcp); - } - - @DataProvider - public static Object[][] clientBuildersWithDirectSession() { - return clientBuildersWithDirectSession(Protocol.Https, Protocol.Tcp); - } - - private static Object[][] clientBuildersWithDirectSession(Protocol... protocols) { - return clientBuildersWithDirect(new ArrayList(){{add(ConsistencyLevel.Session);}} , protocols); - } - - private static Object[][] clientBuildersWithDirectAllConsistencies(Protocol... protocols) { - accountConsistency = parseConsistency(TestConfigurations.CONSISTENCY); - logger.info("Max test consistency to use is [{}]", accountConsistency); - List testConsistencies = new ArrayList<>(); - - switch (accountConsistency) { - case Strong: - testConsistencies.add(ConsistencyLevel.Strong); - case BoundedStaleness: - testConsistencies.add(ConsistencyLevel.BoundedStaleness); - case Session: - testConsistencies.add(ConsistencyLevel.Session); - case ConsistentPrefix: - testConsistencies.add(ConsistencyLevel.ConsistentPrefix); - case Eventual: - testConsistencies.add(ConsistencyLevel.Eventual); - break; - default: - throw new IllegalStateException("Invalid configured test consistency " + accountConsistency); - } - return clientBuildersWithDirect(testConsistencies, protocols); - } - - private static Object[][] clientBuildersWithDirect(List testConsistencies, Protocol... protocols) { - - List preferredLocation = parsePreferredLocation(TestConfigurations.PREFERRED_LOCATIONS); - boolean isMultiMasterEnabled = preferredLocation != null && accountConsistency == ConsistencyLevel.Session; - - List builders = new ArrayList<>(); - builders.add(createGatewayRxDocumentClient(ConsistencyLevel.Session, isMultiMasterEnabled, preferredLocation)); - - for (Protocol protocol : protocols) { - testConsistencies.forEach(consistencyLevel -> builders.add(createDirectRxDocumentClient(consistencyLevel, - protocol, - isMultiMasterEnabled, - preferredLocation))); - } - - builders.forEach(b -> logger.info("Will Use ConnectionMode [{}], Consistency [{}], Protocol [{}]", - b.connectionPolicy.getConnectionMode(), - b.desiredConsistencyLevel, - b.configs.getProtocol() - )); - - return builders.stream().map(b -> new Object[]{b}).collect(Collectors.toList()).toArray(new Object[0][]); - } - - static protected Builder createGatewayHouseKeepingDocumentClient() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - RetryOptions options = new RetryOptions(); - options.setMaxRetryWaitTimeInSeconds(SUITE_SETUP_TIMEOUT); - connectionPolicy.setRetryOptions(options); - return new Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session); - } - - static protected Builder createGatewayRxDocumentClient(ConsistencyLevel consistencyLevel, boolean multiMasterEnabled, List preferredLocations) { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - connectionPolicy.setUsingMultipleWriteLocations(multiMasterEnabled); - connectionPolicy.setPreferredLocations(preferredLocations); - return new Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(consistencyLevel); - } - - static protected Builder createGatewayRxDocumentClient() { - return createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null); - } - - static protected Builder createDirectRxDocumentClient(ConsistencyLevel consistencyLevel, - Protocol protocol, - boolean multiMasterEnabled, - List preferredLocations) { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - - if (preferredLocations != null) { - connectionPolicy.setPreferredLocations(preferredLocations); - } - - if (multiMasterEnabled && consistencyLevel == ConsistencyLevel.Session) { - connectionPolicy.setUsingMultipleWriteLocations(true); - } - - Configs configs = spy(new Configs()); - doAnswer((Answer)invocation -> protocol).when(configs).getProtocol(); - - return new Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(consistencyLevel) - .withConfigs(configs); - } - - protected int expectedNumberOfPages(int totalExpectedResult, int maxPageSize) { - return Math.max((totalExpectedResult + maxPageSize - 1 ) / maxPageSize, 1); - } - - @DataProvider(name = "queryMetricsArgProvider") - public Object[][] queryMetricsArgProvider() { - return new Object[][]{ - {true}, - {false}, - }; - } - - public static class VerboseTestSubscriber extends TestSubscriber { - @Override - public void assertNoErrors() { - List onErrorEvents = getOnErrorEvents(); - StringBuilder errorMessageBuilder = new StringBuilder(); - if (!onErrorEvents.isEmpty()) { - for(Throwable throwable : onErrorEvents) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - throwable.printStackTrace(pw); - String sStackTrace = sw.toString(); // stack trace as a string - errorMessageBuilder.append(sStackTrace); - } - - AssertionError ae = new AssertionError(errorMessageBuilder.toString()); - throw ae; - } - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TokenResolverTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TokenResolverTest.java deleted file mode 100644 index cc9ea0fef0f8..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TokenResolverTest.java +++ /dev/null @@ -1,566 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.CosmosResourceType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.Permission; -import com.microsoft.azure.cosmosdb.PermissionMode; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.StoredProcedure; -import com.microsoft.azure.cosmosdb.StoredProcedureResponse; -import com.microsoft.azure.cosmosdb.TokenResolver; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.ZonedDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.UUID; -import java.util.Map; - -public class TokenResolverTest extends TestSuiteBase { - - private class UserClass { - public String userName; - public int userId; - - public UserClass(String userName, int userId) { - this.userName = userName; - this.userId = userId; - } - } - - private Database createdDatabase; - private DocumentCollection createdCollection; - private User userWithReadPermission; - private User userWithAllPermission; - - private Permission readPermission; - private Permission allPermission; - - private AsyncDocumentClient.Builder clientBuilder; - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public TokenResolverTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @DataProvider(name = "connectionMode") - public Object[][] connectionMode() { - return new Object[][]{ - {ConnectionMode.Gateway}, - {ConnectionMode.Direct}, - }; - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION; - - client = clientBuilder.build(); - - userWithReadPermission = createUser(client, createdDatabase.getId(), getUserDefinition()); - readPermission = client.createPermission(userWithReadPermission.getSelfLink(), getPermission(createdCollection, "ReadPermissionOnColl", PermissionMode.Read), null).toBlocking().single() - .getResource(); - - userWithAllPermission = createUser(client, createdDatabase.getId(), getUserDefinition()); - allPermission = client.createPermission(userWithAllPermission.getSelfLink(), getPermission(createdCollection, "AllPermissionOnColl", PermissionMode.All), null).toBlocking().single() - .getResource(); - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void readDocumentWithReadPermission(ConnectionMode connectionMode) { - Document docDefinition = getDocumentDefinition(); - ResourceResponse resourceResponse = client - .createDocument(BridgeInternal.getAltLink(createdCollection), docDefinition, null, false).toBlocking().first(); - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.Read); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(resourceResponse.getResource().get("mypk"))); - HashMap properties = new HashMap(); - properties.put("UserId", "readUser"); - requestOptions.setProperties(properties); - Observable> readObservable = asyncClientWithTokenResolver.readDocument(resourceResponse.getResource().getSelfLink(), requestOptions); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(resourceResponse.getResource().getId()).build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void deleteDocumentWithReadPermission(ConnectionMode connectionMode) { - Document docDefinition = getDocumentDefinition(); - ResourceResponse resourceResponse = client - .createDocument(BridgeInternal.getAltLink(createdCollection), docDefinition, null, false).toBlocking().first(); - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.Read); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(resourceResponse.getResource().get("mypk"))); - Observable> readObservable = asyncClientWithTokenResolver.deleteDocument(resourceResponse.getResource().getSelfLink(), requestOptions); - FailureValidator validator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.FORBIDDEN).build(); - validateFailure(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void writeDocumentWithReadPermission(ConnectionMode connectionMode) { - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.Read); - Observable> readObservable = asyncClientWithTokenResolver.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, true); - FailureValidator validator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.FORBIDDEN).build(); - validateFailure(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void writeDocumentWithAllPermission(ConnectionMode connectionMode) { - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.All); - Document documentDefinition = getDocumentDefinition(); - Observable> readObservable = asyncClientWithTokenResolver.createDocument(createdCollection.getSelfLink(), documentDefinition, null, true); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(documentDefinition.getId()).build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void deleteDocumentWithAllPermission(ConnectionMode connectionMode) { - Document docDefinition = getDocumentDefinition(); - ResourceResponse resourceResponse = client - .createDocument(BridgeInternal.getAltLink(createdCollection), docDefinition, null, false).toBlocking().first(); - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.All); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(resourceResponse.getResource().get("mypk"))); - Observable> readObservable = asyncClientWithTokenResolver.deleteDocument(resourceResponse.getResource().getSelfLink(), requestOptions); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource().build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void readCollectionWithReadPermission(ConnectionMode connectionMode) { - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.Read); - Observable> readObservable = asyncClientWithTokenResolver.readCollection(createdCollection.getSelfLink(), null); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(createdCollection.getId()).build(); - validateSuccess(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void deleteCollectionWithReadPermission(ConnectionMode connectionMode) { - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.Read); - Observable> readObservable = asyncClientWithTokenResolver.deleteCollection(createdCollection.getSelfLink(), null); - FailureValidator validator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.FORBIDDEN).build(); - validateFailure(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void verifyingAuthTokenAPISequence(ConnectionMode connectionMode) { - Document docDefinition = getDocumentDefinition(); - ResourceResponse resourceResponse = client - .createDocument(BridgeInternal.getAltLink(createdCollection), docDefinition, null, false).toBlocking().first(); - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(connectionMode); - - //Unauthorized error with invalid token resolver, valid master key and valid permission feed, making it sure tokenResolver has higher priority than all. - List permissionFeed = new ArrayList<>(); - permissionFeed.add(readPermission); - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getTokenResolver(null)) //TokenResolver always generating invalid token. - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withPermissionFeed(permissionFeed) - .build(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(resourceResponse.getResource().get("mypk"))); - Observable> readObservable = asyncClientWithTokenResolver.readDocument(resourceResponse.getResource().getSelfLink(), requestOptions); - FailureValidator failureValidator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.UNAUTHORIZED).build(); - validateFailure(readObservable, failureValidator); - - //Success read operation with valid token resolver, invalid master key and invalid permission feed, making it sure tokenResolver has higher priority than all. - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getTokenResolver(PermissionMode.Read)) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withPermissionFeed(permissionFeed) - .build(); - readObservable = asyncClientWithTokenResolver.readDocument(resourceResponse.getResource().getSelfLink(), requestOptions); - ResourceResponseValidator sucessValidator = new ResourceResponseValidator.Builder() - .withId(resourceResponse.getResource().getId()).build(); - validateSuccess(readObservable, sucessValidator); - - - //Success read operation with valid permission feed, supporting above hypothesis. - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withPermissionFeed(permissionFeed) - .build(); - readObservable = asyncClientWithTokenResolver.readDocument(resourceResponse.getResource().getSelfLink(), requestOptions); - validateSuccess(readObservable, sucessValidator); - - - //Success read operation with valid master key, supporting above hypothesis. - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .build(); - readObservable = asyncClientWithTokenResolver.readDocument(resourceResponse.getResource().getSelfLink(), requestOptions); - validateSuccess(readObservable, sucessValidator); - - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = 6000000) - public void createAndExecuteSprocWithWritePermission(ConnectionMode connectionMode) throws InterruptedException { - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.All); - String sprocId = "storedProcedure" + UUID.randomUUID().toString(); - StoredProcedure sproc = new StoredProcedure( - "{" + - " 'id':'" + sprocId + "'," + - " 'body':" + - " 'function() {" + - " var mytext = \"x\";" + - " var myval = 1;" + - " try {" + - " getContext().getResponse().setBody(\"Success!\");" + - " }" + - " catch(err) {" + - " getContext().getResponse().setBody(\"inline err: [\" + err.number + \"] \" + err);" + - " }" + - " }'" + - "}"); - - Observable> createObservable = asyncClientWithTokenResolver.createStoredProcedure(createdCollection.getSelfLink(), sproc, null); - ResourceResponseValidator createSucessValidator = new ResourceResponseValidator.Builder() - .withId(sprocId).build(); - validateSuccess(createObservable, createSucessValidator); - - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey("")); - String sprocLink = "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId() + "/sprocs/" + sprocId; - StoredProcedureResponse result = asyncClientWithTokenResolver.executeStoredProcedure(sprocLink, options, null).toBlocking().single(); - assertThat(result.getResponseAsString()).isEqualTo("\"Success!\""); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void readDocumentsWithAllPermission(ConnectionMode connectionMode) { - AsyncDocumentClient asyncClientWithTokenResolver = null; - String id1 = UUID.randomUUID().toString(); - String id2 = UUID.randomUUID().toString(); - - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.All); - Document document1 = asyncClientWithTokenResolver.createDocument(createdCollection.getSelfLink(), new Document("{'id': '" + id1 + "'}"), null, false) - .toBlocking().single().getResource(); - Document document2 = asyncClientWithTokenResolver.createDocument(createdCollection.getSelfLink(), new Document("{'id': '" + id2 + "'}"), null, false) - .toBlocking().single().getResource(); - List expectedIds = new ArrayList(); - String rid1 = document1.getResourceId(); - String rid2 = document2.getResourceId(); - expectedIds.add(rid1); - expectedIds.add(rid2); - String query = "SELECT * FROM r WHERE r._rid=\"" + rid1 + "\" or r._rid=\"" + rid2 + "\""; - - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = asyncClientWithTokenResolver.queryDocuments(createdCollection.getSelfLink(), query, options); - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .numberOfPages(1) - .exactlyContainsInAnyOrder(expectedIds).build(); - validateQuerySuccess(queryObservable, validator, 10000); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void readChangeFeedWithAllPermission(ConnectionMode connectionMode) throws InterruptedException { - - //setStartDateTime is not currently supported in multimaster mode. So skipping the test - if(BridgeInternal.isEnableMultipleWriteLocations(client.getDatabaseAccount().toBlocking().single())){ - throw new SkipException("StartTime/IfModifiedSince is not currently supported when EnableMultipleWriteLocations is set"); - } - - AsyncDocumentClient asyncClientWithTokenResolver = null; - String id1 = UUID.randomUUID().toString(); - String id2 = UUID.randomUUID().toString(); - String partitionKey = createdCollection.getPartitionKey().getPaths().get(0).substring(1); - String partitionKeyValue = "pk"; - Document document1 = new Document(); - document1.setId(id1); - document1.set(partitionKey, partitionKeyValue); - Document document2 = new Document(); - document2.setId(id2); - document2.set(partitionKey, partitionKeyValue); - try { - asyncClientWithTokenResolver = buildClient(connectionMode, PermissionMode.All); - ZonedDateTime befTime = ZonedDateTime.now(); - Thread.sleep(1000); - - document1 = asyncClientWithTokenResolver - .createDocument(createdCollection.getSelfLink(), document1, null, false).toBlocking().single() - .getResource(); - document2 = asyncClientWithTokenResolver - .createDocument(createdCollection.getSelfLink(), document2, null, false).toBlocking().single() - .getResource(); - List expectedIds = new ArrayList(); - String rid1 = document1.getResourceId(); - String rid2 = document2.getResourceId(); - expectedIds.add(rid1); - expectedIds.add(rid2); - - ChangeFeedOptions options = new ChangeFeedOptions(); - options.setPartitionKey(new PartitionKey(partitionKeyValue)); - options.setStartDateTime(befTime); - - Thread.sleep(1000); - Observable> queryObservable = asyncClientWithTokenResolver - .queryDocumentChangeFeed(createdCollection.getSelfLink(), options); - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .exactlyContainsInAnyOrder(expectedIds).build(); - validateQuerySuccess(queryObservable, validator, 10000); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void verifyRuntimeExceptionWhenUserModifiesProperties(ConnectionMode connectionMode) { - AsyncDocumentClient asyncClientWithTokenResolver = null; - - try { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(connectionMode); - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getBadTokenResolver()) - .build(); - - RequestOptions options = new RequestOptions(); - options.setProperties(new HashMap()); - Observable> readObservable = asyncClientWithTokenResolver.readCollection(createdCollection.getSelfLink(), options); - FailureValidator validator = new FailureValidator.Builder().withRuntimeExceptionClass(UnsupportedOperationException.class).build(); - validateFailure(readObservable, validator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @Test(groups = {"simple"}, dataProvider = "connectionMode", timeOut = TIMEOUT) - public void verifyBlockListedUserThrows(ConnectionMode connectionMode) { - String field = "user"; - UserClass blockListedUser = new UserClass("block listed user", 0); - String errorMessage = "block listed user! access denied!"; - - AsyncDocumentClient asyncClientWithTokenResolver = null; - try { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(connectionMode); - asyncClientWithTokenResolver = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getTokenResolverWithBlockList(PermissionMode.Read, field, blockListedUser, errorMessage)) - .build(); - - RequestOptions options = new RequestOptions(); - HashMap properties = new HashMap(); - properties.put(field, blockListedUser); - options.setProperties(properties); - Observable> readObservable = asyncClientWithTokenResolver.readCollection(createdCollection.getSelfLink(), options); - FailureValidator validator = new FailureValidator.Builder().withRuntimeExceptionMessage(errorMessage).build(); - validateFailure(readObservable, validator); - - properties.put(field, new UserClass("valid user", 1)); - options.setProperties(properties); - readObservable = asyncClientWithTokenResolver.readCollection(createdCollection.getSelfLink(), options); - ResourceResponseValidator sucessValidator = new ResourceResponseValidator.Builder() - .withId(createdCollection.getId()).build(); - validateSuccess(readObservable, sucessValidator); - } finally { - safeClose(asyncClientWithTokenResolver); - } - } - - @AfterClass(groups = {"simple"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - client.close(); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - private AsyncDocumentClient buildClient(ConnectionMode connectionMode, PermissionMode permissionMode) { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(connectionMode); - return new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .withTokenResolver(getTokenResolver(permissionMode)) - .build(); - } - - private static User getUserDefinition() { - User user = new User(); - user.setId(UUID.randomUUID().toString()); - return user; - } - - private Permission getPermission(Resource resource, String permissionId, PermissionMode permissionMode) { - Permission permission = new Permission(); - permission.setId(permissionId); - permission.setPermissionMode(permissionMode); - permission.setResourceLink(resource.getSelfLink()); - return permission; - } - - private TokenResolver getTokenResolver(PermissionMode permissionMode) { - return (String requestVerb, String resourceIdOrFullName, CosmosResourceType resourceType, Map properties) -> { - if (permissionMode == null) { - return "invalid"; - } else if (permissionMode.equals(PermissionMode.Read)) { - return readPermission.getToken(); - } else { - return allPermission.getToken(); - } - }; - } - - private TokenResolver getBadTokenResolver() { - return (String requestVerb, String resourceIdOrFullName, CosmosResourceType resourceType, Map properties) -> { - if (resourceType == CosmosResourceType.System) { - return readPermission.getToken(); - } - if (properties != null) { - properties.put("key", "value"); - } - return null; - }; - } - - private TokenResolver getTokenResolverWithBlockList(PermissionMode permissionMode, String field, UserClass blockListedUser, String errorMessage) { - return (String requestVerb, String resourceIdOrFullName, CosmosResourceType resourceType, Map properties) -> { - UserClass currentUser = null; - if (properties != null && properties.get(field) != null) { - currentUser = (UserClass) properties.get(field); - } - - if (resourceType == CosmosResourceType.System) { - return readPermission.getToken(); - } else if (currentUser != null && - !currentUser.userName.equals(blockListedUser.userName) && - currentUser.userId != blockListedUser.userId) { - if (permissionMode.equals(PermissionMode.Read)) { - return readPermission.getToken(); - } else { - return allPermission.getToken(); - } - } else { - throw new RuntimeException(errorMessage); - } - }; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TopQueryTests.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TopQueryTests.java deleted file mode 100644 index f2b1cbb7a163..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TopQueryTests.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.internal.Utils.ValueHolder; -import com.microsoft.azure.cosmosdb.rx.internal.query.TakeContinuationToken; - -import rx.Observable; - -public class TopQueryTests extends TestSuiteBase { - private Database createdDatabase; - private DocumentCollection createdCollection; - private ArrayList docs = new ArrayList(); - - private String partitionKey = "mypk"; - private int firstPk = 0; - private int secondPk = 1; - private String field = "field"; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public TopQueryTests(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "queryMetricsArgProvider") - public void queryDocumentsWithTop(boolean qmEnabled) throws Exception { - - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(9); - options.setMaxDegreeOfParallelism(2); - options.setPopulateQueryMetrics(qmEnabled); - - int expectedTotalSize = 20; - int expectedNumberOfPages = 3; - int[] expectedPageLengths = new int[] { 9, 9, 2 }; - - for (int i = 0; i < 2; i++) { - Observable> queryObservable1 = client.queryDocuments(createdCollection.getSelfLink(), - "SELECT TOP 0 value AVG(c.field) from c", options); - - FeedResponseListValidator validator1 = new FeedResponseListValidator.Builder() - .totalSize(0).build(); - - try { - validateQuerySuccess(queryObservable1, validator1, TIMEOUT); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", - this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - - Observable> queryObservable2 = client.queryDocuments(createdCollection.getSelfLink(), - "SELECT TOP 1 value AVG(c.field) from c", options); - - FeedResponseListValidator validator2 = new FeedResponseListValidator.Builder() - .totalSize(1).build(); - - validateQuerySuccess(queryObservable2, validator2, TIMEOUT); - - Observable> queryObservable3 = client.queryDocuments(createdCollection.getSelfLink(), - "SELECT TOP 20 * from c", options); - - FeedResponseListValidator validator3 = new FeedResponseListValidator.Builder() - .totalSize(expectedTotalSize).numberOfPages(expectedNumberOfPages).pageLengths(expectedPageLengths) - .hasValidQueryMetrics(qmEnabled).build(); - - validateQuerySuccess(queryObservable3, validator3, TIMEOUT); - - if (i == 0) { - options.setPartitionKey(new PartitionKey(firstPk)); - options.setEnableCrossPartitionQuery(false); - - expectedTotalSize = 10; - expectedNumberOfPages = 2; - expectedPageLengths = new int[] { 9, 1 }; - - } - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void topContinuationTokenRoundTrips() throws Exception { - { - // Positive - TakeContinuationToken takeContinuationToken = new TakeContinuationToken(42, "asdf"); - String serialized = takeContinuationToken.toString(); - ValueHolder outTakeContinuationToken = new ValueHolder(); - - assertThat(TakeContinuationToken.tryParse(serialized, outTakeContinuationToken)).isTrue(); - TakeContinuationToken deserialized = outTakeContinuationToken.v; - - assertThat(deserialized.getTakeCount()).isEqualTo(42); - assertThat(deserialized.getSourceToken()).isEqualTo("asdf"); - } - - { - // Negative - ValueHolder outTakeContinuationToken = new ValueHolder(); - assertThat( - TakeContinuationToken.tryParse("{\"property\": \"Not a valid token\"}", outTakeContinuationToken)) - .isFalse(); - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT * 10) - public void queryDocumentsWithTopContinuationTokens() throws Exception { - String query = "SELECT TOP 8 * FROM c"; - this.queryWithContinuationTokensAndPageSizes(query, new int[] { 1, 5, 10 }, 8); - } - - private void queryWithContinuationTokensAndPageSizes(String query, int[] pageSizes, int topCount) { - for (int pageSize : pageSizes) { - List receivedDocuments = this.queryWithContinuationTokens(query, pageSize); - Set actualIds = new HashSet(); - for (Document document : receivedDocuments) { - actualIds.add(document.getResourceId()); - } - - assertThat(actualIds.size()).describedAs("total number of results").isEqualTo(topCount); - } - } - - private List queryWithContinuationTokens(String query, int pageSize) { - String requestContinuation = null; - List continuationTokens = new ArrayList(); - List receivedDocuments = new ArrayList(); - - do { - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(pageSize); - options.setEnableCrossPartitionQuery(true); - options.setMaxDegreeOfParallelism(2); - options.setRequestContinuation(requestContinuation); - Observable> queryObservable = client.queryDocuments(createdCollection.getSelfLink(), - query, options); - - Observable> firstPageObservable = queryObservable.first(); - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - firstPageObservable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(TIMEOUT, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - - FeedResponse firstPage = testSubscriber.getOnNextEvents().get(0); - requestContinuation = firstPage.getResponseContinuation(); - receivedDocuments.addAll(firstPage.getResults()); - continuationTokens.add(requestContinuation); - } while (requestContinuation != null); - - return receivedDocuments; - } - - public void bulkInsert(AsyncDocumentClient client) { - generateTestData(); - - for (int i = 0; i < docs.size(); i++) { - createDocument(client, createdDatabase.getId(), createdCollection.getId(), docs.get(i)); - } - } - - public void generateTestData() { - - for (int i = 0; i < 10; i++) { - Document d = new Document(); - d.setId(Integer.toString(i)); - d.set(field, i); - d.set(partitionKey, firstPk); - docs.add(d); - } - - for (int i = 10; i < 20; i++) { - Document d = new Document(); - d.setId(Integer.toString(i)); - d.set(field, i); - d.set(partitionKey, secondPk); - docs.add(d); - } - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION); - - bulkInsert(client); - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerCrudTest.java deleted file mode 100644 index 5a729f2ce424..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerCrudTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.UUID; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.TriggerOperation; -import com.microsoft.azure.cosmosdb.TriggerType; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -import rx.Observable; - -import javax.net.ssl.SSLException; - - -public class TriggerCrudTest extends TestSuiteBase { - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public TriggerCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createTrigger() throws Exception { - - // create a trigger - Trigger trigger = new Trigger(); - trigger.setId(UUID.randomUUID().toString()); - trigger.setBody("function() {var x = 10;}"); - trigger.setTriggerOperation(TriggerOperation.Create); - trigger.setTriggerType(TriggerType.Pre); - - Observable> createObservable = client.createTrigger(getCollectionLink(), trigger, null); - - // validate trigger creation - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(trigger.getId()) - .withTriggerBody("function() {var x = 10;}") - .withTriggerInternals(TriggerType.Pre, TriggerOperation.Create) - .notNullEtag() - .build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void readTrigger() throws Exception { - // create a trigger - Trigger trigger = new Trigger(); - trigger.setId(UUID.randomUUID().toString()); - trigger.setBody("function() {var x = 10;}"); - trigger.setTriggerOperation(TriggerOperation.Create); - trigger.setTriggerType(TriggerType.Pre); - Trigger readBackTrigger = client.createTrigger(getCollectionLink(), trigger, null).toBlocking().single().getResource(); - - // read trigger - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readTrigger(readBackTrigger.getSelfLink(), null); - - // validate read trigger - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(trigger.getId()) - .withTriggerBody("function() {var x = 10;}") - .withTriggerInternals(TriggerType.Pre, TriggerOperation.Create) - .notNullEtag() - .build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void deleteTrigger() throws Exception { - // create a trigger - Trigger trigger = new Trigger(); - trigger.setId(UUID.randomUUID().toString()); - trigger.setBody("function() {var x = 10;}"); - trigger.setTriggerOperation(TriggerOperation.Create); - trigger.setTriggerType(TriggerType.Pre); - Trigger readBackTrigger = client.createTrigger(getCollectionLink(), trigger, null).toBlocking().single().getResource(); - - // delete trigger - Observable> deleteObservable = client.deleteTrigger(readBackTrigger.getSelfLink(), null); - - // validate delete trigger - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource() - .build(); - validateSuccess(deleteObservable, validator); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerQueryTest.java deleted file mode 100644 index af8ea0a1bdd4..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerQueryTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.TriggerOperation; -import com.microsoft.azure.cosmosdb.TriggerType; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - - -public class TriggerQueryTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdTriggers = new ArrayList<>(); - - private AsyncDocumentClient client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - @Factory(dataProvider = "clientBuildersWithDirect") - public TriggerQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryWithFilter() throws Exception { - - String filterId = createdTriggers.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - Observable> queryObservable = client - .queryTriggers(getCollectionLink(), query, options); - - List expectedDocs = createdTriggers.stream().filter(sp -> filterId.equals(sp.getId()) ).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void query_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryTriggers(getCollectionLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAll() throws Exception { - - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(3); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryTriggers(getCollectionLink(), query, options); - - List expectedDocs = createdTriggers; - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .exactlyContainsInAnyOrder(expectedDocs - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void invalidQuerySytax() throws Exception { - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryTriggers(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .notNullActivityId() - .build(); - validateQueryFailure(queryObservable, validator); - } - - public Trigger createTrigger(AsyncDocumentClient client) { - Trigger storedProcedure = getTriggerDef(); - return client.createTrigger(getCollectionLink(), storedProcedure, null).toBlocking().single().getResource(); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - for(int i = 0; i < 5; i++) { - createdTriggers.add(createTrigger(client)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static Trigger getTriggerDef() { - Trigger trigger = new Trigger(); - trigger.setId(UUID.randomUUID().toString()); - trigger.setBody("function() {var x = 10;}"); - trigger.setTriggerOperation(TriggerOperation.Create); - trigger.setTriggerType(TriggerType.Pre); - return trigger; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerUpsertReplaceTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerUpsertReplaceTest.java deleted file mode 100644 index 7ef831e458eb..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/TriggerUpsertReplaceTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.UUID; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.Trigger; -import com.microsoft.azure.cosmosdb.TriggerOperation; -import com.microsoft.azure.cosmosdb.TriggerType; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -import rx.Observable; - -import javax.net.ssl.SSLException; - - -public class TriggerUpsertReplaceTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public TriggerUpsertReplaceTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void upsertTrigger() throws Exception { - - // create a trigger - Trigger trigger = new Trigger(); - trigger.setId(UUID.randomUUID().toString()); - trigger.setBody("function() {var x = 10;}"); - trigger.setTriggerOperation(TriggerOperation.Create); - trigger.setTriggerType(TriggerType.Pre); - Trigger readBackTrigger = client.upsertTrigger(getCollectionLink(), trigger, null).toBlocking().single().getResource(); - - // read trigger to validate creation - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readTrigger(readBackTrigger.getSelfLink(), null); - - // validate trigger creation - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackTrigger.getId()) - .withTriggerBody("function() {var x = 10;}") - .withTriggerInternals(TriggerType.Pre, TriggerOperation.Create) - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update trigger - readBackTrigger.setBody("function() {var x = 11;}"); - - Observable> updateObservable = client.upsertTrigger(getCollectionLink(), readBackTrigger, null); - - // validate trigger update - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackTrigger.getId()) - .withTriggerBody("function() {var x = 11;}") - .withTriggerInternals(TriggerType.Pre, TriggerOperation.Create) - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void replaceTrigger() throws Exception { - - // create a trigger - Trigger trigger = new Trigger(); - trigger.setId(UUID.randomUUID().toString()); - trigger.setBody("function() {var x = 10;}"); - trigger.setTriggerOperation(TriggerOperation.Create); - trigger.setTriggerType(TriggerType.Pre); - Trigger readBackTrigger = client.createTrigger(getCollectionLink(), trigger, null).toBlocking().single().getResource(); - - // read trigger to validate creation - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readTrigger(readBackTrigger.getSelfLink(), null); - - // validate trigger creation - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackTrigger.getId()) - .withTriggerBody("function() {var x = 10;}") - .withTriggerInternals(TriggerType.Pre, TriggerOperation.Create) - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update trigger - readBackTrigger.setBody("function() {var x = 11;}"); - - Observable> updateObservable = client.replaceTrigger(readBackTrigger, null); - - // validate trigger replace - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackTrigger.getId()) - .withTriggerBody("function() {var x = 11;}") - .withTriggerInternals(TriggerType.Pre, TriggerOperation.Create) - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UniqueIndexTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UniqueIndexTest.java deleted file mode 100644 index d6bd7f40c6b2..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UniqueIndexTest.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -import java.util.Collections; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import javax.net.ssl.SSLException; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.util.JSONPObject; -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ExcludedPath; -import com.microsoft.azure.cosmosdb.HashIndex; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.IndexingMode; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.UniqueKey; -import com.microsoft.azure.cosmosdb.UniqueKeyPolicy; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; - -import rx.Observable; -import rx.observers.TestSubscriber; - -public class UniqueIndexTest extends TestSuiteBase { - protected static final int TIMEOUT = 30000; - protected static final int SETUP_TIMEOUT = 20000; - protected static final int SHUTDOWN_TIMEOUT = 20000; - - private final String databaseId = DatabaseForTest.generateId(); - private AsyncDocumentClient client; - private Database database; - - private DocumentCollection collection; - - @Test(groups = { "long" }, timeOut = TIMEOUT) - public void insertWithUniqueIndex() throws Exception { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy(); - UniqueKey uniqueKey = new UniqueKey(); - uniqueKey.setPaths(ImmutableList.of("/name", "/description")); - uniqueKeyPolicy.setUniqueKeys(Collections.singleton(uniqueKey)); - collectionDefinition.setUniqueKeyPolicy(uniqueKeyPolicy); - - IndexingPolicy indexingPolicy = new IndexingPolicy(); - indexingPolicy.setIndexingMode(IndexingMode.Consistent); - ExcludedPath excludedPath = new ExcludedPath(); - excludedPath.setPath("/*"); - indexingPolicy.setExcludedPaths(Collections.singletonList(excludedPath)); - - IncludedPath includedPath1 = new IncludedPath(); - includedPath1.setPath("/name/?"); - includedPath1.setIndexes(Collections.singletonList(new HashIndex(DataType.String, 7))); - - IncludedPath includedPath2 = new IncludedPath(); - includedPath2.setPath("/description/?"); - includedPath2.setIndexes(Collections.singletonList(new HashIndex(DataType.String, 7))); - indexingPolicy.setIncludedPaths(ImmutableList.of(includedPath1, includedPath2)); - - ObjectMapper om = new ObjectMapper(); - - JsonNode doc1 = om.readValue("{\"name\":\"Alexander Pushkin\",\"description\":\"poet\"}", JsonNode.class); - JsonNode doc2 = om.readValue("{\"name\":\"Alexander Pushkin\",\"description\":\"playwright\"}", JsonNode.class); - JsonNode doc3 = om.readValue("{\"name\":\"حافظ شیرازی\",\"description\":\"poet\"}", JsonNode.class); - - collection = client.createCollection(getDatabaseLink(), collectionDefinition, null).toBlocking().single().getResource(); - - Document dd = client.createDocument(getCollectionLink(collection), doc1, null, false).toBlocking().single().getResource(); - - client.readDocument(dd.getSelfLink(), null).toBlocking().single(); - - try { - client.createDocument(getCollectionLink(collection), doc1, null, false).toBlocking().single(); - fail("Did not throw due to unique constraint (create)"); - } catch (RuntimeException e) { - assertThat(getDocumentClientException(e).getStatusCode()).isEqualTo(HttpConstants.StatusCodes.CONFLICT); - } - - client.createDocument(getCollectionLink(collection), doc2, null, false).toBlocking().single(); - client.createDocument(getCollectionLink(collection), doc3, null, false).toBlocking().single(); - } - - @Test(groups = { "long" }, timeOut = TIMEOUT) - public void replaceAndDeleteWithUniqueIndex() throws Exception { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy(); - UniqueKey uniqueKey = new UniqueKey(); - uniqueKey.setPaths(ImmutableList.of("/name", "/description")); - uniqueKeyPolicy.setUniqueKeys(Collections.singleton(uniqueKey)); - collectionDefinition.setUniqueKeyPolicy(uniqueKeyPolicy); - - collection = client.createCollection(getDatabaseLink(), collectionDefinition, null).toBlocking().single().getResource(); - - ObjectMapper om = new ObjectMapper(); - - ObjectNode doc1 = om.readValue("{\"name\":\"عمر خیّام\",\"description\":\"poet\"}", ObjectNode.class); - ObjectNode doc3 = om.readValue("{\"name\":\"Rabindranath Tagore\",\"description\":\"poet\"}", ObjectNode.class); - ObjectNode doc2 = om.readValue("{\"name\":\"عمر خیّام\",\"description\":\"mathematician\"}", ObjectNode.class); - - Document doc1Inserted = client.createDocument( - getCollectionLink(collection), doc1, null, false).toBlocking().single().getResource(); - - client.replaceDocument(doc1Inserted.getSelfLink(), doc1Inserted, null).toBlocking().single(); // Replace with same values -- OK. - - Document doc2Inserted = client.createDocument(getCollectionLink(collection), doc2, null, false).toBlocking().single().getResource(); - Document doc2Replacement = new Document(doc1Inserted.toJson()); - doc2Replacement.setId( doc2Inserted.getId()); - - try { - client.replaceDocument(doc2Inserted.getSelfLink(), doc2Replacement, null).toBlocking().single(); // Replace doc2 with values from doc1 -- Conflict. - fail("Did not throw due to unique constraint"); - } - catch (RuntimeException ex) { - assertThat(getDocumentClientException(ex).getStatusCode()).isEqualTo(HttpConstants.StatusCodes.CONFLICT); - } - - doc3.put("id", doc1Inserted.getId()); - client.replaceDocument(doc1Inserted.getSelfLink(), doc3, null).toBlocking().single(); // Replace with values from doc3 -- OK. - - client.deleteDocument(doc1Inserted.getSelfLink(), null).toBlocking().single(); - client.createDocument(getCollectionLink(collection), doc1, null, false).toBlocking().single(); - } - - @Test(groups = { "long" }, timeOut = TIMEOUT) - public void uniqueKeySerializationDeserialization() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - UniqueKeyPolicy uniqueKeyPolicy = new UniqueKeyPolicy(); - UniqueKey uniqueKey = new UniqueKey(); - uniqueKey.setPaths(ImmutableList.of("/name", "/description")); - uniqueKeyPolicy.setUniqueKeys(Collections.singleton(uniqueKey)); - collectionDefinition.setUniqueKeyPolicy(uniqueKeyPolicy); - - IndexingPolicy indexingPolicy = new IndexingPolicy(); - indexingPolicy.setIndexingMode(IndexingMode.Consistent); - ExcludedPath excludedPath = new ExcludedPath(); - excludedPath.setPath("/*"); - indexingPolicy.setExcludedPaths(Collections.singletonList(excludedPath)); - - IncludedPath includedPath1 = new IncludedPath(); - includedPath1.setPath("/name/?"); - includedPath1.setIndexes(Collections.singletonList(new HashIndex(DataType.String, 7))); - - IncludedPath includedPath2 = new IncludedPath(); - includedPath2.setPath("/description/?"); - includedPath2.setIndexes(Collections.singletonList(new HashIndex(DataType.String, 7))); - indexingPolicy.setIncludedPaths(ImmutableList.of(includedPath1, includedPath2)); - - collectionDefinition.setIndexingPolicy(indexingPolicy); - - DocumentCollection createdCollection = client.createCollection(database.getSelfLink(), collectionDefinition, - null).toBlocking().single().getResource(); - - DocumentCollection collection = client.readCollection(getCollectionLink(createdCollection), null) - .toBlocking().single().getResource(); - - assertThat(collection.getUniqueKeyPolicy()).isNotNull(); - assertThat(collection.getUniqueKeyPolicy().getUniqueKeys()).isNotNull(); - assertThat(collection.getUniqueKeyPolicy().getUniqueKeys()) - .hasSameSizeAs(collectionDefinition.getUniqueKeyPolicy().getUniqueKeys()); - assertThat(collection.getUniqueKeyPolicy().getUniqueKeys() - .stream().map(ui -> ui.getPaths()).collect(Collectors.toList())) - .containsExactlyElementsOf( - ImmutableList.of(ImmutableList.of("/name", "/description"))); - } - - private DocumentClientException getDocumentClientException(RuntimeException e) { - DocumentClientException dce = com.microsoft.azure.cosmosdb.rx.internal.Utils.as(e.getCause(), DocumentClientException.class); - assertThat(dce).isNotNull(); - return dce; - } - - private String getDatabaseLink() { - return database.getSelfLink(); - } - - public String getCollectionLink() { - return "dbs/" + database.getId() + "/colls/" + collection.getId(); - } - - @BeforeClass(groups = { "long" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - // set up the client - client = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(ConnectionPolicy.GetDefault()) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - - database = createDatabase(client, databaseId); - } - - @AfterClass(groups = { "long" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId); - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserCrudTest.java deleted file mode 100644 index ce47630b91ad..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserCrudTest.java +++ /dev/null @@ -1,216 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import com.microsoft.azure.cosmosdb.Permission; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.User; - -import rx.Observable; - -import javax.net.ssl.SSLException; - - -public class UserCrudTest extends TestSuiteBase { - - public final String databaseId = DatabaseForTest.generateId(); - - private Database createdDatabase; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuilders") - public UserCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void createUser() throws Exception { - //create user - User user = new User(); - user.setId(UUID.randomUUID().toString()); - - Observable> createObservable = client.createUser(getDatabaseLink(), user, null); - - // validate user creation - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(user.getId()) - .notNullEtag() - .build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void readUser() throws Exception { - - //create user - User user = new User(); - user.setId(UUID.randomUUID().toString()); - - User readBackUser = client.createUser(getDatabaseLink(), user, null).toBlocking().single().getResource(); - - // read user - Observable> readObservable = client.readUser(readBackUser.getSelfLink(), null); - - //validate user read - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(readBackUser.getId()) - .notNullEtag() - .build(); - - validateSuccess(readObservable, validator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void deleteUser() throws Exception { - //create user - User user = new User(); - user.setId(UUID.randomUUID().toString()); - - User readBackUser = client.createUser(getDatabaseLink(), user, null).toBlocking().single().getResource(); - - // delete user - Observable> deleteObservable = client.deleteUser(readBackUser.getSelfLink(), null); - - // validate user delete - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource() - .build(); - validateSuccess(deleteObservable, validator); - - // attempt to read the user which was deleted - Observable> readObservable = client.readUser(readBackUser.getSelfLink(), null); - FailureValidator notFoundValidator = new FailureValidator.Builder().resourceNotFound().build(); - validateFailure(readObservable, notFoundValidator); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void upsertUser() throws Exception { - - //create user - User user = new User(); - user.setId(UUID.randomUUID().toString()); - - User readBackUser = client.upsertUser(getDatabaseLink(), user, null).toBlocking().single().getResource(); - - // read user to validate creation - Observable> readObservable = client.readUser(readBackUser.getSelfLink(), null); - - //validate user read - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackUser.getId()) - .notNullEtag() - .build(); - - validateSuccess(readObservable, validatorForRead); - - client.readUsers(getDatabaseLink(), null).toBlocking().subscribe(users -> { - try { - int initialNumberOfUsers = users.getResults().size(); - //update user - readBackUser.setId(UUID.randomUUID().toString()); - - Observable> updateObservable = client.upsertUser(getDatabaseLink(), readBackUser, null); - - // validate user upsert - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackUser.getId()) - .notNullEtag() - .build(); - - validateSuccess(updateObservable, validatorForUpdate); - - //verify that new user is added due to upsert with changed id - client.readUsers(getDatabaseLink(), null).toBlocking().subscribe(newUsers ->{ - int finalNumberOfUsers = newUsers.getResults().size(); - assertThat(finalNumberOfUsers).isEqualTo(initialNumberOfUsers + 1); - }); - } catch (Exception e) { - e.printStackTrace(); - } - }); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void replaceUser() throws Exception { - - //create user - User user = new User(); - user.setId(UUID.randomUUID().toString()); - - User readBackUser = client.createUser(getDatabaseLink(), user, null).toBlocking().single().getResource(); - - // read user to validate creation - Observable> readObservable = client.readUser(readBackUser.getSelfLink(), null); - - //validate user read - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackUser.getId()) - .notNullEtag() - .build(); - - validateSuccess(readObservable, validatorForRead); - - //update user - readBackUser.setId(UUID.randomUUID().toString()); - - Observable> updateObservable = client.replaceUser(readBackUser, null); - - // validate user replace - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackUser.getId()) - .notNullEtag() - .build(); - - validateSuccess(updateObservable, validatorForUpdate); - } - - @BeforeClass(groups = { "emulator" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - Database d = new Database(); - d.setId(databaseId); - createdDatabase = createDatabase(client, d); - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, createdDatabase.getId()); - safeClose(client); - } - - private String getDatabaseLink() { - return createdDatabase.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionCrudTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionCrudTest.java deleted file mode 100644 index ed03ec2026b2..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionCrudTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.UUID; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -import rx.Observable; - - -public class UserDefinedFunctionCrudTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public UserDefinedFunctionCrudTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createUserDefinedFunction() throws Exception { - // create udf - UserDefinedFunction udf = new UserDefinedFunction(); - udf.setId(UUID.randomUUID().toString()); - udf.setBody("function() {var x = 10;}"); - - Observable> createObservable = client.createUserDefinedFunction(getCollectionLink(), udf, null); - - // validate udf creation - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(udf.getId()) - .withUserDefinedFunctionBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void readUserDefinedFunction() throws Exception { - // create a udf - UserDefinedFunction udf = new UserDefinedFunction(); - udf.setId(UUID.randomUUID().toString()); - udf.setBody("function() {var x = 10;}"); - UserDefinedFunction readBackUdf = client.createUserDefinedFunction(getCollectionLink(), udf, null).toBlocking().single().getResource(); - - - // read udf - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readUserDefinedFunction(readBackUdf.getSelfLink(), null); - - //validate udf read - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(udf.getId()) - .withUserDefinedFunctionBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(readObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void deleteUserDefinedFunction() throws Exception { - // create a udf - UserDefinedFunction udf = new UserDefinedFunction(); - udf.setId(UUID.randomUUID().toString()); - udf.setBody("function() {var x = 10;}"); - UserDefinedFunction readBackUdf = client.createUserDefinedFunction(getCollectionLink(), udf, null).toBlocking().single().getResource(); - - // delete udf - Observable> deleteObservable = client.deleteUserDefinedFunction(readBackUdf.getSelfLink(), null); - - // validate udf delete - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource() - .build(); - validateSuccess(deleteObservable, validator); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionQueryTest.java deleted file mode 100644 index b8ffbc79fe9f..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionQueryTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - - -public class UserDefinedFunctionQueryTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - private List createdUDF = new ArrayList<>(); - - private AsyncDocumentClient client; - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } - - @Factory(dataProvider = "clientBuildersWithDirect") - public UserDefinedFunctionQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryWithFilter() throws Exception { - - String filterId = createdUDF.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - Observable> queryObservable = client - .queryUserDefinedFunctions(getCollectionLink(), query, options); - - List expectedDocs = createdUDF.stream().filter(sp -> filterId.equals(sp.getId()) ).collect(Collectors.toList()); - assertThat(expectedDocs).isNotEmpty(); - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedDocs.size()) - .exactlyContainsInAnyOrder(expectedDocs.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void query_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryUserDefinedFunctions(getCollectionLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAll() throws Exception { - - String query = "SELECT * from root"; - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(3); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryUserDefinedFunctions(getCollectionLink(), query, options); - - List expectedDocs = createdUDF; - - int expectedPageSize = (expectedDocs.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator - .Builder() - .exactlyContainsInAnyOrder(expectedDocs - .stream() - .map(d -> d.getResourceId()) - .collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .allPagesSatisfy(new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void invalidQuerySytax() throws Exception { - String query = "I am an invalid query"; - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - Observable> queryObservable = client - .queryUserDefinedFunctions(getCollectionLink(), query, options); - - FailureValidator validator = new FailureValidator.Builder() - .instanceOf(DocumentClientException.class) - .statusCode(400) - .notNullActivityId() - .build(); - validateQueryFailure(queryObservable, validator); - } - - public UserDefinedFunction createUserDefinedFunction(AsyncDocumentClient client) { - UserDefinedFunction storedProcedure = getUserDefinedFunctionDef(); - return client.createUserDefinedFunction(getCollectionLink(), storedProcedure, null).toBlocking().single().getResource(); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - - for(int i = 0; i < 5; i++) { - createdUDF.add(createUserDefinedFunction(client)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static UserDefinedFunction getUserDefinedFunctionDef() { - UserDefinedFunction udf = new UserDefinedFunction(); - udf.setId(UUID.randomUUID().toString()); - udf.setBody("function() {var x = 10;}"); - return udf; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionUpsertReplaceTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionUpsertReplaceTest.java deleted file mode 100644 index 5d35cf792b2b..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserDefinedFunctionUpsertReplaceTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import java.util.UUID; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.UserDefinedFunction; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; - -import rx.Observable; - -import javax.net.ssl.SSLException; - - -public class UserDefinedFunctionUpsertReplaceTest extends TestSuiteBase { - - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public UserDefinedFunctionUpsertReplaceTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void upsertUserDefinedFunction() throws Exception { - - // create a udf - UserDefinedFunction udf = new UserDefinedFunction(); - udf.setId(UUID.randomUUID().toString()); - udf.setBody("function() {var x = 10;}"); - - UserDefinedFunction readBackUdf = null; - - try { - readBackUdf = client.upsertUserDefinedFunction(getCollectionLink(), udf, null).toBlocking().single().getResource(); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - - // read udf to validate creation - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readUserDefinedFunction(readBackUdf.getSelfLink(), null); - - // validate udf create - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackUdf.getId()) - .withUserDefinedFunctionBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update udf - readBackUdf.setBody("function() {var x = 11;}"); - - Observable> updateObservable = client.upsertUserDefinedFunction(getCollectionLink(), readBackUdf, null); - - // validate udf update - ResourceResponseValidator validatorForUpdate = new ResourceResponseValidator.Builder() - .withId(readBackUdf.getId()) - .withUserDefinedFunctionBody("function() {var x = 11;}") - .notNullEtag() - .build(); - validateSuccess(updateObservable, validatorForUpdate); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void replaceUserDefinedFunction() throws Exception { - - // create a udf - UserDefinedFunction udf = new UserDefinedFunction(); - udf.setId(UUID.randomUUID().toString()); - udf.setBody("function() {var x = 10;}"); - - UserDefinedFunction readBackUdf = null; - - try { - readBackUdf = client.createUserDefinedFunction(getCollectionLink(), udf, null).toBlocking().single().getResource(); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - - // read udf to validate creation - waitIfNeededForReplicasToCatchUp(clientBuilder); - Observable> readObservable = client.readUserDefinedFunction(readBackUdf.getSelfLink(), null); - - // validate udf creation - ResourceResponseValidator validatorForRead = new ResourceResponseValidator.Builder() - .withId(readBackUdf.getId()) - .withUserDefinedFunctionBody("function() {var x = 10;}") - .notNullEtag() - .build(); - validateSuccess(readObservable, validatorForRead); - - //update udf - readBackUdf.setBody("function() {var x = 11;}"); - - Observable> replaceObservable = client.replaceUserDefinedFunction(readBackUdf, null); - - //validate udf replace - ResourceResponseValidator validatorForReplace = new ResourceResponseValidator.Builder() - .withId(readBackUdf.getId()) - .withUserDefinedFunctionBody("function() {var x = 11;}") - .notNullEtag() - .build(); - validateSuccess(replaceObservable, validatorForReplace); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - truncateCollection(createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private String getCollectionLink() { - return createdCollection.getSelfLink(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserQueryTest.java deleted file mode 100644 index a1feb7046b18..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/UserQueryTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import org.apache.commons.lang3.StringUtils; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; - -import rx.Observable; - -public class UserQueryTest extends TestSuiteBase { - - public final String databaseId = DatabaseForTest.generateId(); - - private List createdUsers = new ArrayList<>(); - - private AsyncDocumentClient client; - - private String getDatabaseLink() { - return Utils.getDatabaseNameLink(databaseId); - } - - @Factory(dataProvider = "clientBuilders") - public UserQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryUsersWithFilter() throws Exception { - - String filterUserId = createdUsers.get(0).getId(); - String query = String.format("SELECT * from c where c.id = '%s'", filterUserId); - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(5); - Observable> queryObservable = client.queryUsers(getDatabaseLink(), query, options); - - List expectedUsers = createdUsers.stream() - .filter(c -> StringUtils.equals(filterUserId, c.getId()) ).collect(Collectors.toList()); - - assertThat(expectedUsers).isNotEmpty(); - - int expectedPageSize = (expectedUsers.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedUsers.size()) - .exactlyContainsInAnyOrder(expectedUsers.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryAllUsers() throws Exception { - - String query = "SELECT * from c"; - - FeedOptions options = new FeedOptions(); - options.setMaxItemCount(2); - String databaseLink = Utils.getDatabaseNameLink(databaseId); - Observable> queryObservable = client.queryUsers(databaseLink, query, options); - - List expectedUsers = createdUsers; - - assertThat(expectedUsers).isNotEmpty(); - - int expectedPageSize = (expectedUsers.size() + options.getMaxItemCount() - 1) / options.getMaxItemCount(); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .totalSize(expectedUsers.size()) - .exactlyContainsInAnyOrder(expectedUsers.stream().map(d -> d.getResourceId()).collect(Collectors.toList())) - .numberOfPages(expectedPageSize) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - - validateQuerySuccess(queryObservable, validator, 10000); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void queryUsers_NoResults() throws Exception { - - String query = "SELECT * from root r where r.id = '2'"; - FeedOptions options = new FeedOptions(); - Observable> queryObservable = client.queryUsers(getDatabaseLink(), query, options); - - FeedResponseListValidator validator = new FeedResponseListValidator.Builder() - .containsExactly(new ArrayList<>()) - .numberOfPages(1) - .pageSatisfy(0, new FeedResponseValidator.Builder() - .requestChargeGreaterThanOrEqualTo(1.0).build()) - .build(); - validateQuerySuccess(queryObservable, validator); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - - Database d1 = new Database(); - d1.setId(databaseId); - createDatabase(client, d1); - - for(int i = 0; i < 5; i++) { - User user = new User(); - user.setId(UUID.randomUUID().toString()); - createdUsers.add(createUser(client, databaseId, user)); - } - - waitIfNeededForReplicasToCatchUp(clientBuilder); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteDatabase(client, databaseId); - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/VeryLargeDocumentQueryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/VeryLargeDocumentQueryTest.java deleted file mode 100644 index b196a888e376..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/VeryLargeDocumentQueryTest.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import org.apache.commons.lang3.StringUtils; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import java.util.UUID; - -import static org.apache.commons.io.FileUtils.ONE_MB; - -public class VeryLargeDocumentQueryTest extends TestSuiteBase { - private final static int TIMEOUT = 60000; - private final static int SETUP_TIMEOUT = 60000; - private Database createdDatabase; - private DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "simpleClientBuildersWithDirect") - public VeryLargeDocumentQueryTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void queryLargeDocuments() { - int cnt = 5; - for(int i = 0; i < cnt; i++) { - createLargeDocument(); - } - - try { - validateQuerySuccess(client.queryDocuments(getCollectionLink(), "SELECT * FROM r", null), - new FeedResponseListValidator.Builder().totalSize(cnt).build()); - } catch (Throwable error) { - if (this.clientBuilder.configs.getProtocol() == Protocol.Tcp) { - String message = String.format("Direct TCP test failure ignored: desiredConsistencyLevel=%s", this.clientBuilder.desiredConsistencyLevel); - logger.info(message, error); - throw new SkipException(message, error); - } - throw error; - } - } - - private void createLargeDocument() { - Document docDefinition = getDocumentDefinition(); - - //Keep size as ~ 1.999MB to account for size of other props - int size = (int) (ONE_MB * 1.999); - docDefinition.set("largeString", StringUtils.repeat("x", size)); - - Observable> createObservable = client - .createDocument(getCollectionLink(), docDefinition, null, false); - - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()) - .build(); - - validateSuccess(createObservable, validator); - } - - @BeforeClass(groups = { "emulator" }, timeOut = 2 * SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = clientBuilder.build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY); - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "}" - , uuid, uuid)); - return doc; - } - - public String getCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdCollection.getId()); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConnectionPoolExhaustedRetryTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConnectionPoolExhaustedRetryTest.java deleted file mode 100644 index 395a8a19d805..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConnectionPoolExhaustedRetryTest.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.RetryOptions; -import io.reactivex.netty.client.PoolExhaustedException; -import org.mockito.Mockito; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import java.net.URL; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConnectionPoolExhaustedRetryTest { - private static final int TIMEOUT = 10000; - - @DataProvider(name = "exceptionProvider") - public Object[][] exceptionProvider() { - return new Object[][]{ - {Mockito.mock(PoolExhaustedException.class)}, - {new DocumentClientException(-1, Mockito.mock(PoolExhaustedException.class))}, - }; - } - - @Test(groups = {"unit"}, timeOut = TIMEOUT, dataProvider = "exceptionProvider") - public void retryOnConnectionPoolExhausted(Exception exception) throws Exception { - GlobalEndpointManager globalEndpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(new URL("http://localhost")).when(globalEndpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(globalEndpointManager, false, Mockito.mock(RetryOptions.class)); - - clientRetryPolicy.onBeforeSendRequest(Mockito.mock(RxDocumentServiceRequest.class)); - IRetryPolicy.ShouldRetryResult shouldRetryResult = clientRetryPolicy.shouldRetry(exception).toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(shouldRetryResult.backOffTime).isGreaterThanOrEqualTo(ConnectionPoolExhaustedRetry.RETRY_WAIT_TIME); - - Mockito.verify(globalEndpointManager, Mockito.times(1)).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - Mockito.verify(globalEndpointManager, Mockito.times(1)).CanUseMultipleWriteLocations(Mockito.any(RxDocumentServiceRequest.class)); - Mockito.verifyNoMoreInteractions(globalEndpointManager); - } - - @Test(groups = {"unit"}, timeOut = TIMEOUT, dataProvider = "exceptionProvider") - public void retryOnConnectionPoolExhausted_Exhausted(Exception exception) throws Exception { - GlobalEndpointManager globalEndpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(new URL("http://localhost")).when(globalEndpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - ClientRetryPolicy clientRetryPolicy = new ClientRetryPolicy(globalEndpointManager, false, Mockito.mock(RetryOptions.class)); - - clientRetryPolicy.onBeforeSendRequest(Mockito.mock(RxDocumentServiceRequest.class)); - for (int i = 0; i < ConnectionPoolExhaustedRetry.MAX_RETRY_COUNT; i++) { - IRetryPolicy.ShouldRetryResult shouldRetryResult = clientRetryPolicy.shouldRetry(exception).toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isTrue(); - assertThat(shouldRetryResult.backOffTime).isGreaterThanOrEqualTo(ConnectionPoolExhaustedRetry.RETRY_WAIT_TIME); - } - - IRetryPolicy.ShouldRetryResult shouldRetryResult = clientRetryPolicy.shouldRetry(exception).toBlocking().value(); - assertThat(shouldRetryResult.shouldRetry).isFalse(); - assertThat(shouldRetryResult.backOffTime).isNull(); - // no interaction with global endpoint manager - Mockito.verify(globalEndpointManager, Mockito.times(1)).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - Mockito.verify(globalEndpointManager, Mockito.times(1)).CanUseMultipleWriteLocations(Mockito.any(RxDocumentServiceRequest.class)); - Mockito.verifyNoMoreInteractions(globalEndpointManager); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTests1.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTests1.java deleted file mode 100644 index a7d110a9b8c3..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTests1.java +++ /dev/null @@ -1,306 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.PartitionKind; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.ResourceResponseValidator; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import org.testng.SkipException; -import org.testng.annotations.Test; -import rx.Observable; - -import java.util.ArrayList; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConsistencyTests1 extends ConsistencyTestsBase { - - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateStrongConsistencyOnSyncReplication() throws Exception { - if (!TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.Strong.toString())) { - throw new SkipException("Endpoint does not have strong consistency"); - } - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Strong).build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Strong).build(); - User userDefinition = getUserDefinition(); - userDefinition.setId(userDefinition.getId() + "validateStrongConsistencyOnSyncReplication"); - User user = safeCreateUser(this.initClient, createdDatabase.getId(), userDefinition); - validateStrongConsistency(user); - } - - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateConsistentLSNForDirectTCPClient() { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - validateConsistentLSN(); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateConsistentLSNForDirectHttpsClient() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - validateConsistentLSN(); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateConsistentLSNAndQuorumAckedLSNForDirectTCPClient() { - //TODO Need to test with TCP protocol - //https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - validateConsistentLSNAndQuorumAckedLSN(); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateStrongDynamicQuorum() { - if (!TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.Strong.toString())) { - throw new SkipException("Endpoint does not have strong consistency"); - } - - validateReadQuorum(ConsistencyLevel.Strong, ResourceType.Document, false); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateBoundedStalenessDynamicQuorumSyncReplication() { - if (!(TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.Strong.toString()) || TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.BoundedStaleness.toString()))) { - throw new SkipException("Endpoint does not have strong consistency"); - } - - validateReadQuorum(ConsistencyLevel.BoundedStaleness, ResourceType.Document, true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateConsistentLSNAndQuorumAckedLSNForDirectHttpsClient() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .build(); - validateConsistentLSNAndQuorumAckedLSN(); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateStrongConsistencyOnAsyncReplicationGW() throws InterruptedException { - validateStrongConsistencyOnAsyncReplication(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateStrongConsistencyOnAsyncReplicationDirect() throws InterruptedException { - validateStrongConsistencyOnAsyncReplication(false); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionContainerAfterCollectionCreateReplace() { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - //validateSessionContainerAfterCollectionCreateReplace(false, Protocol.Tcp); - validateSessionContainerAfterCollectionCreateReplace(false); - validateSessionContainerAfterCollectionCreateReplace(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateConsistentPrefixOnSyncReplication() throws InterruptedException { - if (!(TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.Strong.toString()) || TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.BoundedStaleness.toString()))) { - throw new SkipException("Endpoint does not have strong consistency"); - } - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.BoundedStaleness).build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.BoundedStaleness).build(); - User user = safeCreateUser(this.initClient, createdDatabase.getId(), getUserDefinition()); - boolean readLagging = validateConsistentPrefix(user); - assertThat(readLagging).isFalse(); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateConsistentPrefixOnAsyncReplication() throws InterruptedException { - if (!(TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.Strong.toString()) || TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.BoundedStaleness.toString()))) { - throw new SkipException("Endpoint does not have strong consistency"); - } - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.BoundedStaleness) - .build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.BoundedStaleness) - .build(); - Document documentDefinition = getDocumentDefinition(); - Document document = createDocument(this.initClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition); - boolean readLagging = validateConsistentPrefix(document); - //assertThat(readLagging).isTrue(); //Will fail if batch repl is turned off - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateConsistentPrefixWithReplicaRestartWithPause() { - //TODO this need to complete once we implement emulator container in java, and the we can do operation - // like pause, resume, stop, recycle on it needed for this test. - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355053 - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateConsistentPrefixWithReplicaRestart() { - //TODO this need to complete once we implement emulator container in java, and the we can do operation - // like pause, resume, stop, recycle on it needed for this test. - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355053 - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync() { - validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync(false); - validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateBarrierStrongConsistencyForMasterResources() { - //TODO this need to complete once we implement emulator container in java, and the we can do operation - // like pause, resume, stop, recycle on it needed for this test. - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355053 - } - - private void validateSubstatusCodeOnNotFoundExceptionInSessionReadAsync(boolean useGateway) { - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - AsyncDocumentClient client = new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - try { - DocumentCollection documentCollection = new DocumentCollection(); - documentCollection.setId(UUID.randomUUID().toString()); - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - partitionKeyDefinition.setKind(PartitionKind.Hash); - ArrayList paths = new ArrayList(); - paths.add("/id"); - partitionKeyDefinition.setPaths(paths); - documentCollection.setPartitionKey(partitionKeyDefinition); - - DocumentCollection collection = client.createCollection(createdDatabase.getSelfLink(), documentCollection, null).toBlocking().first().getResource(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey("1")); - - Document documentDefinition = new Document(); - documentDefinition.setId("1"); - Document document = client.createDocument(collection.getSelfLink(), documentDefinition, requestOptions, false).toBlocking().first().getResource(); - - Observable> deleteObservable = client.deleteDocument(document.getSelfLink(), requestOptions); - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .nullResource().build(); - validateSuccess(deleteObservable, validator); - Observable> readObservable = client.readDocument(document.getSelfLink(), requestOptions); - FailureValidator notFoundValidator = new FailureValidator.Builder().resourceNotFound().unknownSubStatusCode().build(); - validateFailure(readObservable, notFoundValidator); - - } finally { - safeClose(client); - } - } - - private static User getUserDefinition() { - User user = new User(); - user.setId(USER_NAME); - return user; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTests2.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTests2.java deleted file mode 100644 index 0d61a14ed528..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTests2.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.SessionTokenHelper; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternal; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import org.apache.commons.lang3.Range; -import org.testng.annotations.Test; -import rx.Completable; -import rx.Observable; -import rx.functions.Action1; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConsistencyTests2 extends ConsistencyTestsBase { - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateReadSessionOnAsyncReplication() throws InterruptedException { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - - Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, false).toBlocking().first().getResource(); - Thread.sleep(5000);//WaitForServerReplication - boolean readLagging = this.validateReadSession(document); - //assertThat(readLagging).isTrue(); //Will fail if batch repl is turned off - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateWriteSessionOnAsyncReplication() throws InterruptedException { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - - Document document = this.initClient.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, false).toBlocking().first().getResource(); - Thread.sleep(5000);//WaitForServerReplication - boolean readLagging = this.validateWriteSession(document); - //assertThat(readLagging).isTrue(); //Will fail if batch repl is turned off - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateEventualConsistencyOnAsyncReplicationDirect() { - //TODO this need to complete once we implement emulator container in java, and the we can do operation - // like pause, resume, stop, recycle on it needed for this test. - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355053 - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateEventualConsistencyOnAsyncReplicationGateway() { - //TODO this need to complete once we implement emulator container in java, and the we can do operation - // like pause, resume, stop, recycle on it needed for this test. - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355053 - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionContainerAfterCollectionDeletion() throws Exception { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - // Verify the collection deletion will trigger the session token clean up (even for different client) - //this.ValidateSessionContainerAfterCollectionDeletion(true, Protocol.Tcp); - this.validateSessionContainerAfterCollectionDeletion(true); - this.validateSessionContainerAfterCollectionDeletion(false); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT, enabled = false) - public void validateReadDistributionForSessionReads() { - // .NET uses lock method which is eventfully using LastReadAddress only for the test case to pass, we are not implementing this in java - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionTokenWithPreConditionFailure() throws Exception { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - //this.validateSessionTokenWithPreConditionFailure(false, Protocol.Tcp); - this.validateSessionTokenWithPreConditionFailure(false); - this.validateSessionTokenWithPreConditionFailure(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionTokenWithDocumentNotFound() throws Exception { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - //this.validateSessionTokenWithDocumentNotFoundException(false, Protocol.Tcp); - this.validateSessionTokenWithDocumentNotFoundException(false); - this.validateSessionTokenWithDocumentNotFoundException(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionTokenWithExpectedException() throws Exception { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - //this.validateSessionTokenWithExpectedException(false, Protocol.Tcp); - this.validateSessionTokenWithExpectedException(false); - this.validateSessionTokenWithExpectedException(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionTokenWithConflictException() { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - //this.validateSessionTokenWithConflictException(false, Protocol.Tcp); - this.validateSessionTokenWithConflictException(false); - this.validateSessionTokenWithConflictException(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionTokenMultiPartitionCollection() throws Exception { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - //this.validateSessionTokenMultiPartitionCollection(false, Protocol.Tcp); - this.validateSessionTokenMultiPartitionCollection(false); - this.validateSessionTokenMultiPartitionCollection(true); - } - - @Test(groups = {"direct"}, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateSessionTokenFromCollectionReplaceIsServerToken() { - //TODO Need to test with TCP protocol - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355057 - //this.validateSessionTokenFromCollectionReplaceIsServerToken(false, Protocol.Tcp); - this.validateSessionTokenFromCollectionReplaceIsServerToken(false); - this.validateSessionTokenFromCollectionReplaceIsServerToken(true); - } - - //TODO ReadFeed is broken, will enable the test case once it get fixed - //https://msdata.visualstudio.com/CosmosDB/_workitems/edit/358715 - @Test(groups = {"direct"}, enabled = false, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateNoChargeOnFailedSessionRead() throws Exception { - // Direct clients for read and write operations - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - // Client locked to replica for pause/resume - RxDocumentClientImpl readSecondaryClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - try { - // Create collection - DocumentCollection parentResource = writeClient.createCollection(createdDatabase.getSelfLink(), getCollectionDefinition(), null).toBlocking().first().getResource(); - - // Document to lock pause/resume clients - Document documentDefinition = getDocumentDefinition(); - documentDefinition.setId("test" + documentDefinition.getId()); - ResourceResponse childResource = writeClient.createDocument(parentResource.getSelfLink(), documentDefinition, null, true).toBlocking().first(); - logger.info("Created {} child resource", childResource.getResource().getResourceId()); - - String token = childResource.getSessionToken().split(":")[0] + ":" + this.createSessionToken(SessionTokenHelper.parse(childResource.getSessionToken()), 100000000).convertToString(); - - FeedOptions feedOptions = new FeedOptions(); - feedOptions.setPartitionKey(new PartitionKey(PartitionKeyInternal.Empty.toJson())); - feedOptions.setSessionToken(token); - FailureValidator validator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.NOTFOUND).subStatusCode(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE).build(); - Observable> feedObservable = readSecondaryClient.readDocuments(parentResource.getSelfLink(), feedOptions); - validateQueryFailure(feedObservable, validator); - } finally { - safeClose(writeClient); - safeClose(readSecondaryClient); - } - } - - @Test(groups = {"direct"}, enabled = false, timeOut = CONSISTENCY_TEST_TIMEOUT) - public void validateStrongReadOnOldDocument() { - //TODO this need to complete once we implement emulator container in java, and the we can do operation - // like pause, resume, stop, recycle on it needed for this test. - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355053 - } - - // TODO: DANOBLE: Investigate Direct TCP performance issue - // Note that we need multiple CONSISTENCY_TEST_TIMEOUT - // SEE: https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028https://msdata.visualstudio.com/CosmosDB/_workitems/edit/367028 - - @Test(groups = {"direct"}, timeOut = 2 * CONSISTENCY_TEST_TIMEOUT) - public void validateSessionTokenAsync() { - // Validate that document query never fails - // with NotFoundException - List documents = new ArrayList<>(); - for (int i = 0; i < 1000; i++) { - Document documentDefinition = getDocumentDefinition(); - documentDefinition.set(UUID.randomUUID().toString(), UUID.randomUUID().toString()); - documents.add(documentDefinition); - } - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - RxDocumentClientImpl client = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - try { - Document lastDocument = client.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, true) - .toBlocking() - .first() - .getResource(); - - Completable task1 = ParallelAsync.forEachAsync(Range.between(0, 1000), 5, new Action1() { - @Override - public void call(Integer index) { - client.createDocument(createdCollection.getSelfLink(), documents.get(index % documents.size()), null, true).toBlocking().first(); - } - }); - - Completable task2 = ParallelAsync.forEachAsync(Range.between(0, 1000), 5, new Action1() { - @Override - public void call(Integer index) { - try { - FeedOptions feedOptions = new FeedOptions(); - feedOptions.setEnableCrossPartitionQuery(true); - FeedResponse queryResponse = client.queryDocuments(createdCollection.getSelfLink(), "SELECT * FROM c WHERE c.Id = 'foo'", feedOptions).toBlocking().first(); - String lsnHeaderValue = queryResponse.getResponseHeaders().get(WFConstants.BackendHeaders.LSN); - long lsn = Long.valueOf(lsnHeaderValue); - String sessionTokenHeaderValue = queryResponse.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - ISessionToken sessionToken = SessionTokenHelper.parse(sessionTokenHeaderValue); - logger.info("Session Token = {}, LSN = {}", sessionToken.convertToString(), lsn); - assertThat(lsn).isEqualTo(sessionToken.getLSN()); - } catch (Exception ex) { - DocumentClientException clientException = (DocumentClientException) ex.getCause(); - if (clientException.getStatusCode() != 0) { - if (clientException.getStatusCode() == HttpConstants.StatusCodes.REQUEST_TIMEOUT) { - // ignore - } else if (clientException.getStatusCode() == HttpConstants.StatusCodes.NOTFOUND) { - String lsnHeaderValue = clientException.getResponseHeaders().get(WFConstants.BackendHeaders.LSN); - long lsn = Long.valueOf(lsnHeaderValue); - String sessionTokenHeaderValue = clientException.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - ISessionToken sessionToken = SessionTokenHelper.parse(sessionTokenHeaderValue); - - logger.info("Session Token = {}, LSN = {}", sessionToken.convertToString(), lsn); - assertThat(lsn).isEqualTo(sessionToken.getLSN()); - } else { - throw ex; - } - } else { - throw ex; - } - } - } - }); - Completable.mergeDelayError(task1, task2).await(); - } finally { - safeClose(client); - } - } - -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTestsBase.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTestsBase.java deleted file mode 100644 index c26246436094..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ConsistencyTestsBase.java +++ /dev/null @@ -1,861 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.AccessCondition; -import com.microsoft.azure.cosmosdb.AccessConditionType; -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.PartitionKind; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.ISessionToken; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.SessionContainer; -import com.microsoft.azure.cosmosdb.internal.SessionTokenHelper; -import com.microsoft.azure.cosmosdb.internal.VectorSessionToken; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.WFConstants; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalHelper; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.ResourceResponseValidator; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; -import org.apache.commons.collections4.map.UnmodifiableMap; -import org.apache.commons.lang3.StringUtils; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import rx.Observable; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.Date; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ConsistencyTestsBase extends TestSuiteBase { - static final int CONSISTENCY_TEST_TIMEOUT = 120000; - static final String USER_NAME = "TestUser"; - RxDocumentClientImpl writeClient; - RxDocumentClientImpl readClient; - AsyncDocumentClient initClient; - Database createdDatabase; - DocumentCollection createdCollection; - - @BeforeClass(groups = {"direct"}, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - initClient = createGatewayRxDocumentClient().build(); - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - } - - void validateStrongConsistency(Resource resourceToWorkWith) throws Exception { - int numberOfTestIteration = 5; - Resource writeResource = resourceToWorkWith; - while (numberOfTestIteration-- > 0) //Write from a client and do point read through second client and ensure TS matches. - { - Date sourceTimestamp = writeResource.getTimestamp(); - Thread.sleep(1000); //Timestamp is in granularity of seconds. - Resource updatedResource = null; - if (resourceToWorkWith instanceof User) { - updatedResource = this.writeClient.upsertUser(createdDatabase.getSelfLink(), (User) writeResource, null).toBlocking().first().getResource(); - } else if (resourceToWorkWith instanceof Document) { - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(resourceToWorkWith.get("mypk"))); - updatedResource = this.writeClient.upsertDocument(createdCollection.getSelfLink(), (Document) writeResource, options, false).toBlocking().first().getResource(); - } - assertThat(updatedResource.getTimestamp().after(sourceTimestamp)).isTrue(); - - User readResource = this.readClient.readUser(resourceToWorkWith.getSelfLink(), null).toBlocking().first().getResource(); - assertThat(updatedResource.getTimestamp().equals(readResource.getTimestamp())); - } - } - - void validateConsistentLSN() { - Document documentDefinition = getDocumentDefinition(); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(documentDefinition.get("mypk"))); - Document document = createDocument(this.writeClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition); - ResourceResponse response = this.writeClient.deleteDocument(document.getSelfLink(), options).toBlocking().single(); - assertThat(response.getStatusCode()).isEqualTo(204); - - long quorumAckedLSN = Long.parseLong((String) response.getResponseHeaders().get(WFConstants.BackendHeaders.QUORUM_ACKED_LSN)); - assertThat(quorumAckedLSN > 0).isTrue(); - FailureValidator validator = new FailureValidator.Builder().statusCode(404).lsnGreaterThan(quorumAckedLSN).build(); - Observable> readObservable = this.readClient.readDocument(document.getSelfLink(), options); - validateFailure(readObservable, validator); - } - - void validateConsistentLSNAndQuorumAckedLSN() { - Document documentDefinition = getDocumentDefinition(); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(documentDefinition.get("mypk"))); - Document document = createDocument(this.writeClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition); - ResourceResponse response = this.writeClient.deleteDocument(document.getSelfLink(), options).toBlocking().single(); - assertThat(response.getStatusCode()).isEqualTo(204); - - long quorumAckedLSN = Long.parseLong((String) response.getResponseHeaders().get(WFConstants.BackendHeaders.QUORUM_ACKED_LSN)); - assertThat(quorumAckedLSN > 0).isTrue(); - - FailureValidator validator = new FailureValidator.Builder().statusCode(404).lsnGreaterThanEqualsTo(quorumAckedLSN).exceptionQuorumAckedLSNInNotNull().build(); - Observable> readObservable = this.readClient.deleteDocument(document.getSelfLink(), options); - validateFailure(readObservable, validator); - - } - - void validateReadQuorum(ConsistencyLevel consistencyLevel, ResourceType childResourceType, boolean isBoundedStaleness) { - //TODO this need to complete once we implement emulator container in java, and then we can do operation - // like pause, resume, stop, recycle on it needed for this test. - // https://msdata.visualstudio.com/CosmosDB/_workitems/edit/355053 - } - - void validateStrongConsistencyOnAsyncReplication(boolean useGateway) throws InterruptedException { - if (!TestConfigurations.CONSISTENCY.equalsIgnoreCase(ConsistencyLevel.Strong.toString())) { - throw new SkipException("Endpoint does not have strong consistency"); - } - - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } - - this.writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Strong).build(); - - this.readClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Strong).build(); - - Document documentDefinition = getDocumentDefinition(); - Document document = createDocument(this.writeClient, createdDatabase.getId(), createdCollection.getId(), documentDefinition); - validateStrongConsistency(document); - } - - void validateStrongConsistency(Document documentToWorkWith) throws InterruptedException { - int numberOfTestIteration = 5; - Document writeDocument = documentToWorkWith; - while (numberOfTestIteration-- > 0) { - Date sourceTimestamp = writeDocument.getTimestamp(); - Thread.sleep(1000);//Timestamp is in granularity of seconds. - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(documentToWorkWith.get("mypk"))); - Document updatedDocument = this.writeClient.replaceDocument(writeDocument, options).toBlocking().first().getResource(); - assertThat(updatedDocument.getTimestamp().after(sourceTimestamp)).isTrue(); - - Document readDocument = this.readClient.readDocument(documentToWorkWith.getSelfLink(), options).toBlocking().first().getResource(); - assertThat(updatedDocument.getTimestamp().equals(readDocument.getTimestamp())); - } - } - - void validateSessionContainerAfterCollectionCreateReplace(boolean useGateway) { - // Direct clients for read and write operations - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - - RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session).build(); - - try { - PartitionKeyDefinition partitionKey = new PartitionKeyDefinition(); - partitionKey.setPaths(Arrays.asList("/customerid")); - partitionKey.setKind(PartitionKind.Hash); - DocumentCollection coll = null; - { - // self link - ResourceResponse collection = writeClient.createCollection(createdDatabase.getSelfLink(), getCollectionDefinition(), null).toBlocking().first(); - String globalSessionToken1 = ((SessionContainer) writeClient.getSession()).getSessionToken(collection.getResource().getSelfLink()); - String globalSessionToken2 = ((SessionContainer) writeClient.getSession()).getSessionToken(BridgeInternal.getAltLink(collection.getResource())); - System.out.println("BridgeInternal.getAltLink(collection.getResource()) " + BridgeInternal.getAltLink(collection.getResource())); - assertThat(collection.getSessionToken()).isEqualTo(globalSessionToken1); - assertThat(collection.getSessionToken()).isEqualTo(globalSessionToken2); - - coll = collection.getResource(); - ResourceResponse collectionRead = writeClient.readCollection(coll.getSelfLink(), null).toBlocking().first(); - // timesync might bump the version, comment out the check - //assertThat(collection.getSessionToken()).isEqualTo(collectionRead.getSessionToken()); - } - { - // name link - ResourceResponse collection = writeClient.createCollection(BridgeInternal.getAltLink(createdDatabase), getCollectionDefinition(), null).toBlocking().first(); - - String globalSessionToken1 = ((SessionContainer) writeClient.getSession()).getSessionToken(collection.getResource().getSelfLink()); - String globalSessionToken2 = ((SessionContainer) writeClient.getSession()).getSessionToken(BridgeInternal.getAltLink(collection.getResource())); - assertThat(collection.getSessionToken()).isEqualTo(globalSessionToken1); - //assertThat(collection.getSessionToken()).isEqualTo(globalSessionToken2); - - ResourceResponse collectionRead = - writeClient.readCollection(BridgeInternal.getAltLink(collection.getResource()), null).toBlocking().first(); - // timesync might bump the version, comment out the check - //assertThat(collection.getSessionToken()).isEqualTo(collectionRead.getSessionToken()); - } - { - Document document2 = new Document(); - document2.setId("test" + UUID.randomUUID().toString()); - document2.set("customerid", 2); - // name link - ResourceResponse document = writeClient.createDocument(BridgeInternal.getAltLink(coll), document2, null, false).toBlocking().first(); - String globalSessionToken1 = ((SessionContainer) writeClient.getSession()).getSessionToken(coll.getSelfLink()); - String globalSessionToken2 = ((SessionContainer) writeClient.getSession()).getSessionToken(BridgeInternal.getAltLink(coll)); - - assertThat(globalSessionToken1.indexOf(document.getSessionToken())).isNotNegative(); - assertThat(globalSessionToken2.indexOf(document.getSessionToken())).isNotNegative(); - } - { - Document document2 = new Document(); - document2.setId("test" + UUID.randomUUID().toString()); - document2.set("customerid", 3); - // name link - ResourceResponse document = writeClient.createDocument(BridgeInternal.getAltLink(coll), document2, null, false).toBlocking().first(); - String globalSessionToken1 = ((SessionContainer) writeClient.getSession()).getSessionToken(coll.getSelfLink()); - String globalSessionToken2 = ((SessionContainer) writeClient.getSession()).getSessionToken(BridgeInternal.getAltLink(coll)); - - assertThat(globalSessionToken1.indexOf(document.getSessionToken())).isNotNegative(); - assertThat(globalSessionToken2.indexOf(document.getSessionToken())).isNotNegative(); - } - } finally { - safeClose(writeClient); - } - } - - boolean validateConsistentPrefix(Resource resourceToWorkWith) throws InterruptedException { - int numberOfTestIteration = 5; - Date lastReadDateTime = resourceToWorkWith.getTimestamp(); - boolean readLagging = false; - Resource writeResource = resourceToWorkWith; - - while (numberOfTestIteration-- > 0) { //Write from a client and do point read through second client and ensure TS monotonically increases. - Date sourceTimestamp = writeResource.getTimestamp(); - Thread.sleep(1000); //Timestamp is in granularity of seconds. - Resource updatedResource = null; - if (resourceToWorkWith instanceof User) { - updatedResource = this.writeClient.upsertUser(createdDatabase.getSelfLink(), (User) writeResource, null).toBlocking().first().getResource(); - } else if (resourceToWorkWith instanceof Document) { - updatedResource = this.writeClient.upsertDocument(createdCollection.getSelfLink(), (Document) writeResource, null, false).toBlocking().first().getResource(); - } - assertThat(updatedResource.getTimestamp().after(sourceTimestamp)).isTrue(); - writeResource = updatedResource; - - Resource readResource = null; - if (resourceToWorkWith instanceof User) { - readResource = this.readClient.readUser(resourceToWorkWith.getSelfLink(), null).toBlocking().first().getResource(); - } else if (resourceToWorkWith instanceof Document) { - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(resourceToWorkWith.get("mypk"))); - readResource = this.readClient.readDocument(resourceToWorkWith.getSelfLink(), options).toBlocking().first().getResource(); - } - assertThat(readResource.getTimestamp().compareTo(lastReadDateTime) >= 0).isTrue(); - lastReadDateTime = readResource.getTimestamp(); - if (readResource.getTimestamp().before(updatedResource.getTimestamp())) { - readLagging = true; - } - } - return readLagging; - } - - boolean validateReadSession(Resource resourceToWorkWith) throws InterruptedException { - int numberOfTestIteration = 5; - Date lastReadDateTime = new java.sql.Date(0); - boolean readLagging = false; - Resource writeResource = resourceToWorkWith; - - while (numberOfTestIteration-- > 0) { - Date sourceTimestamp = writeResource.getTimestamp(); - Thread.sleep(1000); - Resource updatedResource = null; - if (resourceToWorkWith instanceof Document) { - updatedResource = this.writeClient.upsertDocument(createdCollection.getSelfLink(), writeResource, null, false).toBlocking().single().getResource(); - } - assertThat(updatedResource.getTimestamp().after(sourceTimestamp)).isTrue(); - writeResource = updatedResource; - - Resource readResource = null; - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(resourceToWorkWith.get("mypk"))); - if (resourceToWorkWith instanceof Document) { - readResource = this.readClient.readDocument(resourceToWorkWith.getSelfLink(), requestOptions).toBlocking().first().getResource(); - } - assertThat(readResource.getTimestamp().compareTo(lastReadDateTime) >= 0).isTrue(); - lastReadDateTime = readResource.getTimestamp(); - - if (readResource.getTimestamp().before(updatedResource.getTimestamp())) { - readLagging = true; - } - } - return readLagging; - } - - boolean validateWriteSession(Resource resourceToWorkWith) throws InterruptedException { - int numberOfTestIteration = 5; - Date lastReadDateTime = new java.sql.Date(0); - boolean readLagging = false; - Resource writeResource = resourceToWorkWith; - - while (numberOfTestIteration-- > 0) { - Date sourceTimestamp = writeResource.getTimestamp(); - Thread.sleep(1000); - Resource updatedResource = null; - if (resourceToWorkWith instanceof Document) { - updatedResource = this.writeClient.upsertDocument(createdCollection.getSelfLink(), writeResource, null, false).toBlocking().single().getResource(); - } - assertThat(updatedResource.getTimestamp().after(sourceTimestamp)).isTrue(); - writeResource = updatedResource; - - Resource readResource = null; - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(resourceToWorkWith.get("mypk"))); - if (resourceToWorkWith instanceof Document) { - readResource = this.readClient.readDocument(resourceToWorkWith.getSelfLink(), requestOptions).toBlocking().first().getResource(); - } - assertThat(readResource.getTimestamp().compareTo(lastReadDateTime) >= 0).isTrue(); - lastReadDateTime = readResource.getTimestamp(); - - if (readResource.getTimestamp().before(updatedResource.getTimestamp())) { - readLagging = true; - } - - //Now perform write on session and update our session token and lastReadTS - Thread.sleep(1000); - if (resourceToWorkWith instanceof Document) { - readResource = this.writeClient.upsertDocument(createdCollection.getSelfLink(), readResource, requestOptions, false).toBlocking().first().getResource(); //Now perform write on session - } - assertThat(readResource.getTimestamp().after(lastReadDateTime)); - - this.readClient.setSession(this.writeClient.getSession()); - } - return readLagging; - } - - void validateSessionContainerAfterCollectionDeletion(boolean useGateway) throws Exception { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - RxDocumentClientImpl client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - - String collectionId = UUID.randomUUID().toString(); - try { - DocumentCollection collectionDefinition = getCollectionDefinition(); - collectionDefinition.setId(collectionId); - DocumentCollection collection = createCollection(client2, createdDatabase.getId(), collectionDefinition, null); - ResourceResponseValidator successValidatorCollection = new ResourceResponseValidator.Builder() - .withId(collection.getId()) - .build(); - Observable> readObservableCollection = client2.readCollection(collection.getSelfLink(), null); - validateSuccess(readObservableCollection, successValidatorCollection); - - for (int i = 0; i < 5; i++) { - String documentId = "Generation1-" + i; - Document documentDefinition = getDocumentDefinition(); - documentDefinition.setId(documentId); - Document documentCreated = client2.createDocument(collection.getSelfLink(), documentDefinition, null, true).toBlocking().first().getResource(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(documentCreated.get("mypk"))); - client2.readDocument(BridgeInternal.getAltLink(documentCreated), requestOptions).toBlocking().first(); - client2.readDocument(documentCreated.getSelfLink(), requestOptions).toBlocking().first(); - } - - { - // just create the second for fun - DocumentCollection collection2 = createCollection(client2, createdDatabase.getId(), getCollectionDefinition(), null); - successValidatorCollection = new ResourceResponseValidator.Builder() - .withId(collection2.getId()) - .build(); - readObservableCollection = client2.readCollection(collection2.getSelfLink(), null); - validateSuccess(readObservableCollection, successValidatorCollection); - } - // verify the client2 has the same token. - { - String token1 = ((SessionContainer) client2.getSession()).getSessionToken(BridgeInternal.getAltLink(collection)); - String token2 = ((SessionContainer) client2.getSession()).getSessionToken(collection.getSelfLink()); - assertThat(token1).isEqualTo(token2); - } - - // now delete collection use different client - client1.deleteCollection(collection.getSelfLink(), null).toBlocking().first(); - - DocumentCollection collectionRandom1 = createCollection(client2, createdDatabase.getId(), getCollectionDefinition()); - DocumentCollection documentCollection = getCollectionDefinition(); - collectionDefinition.setId(collectionId); - DocumentCollection collectionSameName = createCollection(client2, createdDatabase.getId(), collectionDefinition); - String documentId1 = "Generation2-" + 0; - Document databaseDefinition2 = getDocumentDefinition(); - databaseDefinition2.setId(documentId1); - Document createdDocument = client1.createDocument(collectionSameName.getSelfLink(), databaseDefinition2, null, true).toBlocking().first().getResource(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(createdDocument.get("mypk"))); - ResourceResponseValidator successValidator = new ResourceResponseValidator.Builder() - .withId(createdDocument.getId()) - .build(); - Observable> readObservable = client1.readDocument(createdDocument.getSelfLink(), requestOptions); - validateSuccess(readObservable, successValidator); - { - String token1 = ((SessionContainer) client1.getSession()).getSessionToken(BridgeInternal.getAltLink(collectionSameName)); - String token2 = ((SessionContainer) client1.getSession()).getSessionToken(collectionSameName.getSelfLink()); - assertThat(token1).isEqualTo(token2); - } - - { - // Client2 read using name link should fail with higher LSN. - String token = ((SessionContainer) client1.getSession()).getSessionToken(collectionSameName.getSelfLink()); - // artificially bump to higher LSN - String higherLsnToken = this.getDifferentLSNToken(token, 2000); - RequestOptions requestOptions1 = new RequestOptions(); - requestOptions1.setSessionToken(higherLsnToken); - requestOptions1.setPartitionKey(new PartitionKey(createdDocument.get("mypk"))); - readObservable = client2.readDocument(BridgeInternal.getAltLink(createdDocument), requestOptions1); - FailureValidator failureValidator = new FailureValidator.Builder().subStatusCode(1002).build(); - validateFailure(readObservable, failureValidator); - } - // this will trigger client2 to clear the token - { - // verify token by altlink is gone! - String token1 = ((SessionContainer) client2.getSession()).getSessionToken(BridgeInternal.getAltLink(collectionSameName)); - String token2 = ((SessionContainer) client2.getSession()).getSessionToken(collection.getSelfLink()); - assertThat(token1).isEmpty(); - //assertThat(token2).isNotEmpty(); In java both SelfLink and AltLink token remain in sync. - } - { - // second read should succeed! - readObservable = client2.readDocument(BridgeInternal.getAltLink(createdDocument), requestOptions); - validateSuccess(readObservable, successValidator); - } - // verify deleting indeed delete the collection session token - { - Document documentTest = - client1.createDocument(BridgeInternal.getAltLink(collectionSameName), getDocumentDefinition(), null, true).toBlocking().first().getResource(); - RequestOptions options = new RequestOptions(); - options.setPartitionKey(new PartitionKey(documentTest.get("mypk"))); - successValidator = new ResourceResponseValidator.Builder() - .withId(documentTest.getId()) - .build(); - readObservable = client1.readDocument(documentTest.getSelfLink(), options); - validateSuccess(readObservable, successValidator); - - client1.deleteCollection(collectionSameName.getSelfLink(), null).toBlocking().first(); - String token1 = ((SessionContainer) client2.getSession()).getSessionToken(BridgeInternal.getAltLink(collectionSameName)); - String token2 = ((SessionContainer) client2.getSession()).getSessionToken(collectionSameName.getSelfLink()); - // currently we can't delete the token from Altlink when deleting using selflink - assertThat(token1).isNotEmpty(); - //assertThat(token2).isEmpty(); In java both SelfLink and AltLink token remain in sync. - } - } finally { - safeClose(client1); - safeClose(client2); - } - - } - - void validateSessionTokenWithPreConditionFailure(boolean useGateway) throws Exception { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - try { - // write a document, and upsert to it to update etag. - ResourceResponse documentResponse = writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, true).toBlocking().first(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(documentResponse.getResource().get("mypk"))); - ResourceResponse upsertResponse = - writeClient.upsertDocument(BridgeInternal.getAltLink(createdCollection), documentResponse.getResource(), requestOptions, true).toBlocking().first(); - - // create a conditioned read request, with first write request's etag, so the read fails with PreconditionFailure - AccessCondition ac = new AccessCondition(); - ac.setCondition(documentResponse.getResource().getETag()); - ac.setType(AccessConditionType.IfMatch); - RequestOptions requestOptions1 = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(documentResponse.getResource().get("mypk"))); - requestOptions1.setAccessCondition(ac); - Observable> preConditionFailureResponseObservable = validationClient.upsertDocument(BridgeInternal.getAltLink(createdCollection), - documentResponse.getResource(), requestOptions1, true); - FailureValidator failureValidator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.PRECONDITION_FAILED).build(); - validateFailure(preConditionFailureResponseObservable, failureValidator); - assertThat(isSessionEqual(((SessionContainer) validationClient.getSession()), (SessionContainer) writeClient.getSession())).isTrue(); - - } finally { - safeClose(writeClient); - safeClose(validationClient); - } - } - - void validateSessionTokenWithDocumentNotFoundException(boolean useGateway) throws Exception { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - try { - DocumentCollection collectionDefinition = getCollectionDefinition(); - collectionDefinition.setId("TestCollection"); - - ResourceResponse documentResponse = writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, true).toBlocking().first(); - - FailureValidator failureValidator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.NOTFOUND).build(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(documentResponse.getResource().get("mypk"))); - // try to read a non existent document in the same partition that we previously wrote to - Observable> readObservable = validationClient.readDocument(BridgeInternal.getAltLink(documentResponse.getResource()) + "dummy", requestOptions); - validateFailure(readObservable, failureValidator); - assertThat(isSessionEqual(((SessionContainer) validationClient.getSession()), (SessionContainer) writeClient.getSession())).isTrue(); - } finally { - safeClose(writeClient); - safeClose(validationClient); - } - } - - void validateSessionTokenWithExpectedException(boolean useGateway) throws Exception { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - try { - ResourceResponse documentResponse = - writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), getDocumentDefinition(), null, false).toBlocking().first(); - String token = documentResponse.getResponseHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN); - - // artificially bump to higher LSN - String higherLsnToken = this.getDifferentLSNToken(token, 2000); - FailureValidator failureValidator = new FailureValidator.Builder().subStatusCode(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE).build(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(documentResponse.getResource().get("mypk"))); - requestOptions.setSessionToken(higherLsnToken); - // try to read a non existent document in the same partition that we previously wrote to - Observable> readObservable = writeClient.readDocument(BridgeInternal.getAltLink(documentResponse.getResource()), - requestOptions); - validateFailure(readObservable, failureValidator); - - } finally { - safeClose(writeClient); - } - } - - void validateSessionTokenWithConflictException(boolean useGateway) { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - RxDocumentClientImpl validationClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - try { - Document documentDefinition = getDocumentDefinition(); - ResourceResponse documentResponse = - writeClient.createDocument(BridgeInternal.getAltLink(createdCollection), documentDefinition, null, true).toBlocking().first(); - - FailureValidator failureValidator = new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.CONFLICT).build(); - Observable> conflictDocumentResponse = validationClient.createDocument(BridgeInternal.getAltLink(createdCollection), - documentDefinition, null, - true); - validateFailure(conflictDocumentResponse, failureValidator); - } finally { - safeClose(writeClient); - safeClose(validationClient); - } - } - - void validateSessionTokenMultiPartitionCollection(boolean useGateway) throws Exception { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - RxDocumentClientImpl writeClient = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - try { - - Range fullRange = new Range(PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey, - PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey, true, false); - - IRoutingMapProvider routingMapProvider = writeClient.getPartitionKeyRangeCache(); - // assertThat(routingMapProvider.tryGetOverlappingRangesAsync(collection.getResourceId(), fullRange, false).toBlocking().value().size()).isEqualTo(5); - - // Document to lock pause/resume clients - Document document1 = new Document(); - document1.setId("test" + UUID.randomUUID().toString()); - document1.set("mypk", 1); - ResourceResponse childResource1 = writeClient.createDocument(createdCollection.getSelfLink(), document1, null, true).toBlocking().first(); - logger.info("Created {} child resource", childResource1.getResource().getResourceId()); - assertThat(childResource1.getSessionToken()).isNotNull(); - assertThat(childResource1.getSessionToken().contains(":")).isTrue(); - String globalSessionToken1 = ((SessionContainer) writeClient.getSession()).getSessionToken(createdCollection.getSelfLink()); - assertThat(globalSessionToken1.contains(childResource1.getSessionToken())); - - // Document to lock pause/resume clients - Document document2 = new Document(); - document2.setId("test" + UUID.randomUUID().toString()); - document2.set("mypk", 2); - ResourceResponse childResource2 = writeClient.createDocument(createdCollection.getSelfLink(), document2, null, true).toBlocking().first(); - assertThat(childResource2.getSessionToken()).isNotNull(); - assertThat(childResource2.getSessionToken().contains(":")).isTrue(); - String globalSessionToken2 = ((SessionContainer) writeClient.getSession()).getSessionToken(createdCollection.getSelfLink()); - logger.info("globalsessiontoken2 {}, childtoken1 {}, childtoken2 {}", globalSessionToken2, childResource1.getSessionToken(), childResource2.getSessionToken()); - assertThat(globalSessionToken2.contains(childResource2.getSessionToken())).isTrue(); - - // this token can read childresource2 but not childresource1 - String sessionToken = - StringUtils.split(childResource1.getSessionToken(), ':')[0] + ":" + createSessionToken(SessionTokenHelper.parse(childResource1.getSessionToken()), 100000000).convertToString() + "," + childResource2.getSessionToken(); - - RequestOptions option = new RequestOptions(); - option.setSessionToken(sessionToken); - option.setPartitionKey(new PartitionKey(2)); - writeClient.readDocument(childResource2.getResource().getSelfLink(), option).toBlocking().first(); - - option = new RequestOptions(); - option.setSessionToken(StringUtils.EMPTY); - option.setPartitionKey(new PartitionKey(1)); - writeClient.readDocument(childResource1.getResource().getSelfLink(), option).toBlocking().first(); - - option = new RequestOptions(); - option.setSessionToken(sessionToken); - option.setPartitionKey(new PartitionKey(1)); - Observable> readObservable = writeClient.readDocument(childResource1.getResource().getSelfLink(), option); - FailureValidator failureValidator = - new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.NOTFOUND).subStatusCode(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE).build(); - validateFailure(readObservable, failureValidator); - - readObservable = writeClient.readDocument(childResource2.getResource().getSelfLink(), option); - failureValidator = - new FailureValidator.Builder().statusCode(HttpConstants.StatusCodes.NOTFOUND).subStatusCode(HttpConstants.SubStatusCodes.READ_SESSION_NOT_AVAILABLE).build(); - validateFailure(readObservable, failureValidator); - - assertThat(((SessionContainer) writeClient.getSession()).getSessionToken(createdCollection.getSelfLink())).isEqualTo - (((SessionContainer) writeClient.getSession()).getSessionToken(BridgeInternal.getAltLink(createdCollection))); - - assertThat(((SessionContainer) writeClient.getSession()).getSessionToken("asdfasdf")).isEmpty(); - assertThat(((SessionContainer) writeClient.getSession()).getSessionToken(createdDatabase.getSelfLink())).isEmpty(); - } finally { - safeClose(writeClient); - } - } - - void validateSessionTokenFromCollectionReplaceIsServerToken(boolean useGateway) { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - if (useGateway) { - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - } else { - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - } - RxDocumentClientImpl client1 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - RxDocumentClientImpl client2 = null; - try { - Document doc = client1.createDocument(createdCollection.getSelfLink(), getDocumentDefinition(), null, true).toBlocking().first().getResource(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setPartitionKey(new PartitionKey(doc.get("mypk"))); - Document doc1 = client1.readDocument(BridgeInternal.getAltLink(doc), requestOptions).toBlocking().first().getResource(); - - String token1 = ((SessionContainer) client1.getSession()).getSessionToken(createdCollection.getSelfLink()); - client2 = (RxDocumentClientImpl) new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session) - .build(); - client2.replaceCollection(createdCollection, null).toBlocking().first(); - String token2 = ((SessionContainer) client2.getSession()).getSessionToken(createdCollection.getSelfLink()); - - logger.info("Token after document and after collection replace {} = {}", token1, token2); - } finally { - safeClose(client1); - safeClose(client2); - } - } - - @AfterClass(groups = {"direct"}, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(this.initClient); - safeClose(this.writeClient); - safeClose(this.readClient); - } - - private String getDifferentLSNToken(String token, long lsnDifferent) throws Exception { - String[] tokenParts = StringUtils.split(token, ':'); - ISessionToken sessionToken = SessionTokenHelper.parse(tokenParts[1]); - ISessionToken differentSessionToken = createSessionToken(sessionToken, sessionToken.getLSN() + lsnDifferent); - return String.format("%s:%s", tokenParts[0], differentSessionToken.convertToString()); - } - - public static ISessionToken createSessionToken(ISessionToken from, long globalLSN) throws Exception { - // Creates session token with specified GlobalLSN - if (from instanceof VectorSessionToken) { - VectorSessionToken fromSessionToken = (VectorSessionToken) from; - Field fieldVersion = VectorSessionToken.class.getDeclaredField("version"); - fieldVersion.setAccessible(true); - Long version = (Long) fieldVersion.get(fromSessionToken); - - Field fieldLocalLsnByRegion = VectorSessionToken.class.getDeclaredField("localLsnByRegion"); - fieldLocalLsnByRegion.setAccessible(true); - UnmodifiableMap localLsnByRegion = (UnmodifiableMap) fieldLocalLsnByRegion.get(fromSessionToken); - - Constructor constructor = VectorSessionToken.class.getDeclaredConstructor(long.class, long.class, UnmodifiableMap.class); - constructor.setAccessible(true); - VectorSessionToken vectorSessionToken = constructor.newInstance(version, globalLSN, localLsnByRegion); - return vectorSessionToken; - } else { - throw new IllegalArgumentException(); - } - } - - Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - private boolean isSessionEqual(SessionContainer sessionContainer1, SessionContainer sessionContainer2) throws Exception { - if (sessionContainer1 == null) { - return false; - } - - if (sessionContainer2 == null) { - return false; - } - - if (sessionContainer1 == sessionContainer2) { - return true; - } - - Field fieldCollectionResourceIdToSessionTokens1 = SessionContainer.class.getDeclaredField("collectionResourceIdToSessionTokens"); - Field fieldCollectionNameToCollectionResourceId1 = SessionContainer.class.getDeclaredField("collectionNameToCollectionResourceId"); - fieldCollectionResourceIdToSessionTokens1.setAccessible(true); - fieldCollectionNameToCollectionResourceId1.setAccessible(true); - ConcurrentHashMap> collectionResourceIdToSessionTokens1 = - (ConcurrentHashMap>) fieldCollectionResourceIdToSessionTokens1.get(sessionContainer1); - ConcurrentHashMap collectionNameToCollectionResourceId1 = (ConcurrentHashMap) fieldCollectionNameToCollectionResourceId1.get(sessionContainer1); - - - Field fieldCollectionResourceIdToSessionTokens2 = SessionContainer.class.getDeclaredField("collectionResourceIdToSessionTokens"); - Field fieldCollectionNameToCollectionResourceId2 = SessionContainer.class.getDeclaredField("collectionNameToCollectionResourceId"); - fieldCollectionResourceIdToSessionTokens2.setAccessible(true); - fieldCollectionNameToCollectionResourceId2.setAccessible(true); - ConcurrentHashMap> collectionResourceIdToSessionTokens2 = - (ConcurrentHashMap>) fieldCollectionResourceIdToSessionTokens2.get(sessionContainer2); - ConcurrentHashMap collectionNameToCollectionResourceId2 = (ConcurrentHashMap) fieldCollectionNameToCollectionResourceId2.get(sessionContainer2); - - if (collectionResourceIdToSessionTokens1.size() != collectionResourceIdToSessionTokens2.size() || - collectionNameToCollectionResourceId1.size() != collectionNameToCollectionResourceId2.size()) { - return false; - } - - // get keys, and compare entries - for (Long resourceId : collectionResourceIdToSessionTokens1.keySet()) { - if (!collectionResourceIdToSessionTokens1.get(resourceId).equals(collectionResourceIdToSessionTokens2.get(resourceId))) { - return false; - } - } - - for (String collectionName : collectionNameToCollectionResourceId1.keySet()) { - if (!collectionNameToCollectionResourceId1.get(collectionName).equals(collectionNameToCollectionResourceId2.get(collectionName))) { - return false; - } - } - - return true; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/DocumentQuerySpyWireContentTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/DocumentQuerySpyWireContentTest.java deleted file mode 100644 index 79e792a5c0cf..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/DocumentQuerySpyWireContentTest.java +++ /dev/null @@ -1,222 +0,0 @@ -/** - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.SpyClientBuilder; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; -import com.microsoft.azure.cosmosdb.rx.Utils; - -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import rx.Observable; - -public class DocumentQuerySpyWireContentTest extends TestSuiteBase { - private Database createdDatabase; - private DocumentCollection createdSinglePartitionCollection; - private DocumentCollection createdMultiPartitionCollection; - - private List createdDocumentsInSinglePartitionCollection = new ArrayList<>(); - private List createdDocumentsInMultiPartitionCollection = new ArrayList<>(); - - private SpyClientUnderTestFactory.ClientUnderTest client; - - public String getSinglePartitionCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdSinglePartitionCollection.getId()); - } - - public String getMultiPartitionCollectionLink() { - return Utils.getCollectionNameLink(createdDatabase.getId(), createdMultiPartitionCollection.getId()); - } - - @Factory(dataProvider = "clientBuilders") - public DocumentQuerySpyWireContentTest(Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @DataProvider(name = "responseContinuationTokenLimitParamProvider") - public static Object[][] responseContinuationTokenLimitParamProvider() { - - FeedOptions options1 = new FeedOptions(); - options1.setMaxItemCount(1); - options1.setResponseContinuationTokenLimitInKb(5); - options1.setPartitionKey(new PartitionKey("99")); - String query1 = "Select * from r"; - boolean multiPartitionCollection1 = true; - - FeedOptions options2 = new FeedOptions(); - options2.setMaxItemCount(1); - options2.setResponseContinuationTokenLimitInKb(5); - options2.setPartitionKey(new PartitionKey("99")); - String query2 = "Select * from r order by r.prop"; - boolean multiPartitionCollection2 = false; - - FeedOptions options3 = new FeedOptions(); - options3.setMaxItemCount(1); - options3.setResponseContinuationTokenLimitInKb(5); - options3.setPartitionKey(new PartitionKey("99")); - String query3 = "Select * from r"; - boolean multiPartitionCollection3 = false; - - FeedOptions options4 = new FeedOptions(); - options4.setPartitionKey(new PartitionKey("99")); - String query4 = "Select * from r order by r.prop"; - boolean multiPartitionCollection4 = false; - - return new Object[][]{ - {options1, query1, multiPartitionCollection1}, - {options2, query2, multiPartitionCollection2}, - {options3, query3, multiPartitionCollection3}, - {options4, query4, multiPartitionCollection4}, - }; - } - - @Test(dataProvider = "responseContinuationTokenLimitParamProvider", groups = { "simple" }, timeOut = TIMEOUT) - public void queryWithContinuationTokenLimit(FeedOptions options, String query, boolean isMultiParitionCollection) throws Exception { - String collectionLink; - if (isMultiParitionCollection) { - collectionLink = getMultiPartitionCollectionLink(); - } else { - collectionLink = getSinglePartitionCollectionLink(); - } - - client.clearCapturedRequests(); - - Observable> queryObservable = client - .queryDocuments(collectionLink, query, options); - - List results = queryObservable.flatMap(p -> Observable.from(p.getResults())) - .toList().toBlocking().single(); - - assertThat(results.size()).describedAs("total results").isGreaterThanOrEqualTo(1); - - List> requests = client.getCapturedRequests(); - - for(HttpClientRequest req: requests) { - validateRequestHasContinuationTokenLimit(req, options.getResponseContinuationTokenLimitInKb()); - } - } - - private void validateRequestHasContinuationTokenLimit(HttpClientRequest request, Integer expectedValue) { - if (expectedValue != null && expectedValue > 0) { - assertThat(request.getHeaders() - .contains(HttpConstants.HttpHeaders.RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB)) - .isTrue(); - assertThat(request.getHeaders() - .get("x-ms-documentdb-responsecontinuationtokenlimitinkb")) - .isEqualTo(Integer.toString(expectedValue)); - } else { - assertThat(request.getHeaders() - .contains(HttpConstants.HttpHeaders.RESPONSE_CONTINUATION_TOKEN_LIMIT_IN_KB)) - .isFalse(); - } - } - - public Document createDocument(AsyncDocumentClient client, String collectionLink, int cnt) { - - Document docDefinition = getDocumentDefinition(cnt); - return client - .createDocument(collectionLink, docDefinition, null, false).toBlocking().single().getResource(); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() throws Exception { - client = new SpyClientBuilder(clientBuilder).build(); - createdDatabase = SHARED_DATABASE; - createdSinglePartitionCollection = SHARED_SINGLE_PARTITION_COLLECTION; - truncateCollection(SHARED_SINGLE_PARTITION_COLLECTION); - - createdMultiPartitionCollection = SHARED_MULTI_PARTITION_COLLECTION; - truncateCollection(SHARED_MULTI_PARTITION_COLLECTION); - - for(int i = 0; i < 3; i++) { - createdDocumentsInSinglePartitionCollection.add(createDocument(client, getCollectionLink(createdSinglePartitionCollection), i)); - createdDocumentsInMultiPartitionCollection.add(createDocument(client, getCollectionLink(createdMultiPartitionCollection), i)); - } - - for(int i = 0; i < 5; i++) { - createdDocumentsInSinglePartitionCollection.add(createDocument(client, getCollectionLink(createdSinglePartitionCollection), 99)); - createdDocumentsInMultiPartitionCollection.add(createDocument(client, getCollectionLink(createdMultiPartitionCollection), 99)); - } - - // wait for catch up - TimeUnit.SECONDS.sleep(1); - - FeedOptions options = new FeedOptions(); - options.setEnableCrossPartitionQuery(true); - - // do the query once to ensure the collection is cached. - client.queryDocuments(getMultiPartitionCollectionLink(), "select * from root", options) - .toCompletable().await(); - - // do the query once to ensure the collection is cached. - client.queryDocuments(getSinglePartitionCollectionLink(), "select * from root", options) - .toCompletable().await(); - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private static Document getDocumentDefinition(int cnt) { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"prop\" : %d, " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, cnt, cnt)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/NetworkFailureTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/NetworkFailureTest.java deleted file mode 100644 index 4ce4abf58452..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/NetworkFailureTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.CollectionCrudTest; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; -import org.mockito.Mockito; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import java.net.UnknownHostException; -import java.time.Instant; - -import static org.assertj.core.api.Java6Assertions.assertThat; - -public class NetworkFailureTest extends TestSuiteBase { - private static final int TIMEOUT = ClientRetryPolicy.MaxRetryCount * ClientRetryPolicy.RetryIntervalInMS + 60000; - private final DocumentCollection collectionDefinition; - - @Factory(dataProvider = "simpleClientBuildersWithDirect") - public NetworkFailureTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - this.collectionDefinition = getCollectionDefinition(); - } - - @Test(groups = { "emulator" }, timeOut = TIMEOUT) - public void createCollectionWithUnreachableHost() { - SpyClientUnderTestFactory.ClientWithGatewaySpy client = null; - - try { - client = SpyClientUnderTestFactory.createClientWithGatewaySpy(clientBuilder); - - Database database = SHARED_DATABASE; - - Observable> createObservable = client - .createCollection(database.getSelfLink(), collectionDefinition, null); - - - final RxGatewayStoreModel origGatewayStoreModel = client.getOrigGatewayStoreModel(); - - Mockito.doAnswer(invocation -> { - RxDocumentServiceRequest request = invocation.getArgumentAt(0, RxDocumentServiceRequest.class); - - if (request.getResourceType() == ResourceType.DocumentCollection) { - return Observable.error(new UnknownHostException()); - } - - return origGatewayStoreModel.processMessage(request); - - }).when(client.getSpyGatewayStoreModel()).processMessage(Mockito.any()); - - - FailureValidator validator = new FailureValidator.Builder().instanceOf(UnknownHostException.class).build(); - Instant start = Instant.now(); - validateFailure(createObservable, validator, TIMEOUT); - Instant after = Instant.now(); - assertThat(after.toEpochMilli() - start.toEpochMilli()) - .isGreaterThanOrEqualTo(ClientRetryPolicy.MaxRetryCount * ClientRetryPolicy.RetryIntervalInMS); - - } finally { - safeClose(client); - } - } - - @AfterClass(groups = { "emulator" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - AsyncDocumentClient client = createGatewayHouseKeepingDocumentClient().build(); - safeDeleteCollection(client, collectionDefinition); - client.close(); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ParallelAsync.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ParallelAsync.java deleted file mode 100644 index 47e7987673f1..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/ParallelAsync.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import org.apache.commons.lang3.Range; -import rx.Completable; -import rx.functions.Action1; - -import java.util.ArrayList; -import java.util.List; - -public class ParallelAsync { - - static Completable forEachAsync(Range range, int partition, Action1 func) { - - int partitionSize = (range.getMaximum() - range.getMinimum()) / partition; - List task = new ArrayList<>(); - int startRange = range.getMinimum(); - for (int i = 0; i < partition; i++) { - Range integerRange = Range.between(startRange, startRange + partitionSize); - task.add(Completable.defer(() -> { - for(int j = integerRange.getMinimum(); j < integerRange.getMaximum();j++) { - func.call(j); - } - return Completable.complete(); - })); - startRange = startRange + partitionSize ; - } - return Completable.mergeDelayError(task); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryCreateDocumentTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryCreateDocumentTest.java deleted file mode 100644 index 536ac8e7c38b..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryCreateDocumentTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.google.common.collect.ImmutableMap; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.ResourceResponseValidator; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; -import rx.Observable; - -import javax.net.ssl.SSLException; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doAnswer; - -public class RetryCreateDocumentTest extends TestSuiteBase { - - private SpyClientUnderTestFactory.ClientWithGatewaySpy client; - - private Database database; - private DocumentCollection collection; - - @Factory(dataProvider = "clientBuilders") - public RetryCreateDocumentTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void retryDocumentCreate() throws Exception { - // create a document to ensure collection is cached - client.createDocument(collection.getSelfLink(), getDocumentDefinition(), null, false).toBlocking().single(); - - Document docDefinition = getDocumentDefinition(); - - Observable> createObservable = client - .createDocument(collection.getSelfLink(), docDefinition, null, false); - AtomicInteger count = new AtomicInteger(); - - doAnswer(new Answer< Observable>() { - @Override - public Observable answer(InvocationOnMock invocation) throws Throwable { - RxDocumentServiceRequest req = (RxDocumentServiceRequest) invocation.getArguments()[0]; - if (req.getOperationType() != OperationType.Create) { - return client.getOrigGatewayStoreModel().processMessage(req); - } - - int currentAttempt = count.getAndIncrement(); - if (currentAttempt == 0) { - Map header = ImmutableMap.of( - HttpConstants.HttpHeaders.SUB_STATUS, - Integer.toString(HttpConstants.SubStatusCodes.PARTITION_KEY_MISMATCH)); - - return Observable.error(new DocumentClientException(HttpConstants.StatusCodes.BADREQUEST, new Error() , header)); - } else { - return client.getOrigGatewayStoreModel().processMessage(req); - } - } - }).when(client.getSpyGatewayStoreModel()).processMessage(anyObject()); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()).build(); - validateSuccess(createObservable, validator); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocument_noRetryOnNonRetriableFailure() throws Exception { - - AtomicInteger count = new AtomicInteger(); - doAnswer(new Answer< Observable>() { - @Override - public Observable answer(InvocationOnMock invocation) throws Throwable { - RxDocumentServiceRequest req = (RxDocumentServiceRequest) invocation.getArguments()[0]; - - if (req.getResourceType() != ResourceType.Document) { - return client.getOrigGatewayStoreModel().processMessage(req); - } - - int currentAttempt = count.getAndIncrement(); - if (currentAttempt == 0) { - return client.getOrigGatewayStoreModel().processMessage(req); - } else { - Map header = ImmutableMap.of( - HttpConstants.HttpHeaders.SUB_STATUS, - Integer.toString(2)); - - return Observable.error(new DocumentClientException(1, new Error() , header)); - } - } - }).when(client.getSpyGatewayStoreModel()).processMessage(anyObject()); - - // create a document to ensure collection is cached - client.createDocument(collection.getSelfLink(), getDocumentDefinition(), null, false) - .toBlocking() - .single(); - - Document docDefinition = getDocumentDefinition(); - - Observable> createObservable = client - .createDocument(collection.getSelfLink(), docDefinition, null, false); - - // validate - FailureValidator validator = new FailureValidator.Builder().statusCode(1).subStatusCode(2).build(); - validateFailure(createObservable, validator, TIMEOUT); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void createDocument_failImmediatelyOnNonRetriable() throws Exception { - // create a document to ensure collection is cached - client.createDocument(collection.getSelfLink(), getDocumentDefinition(), null, false).toBlocking().single(); - AtomicInteger count = new AtomicInteger(); - - doAnswer(new Answer< Observable>() { - @Override - public Observable answer(InvocationOnMock invocation) throws Throwable { - RxDocumentServiceRequest req = (RxDocumentServiceRequest) invocation.getArguments()[0]; - if (req.getOperationType() != OperationType.Create) { - return client.getOrigGatewayStoreModel().processMessage(req); - } - int currentAttempt = count.getAndIncrement(); - if (currentAttempt == 0) { - Map header = ImmutableMap.of( - HttpConstants.HttpHeaders.SUB_STATUS, - Integer.toString(2)); - - return Observable.error(new DocumentClientException(1, new Error() , header)); - } else { - return client.getOrigGatewayStoreModel().processMessage(req); - } - } - }).when(client.getSpyGatewayStoreModel()).processMessage(anyObject()); - - Document docDefinition = getDocumentDefinition(); - - Observable> createObservable = client - .createDocument(collection.getSelfLink(), docDefinition, null, false); - // validate - - FailureValidator validator = new FailureValidator.Builder().statusCode(1).subStatusCode(2).build(); - validateFailure(createObservable.timeout(100, TimeUnit.MILLISECONDS), validator); - } - - @BeforeMethod(groups = { "simple" }) - public void beforeMethod(Method method) { - super.beforeMethod(method); - Mockito.reset(client.getSpyGatewayStoreModel()); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - // set up the client - client = SpyClientUnderTestFactory.createClientWithGatewaySpy(clientBuilder); - - database = SHARED_DATABASE; - collection = SHARED_SINGLE_PARTITION_COLLECTION; - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryThrottleTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryThrottleTest.java deleted file mode 100644 index 2f438b764604..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RetryThrottleTest.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doAnswer; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.RetryOptions; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.ResourceResponseValidator; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; - -import rx.Observable; - -public class RetryThrottleTest extends TestSuiteBase { - private final static int TIMEOUT = 10000; - private final static int TOTAL_DOCS = 500; - private final static int LARGE_TIMEOUT = 30000; - - private SpyClientUnderTestFactory.ClientWithGatewaySpy client; - private Database database; - private DocumentCollection collection; - - @Test(groups = { "long" }, timeOut = LARGE_TIMEOUT ) - public void retryCreateDocumentsOnSpike() throws Exception { - ConnectionPolicy policy = new ConnectionPolicy(); - RetryOptions retryOptions = new RetryOptions(); - retryOptions.setMaxRetryAttemptsOnThrottledRequests(Integer.MAX_VALUE); - retryOptions.setMaxRetryWaitTimeInSeconds(LARGE_TIMEOUT); - policy.setRetryOptions(retryOptions); - - AsyncDocumentClient.Builder builder = new AsyncDocumentClient.Builder() - .withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(policy) - .withConsistencyLevel(ConsistencyLevel.Eventual); - - client = SpyClientUnderTestFactory.createClientWithGatewaySpy(builder); - - // create a document to ensure collection is cached - client.createDocument(getCollectionLink(collection), getDocumentDefinition(), null, false).toBlocking().single(); - - List>> list = new ArrayList<>(); - for(int i = 0; i < TOTAL_DOCS; i++) { - Observable> obs = client.createDocument(getCollectionLink(collection), getDocumentDefinition(), null, false); - list.add(obs); - } - - // registers a spy to count number of invocation - AtomicInteger totalCount = new AtomicInteger(); - AtomicInteger successCount = new AtomicInteger(); - - doAnswer(new Answer< Observable>() { - @Override - public Observable answer(InvocationOnMock invocation) throws Throwable { - RxDocumentServiceRequest req = (RxDocumentServiceRequest) invocation.getArguments()[0]; - if (req.getResourceType() == ResourceType.Document && req.getOperationType() == OperationType.Create) { - // increment the counter per Document Create operations - totalCount.incrementAndGet(); - } - return client.getOrigGatewayStoreModel().processMessage(req).doOnNext(rsp -> successCount.incrementAndGet()); - } - }).when(client.getSpyGatewayStoreModel()).processMessage(anyObject()); - - List> rsps = Observable.merge(list, 100).toList().toSingle().toBlocking().value(); - System.out.println("total: " + totalCount.get()); - assertThat(rsps).hasSize(TOTAL_DOCS); - assertThat(successCount.get()).isEqualTo(TOTAL_DOCS); - System.out.println("total count is " + totalCount.get()); - } - - @Test(groups = { "long" }, timeOut = TIMEOUT) - public void retryDocumentCreate() throws Exception { - client = SpyClientUnderTestFactory.createClientWithGatewaySpy(createGatewayRxDocumentClient()); - - // create a document to ensure collection is cached - client.createDocument(getCollectionLink(collection), getDocumentDefinition(), null, false).toBlocking().single(); - - Document docDefinition = getDocumentDefinition(); - - Observable> createObservable = client - .createDocument(collection.getSelfLink(), docDefinition, null, false); - AtomicInteger count = new AtomicInteger(); - - doAnswer(new Answer< Observable>() { - @Override - public Observable answer(InvocationOnMock invocation) throws Throwable { - RxDocumentServiceRequest req = (RxDocumentServiceRequest) invocation.getArguments()[0]; - if (req.getOperationType() != OperationType.Create) { - return client.getOrigGatewayStoreModel().processMessage(req); - } - int currentAttempt = count.getAndIncrement(); - if (currentAttempt == 0) { - return Observable.error(new DocumentClientException(HttpConstants.StatusCodes.TOO_MANY_REQUESTS)); - } else { - return client.getOrigGatewayStoreModel().processMessage(req); - } - } - }).when(client.getSpyGatewayStoreModel()).processMessage(anyObject()); - - // validate - ResourceResponseValidator validator = new ResourceResponseValidator.Builder() - .withId(docDefinition.getId()).build(); - validateSuccess(createObservable, validator, TIMEOUT); - } - - @AfterMethod(groups = { "long" }) - private void afterMethod() { - safeClose(client); - } - - @BeforeClass(groups = { "long" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - // set up the client - database = SHARED_DATABASE; - collection = SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } - - @AfterClass(groups = { "long" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentClientUnderTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentClientUnderTest.java deleted file mode 100644 index 3cf2844149a3..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/RxDocumentClientUnderTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.QueryCompatibilityMode; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; - -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpClientResponse; -import org.mockito.Mockito; -import org.mockito.stubbing.Answer; -import rx.Observable; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.mockito.Matchers.anyObject; -import static org.mockito.Mockito.doAnswer; - -/** - * This class in conjunction with {@link com.microsoft.azure.cosmosdb.rx.ClientUnderTestBuilder} - * provides the functionality for spying the client behavior and the http requests sent. - */ -public class RxDocumentClientUnderTest extends RxDocumentClientImpl { - - public CompositeHttpClient spyHttpClient; - public CompositeHttpClient origHttpClient; - - public List> httpRequests = Collections.synchronizedList( - new ArrayList>()); - - public RxDocumentClientUnderTest(URI serviceEndpoint, - String masterKey, - ConnectionPolicy connectionPolicy, - ConsistencyLevel consistencyLevel, - Configs configs) { - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs); - init(); - } - - RxGatewayStoreModel createRxGatewayProxy( - ISessionContainer sessionContainer, - ConsistencyLevel consistencyLevel, - QueryCompatibilityMode queryCompatibilityMode, - UserAgentContainer userAgentContainer, - GlobalEndpointManager globalEndpointManager, - CompositeHttpClient rxOrigClient) { - - origHttpClient = rxOrigClient; - spyHttpClient = Mockito.spy(rxOrigClient); - - doAnswer((Answer>>) invocationOnMock -> { - - RxClient.ServerInfo serverInfo = - invocationOnMock.getArgumentAt(0, RxClient.ServerInfo.class); - - HttpClientRequest request - = invocationOnMock.getArgumentAt(1, HttpClientRequest.class); - - httpRequests.add(request); - - Observable> httpRespObs = - origHttpClient.submit(serverInfo, request); - - return httpRespObs; - }).when(spyHttpClient).submit( anyObject(), - (HttpClientRequest) anyObject()); - - return super.createRxGatewayProxy(sessionContainer, - consistencyLevel, - queryCompatibilityMode, - userAgentContainer, - globalEndpointManager, - spyHttpClient); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/SessionTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/SessionTest.java deleted file mode 100644 index 209bc4e792df..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/SessionTest.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; - -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.http.HttpMethod; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; - -import org.apache.commons.lang3.StringUtils; -import org.testng.SkipException; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URLDecoder; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; - -public class SessionTest extends TestSuiteBase { - protected static final int TIMEOUT = 20000; - - private Database createdDatabase; - private DocumentCollection createdCollection; - private String collectionId = "+ -_,:.|~" + UUID.randomUUID().toString() + " +-_,:.|~"; - private SpyClientUnderTestFactory.SpyBaseClass> spyClient; - private AsyncDocumentClient houseKeepingClient; - private ConnectionMode connectionMode; - - @Factory(dataProvider = "clientBuildersWithDirectSession") - public SessionTest(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - this.subscriberValidationTimeout = TIMEOUT; - } - - @DataProvider(name = "sessionTestArgProvider") - public Object[] sessionTestArgProvider() { - return new Object[] { - // boolean indicating whether requests should be name based or not - true, - false - }; - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - createdDatabase = SHARED_DATABASE; - - DocumentCollection collection = new DocumentCollection(); - collection.setId(collectionId); - createdCollection = createCollection(createGatewayHouseKeepingDocumentClient().build(), createdDatabase.getId(), - collection, null); - houseKeepingClient = clientBuilder.build(); - connectionMode = houseKeepingClient.getConnectionPolicy().getConnectionMode(); - - if (connectionMode == ConnectionMode.Direct) { - spyClient = SpyClientUnderTestFactory.createDirectHttpsClientUnderTest(clientBuilder); - } else { - spyClient = SpyClientUnderTestFactory.createClientUnderTest(clientBuilder); - } - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeDeleteCollection(houseKeepingClient, createdCollection); - safeClose(houseKeepingClient); - safeClose(spyClient); - - } - - @BeforeMethod(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeTest(Method method) { - super.beforeMethod(method); - spyClient.clearCapturedRequests(); - } - - private List getSessionTokensInRequests() { - return spyClient.getCapturedRequests().stream() - .map(r -> r.getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN)).collect(Collectors.toList()); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "sessionTestArgProvider") - public void sessionConsistency_ReadYourWrites(boolean isNameBased) { - spyClient.readCollection(getCollectionLink(isNameBased), null).toBlocking().single(); - spyClient.createDocument(getCollectionLink(isNameBased), new Document(), null, false).toBlocking().single(); - - spyClient.clearCapturedRequests(); - - for (int i = 0; i < 10; i++) { - Document documentCreated = spyClient.createDocument(getCollectionLink(isNameBased), new Document(), null, false) - .toBlocking().single().getResource(); - - // We send session tokens on Writes in Gateway mode - if (connectionMode == ConnectionMode.Gateway) { - assertThat(getSessionTokensInRequests()).hasSize(3 * i + 1); - assertThat(getSessionTokensInRequests().get(3 * i + 0)).isNotEmpty(); - } - - spyClient.readDocument(getDocumentLink(documentCreated, isNameBased), null).toBlocking().single(); - - assertThat(getSessionTokensInRequests()).hasSize(3 * i + 2); - assertThat(getSessionTokensInRequests().get(3 * i + 1)).isNotEmpty(); - - spyClient.readDocument(getDocumentLink(documentCreated, isNameBased), null).toBlocking().single(); - - assertThat(getSessionTokensInRequests()).hasSize(3 * i + 3); - assertThat(getSessionTokensInRequests().get(3 * i + 2)).isNotEmpty(); - } - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "sessionTestArgProvider") - public void sessionTokenInDocumentRead(boolean isNameBased) throws UnsupportedEncodingException { - Document document = new Document(); - document.setId(UUID.randomUUID().toString()); - document.set("pk", "pk"); - document = spyClient.createDocument(getCollectionLink(isNameBased), document, null, false).toBlocking().single() - .getResource(); - - final String documentLink = getDocumentLink(document, isNameBased); - spyClient.readDocument(documentLink, null).toBlocking().single() - .getResource(); - - List> documentReadHttpRequests = spyClient.getCapturedRequests().stream() - .filter(r -> r.getMethod() == HttpMethod.GET) - .filter(r -> { - try { - return URLDecoder.decode(r.getUri().replaceAll("\\+", "%2b"), "UTF-8").contains( - StringUtils.removeEnd(documentLink, "/")); - } catch (UnsupportedEncodingException e) { - return false; - } - }).collect(Collectors.toList()); - - // Direct mode may make more than one call (multiple replicas) - assertThat(documentReadHttpRequests.size() >= 1).isTrue(); - assertThat(documentReadHttpRequests.get(0).getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN)).isNotEmpty(); - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT, dataProvider = "sessionTestArgProvider") - public void sessionTokenRemovedForMasterResource(boolean isNameBased) throws UnsupportedEncodingException { - if (connectionMode == ConnectionMode.Direct) { - throw new SkipException("Master resource access is only through gateway"); - } - String collectionLink = getCollectionLink(isNameBased); - spyClient.readCollection(collectionLink, null).toBlocking().single(); - - List> collectionReadHttpRequests = spyClient.getCapturedRequests().stream() - .filter(r -> r.getMethod() == HttpMethod.GET) - .filter(r -> { - try { - return URLDecoder.decode(r.getUri().replaceAll("\\+", "%2b"), "UTF-8").contains( - StringUtils.removeEnd(collectionLink, "/")); - } catch (UnsupportedEncodingException e) { - return false; - } - }) - .collect(Collectors.toList()); - - assertThat(collectionReadHttpRequests).hasSize(1); - assertThat(collectionReadHttpRequests.get(0).getHeaders().get(HttpConstants.HttpHeaders.SESSION_TOKEN)).isNull(); - } - - private String getCollectionLink(boolean isNameBased) { - return isNameBased ? "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId(): - createdCollection.getSelfLink(); - } - - private String getDocumentLink(Document doc, boolean isNameBased) { - return isNameBased ? "dbs/" + createdDatabase.getId() + "/colls/" + createdCollection.getId() + "/docs/" + doc.getId() : - "dbs/" + createdDatabase.getResourceId() + "/colls/" + createdCollection.getResourceId() + "/docs/" + doc.getResourceId() + "/"; - } -} \ No newline at end of file diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/SpyClientUnderTestFactory.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/SpyClientUnderTestFactory.java deleted file mode 100644 index b9082124c091..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/SpyClientUnderTestFactory.java +++ /dev/null @@ -1,317 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.ISessionContainer; -import com.microsoft.azure.cosmosdb.internal.QueryCompatibilityMode; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.SpyClientBuilder; -import com.microsoft.azure.cosmosdb.rx.internal.directconnectivity.ReflectionUtils; - -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.client.RxClient; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import io.reactivex.netty.protocol.http.client.HttpClientRequest; -import io.reactivex.netty.protocol.http.client.HttpResponseHeaders; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; -import java.util.stream.Collectors; - -import static org.mockito.Mockito.doAnswer; - -public class SpyClientUnderTestFactory { - - public static abstract class SpyBaseClass extends RxDocumentClientImpl { - - public SpyBaseClass(URI serviceEndpoint, String masterKeyOrResourceToken, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs) { - super(serviceEndpoint, masterKeyOrResourceToken, connectionPolicy, consistencyLevel, configs); - } - - public abstract List getCapturedRequests(); - - public abstract void clearCapturedRequests(); - } - - public static class ClientWithGatewaySpy extends SpyBaseClass { - - private RxGatewayStoreModel origRxGatewayStoreModel; - private RxGatewayStoreModel spyRxGatewayStoreModel; - - private List requests; - - - ClientWithGatewaySpy(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs) { - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs); - init(); - } - - @Override - public List getCapturedRequests() { - return requests; - } - - @Override - RxGatewayStoreModel createRxGatewayProxy(ISessionContainer sessionContainer, - ConsistencyLevel consistencyLevel, - QueryCompatibilityMode queryCompatibilityMode, - UserAgentContainer userAgentContainer, - GlobalEndpointManager globalEndpointManager, - CompositeHttpClient rxClient) { - this.origRxGatewayStoreModel = super.createRxGatewayProxy( - sessionContainer, - consistencyLevel, - queryCompatibilityMode, - userAgentContainer, - globalEndpointManager, - rxClient); - this.requests = Collections.synchronizedList(new ArrayList<>()); - this.spyRxGatewayStoreModel = Mockito.spy(this.origRxGatewayStoreModel); - this.initRequestCapture(); - return this.spyRxGatewayStoreModel; - } - - protected void initRequestCapture() { - doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) { - RxDocumentServiceRequest req = invocationOnMock.getArgumentAt(0, RxDocumentServiceRequest.class); - requests.add(req); - return ClientWithGatewaySpy.this.origRxGatewayStoreModel.processMessage(req); - } - }).when(ClientWithGatewaySpy.this.spyRxGatewayStoreModel).processMessage(Mockito.any(RxDocumentServiceRequest.class)); - } - - @Override - public void clearCapturedRequests() { - requests.clear(); - } - - public RxGatewayStoreModel getSpyGatewayStoreModel() { - return spyRxGatewayStoreModel; - } - - public RxGatewayStoreModel getOrigGatewayStoreModel() { - return origRxGatewayStoreModel; - } - } - - public static class ClientUnderTest extends SpyBaseClass> { - - CompositeHttpClient origHttpClient; - CompositeHttpClient spyHttpClient; - List, Future>> requestsResponsePairs = - Collections.synchronizedList(new ArrayList, Future>>()); - - ClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel, Configs configs) { - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs); - init(); - } - - public List, Future>> capturedRequestResponseHeaderPairs() { - return requestsResponsePairs; - } - - @Override - public List> getCapturedRequests() { - return requestsResponsePairs.stream().map(pair -> pair.getLeft()).collect(Collectors.toList()); - } - - void initRequestCapture(CompositeHttpClient spyClient) { - - doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - RxClient.ServerInfo serverInfo = invocationOnMock.getArgumentAt(0, RxClient.ServerInfo.class); - HttpClientRequest httpReq = invocationOnMock.getArgumentAt(1, HttpClientRequest.class); - - CompletableFuture f = new CompletableFuture<>(); - requestsResponsePairs.add(Pair.of(httpReq, f)); - - return origHttpClient.submit(serverInfo, httpReq) - .doOnNext( - res -> f.complete(res.getHeaders()) - ).doOnError( - e -> f.completeExceptionally(e) - ); - - } - }).when(spyClient).submit(Mockito.any(RxClient.ServerInfo.class), Mockito.any(HttpClientRequest.class)); - } - - @Override - public void clearCapturedRequests() { - requestsResponsePairs.clear(); - } - - public ISessionContainer getSessionContainer() { - try { - return (ISessionContainer) FieldUtils.readField(this, "sessionContainer", true); - } catch (Exception e){ - throw new RuntimeException(e); - } - } - - public CompositeHttpClient getSpyHttpClient() { - return spyHttpClient; - } - } - - public static class DirectHttpsClientUnderTest extends SpyBaseClass> { - - CompositeHttpClient origHttpClient; - CompositeHttpClient spyHttpClient; - List, Future>> requestsResponsePairs = - Collections.synchronizedList(new ArrayList, Future>>()); - - DirectHttpsClientUnderTest(URI serviceEndpoint, String masterKey, ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel) { - // TODO: DANOBLE: ensure the configs instance instantiated here specifies Protocol.Https - super(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, new Configs()); - assert connectionPolicy.getConnectionMode() == ConnectionMode.Direct; - init(); - this.origHttpClient = ReflectionUtils.getDirectHttpsHttpClient(this); - this.spyHttpClient = Mockito.spy(this.origHttpClient); - ReflectionUtils.setDirectHttpsHttpClient(this, this.spyHttpClient); - this.initRequestCapture(this.spyHttpClient); - } - - public List, Future>> capturedRequestResponseHeaderPairs() { - return requestsResponsePairs; - } - - @Override - public List> getCapturedRequests() { - return requestsResponsePairs.stream().map(pair -> pair.getLeft()).collect(Collectors.toList()); - } - - void initRequestCapture(CompositeHttpClient spyClient) { - - doAnswer(new Answer() { - @Override - public Object answer(InvocationOnMock invocationOnMock) throws Throwable { - RxClient.ServerInfo serverInfo = invocationOnMock.getArgumentAt(0, RxClient.ServerInfo.class); - HttpClientRequest httpReq = invocationOnMock.getArgumentAt(1, HttpClientRequest.class); - - CompletableFuture f = new CompletableFuture<>(); - requestsResponsePairs.add(Pair.of(httpReq, f)); - - return origHttpClient.submit(serverInfo, httpReq) - .doOnNext( - res -> f.complete(res.getHeaders()) - ).doOnError( - e -> f.completeExceptionally(e) - ); - - } - }).when(spyClient).submit(Mockito.any(RxClient.ServerInfo.class), Mockito.any(HttpClientRequest.class)); - } - - @Override - public void clearCapturedRequests() { - requestsResponsePairs.clear(); - } - - public ISessionContainer getSessionContainer() { - try { - return (ISessionContainer) FieldUtils.readField(this, "sessionContainer", true); - } catch (Exception e){ - throw new RuntimeException(e); - } - } - - public CompositeHttpClient getSpyHttpClient() { - return spyHttpClient; - } - } - - public static ClientWithGatewaySpy createClientWithGatewaySpy(AsyncDocumentClient.Builder builder) { - return new SpyClientBuilder(builder).buildWithGatewaySpy(); - } - - public static ClientWithGatewaySpy createClientWithGatewaySpy(URI serviceEndpoint, - String masterKey, - ConnectionPolicy connectionPolicy, - ConsistencyLevel consistencyLevel, - Configs configs) { - return new ClientWithGatewaySpy(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs); - } - - public static ClientUnderTest createClientUnderTest(AsyncDocumentClient.Builder builder) { - return new SpyClientBuilder(builder).build(); - } - - public static DirectHttpsClientUnderTest createDirectHttpsClientUnderTest(AsyncDocumentClient.Builder builder) { - return new SpyClientBuilder(builder).buildWithDirectHttps(); - } - - public static ClientUnderTest createClientUnderTest(URI serviceEndpoint, - String masterKey, - ConnectionPolicy connectionPolicy, - ConsistencyLevel consistencyLevel, - Configs configs) { - return new ClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel, configs) { - - @Override - RxGatewayStoreModel createRxGatewayProxy(ISessionContainer sessionContainer, - ConsistencyLevel consistencyLevel, - QueryCompatibilityMode queryCompatibilityMode, - UserAgentContainer userAgentContainer, - GlobalEndpointManager globalEndpointManager, - CompositeHttpClient rxClient) { - - CompositeHttpClient spyClient = Mockito.spy(rxClient); - - this.origHttpClient = rxClient; - this.spyHttpClient = spyClient; - - this.initRequestCapture(spyHttpClient); - - return super.createRxGatewayProxy( - sessionContainer, - consistencyLevel, - queryCompatibilityMode, - userAgentContainer, - globalEndpointManager, - spyClient); - } - }; - } - - public static DirectHttpsClientUnderTest createDirectHttpsClientUnderTest(URI serviceEndpoint, String masterKey, - ConnectionPolicy connectionPolicy, ConsistencyLevel consistencyLevel) { - return new DirectHttpsClientUnderTest(serviceEndpoint, masterKey, connectionPolicy, consistencyLevel); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/StoreHeaderTests.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/StoreHeaderTests.java deleted file mode 100644 index ecdb689b542b..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/StoreHeaderTests.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.TestSuiteBase; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Factory; -import org.testng.annotations.Test; - -import java.util.UUID; - -public class StoreHeaderTests extends TestSuiteBase { - - private static Database createdDatabase; - private static DocumentCollection createdCollection; - - private AsyncDocumentClient client; - - @Factory(dataProvider = "clientBuildersWithDirect") - public StoreHeaderTests(AsyncDocumentClient.Builder clientBuilder) { - this.clientBuilder = clientBuilder; - } - - @Test(groups = { "simple" }, timeOut = TIMEOUT) - public void validateStoreHeader() { - Document docDefinition1 = getDocumentDefinition(); - Document responseDoc1 = createDocument(client, createdDatabase.getId(), createdCollection.getId(), docDefinition1); - Assert.assertNotNull(responseDoc1.getSelfLink()); - Assert.assertNotNull(responseDoc1.get("_attachments")); - - Document docDefinition2 = getDocumentDefinition(); - RequestOptions requestOptions = new RequestOptions(); - requestOptions.setHeader("x-ms-exclude-system-properties", "true"); - Document responseDoc2 = createDocument(client, createdDatabase.getId(), createdCollection.getId(), docDefinition2, requestOptions); - Assert.assertNull(responseDoc2.getSelfLink()); - Assert.assertNull(responseDoc2.get("_attachments")); - } - - @BeforeClass(groups = { "simple" }, timeOut = SETUP_TIMEOUT) - public void beforeClass() { - client = clientBuilder.build(); - - createdDatabase = SHARED_DATABASE; - createdCollection = SHARED_MULTI_PARTITION_COLLECTION; - } - - @AfterClass(groups = { "simple" }, timeOut = SHUTDOWN_TIMEOUT, alwaysRun = true) - public void afterClass() { - safeClose(client); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]]" - + "}" - , uuid, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/TestSuiteBase.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/TestSuiteBase.java deleted file mode 100644 index fa92ee2af634..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/TestSuiteBase.java +++ /dev/null @@ -1,1012 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.azure.cosmosdb.CompositePath; -import com.microsoft.azure.cosmosdb.CompositePathSortOrder; -import com.microsoft.azure.cosmosdb.ConnectionMode; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.ConsistencyLevel; -import com.microsoft.azure.cosmosdb.DataType; -import com.microsoft.azure.cosmosdb.Database; -import com.microsoft.azure.cosmosdb.DatabaseForTest; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.IncludedPath; -import com.microsoft.azure.cosmosdb.Index; -import com.microsoft.azure.cosmosdb.IndexingPolicy; -import com.microsoft.azure.cosmosdb.PartitionKey; -import com.microsoft.azure.cosmosdb.PartitionKeyDefinition; -import com.microsoft.azure.cosmosdb.RequestOptions; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.ResourceResponse; -import com.microsoft.azure.cosmosdb.RetryOptions; -import com.microsoft.azure.cosmosdb.SqlQuerySpec; -import com.microsoft.azure.cosmosdb.Undefined; -import com.microsoft.azure.cosmosdb.User; -import com.microsoft.azure.cosmosdb.internal.PathParser; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient; -import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient.Builder; -import com.microsoft.azure.cosmosdb.rx.FailureValidator; -import com.microsoft.azure.cosmosdb.rx.FeedResponseListValidator; -import com.microsoft.azure.cosmosdb.rx.ResourceResponseValidator; -import com.microsoft.azure.cosmosdb.rx.TestConfigurations; -import org.apache.commons.lang3.StringUtils; -import org.mockito.stubbing.Answer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.AfterSuite; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Observable; -import rx.observers.TestSubscriber; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.spy; - -public class TestSuiteBase { - private static final int DEFAULT_BULK_INSERT_CONCURRENCY_LEVEL = 500; - private static final ObjectMapper objectMapper = new ObjectMapper(); - protected static Logger logger = LoggerFactory.getLogger(TestSuiteBase.class.getSimpleName()); - protected static final int TIMEOUT = 8000; - protected static final int FEED_TIMEOUT = 12000; - protected static final int SETUP_TIMEOUT = 30000; - protected static final int SHUTDOWN_TIMEOUT = 12000; - - protected static final int SUITE_SETUP_TIMEOUT = 120000; - protected static final int SUITE_SHUTDOWN_TIMEOUT = 60000; - - protected static final int WAIT_REPLICA_CATCH_UP_IN_MILLIS = 4000; - - protected int subscriberValidationTimeout = TIMEOUT; - - protected static ConsistencyLevel accountConsistency; - - protected Builder clientBuilder; - - protected static Database SHARED_DATABASE; - protected static DocumentCollection SHARED_MULTI_PARTITION_COLLECTION; - protected static DocumentCollection SHARED_SINGLE_PARTITION_COLLECTION; - protected static DocumentCollection SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY; - protected static DocumentCollection SHARED_MULTI_PARTITION_COLLECTION_WITH_COMPOSITE_AND_SPATIAL_INDEXES; - - - protected TestSuiteBase() { - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); - objectMapper.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA, true); - objectMapper.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION, true); - logger.debug("Initializing {} ...", this.getClass().getSimpleName()); - } - - @BeforeMethod(groups = { "simple", "long", "direct", "multi-master", "emulator" }) - public void beforeMethod(Method method) { - if (this.clientBuilder != null) { - logger.info("Starting {}::{} using {} {} mode with {} consistency", - method.getDeclaringClass().getSimpleName(), method.getName(), - this.clientBuilder.getConnectionPolicy().getConnectionMode(), - this.clientBuilder.getConfigs().getProtocol(), - this.clientBuilder.getDesiredConsistencyLevel()); - return; - } - logger.info("Starting {}::{}", method.getDeclaringClass().getSimpleName(), method.getName()); - } - - @AfterMethod(groups = { "simple", "long", "direct", "multi-master", "emulator" }) - public void afterMethod(Method m) { - Test t = m.getAnnotation(Test.class); - logger.info("Finished {}:{}.", m.getDeclaringClass().getSimpleName(), m.getName()); - } - - private static class DatabaseManagerImpl implements DatabaseForTest.DatabaseManager { - public static DatabaseManagerImpl getInstance(AsyncDocumentClient client) { - return new DatabaseManagerImpl(client); - } - - private final AsyncDocumentClient client; - - private DatabaseManagerImpl(AsyncDocumentClient client) { - this.client = client; - } - - @Override - public Observable> queryDatabases(SqlQuerySpec query) { - return client.queryDatabases(query, null); - } - - @Override - public Observable> createDatabase(Database databaseDefinition) { - return client.createDatabase(databaseDefinition, null); - } - - @Override - public Observable> deleteDatabase(String id) { - - return client.deleteDatabase("dbs/" + id, null); - } - } - - @BeforeSuite(groups = { "simple", "long", "direct", "multi-master", "emulator" }, timeOut = SUITE_SETUP_TIMEOUT) - public static void beforeSuite() { - logger.info("beforeSuite Started"); - AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build(); - try { - DatabaseForTest dbForTest = DatabaseForTest.create(DatabaseManagerImpl.getInstance(houseKeepingClient)); - SHARED_DATABASE = dbForTest.createdDatabase; - RequestOptions options = new RequestOptions(); - options.setOfferThroughput(10100); - SHARED_MULTI_PARTITION_COLLECTION = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinitionWithRangeRangeIndex(), options); - SHARED_SINGLE_PARTITION_COLLECTION = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinition(), null); - SHARED_SINGLE_PARTITION_COLLECTION_WITHOUT_PARTITION_KEY = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinitionSinglePartitionWithoutPartitionKey()); - SHARED_MULTI_PARTITION_COLLECTION_WITH_COMPOSITE_AND_SPATIAL_INDEXES = createCollection(houseKeepingClient, SHARED_DATABASE.getId(), getCollectionDefinitionMultiPartitionWithCompositeAndSpatialIndexes(), options); - } finally { - houseKeepingClient.close(); - } - } - - @AfterSuite(groups = { "simple", "long", "direct", "multi-master", "emulator" }, timeOut = SUITE_SHUTDOWN_TIMEOUT) - public static void afterSuite() { - logger.info("afterSuite Started"); - AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build(); - try { - safeDeleteDatabase(houseKeepingClient, SHARED_DATABASE); - DatabaseForTest.cleanupStaleTestDatabases(DatabaseManagerImpl.getInstance(houseKeepingClient)); - } finally { - safeClose(houseKeepingClient); - } - } - - protected static void truncateCollection(DocumentCollection collection) { - logger.info("Truncating collection {} ...", collection.getId()); - AsyncDocumentClient houseKeepingClient = createGatewayHouseKeepingDocumentClient().build(); - try { - List paths = collection.getPartitionKey().getPaths(); - - FeedOptions options = new FeedOptions(); - options.setMaxDegreeOfParallelism(-1); - options.setEnableCrossPartitionQuery(true); - options.setMaxItemCount(100); - - logger.info("Truncating collection {} documents ...", collection.getId()); - - houseKeepingClient.queryDocuments(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(doc -> { - RequestOptions requestOptions = new RequestOptions(); - - if (paths != null && !paths.isEmpty()) { - List pkPath = PathParser.getPathParts(paths.get(0)); - Object propertyValue = doc.getObjectByPath(pkPath); - if (propertyValue == null) { - propertyValue = Undefined.Value(); - } - - requestOptions.setPartitionKey(new PartitionKey(propertyValue)); - } - - return houseKeepingClient.deleteDocument(doc.getSelfLink(), requestOptions); - }).toCompletable().await(); - - logger.info("Truncating collection {} triggers ...", collection.getId()); - - houseKeepingClient.queryTriggers(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(trigger -> { - RequestOptions requestOptions = new RequestOptions(); - -// if (paths != null && !paths.isEmpty()) { -// Object propertyValue = trigger.getObjectByPath(PathParser.getPathParts(paths.get(0))); -// requestOptions.setPartitionKey(new PartitionKey(propertyValue)); -// } - - return houseKeepingClient.deleteTrigger(trigger.getSelfLink(), requestOptions); - }).toCompletable().await(); - - logger.info("Truncating collection {} storedProcedures ...", collection.getId()); - - houseKeepingClient.queryStoredProcedures(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(storedProcedure -> { - RequestOptions requestOptions = new RequestOptions(); - -// if (paths != null && !paths.isEmpty()) { -// Object propertyValue = storedProcedure.getObjectByPath(PathParser.getPathParts(paths.get(0))); -// requestOptions.setPartitionKey(new PartitionKey(propertyValue)); -// } - - return houseKeepingClient.deleteStoredProcedure(storedProcedure.getSelfLink(), requestOptions); - }).toCompletable().await(); - - logger.info("Truncating collection {} udfs ...", collection.getId()); - - houseKeepingClient.queryUserDefinedFunctions(collection.getSelfLink(), "SELECT * FROM root", options) - .flatMap(page -> Observable.from(page.getResults())) - .flatMap(udf -> { - RequestOptions requestOptions = new RequestOptions(); - -// if (paths != null && !paths.isEmpty()) { -// Object propertyValue = udf.getObjectByPath(PathParser.getPathParts(paths.get(0))); -// requestOptions.setPartitionKey(new PartitionKey(propertyValue)); -// } - - return houseKeepingClient.deleteUserDefinedFunction(udf.getSelfLink(), requestOptions); - }).toCompletable().await(); - - } finally { - houseKeepingClient.close(); - } - - logger.info("Finished truncating collection {}.", collection.getId()); - } - - protected static void waitIfNeededForReplicasToCatchUp(AsyncDocumentClient.Builder clientBuilder) { - switch (clientBuilder.getDesiredConsistencyLevel()) { - case Eventual: - case ConsistentPrefix: - logger.info(" additional wait in Eventual mode so the replica catch up"); - // give times to replicas to catch up after a write - try { - TimeUnit.MILLISECONDS.sleep(WAIT_REPLICA_CATCH_UP_IN_MILLIS); - } catch (Exception e) { - logger.error("unexpected failure", e); - } - - case Session: - case BoundedStaleness: - case Strong: - default: - break; - } - } - - private static DocumentCollection getCollectionDefinitionSinglePartitionWithoutPartitionKey() { - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - - return collectionDefinition; - } - - - public static DocumentCollection createCollection(String databaseId, - DocumentCollection collection, - RequestOptions options) { - AsyncDocumentClient client = createGatewayHouseKeepingDocumentClient().build(); - try { - return client.createCollection("dbs/" + databaseId, collection, options).toBlocking().single().getResource(); - } finally { - client.close(); - } - } - - public static DocumentCollection createCollection(AsyncDocumentClient client, String databaseId, - DocumentCollection collection, RequestOptions options) { - return client.createCollection("dbs/" + databaseId, collection, options).toBlocking().single().getResource(); - } - - public static DocumentCollection createCollection(AsyncDocumentClient client, String databaseId, - DocumentCollection collection) { - return client.createCollection("dbs/" + databaseId, collection, null).toBlocking().single().getResource(); - } - - private static DocumentCollection getCollectionDefinitionMultiPartitionWithCompositeAndSpatialIndexes() { - final String NUMBER_FIELD = "numberField"; - final String STRING_FIELD = "stringField"; - final String NUMBER_FIELD_2 = "numberField2"; - final String STRING_FIELD_2 = "stringField2"; - final String BOOL_FIELD = "boolField"; - final String NULL_FIELD = "nullField"; - final String OBJECT_FIELD = "objectField"; - final String ARRAY_FIELD = "arrayField"; - final String SHORT_STRING_FIELD = "shortStringField"; - final String MEDIUM_STRING_FIELD = "mediumStringField"; - final String LONG_STRING_FIELD = "longStringField"; - final String PARTITION_KEY = "pk"; - - DocumentCollection documentCollection = new DocumentCollection(); - - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection> compositeIndexes = new ArrayList>(); - - //Simple - ArrayList compositeIndexSimple = new ArrayList(); - CompositePath compositePath1 = new CompositePath(); - compositePath1.setPath("/" + NUMBER_FIELD); - compositePath1.setOrder(CompositePathSortOrder.Ascending); - - CompositePath compositePath2 = new CompositePath(); - compositePath2.setPath("/" + STRING_FIELD); - compositePath2.setOrder(CompositePathSortOrder.Descending); - - compositeIndexSimple.add(compositePath1); - compositeIndexSimple.add(compositePath2); - - //Max Columns - ArrayList compositeIndexMaxColumns = new ArrayList(); - CompositePath compositePath3 = new CompositePath(); - compositePath3.setPath("/" + NUMBER_FIELD); - compositePath3.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath4 = new CompositePath(); - compositePath4.setPath("/" + STRING_FIELD); - compositePath4.setOrder(CompositePathSortOrder.Ascending); - - CompositePath compositePath5 = new CompositePath(); - compositePath5.setPath("/" + NUMBER_FIELD_2); - compositePath5.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath6 = new CompositePath(); - compositePath6.setPath("/" + STRING_FIELD_2); - compositePath6.setOrder(CompositePathSortOrder.Ascending); - - compositeIndexMaxColumns.add(compositePath3); - compositeIndexMaxColumns.add(compositePath4); - compositeIndexMaxColumns.add(compositePath5); - compositeIndexMaxColumns.add(compositePath6); - - //Primitive Values - ArrayList compositeIndexPrimitiveValues = new ArrayList(); - CompositePath compositePath7 = new CompositePath(); - compositePath7.setPath("/" + NUMBER_FIELD); - compositePath7.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath8 = new CompositePath(); - compositePath8.setPath("/" + STRING_FIELD); - compositePath8.setOrder(CompositePathSortOrder.Ascending); - - CompositePath compositePath9 = new CompositePath(); - compositePath9.setPath("/" + BOOL_FIELD); - compositePath9.setOrder(CompositePathSortOrder.Descending); - - CompositePath compositePath10 = new CompositePath(); - compositePath10.setPath("/" + NULL_FIELD); - compositePath10.setOrder(CompositePathSortOrder.Ascending); - - compositeIndexPrimitiveValues.add(compositePath7); - compositeIndexPrimitiveValues.add(compositePath8); - compositeIndexPrimitiveValues.add(compositePath9); - compositeIndexPrimitiveValues.add(compositePath10); - - //Long Strings - ArrayList compositeIndexLongStrings = new ArrayList(); - CompositePath compositePath11 = new CompositePath(); - compositePath11.setPath("/" + STRING_FIELD); - - CompositePath compositePath12 = new CompositePath(); - compositePath12.setPath("/" + SHORT_STRING_FIELD); - - CompositePath compositePath13 = new CompositePath(); - compositePath13.setPath("/" + MEDIUM_STRING_FIELD); - - CompositePath compositePath14 = new CompositePath(); - compositePath14.setPath("/" + LONG_STRING_FIELD); - - compositeIndexLongStrings.add(compositePath11); - compositeIndexLongStrings.add(compositePath12); - compositeIndexLongStrings.add(compositePath13); - compositeIndexLongStrings.add(compositePath14); - - compositeIndexes.add(compositeIndexSimple); - compositeIndexes.add(compositeIndexMaxColumns); - compositeIndexes.add(compositeIndexPrimitiveValues); - compositeIndexes.add(compositeIndexLongStrings); - - indexingPolicy.setCompositeIndexes(compositeIndexes); - documentCollection.setIndexingPolicy(indexingPolicy); - - PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition(); - ArrayList partitionKeyPaths = new ArrayList(); - partitionKeyPaths.add("/" + PARTITION_KEY); - partitionKeyDefinition.setPaths(partitionKeyPaths); - documentCollection.setPartitionKey(partitionKeyDefinition); - - documentCollection.setId(UUID.randomUUID().toString()); - - return documentCollection; - } - - public static Document createDocument(AsyncDocumentClient client, String databaseId, String collectionId, Document document) { - return createDocument(client, databaseId, collectionId, document, null); - } - - public static Document createDocument(AsyncDocumentClient client, String databaseId, String collectionId, Document document, RequestOptions options) { - return client.createDocument(com.microsoft.azure.cosmosdb.rx.Utils.getCollectionNameLink(databaseId, collectionId), document, options, false).toBlocking().single().getResource(); - } - - public Observable> bulkInsert(AsyncDocumentClient client, - String collectionLink, - List documentDefinitionList, - int concurrencyLevel) { - ArrayList>> result = new ArrayList>>(documentDefinitionList.size()); - for (Document docDef : documentDefinitionList) { - result.add(client.createDocument(collectionLink, docDef, null, false)); - } - - return Observable.merge(result, concurrencyLevel); - } - - public Observable> bulkInsert(AsyncDocumentClient client, - String collectionLink, - List documentDefinitionList) { - return bulkInsert(client, collectionLink, documentDefinitionList, DEFAULT_BULK_INSERT_CONCURRENCY_LEVEL); - } - - public List bulkInsertBlocking(AsyncDocumentClient client, - String collectionLink, - List documentDefinitionList) { - return bulkInsert(client, collectionLink, documentDefinitionList, DEFAULT_BULK_INSERT_CONCURRENCY_LEVEL) - .map(ResourceResponse::getResource) - .toList() - .toBlocking() - .single(); - } - - public static ConsistencyLevel getAccountDefaultConsistencyLevel(AsyncDocumentClient client) { - return client.getDatabaseAccount().toBlocking().single().getConsistencyPolicy().getDefaultConsistencyLevel(); - } - - public static User createUser(AsyncDocumentClient client, String databaseId, User user) { - return client.createUser("dbs/" + databaseId, user, null).toBlocking().single().getResource(); - } - - public static User safeCreateUser(AsyncDocumentClient client, String databaseId, User user) { - deleteUserIfExists(client, databaseId, user.getId()); - return createUser(client, databaseId, user); - } - - private static DocumentCollection safeCreateCollection(AsyncDocumentClient client, String databaseId, DocumentCollection collection, RequestOptions options) { - deleteCollectionIfExists(client, databaseId, collection.getId()); - return createCollection(client, databaseId, collection, options); - } - - public static String getCollectionLink(DocumentCollection collection) { - return collection.getSelfLink(); - } - - static protected DocumentCollection getCollectionDefinition() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } - - static protected DocumentCollection getCollectionDefinitionWithRangeRangeIndex() { - PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition(); - ArrayList paths = new ArrayList<>(); - paths.add("/mypk"); - partitionKeyDef.setPaths(paths); - IndexingPolicy indexingPolicy = new IndexingPolicy(); - Collection includedPaths = new ArrayList<>(); - IncludedPath includedPath = new IncludedPath(); - includedPath.setPath("/*"); - Collection indexes = new ArrayList<>(); - Index stringIndex = Index.Range(DataType.String); - stringIndex.set("precision", -1); - indexes.add(stringIndex); - - Index numberIndex = Index.Range(DataType.Number); - numberIndex.set("precision", -1); - indexes.add(numberIndex); - includedPath.setIndexes(indexes); - includedPaths.add(includedPath); - indexingPolicy.setIncludedPaths(includedPaths); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setIndexingPolicy(indexingPolicy); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionDefinition.setPartitionKey(partitionKeyDef); - - return collectionDefinition; - } - - public static void deleteCollectionIfExists(AsyncDocumentClient client, String databaseId, String collectionId) { - List res = client.queryCollections("dbs/" + databaseId, - String.format("SELECT * FROM root r where r.id = '%s'", collectionId), null).toBlocking().single() - .getResults(); - if (!res.isEmpty()) { - deleteCollection(client, com.microsoft.azure.cosmosdb.rx.Utils.getCollectionNameLink(databaseId, collectionId)); - } - } - - public static void deleteCollection(AsyncDocumentClient client, String collectionLink) { - client.deleteCollection(collectionLink, null).toBlocking().single(); - } - - public static void deleteDocumentIfExists(AsyncDocumentClient client, String databaseId, String collectionId, String docId) { - FeedOptions options = new FeedOptions(); - options.setPartitionKey(new PartitionKey(docId)); - List res = client - .queryDocuments(com.microsoft.azure.cosmosdb.rx.Utils.getCollectionNameLink(databaseId, collectionId), String.format("SELECT * FROM root r where r.id = '%s'", docId), options) - .toBlocking().single().getResults(); - if (!res.isEmpty()) { - deleteDocument(client, com.microsoft.azure.cosmosdb.rx.Utils.getDocumentNameLink(databaseId, collectionId, docId)); - } - } - - public static void safeDeleteDocument(AsyncDocumentClient client, String documentLink, RequestOptions options) { - if (client != null && documentLink != null) { - try { - client.deleteDocument(documentLink, options).toBlocking().single(); - } catch (Exception e) { - DocumentClientException dce = com.microsoft.azure.cosmosdb.rx.internal.Utils.as(e, DocumentClientException.class); - if (dce == null || dce.getStatusCode() != 404) { - throw e; - } - } - } - } - - public static void deleteDocument(AsyncDocumentClient client, String documentLink) { - client.deleteDocument(documentLink, null).toBlocking().single(); - } - - public static void deleteUserIfExists(AsyncDocumentClient client, String databaseId, String userId) { - List res = client - .queryUsers("dbs/" + databaseId, String.format("SELECT * FROM root r where r.id = '%s'", userId), null) - .toBlocking().single().getResults(); - if (!res.isEmpty()) { - deleteUser(client, com.microsoft.azure.cosmosdb.rx.Utils.getUserNameLink(databaseId, userId)); - } - } - - public static void deleteUser(AsyncDocumentClient client, String userLink) { - client.deleteUser(userLink, null).toBlocking().single(); - } - - public static String getDatabaseLink(Database database) { - return database.getSelfLink(); - } - - static private Database safeCreateDatabase(AsyncDocumentClient client, Database database) { - safeDeleteDatabase(client, database.getId()); - return createDatabase(client, database); - } - - static protected Database createDatabase(AsyncDocumentClient client, Database database) { - Observable> databaseObservable = client.createDatabase(database, null); - return databaseObservable.toBlocking().single().getResource(); - } - - static protected Database createDatabase(AsyncDocumentClient client, String databaseId) { - Database databaseDefinition = new Database(); - databaseDefinition.setId(databaseId); - return createDatabase(client, databaseDefinition); - } - - static protected Database createDatabaseIfNotExists(AsyncDocumentClient client, String databaseId) { - return client.queryDatabases(String.format("SELECT * FROM r where r.id = '%s'", databaseId), null).flatMap(p -> Observable.from(p.getResults())).switchIfEmpty( - Observable.defer(() -> { - - Database databaseDefinition = new Database(); - databaseDefinition.setId(databaseId); - - return client.createDatabase(databaseDefinition, null).map(ResourceResponse::getResource); - }) - ).toBlocking().single(); - } - - static protected void safeDeleteDatabase(AsyncDocumentClient client, Database database) { - if (database != null) { - safeDeleteDatabase(client, database.getId()); - } - } - - static protected void safeDeleteDatabase(AsyncDocumentClient client, String databaseId) { - if (client != null) { - try { - client.deleteDatabase(com.microsoft.azure.cosmosdb.rx.Utils.getDatabaseNameLink(databaseId), null).toBlocking().single(); - } catch (Exception e) { - } - } - } - - static protected void safeDeleteAllCollections(AsyncDocumentClient client, Database database) { - if (database != null) { - List collections = client.readCollections(database.getSelfLink(), null) - .flatMap(p -> Observable.from(p.getResults())) - .toList() - .toBlocking() - .single(); - - for(DocumentCollection collection: collections) { - client.deleteCollection(collection.getSelfLink(), null).toBlocking().single().getResource(); - } - } - } - - static protected void safeDeleteCollection(AsyncDocumentClient client, DocumentCollection collection) { - if (client != null && collection != null) { - try { - client.deleteCollection(collection.getSelfLink(), null).toBlocking().single(); - } catch (Exception e) { - } - } - } - - static protected void safeDeleteCollection(AsyncDocumentClient client, String databaseId, String collectionId) { - if (client != null && databaseId != null && collectionId != null) { - try { - client.deleteCollection("/dbs/" + databaseId + "/colls/" + collectionId, null).toBlocking().single(); - } catch (Exception e) { - } - } - } - - static protected void safeClose(AsyncDocumentClient client) { - if (client != null) { - try { - client.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - - public void validateSuccess(Observable> observable, - ResourceResponseValidator validator) { - validateSuccess(observable, validator, subscriberValidationTimeout); - } - - public static void validateSuccess(Observable> observable, - ResourceResponseValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - testSubscriber.assertValueCount(1); - validator.validate(testSubscriber.getOnNextEvents().get(0)); - } - - public void validateFailure(Observable> observable, - FailureValidator validator) { - validateFailure(observable, validator, subscriberValidationTimeout); - } - - public static void validateFailure(Observable> observable, - FailureValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - public void validateQuerySuccess(Observable> observable, - FeedResponseListValidator validator) { - validateQuerySuccess(observable, validator, subscriberValidationTimeout); - } - - public static void validateQuerySuccess(Observable> observable, - FeedResponseListValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNoErrors(); - testSubscriber.assertCompleted(); - validator.validate(testSubscriber.getOnNextEvents()); - } - - public void validateQueryFailure(Observable> observable, - FailureValidator validator) { - validateQueryFailure(observable, validator, subscriberValidationTimeout); - } - - public static void validateQueryFailure(Observable> observable, - FailureValidator validator, long timeout) { - - VerboseTestSubscriber> testSubscriber = new VerboseTestSubscriber<>(); - - observable.subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(timeout, TimeUnit.MILLISECONDS); - testSubscriber.assertNotCompleted(); - testSubscriber.assertTerminalEvent(); - assertThat(testSubscriber.getOnErrorEvents()).hasSize(1); - validator.validate(testSubscriber.getOnErrorEvents().get(0)); - } - - @DataProvider - public static Object[][] clientBuilders() { - return new Object[][] { { createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null) } }; - } - - @DataProvider - public static Object[][] clientBuildersWithSessionConsistency() { - return new Object[][] { - { createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null) }, - { createDirectRxDocumentClient(ConsistencyLevel.Session, Protocol.Https, false, null) }, - { createDirectRxDocumentClient(ConsistencyLevel.Session, Protocol.Tcp, false, null) } - }; - } - - private static ConsistencyLevel parseConsistency(String consistency) { - if (consistency != null) { - for (ConsistencyLevel consistencyLevel : ConsistencyLevel.values()) { - if (consistencyLevel.name().toLowerCase().equals(consistency.toLowerCase())) { - return consistencyLevel; - } - } - } - - logger.error("Invalid configured test consistency [{}].", consistency); - throw new IllegalStateException("Invalid configured test consistency " + consistency); - } - - private static List parsePreferredLocation(String preferredLocations) { - if (StringUtils.isEmpty(preferredLocations)) { - return null; - } - - try { - return objectMapper.readValue(preferredLocations, new TypeReference>(){}); - } catch (Exception e) { - logger.error("Invalid configured test preferredLocations [{}].", preferredLocations); - throw new IllegalStateException("Invalid configured test preferredLocations " + preferredLocations); - } - } - - @DataProvider - public static Object[][] simpleClientBuildersWithDirect() { - return simpleClientBuildersWithDirect(Protocol.Https, Protocol.Tcp); - } - - @DataProvider - public static Object[][] simpleClientBuildersWithDirectHttps() { - return simpleClientBuildersWithDirect(Protocol.Https); - } - - @DataProvider - public static Object[][] simpleClientBuildersWithDirectTcp() { - return simpleClientBuildersWithDirect(Protocol.Tcp); - } - - private static Object[][] simpleClientBuildersWithDirect(Protocol... protocols) { - - accountConsistency = parseConsistency(TestConfigurations.CONSISTENCY); - logger.info("Max test consistency to use is [{}]", accountConsistency); - List testConsistencies = new ArrayList<>(); - - switch (accountConsistency) { - case Strong: - case BoundedStaleness: - case Session: - case ConsistentPrefix: - case Eventual: - testConsistencies.add(ConsistencyLevel.Eventual); - break; - default: - throw new IllegalStateException("Invalid configured test consistency " + accountConsistency); - } - - List preferredLocation = parsePreferredLocation(TestConfigurations.PREFERRED_LOCATIONS); - boolean isMultiMasterEnabled = preferredLocation != null && accountConsistency == ConsistencyLevel.Session; - - List builders = new ArrayList<>(); - builders.add(createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null)); - - for (Protocol protocol : protocols) { - testConsistencies.forEach(consistencyLevel -> builders.add(createDirectRxDocumentClient(consistencyLevel, - protocol, - isMultiMasterEnabled, - preferredLocation))); - } - - builders.forEach(b -> logger.info("Will Use ConnectionMode [{}], Consistency [{}], Protocol [{}]", - b.getConnectionPolicy().getConnectionMode(), - b.getDesiredConsistencyLevel(), - b.getConfigs().getProtocol() - )); - - return builders.stream().map(b -> new Object[]{b}).collect(Collectors.toList()).toArray(new Object[0][]); - } - - @DataProvider - public static Object[][] clientBuildersWithDirect() { - return clientBuildersWithDirectAllConsistencies(Protocol.Https, Protocol.Tcp); - } - - @DataProvider - public static Object[][] clientBuildersWithDirectHttps() { - return clientBuildersWithDirectAllConsistencies(Protocol.Https); - } - - @DataProvider - public static Object[][] clientBuildersWithDirectTcp() { - return clientBuildersWithDirectAllConsistencies(Protocol.Tcp); - } - - @DataProvider - public static Object[][] clientBuildersWithDirectSession() { - return clientBuildersWithDirectSession(Protocol.Https, Protocol.Tcp); - } - - private static Object[][] clientBuildersWithDirectSession(Protocol... protocols) { - return clientBuildersWithDirect(new ArrayList(){{add(ConsistencyLevel.Session);}} , protocols); - } - - private static Object[][] clientBuildersWithDirectAllConsistencies(Protocol... protocols) { - accountConsistency = parseConsistency(TestConfigurations.CONSISTENCY); - logger.info("Max test consistency to use is [{}]", accountConsistency); - List testConsistencies = new ArrayList<>(); - - switch (accountConsistency) { - case Strong: - testConsistencies.add(ConsistencyLevel.Strong); - case BoundedStaleness: - testConsistencies.add(ConsistencyLevel.BoundedStaleness); - case Session: - testConsistencies.add(ConsistencyLevel.Session); - case ConsistentPrefix: - testConsistencies.add(ConsistencyLevel.ConsistentPrefix); - case Eventual: - testConsistencies.add(ConsistencyLevel.Eventual); - break; - default: - throw new IllegalStateException("Invalid configured test consistency " + accountConsistency); - } - return clientBuildersWithDirect(testConsistencies, protocols); - } - - private static Object[][] clientBuildersWithDirect(List testConsistencies, Protocol... protocols) { - - List preferredLocation = parsePreferredLocation(TestConfigurations.PREFERRED_LOCATIONS); - boolean isMultiMasterEnabled = preferredLocation != null && accountConsistency == ConsistencyLevel.Session; - - List builders = new ArrayList<>(); - builders.add(createGatewayRxDocumentClient(ConsistencyLevel.Session, isMultiMasterEnabled, preferredLocation)); - - for (Protocol protocol : protocols) { - testConsistencies.forEach(consistencyLevel -> builders.add(createDirectRxDocumentClient(consistencyLevel, - protocol, - isMultiMasterEnabled, - preferredLocation))); - } - - builders.forEach(b -> logger.info("Will Use ConnectionMode [{}], Consistency [{}], Protocol [{}]", - b.getConnectionPolicy().getConnectionMode(), - b.getDesiredConsistencyLevel(), - b.getConfigs().getProtocol() - )); - - return builders.stream().map(b -> new Object[]{b}).collect(Collectors.toList()).toArray(new Object[0][]); - } - - static protected AsyncDocumentClient.Builder createGatewayHouseKeepingDocumentClient() { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - RetryOptions options = new RetryOptions(); - options.setMaxRetryWaitTimeInSeconds(SUITE_SETUP_TIMEOUT); - connectionPolicy.setRetryOptions(options); - return new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(ConsistencyLevel.Session); - } - - static protected AsyncDocumentClient.Builder createGatewayRxDocumentClient(ConsistencyLevel consistencyLevel, boolean multiMasterEnabled, List preferredLocations) { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Gateway); - connectionPolicy.setUsingMultipleWriteLocations(multiMasterEnabled); - connectionPolicy.setPreferredLocations(preferredLocations); - return new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(consistencyLevel); - } - - static protected AsyncDocumentClient.Builder createGatewayRxDocumentClient() { - return createGatewayRxDocumentClient(ConsistencyLevel.Session, false, null); - } - - static protected AsyncDocumentClient.Builder createDirectRxDocumentClient(ConsistencyLevel consistencyLevel, - Protocol protocol, - boolean multiMasterEnabled, - List preferredLocations) { - ConnectionPolicy connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setConnectionMode(ConnectionMode.Direct); - - if (preferredLocations != null) { - connectionPolicy.setPreferredLocations(preferredLocations); - } - - if (multiMasterEnabled && consistencyLevel == ConsistencyLevel.Session) { - connectionPolicy.setUsingMultipleWriteLocations(true); - } - - Configs configs = spy(new Configs()); - doAnswer((Answer) invocation -> protocol).when(configs).getProtocol(); - - return new AsyncDocumentClient.Builder().withServiceEndpoint(TestConfigurations.HOST) - .withMasterKeyOrResourceToken(TestConfigurations.MASTER_KEY) - .withConnectionPolicy(connectionPolicy) - .withConsistencyLevel(consistencyLevel) - .withConfigs(configs); - } - - protected int expectedNumberOfPages(int totalExpectedResult, int maxPageSize) { - return Math.max((totalExpectedResult + maxPageSize - 1 ) / maxPageSize, 1); - } - - @DataProvider(name = "queryMetricsArgProvider") - public Object[][] queryMetricsArgProvider() { - return new Object[][]{ - {true}, - {false}, - }; - } - - public static class VerboseTestSubscriber extends TestSubscriber { - @Override - public void assertNoErrors() { - List onErrorEvents = getOnErrorEvents(); - StringBuilder errorMessageBuilder = new StringBuilder(); - if (!onErrorEvents.isEmpty()) { - for(Throwable throwable : onErrorEvents) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - throwable.printStackTrace(pw); - String sStackTrace = sw.toString(); // stack trace as a string - errorMessageBuilder.append(sStackTrace); - } - - AssertionError ae = new AssertionError(errorMessageBuilder.toString()); - throw ae; - } - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/GlobalAddressResolverTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/GlobalAddressResolverTest.java deleted file mode 100644 index badd57df6db5..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/GlobalAddressResolverTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.directconnectivity; - - -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.DocumentCollection; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.OperationType; -import com.microsoft.azure.cosmosdb.internal.ResourceType; -import com.microsoft.azure.cosmosdb.internal.UserAgentContainer; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GatewayAddressCache; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.GatewayServiceConfigurationReader; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.Protocol; -import com.microsoft.azure.cosmosdb.internal.routing.CollectionRoutingMap; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyInternalHelper; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.rx.internal.GlobalEndpointManager; -import com.microsoft.azure.cosmosdb.rx.internal.IAuthorizationTokenProvider; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxCollectionCache; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxPartitionKeyRangeCache; -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import org.apache.commons.collections4.list.UnmodifiableList; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import rx.Completable; -import rx.Single; -import rx.functions.Action0; - -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GlobalAddressResolverTest { - - private CompositeHttpClient httpClient; - private GlobalEndpointManager endpointManager; - private IAuthorizationTokenProvider authorizationTokenProvider; - private UserAgentContainer userAgentContainer; - private RxCollectionCache collectionCache; - private GatewayServiceConfigurationReader serviceConfigReader; - private RxPartitionKeyRangeCache routingMapProvider; - private ConnectionPolicy connectionPolicy; - private URL urlforRead1; - private URL urlforRead2; - private URL urlforRead3; - - private URL urlforWrite1; - private URL urlforWrite2; - private URL urlforWrite3; - - @BeforeClass(groups = "unit") - public void setup() throws Exception { - urlforRead1 = new URL("http://testRead1.com/"); - urlforRead2 = new URL("http://testRead2.com/"); - urlforRead3 = new URL("http://testRead3.com/"); - urlforWrite1 = new URL("http://testWrite1.com/"); - urlforWrite2 = new URL("http://testWrite2.com/"); - urlforWrite3 = new URL("http://testWrite3.com/"); - - connectionPolicy = new ConnectionPolicy(); - connectionPolicy.setEnableReadRequestsFallback(true); - httpClient = Mockito.mock(CompositeHttpClient.class); - endpointManager = Mockito.mock(GlobalEndpointManager.class); - - List readEndPointList = new ArrayList<>(); - readEndPointList.add(urlforRead1); - readEndPointList.add(urlforRead2); - readEndPointList.add(urlforRead3); - UnmodifiableList readList = new UnmodifiableList(readEndPointList); - - List writeEndPointList = new ArrayList<>(); - writeEndPointList.add(urlforWrite1); - writeEndPointList.add(urlforWrite2); - writeEndPointList.add(urlforWrite3); - UnmodifiableList writeList = new UnmodifiableList(writeEndPointList); - - Mockito.when(endpointManager.getReadEndpoints()).thenReturn(readList); - Mockito.when(endpointManager.getWriteEndpoints()).thenReturn(writeList); - - authorizationTokenProvider = Mockito.mock(IAuthorizationTokenProvider.class); - - DocumentCollection collectionDefinition = new DocumentCollection(); - collectionDefinition.setId(UUID.randomUUID().toString()); - collectionCache = Mockito.mock(RxCollectionCache.class); - Mockito.when(collectionCache.resolveCollectionAsync(Matchers.any(RxDocumentServiceRequest.class))).thenReturn(Single.just(collectionDefinition)); - routingMapProvider = Mockito.mock(RxPartitionKeyRangeCache.class); - userAgentContainer = Mockito.mock(UserAgentContainer.class); - serviceConfigReader = Mockito.mock(GatewayServiceConfigurationReader.class); - - } - - @Test(groups = "unit") - public void resolveAsync() throws Exception { - - GlobalAddressResolver globalAddressResolver = new GlobalAddressResolver(httpClient, endpointManager, Protocol.Https, authorizationTokenProvider, collectionCache, routingMapProvider, - userAgentContainer, - serviceConfigReader, connectionPolicy); - RxDocumentServiceRequest request; - request = RxDocumentServiceRequest.createFromName( - OperationType.Read, - "dbs/db/colls/coll/docs/doc1", - ResourceType.Document); - - Set urlsBeforeResolve = globalAddressResolver.addressCacheByEndpoint.keySet(); - assertThat(urlsBeforeResolve.size()).isEqualTo(5); - assertThat(urlsBeforeResolve.contains(urlforRead3)).isFalse();//Last read will be removed from addressCacheByEndpoint after 5 endpoints - assertThat(urlsBeforeResolve.contains(urlforRead2)).isTrue(); - - URL testUrl = new URL("http://Test.com/"); - Mockito.when(endpointManager.resolveServiceEndpoint(Matchers.any(RxDocumentServiceRequest.class))).thenReturn(testUrl); - globalAddressResolver.resolveAsync(request, true); - Set urlsAfterResolve = globalAddressResolver.addressCacheByEndpoint.keySet(); - assertThat(urlsAfterResolve.size()).isEqualTo(5); - assertThat(urlsAfterResolve.contains(urlforRead2)).isFalse();//Last read will be removed from addressCacheByEndpoint after 5 endpoints - assertThat(urlsBeforeResolve.contains(testUrl)).isTrue();//New endpoint will be added in addressCacheByEndpoint - } - - @Test(groups = "unit") - public void openAsync() throws Exception { - GlobalAddressResolver globalAddressResolver = new GlobalAddressResolver(httpClient, endpointManager, Protocol.Https, authorizationTokenProvider, collectionCache, routingMapProvider, - userAgentContainer, - serviceConfigReader, connectionPolicy); - Map addressCacheByEndpoint = Mockito.spy(globalAddressResolver.addressCacheByEndpoint); - GlobalAddressResolver.EndpointCache endpointCache = new GlobalAddressResolver.EndpointCache(); - GatewayAddressCache gatewayAddressCache = Mockito.mock(GatewayAddressCache.class); - AtomicInteger numberOfTaskCompleted = new AtomicInteger(0); - endpointCache.addressCache = gatewayAddressCache; - globalAddressResolver.addressCacheByEndpoint.clear(); - globalAddressResolver.addressCacheByEndpoint.put(urlforRead1, endpointCache); - globalAddressResolver.addressCacheByEndpoint.put(urlforRead2, endpointCache); - - - DocumentCollection documentCollection = new DocumentCollection(); - documentCollection.setId("TestColl"); - documentCollection.setResourceId("IXYFAOHEBPM="); - CollectionRoutingMap collectionRoutingMap = Mockito.mock(CollectionRoutingMap.class); - PartitionKeyRange range = new PartitionKeyRange("0", PartitionKeyInternalHelper.MinimumInclusiveEffectivePartitionKey, - PartitionKeyInternalHelper.MaximumExclusiveEffectivePartitionKey); - List partitionKeyRanges = new ArrayList<>(); - partitionKeyRanges.add(range); - Mockito.when(collectionRoutingMap.getOrderedPartitionKeyRanges()).thenReturn(partitionKeyRanges); - Single collectionRoutingMapSingle = Single.just(collectionRoutingMap); - Mockito.when(routingMapProvider.tryLookupAsync(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(collectionRoutingMapSingle); - - List ranges = new ArrayList<>(); - for (PartitionKeyRange partitionKeyRange : (List) collectionRoutingMap.getOrderedPartitionKeyRanges()) { - PartitionKeyRangeIdentity partitionKeyRangeIdentity = new PartitionKeyRangeIdentity(documentCollection.getResourceId(), partitionKeyRange.getId()); - ranges.add(partitionKeyRangeIdentity); - } - Completable completable = Completable.fromAction(new Action0() { - @Override - public void call() { - numberOfTaskCompleted.getAndIncrement(); - } - }); - Mockito.when(gatewayAddressCache.openAsync(documentCollection, ranges)).thenReturn(completable); - - globalAddressResolver.openAsync(documentCollection).await(); - assertThat(numberOfTaskCompleted.get()).isEqualTo(2); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/ReflectionUtils.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/ReflectionUtils.java deleted file mode 100644 index 944089112f01..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/directconnectivity/ReflectionUtils.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.directconnectivity; - -import com.microsoft.azure.cosmosdb.internal.directconnectivity.HttpTransportClient; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.ServerStoreModel; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.StoreClient; -import com.microsoft.azure.cosmosdb.internal.directconnectivity.TransportClient; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentClientImpl; -import io.netty.buffer.ByteBuf; -import io.reactivex.netty.protocol.http.client.CompositeHttpClient; -import org.apache.commons.lang3.reflect.FieldUtils; - -/** - * - * TransportClient transportClient = ReflectionUtils.getDirectHttpsHttpClient(documentClient); - * TransportClient spyTransportClient = Mockito.spy(transportClient); - * ReflectionUtils.setTransportClient(documentClient, spyTransportClient); - * - * // use the documentClient - * // do assertion on the request and response spyTransportClient recieves using Mockito - */ -public class ReflectionUtils { - - private static void set(Object object, T newValue, String fieldName) { - try { - FieldUtils.writeField(object, fieldName, newValue, true); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - private static T get(Class klass, Object object, String fieldName) { - try { - return (T) FieldUtils.readField(object, fieldName, true); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public static ServerStoreModel getServerStoreModel(RxDocumentClientImpl client) { - return get(ServerStoreModel.class, client, "storeModel"); - } - - public static StoreClient getStoreClient(RxDocumentClientImpl client) { - ServerStoreModel serverStoreModel = getServerStoreModel(client); - return get(StoreClient.class, serverStoreModel, "storeClient"); - } - - public static TransportClient getTransportClient(RxDocumentClientImpl client) { - StoreClient storeClient = getStoreClient(client); - return get(TransportClient.class, storeClient, "transportClient"); - } - - public static void setTransportClient(RxDocumentClientImpl client, TransportClient transportClient) { - StoreClient storeClient = getStoreClient(client); - set(storeClient, transportClient, "transportClient"); - } - - public static CompositeHttpClient getDirectHttpsHttpClient(RxDocumentClientImpl client) { - TransportClient transportClient = getTransportClient(client); - assert transportClient instanceof HttpTransportClient; - return get(CompositeHttpClient.class, transportClient, "httpClient"); - } - - public static void setDirectHttpsHttpClient(RxDocumentClientImpl client, CompositeHttpClient newHttpClient) { - TransportClient transportClient = getTransportClient(client); - assert transportClient instanceof HttpTransportClient; - set(transportClient, newHttpClient, "httpClient"); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentProducerTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentProducerTest.java deleted file mode 100644 index 479fe761b0cc..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/DocumentProducerTest.java +++ /dev/null @@ -1,1076 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.collect.LinkedListMultimap; -import com.microsoft.azure.cosmosdb.ConnectionPolicy; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.DocumentClientException; -import com.microsoft.azure.cosmosdb.Error; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.PartitionKeyRange; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.internal.query.QueryItem; -import com.microsoft.azure.cosmosdb.internal.query.SortOrder; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderByRowResult; -import com.microsoft.azure.cosmosdb.internal.query.orderbyquery.OrderbyRowComparer; -import com.microsoft.azure.cosmosdb.internal.routing.PartitionKeyRangeIdentity; -import com.microsoft.azure.cosmosdb.internal.routing.Range; -import com.microsoft.azure.cosmosdb.rx.internal.GlobalEndpointManager; -import com.microsoft.azure.cosmosdb.rx.internal.IRetryPolicyFactory; -import com.microsoft.azure.cosmosdb.rx.internal.RetryPolicy; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; -import com.microsoft.azure.cosmosdb.rx.internal.caches.RxPartitionKeyRangeCache; -import org.apache.commons.lang3.RandomUtils; -import org.mockito.Matchers; -import org.mockito.Mockito; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import rx.Observable; -import rx.Single; -import rx.functions.Func1; -import rx.functions.Func3; -import rx.observers.TestSubscriber; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.BiFunction; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; - -public class DocumentProducerTest { - private final static Logger logger = LoggerFactory.getLogger(DocumentProducerTest.class); - private static final long TIMEOUT = 10000; - private final static String OrderByPayloadFieldName = "payload"; - private final static String OrderByItemsFieldName = "orderByItems"; - - private final static String OrderByIntFieldName = "propInt"; - private final static String DocumentPartitionKeyRangeIdFieldName = "_pkrId"; - private final static String DocumentPartitionKeyRangeMinInclusiveFieldName = "_pkrMinInclusive"; - private final static String DocumentPartitionKeyRangeMaxExclusiveFieldName = "_pkrMaxExclusive"; - - private final String collectionRid = "myrid"; - private final String collectionLink = "/dbs/mydb/colls/mycol"; - - @DataProvider(name = "splitParamProvider") - public Object[][] splitParamProvider() { - return new Object[][] { - // initial continuation token, - // # pages from parent before split, - // # pages from left child after split, - // # pages from right child after split - { "init-cp", 10, 5, 6 }, - { null, 10, 5, 6 }, - { null, 1000, 500, 600 }, - { "init-cp", 1000, 500, 600 }, - { "init-cp", 0, 10, 12 }, - { null, 0, 10, 12 }, - { null, 0, 1, 1 }, - { null, 10, 1, 1 }, - }; - } - - private IRetryPolicyFactory mockDocumentClientIRetryPolicyFactory() { - URL url; - try { - url = new URL("http://localhost"); - } catch (Exception e) { - throw new IllegalStateException(e); - } - - GlobalEndpointManager globalEndpointManager = Mockito.mock(GlobalEndpointManager.class); - Mockito.doReturn(url).when(globalEndpointManager).resolveServiceEndpoint(Mockito.any(RxDocumentServiceRequest.class)); - doReturn(false).when(globalEndpointManager).isClosed(); - return new RetryPolicy(globalEndpointManager, ConnectionPolicy.GetDefault()); - } - - @Test(groups = { "unit" }, dataProvider = "splitParamProvider", timeOut = TIMEOUT) - public void partitionSplit(String initialContinuationToken, - int numberOfResultPagesFromParentBeforeSplit, - int numberOfResultPagesFromLeftChildAfterSplit, - int numberOfResultPagesFromRightChildAfterSplit) { - int initialPageSize = 7; - int top = -1; - - String parentPartitionId = "1"; - String leftChildPartitionId = "2"; - String rightChildPartitionId = "3"; - - List> resultFromParentPartition = mockFeedResponses(parentPartitionId, numberOfResultPagesFromParentBeforeSplit, 3, false); - List> resultFromLeftChildPartition = mockFeedResponses(leftChildPartitionId, numberOfResultPagesFromLeftChildAfterSplit, 3, true); - List> resultFromRightChildPartition = mockFeedResponses(rightChildPartitionId, numberOfResultPagesFromRightChildAfterSplit, 3, true); - - // sanity check - sanityCheckSplitValidation(parentPartitionId, leftChildPartitionId, rightChildPartitionId, - numberOfResultPagesFromParentBeforeSplit, - numberOfResultPagesFromLeftChildAfterSplit, - numberOfResultPagesFromRightChildAfterSplit, - resultFromParentPartition, resultFromLeftChildPartition, resultFromRightChildPartition); - - // setting up behaviour - RequestExecutor.PartitionAnswer answerFromParentPartition = RequestExecutor.PartitionAnswer.just(parentPartitionId, resultFromParentPartition); - RequestExecutor.PartitionAnswer splitAnswerFromParentPartition = RequestExecutor.PartitionAnswer.alwaysPartitionSplit(parentPartitionId); - - RequestExecutor.PartitionAnswer answerFromLeftChildPartition = RequestExecutor.PartitionAnswer.just(leftChildPartitionId, resultFromLeftChildPartition); - RequestExecutor.PartitionAnswer answerFromRightChildPartition = RequestExecutor.PartitionAnswer.just(rightChildPartitionId, resultFromRightChildPartition); - - RequestCreator requestCreator = RequestCreator.simpleMock(); - RequestExecutor requestExecutor = RequestExecutor. - fromPartitionAnswer(ImmutableList.of(answerFromParentPartition, splitAnswerFromParentPartition, - answerFromLeftChildPartition, answerFromRightChildPartition)); - - PartitionKeyRange parentPartitionKeyRange = mockPartitionKeyRange(parentPartitionId); - PartitionKeyRange leftChildPartitionKeyRange = mockPartitionKeyRange(leftChildPartitionId); - PartitionKeyRange rightChildPartitionKeyRange = mockPartitionKeyRange(rightChildPartitionId); - - // this returns replacement ranges upon split detection - IDocumentQueryClient queryClient = mockQueryClient(ImmutableList.of(leftChildPartitionKeyRange, rightChildPartitionKeyRange)); - - DocumentProducer documentProducer = new DocumentProducer( - queryClient, - collectionRid, - null, - requestCreator, - requestExecutor, - parentPartitionKeyRange, - collectionLink, - () -> mockDocumentClientIRetryPolicyFactory().getRequestPolicy(), - Document.class, - null, - initialPageSize, - initialContinuationToken, - top); - - TestSubscriber.DocumentProducerFeedResponse> subscriber = new TestSubscriber<>(); - - documentProducer.produceAsync().subscribe(subscriber); - subscriber.awaitTerminalEvent(); - - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - - validateSplitCaptureRequests( - requestCreator.invocations, - initialContinuationToken, - parentPartitionId, - leftChildPartitionId, - rightChildPartitionId, - resultFromParentPartition, - resultFromLeftChildPartition, - resultFromRightChildPartition); - - // page size match - assertThat(requestCreator.invocations.stream().map(i -> i.maxItemCount) - .distinct().collect(Collectors.toList())).containsExactlyElementsOf(Collections.singleton(initialPageSize)); - - // expected results - validateSplitResults(subscriber.getOnNextEvents(), parentPartitionId, leftChildPartitionId, rightChildPartitionId, resultFromParentPartition, - resultFromLeftChildPartition, resultFromRightChildPartition, false); - - Mockito.verify(queryClient, times(1)).getPartitionKeyRangeCache(); - } - - @Test(groups = { "unit" }, dataProvider = "splitParamProvider", timeOut = TIMEOUT) - public void orderByPartitionSplit(String initialContinuationToken, - int numberOfResultPagesFromParentBeforeSplit, - int numberOfResultPagesFromLeftChildAfterSplit, - int numberOfResultPagesFromRightChildAfterSplit) { - int initialPageSize = 7; - int top = -1; - - String parentPartitionId = "1"; - String leftChildPartitionId = "2"; - String rightChildPartitionId = "3"; - - Integer initialPropVal = 1; - List> resultFromParentPartition = mockFeedResponses( - parentPartitionId, numberOfResultPagesFromParentBeforeSplit, 3, initialPropVal, false); - Integer highestValInParentPage = getLastValueInAsc(initialPropVal, resultFromParentPartition); - - List> resultFromLeftChildPartition = mockFeedResponses(leftChildPartitionId, - numberOfResultPagesFromLeftChildAfterSplit, 3, highestValInParentPage,true); - - List> resultFromRightChildPartition = mockFeedResponses(rightChildPartitionId, - numberOfResultPagesFromRightChildAfterSplit, 3, highestValInParentPage,true); - - // sanity check - sanityCheckSplitValidation(parentPartitionId, leftChildPartitionId, rightChildPartitionId, - numberOfResultPagesFromParentBeforeSplit, - numberOfResultPagesFromLeftChildAfterSplit, - numberOfResultPagesFromRightChildAfterSplit, - resultFromParentPartition, resultFromLeftChildPartition, resultFromRightChildPartition); - - // setting up behaviour - RequestExecutor.PartitionAnswer answerFromParentPartition = RequestExecutor.PartitionAnswer.just( - parentPartitionId, resultFromParentPartition); - RequestExecutor.PartitionAnswer splitAnswerFromParentPartition = RequestExecutor - .PartitionAnswer.alwaysPartitionSplit(parentPartitionId); - - RequestExecutor.PartitionAnswer answerFromLeftChildPartition = RequestExecutor.PartitionAnswer.just(leftChildPartitionId, resultFromLeftChildPartition); - RequestExecutor.PartitionAnswer answerFromRightChildPartition = RequestExecutor.PartitionAnswer.just(rightChildPartitionId, resultFromRightChildPartition); - - RequestCreator requestCreator = RequestCreator.simpleMock(); - RequestExecutor requestExecutor = RequestExecutor. - fromPartitionAnswer(ImmutableList.of(answerFromParentPartition, splitAnswerFromParentPartition, - answerFromLeftChildPartition, answerFromRightChildPartition)); - - PartitionKeyRange parentPartitionKeyRange = mockPartitionKeyRange(parentPartitionId); - PartitionKeyRange leftChildPartitionKeyRange = mockPartitionKeyRange(leftChildPartitionId); - PartitionKeyRange rightChildPartitionKeyRange = mockPartitionKeyRange(rightChildPartitionId); - - // this returns replacement ranges upon split detection - IDocumentQueryClient queryCl = mockQueryClient( - ImmutableList.of(leftChildPartitionKeyRange, rightChildPartitionKeyRange)); - - OrderByDocumentProducer documentProducer = new OrderByDocumentProducer<>( - new OrderbyRowComparer<>(ImmutableList.of(SortOrder.Ascending)), - queryCl, - collectionRid, - null, - requestCreator, - requestExecutor, - parentPartitionKeyRange, - collectionLink, - null, - Document.class, - null, - initialPageSize, - initialContinuationToken, - top, - /*targetRangeToOrderByContinuationTokenMap*/new HashMap<>()); - - TestSubscriber.DocumentProducerFeedResponse> subscriber = new TestSubscriber<>(); - - documentProducer.produceAsync().subscribe(subscriber); - subscriber.awaitTerminalEvent(); - - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - - validateSplitCaptureRequests( - requestCreator.invocations, - initialContinuationToken, - parentPartitionId, - leftChildPartitionId, - rightChildPartitionId, - resultFromParentPartition, - resultFromLeftChildPartition, - resultFromRightChildPartition); - - // page size match - assertThat(requestCreator.invocations.stream().map(i -> i.maxItemCount) - .distinct().collect(Collectors.toList())).containsExactlyElementsOf(Collections.singleton(initialPageSize)); - - // expected results - validateSplitResults(subscriber.getOnNextEvents(), - parentPartitionId, - leftChildPartitionId, - rightChildPartitionId, - resultFromParentPartition, - resultFromLeftChildPartition, resultFromRightChildPartition, true); - - Mockito.verify(queryCl, times(1)).getPartitionKeyRangeCache(); - } - - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void simple() { - int initialPageSize = 7; - int top = -1; - - String partitionId = "1"; - - List requests = new ArrayList<>(); - for(int i = 0; i < 10; i++) { - requests.add(mockRequest(partitionId)); - } - - List> responses = mockFeedResponses(partitionId, 10, 3, true); - - RequestCreator requestCreator = RequestCreator.give(requests); - RequestExecutor requestExecutor = RequestExecutor.fromPartitionAnswer( - RequestExecutor.PartitionAnswer.just("1", responses)); - - PartitionKeyRange targetRange = mockPartitionKeyRange(partitionId); - - IDocumentQueryClient queryClient = Mockito.mock(IDocumentQueryClient.class); - String initialContinuationToken = "initial-cp"; - DocumentProducer documentProducer = new DocumentProducer<>( - queryClient, - collectionRid, - null, - requestCreator, - requestExecutor, - targetRange, - collectionLink, - () -> mockDocumentClientIRetryPolicyFactory().getRequestPolicy(), - Document.class, - null, - initialPageSize, - initialContinuationToken, - top); - - TestSubscriber subscriber = new TestSubscriber<>(); - - documentProducer.produceAsync().subscribe(subscriber); - subscriber.awaitTerminalEvent(); - - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - - subscriber.assertValueCount(responses.size()); - - // requests match - assertThat(requestCreator.invocations.stream().map(i -> i.invocationResult) - .collect(Collectors.toList())).containsExactlyElementsOf(requests); - - // requested max page size match - assertThat(requestCreator.invocations.stream().map(i -> i.maxItemCount) - .distinct().collect(Collectors.toList())).containsExactlyElementsOf(Collections.singleton(7)); - - // continuation tokens - assertThat(requestCreator.invocations.get(0).continuationToken).isEqualTo(initialContinuationToken); - assertThat(requestCreator.invocations.stream().skip(1).map(i -> i.continuationToken) - .collect(Collectors.toList())).containsExactlyElementsOf( - responses.stream().limit(9).map(r -> r.getResponseContinuation()).collect(Collectors.toList())); - - // source partition - assertThat(requestCreator.invocations.stream().map(i -> i.sourcePartition).distinct() - .collect(Collectors.toList())).containsExactlyElementsOf(Collections.singletonList(targetRange)); - } - - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void retries() { - int initialPageSize = 7; - int top = -1; - - String partitionKeyRangeId = "1"; - - RequestCreator requestCreator = RequestCreator.simpleMock(); - - List> responsesBeforeThrottle = mockFeedResponses(partitionKeyRangeId, 2, 1, false); - Exception throttlingException = mockThrottlingException(10); - List> responsesAfterThrottle = mockFeedResponses(partitionKeyRangeId, 5, 1, true); - - RequestExecutor.PartitionAnswer behaviourBeforeException = RequestExecutor.PartitionAnswer.just(partitionKeyRangeId, responsesBeforeThrottle); - RequestExecutor.PartitionAnswer exceptionBehaviour = RequestExecutor.PartitionAnswer.errors(partitionKeyRangeId, Collections.singletonList(throttlingException)); - RequestExecutor.PartitionAnswer behaviourAfterException = RequestExecutor.PartitionAnswer.just(partitionKeyRangeId, responsesAfterThrottle); - - RequestExecutor requestExecutor = RequestExecutor.fromPartitionAnswer(behaviourBeforeException, exceptionBehaviour, behaviourAfterException); - - PartitionKeyRange targetRange = mockPartitionKeyRange(partitionKeyRangeId); - - IDocumentQueryClient queryClient = Mockito.mock(IDocumentQueryClient.class); - String initialContinuationToken = "initial-cp"; - DocumentProducer documentProducer = new DocumentProducer<>( - queryClient, - collectionRid, - null, - requestCreator, - requestExecutor, - targetRange, - collectionLink, - () -> mockDocumentClientIRetryPolicyFactory().getRequestPolicy(), - Document.class, - null, - initialPageSize, - initialContinuationToken, - top); - - TestSubscriber subscriber = new TestSubscriber<>(); - - documentProducer.produceAsync().subscribe(subscriber); - subscriber.awaitTerminalEvent(); - - subscriber.assertNoErrors(); - subscriber.assertCompleted(); - - subscriber.assertValueCount(responsesBeforeThrottle.size() + responsesAfterThrottle.size()); - - // requested max page size match - assertThat(requestCreator.invocations.stream().map(i -> i.maxItemCount) - .distinct().collect(Collectors.toList())).containsExactlyElementsOf(Collections.singleton(7)); - - // continuation tokens - assertThat(requestCreator.invocations.get(0).continuationToken).isEqualTo(initialContinuationToken); - - // source partition - assertThat(requestCreator.invocations.stream().map(i -> i.sourcePartition).distinct() - .collect(Collectors.toList())).containsExactlyElementsOf(Collections.singletonList(targetRange)); - - List resultContinuationToken = subscriber.getOnNextEvents() - .stream().map(r -> r.pageResult.getResponseContinuation()).collect(Collectors.toList()); - List beforeExceptionContinuationTokens = responsesBeforeThrottle.stream() - .map(r -> r.getResponseContinuation()).collect(Collectors.toList()); - List afterExceptionContinuationTokens = responsesAfterThrottle.stream() - .map(r -> r.getResponseContinuation()).collect(Collectors.toList()); - - assertThat(resultContinuationToken).containsExactlyElementsOf( - Iterables.concat(beforeExceptionContinuationTokens, afterExceptionContinuationTokens)); - - String continuationTokenOnException = Iterables.getLast(beforeExceptionContinuationTokens); - - assertThat(requestCreator.invocations.stream().map(cr -> cr.continuationToken)).containsExactlyElementsOf( - Iterables.concat( - ImmutableList.of(initialContinuationToken), - Iterables.limit(resultContinuationToken, resultContinuationToken.size()-1))); - - assertThat(requestExecutor.partitionKeyRangeIdToCapturedInvocation.get(partitionKeyRangeId) - .stream().map(cr -> cr.request.getContinuation())).containsExactlyElementsOf( - Iterables.concat( - ImmutableList.of(initialContinuationToken), - beforeExceptionContinuationTokens, - Collections.singletonList(continuationTokenOnException), - Iterables.limit(afterExceptionContinuationTokens, afterExceptionContinuationTokens.size()-1))); - } - - @Test(groups = { "unit" }, timeOut = TIMEOUT) - public void retriesExhausted() { - int initialPageSize = 7; - int top = -1; - - String partitionKeyRangeId = "1"; - - RequestCreator requestCreator = RequestCreator.simpleMock(); - - List> responsesBeforeThrottle = mockFeedResponses(partitionKeyRangeId, 1, 1, false); - Exception throttlingException = mockThrottlingException(10); - - RequestExecutor.PartitionAnswer behaviourBeforeException = RequestExecutor.PartitionAnswer.just(partitionKeyRangeId, responsesBeforeThrottle); - RequestExecutor.PartitionAnswer exceptionBehaviour = RequestExecutor.PartitionAnswer.errors(partitionKeyRangeId, Collections.nCopies(10, throttlingException)); - - RequestExecutor requestExecutor = RequestExecutor.fromPartitionAnswer(behaviourBeforeException, exceptionBehaviour); - - PartitionKeyRange targetRange = mockPartitionKeyRange(partitionKeyRangeId); - - IDocumentQueryClient queryClient = Mockito.mock(IDocumentQueryClient.class); - String initialContinuationToken = "initial-cp"; - DocumentProducer documentProducer = new DocumentProducer<>( - queryClient, - collectionRid, - null, - requestCreator, - requestExecutor, - targetRange, - collectionRid, - () -> mockDocumentClientIRetryPolicyFactory().getRequestPolicy(), - Document.class, - null, - initialPageSize, - initialContinuationToken, - top); - - TestSubscriber subscriber = new TestSubscriber<>(); - - documentProducer.produceAsync().subscribe(subscriber); - subscriber.awaitTerminalEvent(); - - subscriber.assertError(throttlingException); - subscriber.assertValueCount(responsesBeforeThrottle.size()); - } - - private DocumentClientException mockThrottlingException(long retriesAfter) { - DocumentClientException throttleException = mock(DocumentClientException.class); - doReturn(429).when(throttleException).getStatusCode(); - doReturn(retriesAfter).when(throttleException).getRetryAfterInMilliseconds(); - return throttleException; - } - - private List> mockFeedResponses(String partitionKeyRangeId, - int numberOfPages, - int numberOfDocsPerPage, - boolean completed) { - return mockFeedResponsesPartiallySorted(partitionKeyRangeId, - numberOfPages, - numberOfDocsPerPage, - false, - -1, - completed); - } - - private List> mockFeedResponses(String partitionKeyRangeId, - int numberOfPages, - int numberOfDocsPerPage, - int orderByFieldInitialVal, - boolean completed) { - return mockFeedResponsesPartiallySorted(partitionKeyRangeId, - numberOfPages, - numberOfDocsPerPage, - true, - orderByFieldInitialVal, - completed); - } - - private List> mockFeedResponsesPartiallySorted(String partitionKeyRangeId, - int numberOfPages, - int numberOfDocsPerPage, - boolean isOrderby, - int orderByFieldInitialVal, - boolean completed) { - String uuid = UUID.randomUUID().toString(); - List> responses = new ArrayList<>(); - for(int i = 0; i < numberOfPages; i++) { - FeedResponseBuilder rfb = FeedResponseBuilder.queryFeedResponseBuilder(Document.class); - List res = new ArrayList<>(); - - for(int j = 0; j < numberOfDocsPerPage; j++) { - - Document d = getDocumentDefinition(); - if (isOrderby) { - d.set(OrderByIntFieldName, orderByFieldInitialVal + RandomUtils.nextInt(0, 3)); - d.set(DocumentPartitionKeyRangeIdFieldName, partitionKeyRangeId); - PartitionKeyRange pkr = mockPartitionKeyRange(partitionKeyRangeId); - - d.set(DocumentPartitionKeyRangeMinInclusiveFieldName, pkr.getMinInclusive()); - d.set(DocumentPartitionKeyRangeMaxExclusiveFieldName, pkr.getMaxExclusive()); - - QueryItem qi = new QueryItem( - "{ \"item\": " + Integer.toString(d.getInt(OrderByIntFieldName)) + " }"); - String json = "{\"" + OrderByPayloadFieldName + "\" : " + d.toJson() + ", \"" + OrderByItemsFieldName - + "\" : [ " + qi.toJson() + " ] }"; - - OrderByRowResult row = - new OrderByRowResult<>(Document.class, json, mockPartitionKeyRange(partitionKeyRangeId), "backend continuation token"); - res.add(row); - } else { - res.add(d); - } - } - rfb.withResults(res); - - if (!(completed && i == numberOfPages - 1)) { - rfb.withContinuationToken("cp:" + uuid + ":" + i); - } - - FeedResponse resp = rfb.build(); - responses.add(resp); - } - return responses; - } - - private int getLastValueInAsc(int initialValue, List> responsesList) { - Integer value = null; - for(FeedResponse page: responsesList) { - for(Document d: page.getResults()) { - Integer tmp = d.getInt(OrderByIntFieldName); - if (tmp != null) { - value = tmp; - } - } - } - if (value != null) { - return value; - } else { - return initialValue; - } - } - - private IDocumentQueryClient mockQueryClient(List replacementRanges) { - IDocumentQueryClient client = Mockito.mock(IDocumentQueryClient.class); - RxPartitionKeyRangeCache cache = Mockito.mock(RxPartitionKeyRangeCache.class); - doReturn(cache).when(client).getPartitionKeyRangeCache(); - doReturn(Single.just(replacementRanges)).when(cache). - tryGetOverlappingRangesAsync(anyString(), any(Range.class), anyBoolean(), Matchers.anyMap()); - return client; - } - - private PartitionKeyRange mockPartitionKeyRange(String partitionKeyRangeId) { - PartitionKeyRange pkr = Mockito.mock(PartitionKeyRange.class); - doReturn(partitionKeyRangeId).when(pkr).getId(); - doReturn(partitionKeyRangeId + ":AA").when(pkr).getMinInclusive(); - doReturn(partitionKeyRangeId + ":FF").when(pkr).getMaxExclusive(); - return pkr; - } - - private RxDocumentServiceRequest mockRequest(String partitionKeyRangeId) { - RxDocumentServiceRequest req = Mockito.mock(RxDocumentServiceRequest.class); - PartitionKeyRangeIdentity pkri = new PartitionKeyRangeIdentity(partitionKeyRangeId); - doReturn(pkri).when(req).getPartitionKeyRangeIdentity(); - return req; - } - - private static void validateSplitCaptureRequests( - List capturedInvocationList, - String initialContinuationToken, - String parentPartitionId, - String leftChildPartitionId, - String rightChildPartitionId, - List> expectedResultPagesFromParentPartitionBeforeSplit, - List> expectedResultPagesFromLeftChildPartition, - List> expectedResultPagesFromRightChildPartition) { - - int numberOfResultPagesFromParentBeforeSplit = expectedResultPagesFromParentPartitionBeforeSplit.size(); - int numberOfResultPagesFromLeftChildAfterSplit = expectedResultPagesFromLeftChildPartition.size(); - int numberOfResultPagesFromRightChildAfterSplit = expectedResultPagesFromRightChildPartition.size(); - - // numberOfResultPagesFromParentBeforeSplit + 1 requests to parent partition - assertThat(capturedInvocationList.stream().limit(numberOfResultPagesFromParentBeforeSplit + 1) - .filter(i -> i.sourcePartition.getId().equals(parentPartitionId))) - .hasSize(numberOfResultPagesFromParentBeforeSplit + 1); - - assertThat(capturedInvocationList.stream().skip(numberOfResultPagesFromParentBeforeSplit + 1) - .filter(i -> i.sourcePartition.getId().equals(leftChildPartitionId))) - .hasSize(numberOfResultPagesFromLeftChildAfterSplit); - - assertThat(capturedInvocationList.stream().skip(numberOfResultPagesFromParentBeforeSplit + 1) - .filter(i -> i.sourcePartition.getId().equals(rightChildPartitionId))) - .hasSize(numberOfResultPagesFromRightChildAfterSplit); - - - BiFunction, String, Stream> - filterByPartition = (stream, partitionId) - -> stream.filter(i -> i.sourcePartition.getId().equals(partitionId)); - - Function>, Stream> extractContinuationToken = - (list) -> list.stream().map(p -> p.getResponseContinuation()); - - assertThat(filterByPartition.apply(capturedInvocationList.stream(), parentPartitionId) - .map(r -> r.continuationToken)).containsExactlyElementsOf( - toList(Stream.concat( - Stream.of(initialContinuationToken), - extractContinuationToken.apply(expectedResultPagesFromParentPartitionBeforeSplit)))); - - String expectedInitialChildContinuationTokenInheritedFromParent = - expectedResultPagesFromParentPartitionBeforeSplit.size() > 0 ? - expectedResultPagesFromParentPartitionBeforeSplit.get( - expectedResultPagesFromParentPartitionBeforeSplit.size() - 1) - .getResponseContinuation() :initialContinuationToken; - - assertThat( - filterByPartition.andThen(s -> s.map(r -> r.continuationToken)) - .apply(capturedInvocationList.stream(), leftChildPartitionId) - ).containsExactlyElementsOf( - toList( - Stream.concat( - Stream.of(expectedInitialChildContinuationTokenInheritedFromParent), - extractContinuationToken.apply(expectedResultPagesFromLeftChildPartition) - //drop last page with null cp which doesn't trigger any request - .limit(expectedResultPagesFromLeftChildPartition.size() - 1) - ) - )); - - assertThat( - filterByPartition.andThen(s -> s.map(r -> r.continuationToken)) - .apply(capturedInvocationList.stream(), rightChildPartitionId) - ).containsExactlyElementsOf( - toList( - Stream.concat( - Stream.of(expectedInitialChildContinuationTokenInheritedFromParent), - extractContinuationToken.apply(expectedResultPagesFromRightChildPartition) - //drop last page with null cp which doesn't trigger any request - .limit(expectedResultPagesFromRightChildPartition.size() - 1) - ) - )); - } - - private static void sanityCheckSplitValidation(String parentPartitionId, - String leftChildPartitionId, - String rightChildPartitionId, - int numberOfResultPagesFromParentBeforeSplit, - int numberOfResultPagesFromLeftChildAfterSplit, - int numberOfResultPagesFromRightChildAfterSplit, - List> resultFromParent, - List> resultFromLeftChild, - List> resultFromRightChild) { - // test sanity check - assertThat(resultFromParent).hasSize(numberOfResultPagesFromParentBeforeSplit); - assertThat(resultFromLeftChild).hasSize(numberOfResultPagesFromLeftChildAfterSplit); - assertThat(resultFromRightChild).hasSize(numberOfResultPagesFromRightChildAfterSplit); - - //validate expected result continuation token - assertThat(toList(resultFromParent.stream().map(p -> p.getResponseContinuation()) - .filter(cp -> Strings.isNullOrEmpty(cp)))).isEmpty(); - - assertThat(toList(resultFromLeftChild.stream().map(p -> p.getResponseContinuation()) - .limit(resultFromLeftChild.size() - 1) - .filter(cp -> Strings.isNullOrEmpty(cp)))).isEmpty(); - - assertThat(resultFromLeftChild.get(resultFromLeftChild.size() - 1).getResponseContinuation()).isNullOrEmpty(); - - assertThat(toList(resultFromRightChild.stream().map(p -> p.getResponseContinuation()) - .limit(resultFromRightChild.size() - 1) - .filter(cp -> Strings.isNullOrEmpty(cp)))).isEmpty(); - - assertThat(resultFromRightChild.get(resultFromRightChild.size() - 1).getResponseContinuation()).isNullOrEmpty(); - } - - private void validateSplitResults(List.DocumentProducerFeedResponse> actualPages, - String parentPartitionId, - String leftChildPartitionId, - String rightChildPartitionId, - List> resultFromParent, - List> resultFromLeftChild, - List> resultFromRightChild, - boolean isOrderby) { - - if (isOrderby) { - Supplier> getStreamOfActualDocuments = - () -> actualPages.stream().flatMap(p -> p.pageResult.getResults().stream()); - - Comparator comparator = new Comparator() { - @Override - public int compare(Document o1, Document o2) { - ObjectNode obj1 = (ObjectNode) o1.get(OrderByPayloadFieldName); - ObjectNode obj2 = (ObjectNode) o1.get(OrderByPayloadFieldName); - - int cmp = (obj1).get(OrderByIntFieldName).asInt() - - (obj2).get(OrderByIntFieldName).asInt(); - if (cmp != 0) { - return cmp; - } - - return obj1.get(DocumentPartitionKeyRangeMinInclusiveFieldName).asText() - .compareTo(obj2.get(DocumentPartitionKeyRangeMinInclusiveFieldName).asText()); - } - }; - - List expectedDocuments = Stream.concat(Stream.concat(resultFromParent.stream(), - resultFromLeftChild.stream()), resultFromRightChild.stream()) - .flatMap(p -> p.getResults().stream()) - .sorted(comparator) - .collect(Collectors.toList()); - - List actualDocuments = getStreamOfActualDocuments.get().map(d -> d.getId()).collect(Collectors.toList()); - assertThat(actualDocuments) - .containsExactlyElementsOf(expectedDocuments.stream().map(d -> d.getId()).collect(Collectors.toList())); - - } else { - assertThat(actualPages).hasSize(resultFromParent.size() - + resultFromLeftChild.size() - + resultFromRightChild.size()); - - BiFunction> repeater = (v, cnt) -> { - return IntStream.range(0, cnt).mapToObj(i -> v); - }; - - List expectedCapturedPartitionIds = toList(Stream.concat(Stream.concat(repeater.apply(parentPartitionId, resultFromParent.size()), - repeater.apply(leftChildPartitionId, resultFromLeftChild.size())), - repeater.apply(rightChildPartitionId, resultFromRightChild.size()))); - - - - assertThat(toList(partitionKeyRangeIds(actualPages).stream())).containsExactlyInAnyOrderElementsOf( - expectedCapturedPartitionIds); - - validateResults(feedResponses(actualPages), ImmutableList.of(resultFromParent, resultFromLeftChild, resultFromRightChild)); - } - } - - private static List repeat(T t, int cnt) { - return IntStream.range(0, cnt).mapToObj(i -> t).collect(Collectors.toList()); - } - - private static List> feedResponses(List.DocumentProducerFeedResponse> responses) { - return responses.stream().map(dpFR -> dpFR.pageResult).collect(Collectors.toList()); - } - - private static List toList(Stream stream) { - return stream.collect(Collectors.toList()); - } - - private static List partitionKeyRangeIds(List.DocumentProducerFeedResponse> responses) { - return responses.stream().map(dpFR -> dpFR.sourcePartitionKeyRange.getId()).collect(Collectors.toList()); - } - - private static void validateResults(List> captured, List>> expectedResponsesFromPartitions) { - List> expected = expectedResponsesFromPartitions - .stream().flatMap(l -> l.stream()).collect(Collectors.toList()); - assertThat(captured).hasSameSizeAs(expected); - for(int i = 0; i < expected.size(); i++) { - FeedResponse actualPage = captured.get(i); - FeedResponse expectedPage = expected.get(i); - assertEqual(actualPage, expectedPage); - } - } - - private static void assertEqual(FeedResponse actualPage, FeedResponse expectedPage) { - assertThat(actualPage.getResults()).hasSameSizeAs(actualPage.getResults()); - assertThat(actualPage.getResponseContinuation()).isEqualTo(expectedPage.getResponseContinuation()); - - for(int i = 0; i < actualPage.getResults().size(); i++) { - Document actualDoc = actualPage.getResults().get(i); - Document expectedDoc = expectedPage.getResults().get(i); - assertThat(actualDoc.getId()).isEqualTo(expectedDoc.getId()); - assertThat(actualDoc.getString("prop")).isEqualTo(expectedDoc.getString("prop")); - } - } - - static abstract class RequestExecutor implements Func1>> { - - LinkedListMultimap partitionKeyRangeIdToCapturedInvocation = - LinkedListMultimap.create(); - class CapturedInvocation { - long time = System.nanoTime(); - RxDocumentServiceRequest request; - FeedResponse invocationResult; - Exception failureResult; - - public CapturedInvocation(RxDocumentServiceRequest request, Exception ex) { - this.request = request; - this.failureResult = ex; - } - - public CapturedInvocation(RxDocumentServiceRequest request, PartitionAnswer.Response resp) { - this.request = request; - this.invocationResult = resp.invocationResult; - this.failureResult = resp.failureResult; - } - } - - private static DocumentClientException partitionKeyRangeGoneException() { - Map headers = new HashMap<>(); - headers.put(HttpConstants.HttpHeaders.SUB_STATUS, - Integer.toString(HttpConstants.SubStatusCodes.PARTITION_KEY_RANGE_GONE)); - return new DocumentClientException(HttpConstants.StatusCodes.GONE, new Error(), headers); - } - - protected void capture(String partitionId, CapturedInvocation captureInvocation) { - partitionKeyRangeIdToCapturedInvocation.put(partitionId, captureInvocation); - } - - public static RequestExecutor fromPartitionAnswer(List answers) { - return new RequestExecutor() { - @Override - public Observable> call(RxDocumentServiceRequest request) { - synchronized (this) { - logger.debug("executing request: " + request + " cp is: " + request.getContinuation()); - for (PartitionAnswer a : answers) { - if (a.getPartitionKeyRangeId().equals( - request.getPartitionKeyRangeIdentity().getPartitionKeyRangeId())) { - try { - PartitionAnswer.Response resp = a.onRequest(request); - if (resp != null) { - CapturedInvocation ci = new CapturedInvocation(request, resp); - capture(a.getPartitionKeyRangeId(), ci); - return resp.toSingle().toObservable(); - } - - } catch (Exception e) { - capture(a.getPartitionKeyRangeId(), new CapturedInvocation(request, e)); - return Observable.error(e); - } - } - } - throw new RuntimeException(); - } - } - }; - } - - public static RequestExecutor fromPartitionAnswer(PartitionAnswer... answers) { - return fromPartitionAnswer(ImmutableList.copyOf(answers)); - } - - abstract static class PartitionAnswer { - class Response { - FeedResponse invocationResult; - Exception failureResult; - - public Response(FeedResponse invocationResult) { - this.invocationResult = invocationResult; - } - - public Response(Exception ex) { - this.failureResult = ex; - } - - public Single> toSingle() { - if (invocationResult != null) { - return Single.just(invocationResult); - } else { - return Single.error(failureResult); - } - } - } - - private String partitionKeyRangeId; - - private static boolean targetsPartition(RxDocumentServiceRequest req, String partitionKeyRangeId) { - return partitionKeyRangeId.equals(req.getPartitionKeyRangeIdentity().getPartitionKeyRangeId()); - } - - protected PartitionAnswer(String partitionKeyRangeId) { - this.partitionKeyRangeId = partitionKeyRangeId; - } - - public String getPartitionKeyRangeId() { - return partitionKeyRangeId; - } - - public abstract Response onRequest(final RxDocumentServiceRequest req); - - public static PartitionAnswer just(String partitionId, List> resps) { - AtomicInteger index = new AtomicInteger(); - return new PartitionAnswer(partitionId) { - @Override - public Response onRequest(RxDocumentServiceRequest request) { - if (!PartitionAnswer.targetsPartition(request, partitionId)) { - return null; - } - synchronized (this) { - if (index.get() < resps.size()) { - return new Response(resps.get(index.getAndIncrement())); - } - } - return null; - } - }; - } - - public static PartitionAnswer always(String partitionId, final Exception ex) { - return new PartitionAnswer(partitionId) { - @Override - public Response onRequest(RxDocumentServiceRequest request) { - if (!PartitionAnswer.targetsPartition(request, partitionId)) { - return null; - } - - return new Response(ex); - } - }; - } - - public static PartitionAnswer errors(String partitionId, List exs) { - AtomicInteger index = new AtomicInteger(); - return new PartitionAnswer(partitionId) { - @Override - public Response onRequest(RxDocumentServiceRequest request) { - if (!PartitionAnswer.targetsPartition(request, partitionId)) { - return null; - } - synchronized (this) { - if (index.get() < exs.size()) { - return new Response(exs.get(index.getAndIncrement())); - } - } - return null; - } - }; - } - - public static PartitionAnswer alwaysPartitionSplit(String partitionId) { - return new PartitionAnswer(partitionId) { - @Override - public Response onRequest(RxDocumentServiceRequest request) { - if (!PartitionAnswer.targetsPartition(request, partitionId)) { - return null; - } - return new Response(partitionKeyRangeGoneException()); - } - }; - } - } - } - - static abstract class RequestCreator implements - Func3 { - - public static RequestCreator give(List requests) { - AtomicInteger i = new AtomicInteger(0); - return new RequestCreator() { - - @Override - public RxDocumentServiceRequest call(PartitionKeyRange pkr, String cp, Integer ps) { - synchronized (this) { - RxDocumentServiceRequest req = requests.get(i.getAndIncrement()); - invocations.add(new CapturedInvocation(pkr, cp, ps, req)); - return req; - } - } - }; - } - - public static RequestCreator simpleMock() { - return new RequestCreator() { - @Override - public RxDocumentServiceRequest call(PartitionKeyRange pkr, String cp, Integer ps) { - synchronized (this) { - RxDocumentServiceRequest req = Mockito.mock(RxDocumentServiceRequest.class); - PartitionKeyRangeIdentity pkri = new PartitionKeyRangeIdentity(pkr.getId()); - doReturn(pkri).when(req).getPartitionKeyRangeIdentity(); - doReturn(cp).when(req).getContinuation(); - invocations.add(new CapturedInvocation(pkr, cp, ps, req)); - logger.debug("creating request: " + req + " cp is " + cp); - return req; - } - } - }; - } - - class CapturedInvocation { - PartitionKeyRange sourcePartition; - String continuationToken; - Integer maxItemCount; - RxDocumentServiceRequest invocationResult; - - public CapturedInvocation(PartitionKeyRange sourcePartition, - String continuationToken, - Integer maxItemCount, - RxDocumentServiceRequest invocationResult) { - this.sourcePartition = sourcePartition; - this.continuationToken = continuationToken; - this.maxItemCount = maxItemCount; - this.invocationResult = invocationResult; - } - } - - List invocations = Collections.synchronizedList(new ArrayList<>()); - - abstract public RxDocumentServiceRequest call(PartitionKeyRange pkr, String cp, Integer ps); - } - - private Document getDocumentDefinition() { - String uuid = UUID.randomUUID().toString(); - Document doc = new Document(String.format("{ " - + "\"id\": \"%s\", " - + "\"mypk\": \"%s\", " - + "\"sgmts\": [[6519456, 1471916863], [2498434, 1455671440]], " - + "\"prop\": \"%s\"" - + "}" - , uuid, uuid, uuid)); - return doc; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/FeedResponseBuilder.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/FeedResponseBuilder.java deleted file mode 100644 index 60be8309a2c6..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/FeedResponseBuilder.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import com.microsoft.azure.cosmosdb.BridgeInternal; -import com.microsoft.azure.cosmosdb.BridgeUtils; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.Resource; -import com.microsoft.azure.cosmosdb.internal.HttpConstants; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceResponse; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class FeedResponseBuilder { - private final boolean isChangeFeed; - private final Class klass; - - private Map headers = new HashMap<>(); - private boolean noMoreChangesInChangeFeed = false; - private List results; - - private FeedResponseBuilder(Class klass, boolean isChangeFeed) { - this.klass = klass; - this.isChangeFeed = isChangeFeed; - } - - public FeedResponseBuilder withContinuationToken(String continuationToken) { - - if (isChangeFeed) { - headers.put(HttpConstants.HttpHeaders.E_TAG, continuationToken); - } else { - headers.put(HttpConstants.HttpHeaders.CONTINUATION, continuationToken); - } - return this; - } - - public FeedResponseBuilder withResults(List results) { - this.results = results; - return this; - } - - public FeedResponseBuilder withResults(T... results) { - this.results = Arrays.asList(results); - return this; - } - - public FeedResponseBuilder lastChangeFeedPage() { - this.noMoreChangesInChangeFeed = true; - return this; - } - - public FeedResponse build() { - RxDocumentServiceResponse rsp = mock(RxDocumentServiceResponse.class); - when(rsp.getResponseHeaders()).thenReturn(headers); - when(rsp.getQueryResponse(klass)).thenReturn(results); - if (isChangeFeed) { - when(rsp.getStatusCode()).thenReturn(noMoreChangesInChangeFeed? - HttpConstants.StatusCodes.NOT_MODIFIED : 200); - return BridgeInternal.toChaneFeedResponsePage(rsp, klass); - } else { - return BridgeInternal.toFeedResponsePage(rsp, klass); - } - } - - public static FeedResponseBuilder queryFeedResponseBuilder(Class klass) { - return new FeedResponseBuilder(klass, false); - } - - public static FeedResponseBuilder changeFeedResponseBuilder(Class klass) { - return new FeedResponseBuilder(klass, true); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/FetcherTest.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/FetcherTest.java deleted file mode 100644 index f81bda40d3eb..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/internal/query/FetcherTest.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package com.microsoft.azure.cosmosdb.rx.internal.query; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import com.microsoft.azure.cosmosdb.ChangeFeedOptions; -import com.microsoft.azure.cosmosdb.Document; -import com.microsoft.azure.cosmosdb.FeedOptions; -import com.microsoft.azure.cosmosdb.FeedOptionsBase; -import com.microsoft.azure.cosmosdb.FeedResponse; -import com.microsoft.azure.cosmosdb.rx.internal.RxDocumentServiceRequest; - -import rx.Observable; -import rx.functions.Func1; -import rx.functions.Func2; -import rx.observers.TestSubscriber; - -public class FetcherTest { - - @DataProvider(name = "queryParams") - public static Object[][] queryParamProvider() { - - FeedOptions options1 = new FeedOptions(); - options1.setMaxItemCount(100); - options1.setRequestContinuation("cp-init"); // initial continuation token - int top1 = -1; // no top - - // no continuation token - FeedOptions options2 = new FeedOptions(); - options2.setMaxItemCount(100); - int top2 = -1; // no top - - // top more than max item count - FeedOptions options3 = new FeedOptions(); - options3.setMaxItemCount(100); - int top3 = 200; - - // top less than max item count - FeedOptions options4 = new FeedOptions(); - options4.setMaxItemCount(100); - int top4 = 20; - - return new Object[][] { - { options1, top1 }, - { options2, top2 }, - { options3, top3 }, - { options4, top4 }}; - } - - @Test(groups = { "unit" }, dataProvider = "queryParams") - public void query(FeedOptions options, int top) { - - FeedResponse fp1 = FeedResponseBuilder.queryFeedResponseBuilder(Document.class) - .withContinuationToken("cp1") - .withResults(new Document(), new Document(), new Document()) - .build(); - - FeedResponse fp2 = FeedResponseBuilder.queryFeedResponseBuilder(Document.class) - .withContinuationToken(null) - .withResults(new Document()) - .build(); - - List> feedResponseList = Arrays.asList(fp1, fp2); - - AtomicInteger totalResultsReceived = new AtomicInteger(0); - - AtomicInteger requestIndex = new AtomicInteger(0); - - Func2 createRequestFunc = (token, maxItemCount) -> { - assertThat(maxItemCount).describedAs("max item count").isEqualTo( - getExpectedMaxItemCountInRequest(options, top, feedResponseList, requestIndex.get())); - assertThat(token).describedAs("continuation token").isEqualTo( - getExpectedContinuationTokenInRequest(options, feedResponseList, requestIndex.get())); - requestIndex.getAndIncrement(); - - return mock(RxDocumentServiceRequest.class); - }; - - AtomicInteger executeIndex = new AtomicInteger(0); - - Func1>> executeFunc = request -> { - FeedResponse rsp = feedResponseList.get(executeIndex.getAndIncrement()); - totalResultsReceived.addAndGet(rsp.getResults().size()); - return Observable.just(rsp); - }; - - Fetcher fetcher = - new Fetcher<>(createRequestFunc, executeFunc, options, false, top, - options.getMaxItemCount()); - - validateFetcher(fetcher, options, top, feedResponseList); - } - - private void validateFetcher(Fetcher fetcher, - FeedOptions options, - int top, - List> feedResponseList) { - - int totalNumberOfDocs = 0; - - int index = 0; - while(index < feedResponseList.size()) { - assertThat(fetcher.shouldFetchMore()).describedAs("should fetch more pages").isTrue(); - totalNumberOfDocs += validate(fetcher.nextPage()).getResults().size(); - - if ((top != -1) && (totalNumberOfDocs >= top)) { - break; - } - index++; - } - assertThat(fetcher.shouldFetchMore()).describedAs("should not fetch more pages").isFalse(); - } - - @Test(groups = { "unit" }) - public void changeFeed() { - - ChangeFeedOptions options = new ChangeFeedOptions(); - options.setMaxItemCount(100); - - boolean isChangeFeed = true; - int top = -1; - - FeedResponse fp1 = FeedResponseBuilder.changeFeedResponseBuilder(Document.class) - .withContinuationToken("cp1") - .withResults(new Document()) - .build(); - - FeedResponse fp2 = FeedResponseBuilder.changeFeedResponseBuilder(Document.class) - .withContinuationToken("cp2") - .lastChangeFeedPage() - .build(); - - List> feedResponseList = Arrays.asList(fp1, fp2); - - AtomicInteger requestIndex = new AtomicInteger(0); - - Func2 createRequestFunc = (token, maxItemCount) -> { - assertThat(maxItemCount).describedAs("max item count").isEqualTo(options.getMaxItemCount()); - assertThat(token).describedAs("continuation token").isEqualTo( - getExpectedContinuationTokenInRequest(options, feedResponseList, requestIndex.getAndIncrement())); - - return mock(RxDocumentServiceRequest.class); - }; - - AtomicInteger executeIndex = new AtomicInteger(0); - - Func1>> executeFunc = request -> { - return Observable.just(feedResponseList.get(executeIndex.getAndIncrement())); - }; - - Fetcher fetcher = - new Fetcher<>(createRequestFunc, executeFunc, options, isChangeFeed, top, - options.getMaxItemCount()); - - validateFetcher(fetcher, options, feedResponseList); - } - - private void validateFetcher(Fetcher fetcher, - ChangeFeedOptions options, - List> feedResponseList) { - - - for(FeedResponse change: feedResponseList) { - assertThat(fetcher.shouldFetchMore()).describedAs("should fetch more pages").isTrue(); - validate(fetcher.nextPage()); - } - - assertThat(fetcher.shouldFetchMore()).describedAs("should not fetch more pages").isFalse(); - } - - private FeedResponse validate(Observable> page) { - TestSubscriber> subscriber = new TestSubscriber(); - page.subscribe(subscriber); - subscriber.awaitTerminalEvent(); - subscriber.assertCompleted(); - subscriber.assertNoErrors(); - subscriber.assertValueCount(1); - return subscriber.getOnNextEvents().get(0); - } - - private String getExpectedContinuationTokenInRequest(FeedOptionsBase options, - List> feedResponseList, - int requestIndex) { - if (requestIndex == 0) { - return options.getRequestContinuation(); - } - - return feedResponseList.get(requestIndex - 1).getResponseContinuation(); - } - - private int getExpectedMaxItemCountInRequest(FeedOptionsBase options, - int top, - List> feedResponseList, - int requestIndex) { - if (top == -1) { - return options.getMaxItemCount(); - } - - int numberOfReceivedItemsSoFar = - feedResponseList.subList(0, requestIndex).stream().mapToInt(rsp -> rsp.getResults().size()).sum(); - - return Math.min(top - numberOfReceivedItemsSoFar, options.getMaxItemCount()); - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyChannelInitializer.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyChannelInitializer.java deleted file mode 100644 index 7b1f613713c1..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyChannelInitializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.proxy; - -import java.util.concurrent.atomic.AtomicLong; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.netty.channel.ChannelInitializer; -import io.netty.channel.socket.SocketChannel; - -/** - * The channel initializer. - * - */ -public class HttpProxyChannelInitializer extends ChannelInitializer { - private final Logger logger = LoggerFactory.getLogger(HttpProxyChannelInitializer.class); - private AtomicLong taskCounter = new AtomicLong(); - private HttpProxyClientHandler httpProxyClientHandler; - - @Override - protected void initChannel(SocketChannel ch) throws Exception { - httpProxyClientHandler = new HttpProxyClientHandler("task-" + taskCounter.getAndIncrement()); - logger.info("task-" + taskCounter.getAndIncrement()); - ch.pipeline().addLast(httpProxyClientHandler); - } - -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyClientHandler.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyClientHandler.java deleted file mode 100644 index 4afdcc7181a5..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyClientHandler.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.proxy; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.netty.bootstrap.Bootstrap; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; - -/** - * Handle data from client. - * - */ -public class HttpProxyClientHandler extends ChannelInboundHandlerAdapter { - private final Logger logger = LoggerFactory.getLogger(HttpProxyClientHandler.class); - private final String id; - private Channel clientChannel; - private Channel remoteChannel; - private HttpProxyClientHeader header ; - public HttpProxyClientHandler(String id) { - this.id = id; - header = new HttpProxyClientHeader(); - } - - @Override - public void channelActive(ChannelHandlerContext ctx) { - clientChannel = ctx.channel(); - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) { - if (header.isComplete()) { - remoteChannel.writeAndFlush(msg); // just forward - return; - } - - ByteBuf in = (ByteBuf) msg; - header.digest(in); - - if (!header.isComplete()) { - in.release(); - return; - } - - logger.info(id + " {}", header); - clientChannel.config().setAutoRead(false); // disable AutoRead until remote connection is ready - - if (header.isHttps()) { // if https, respond 200 to create tunnel - clientChannel.writeAndFlush(Unpooled.wrappedBuffer("HTTP/1.1 200 Connection Established\r\n\r\n".getBytes())); - } - - Bootstrap b = new Bootstrap(); - b.group(clientChannel.eventLoop()) // use the same EventLoop - .channel(clientChannel.getClass()) - .handler(new HttpProxyRemoteHandler(id, clientChannel)); - ChannelFuture f = b.connect(header.getHost(), header.getPort()); - remoteChannel = f.channel(); - - f.addListener((ChannelFutureListener) future -> { - if (future.isSuccess()) { - clientChannel.config().setAutoRead(true); // connection is ready, enable AutoRead - if (!header.isHttps()) { // forward header and remaining bytes - remoteChannel.write(header.getByteBuf()); - } - - remoteChannel.writeAndFlush(in); - } else { - in.release(); - clientChannel.close(); - } - }); - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) { - flushAndClose(remoteChannel); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) { - logger.error(id + " error occured", e); - flushAndClose(clientChannel); - } - - private void flushAndClose(Channel ch) { - if (ch != null && ch.isActive()) { - ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyClientHeader.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyClientHeader.java deleted file mode 100644 index 287f54151c8d..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyClientHeader.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.proxy; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; - -/** - * The http header of client. - * - */ -public class HttpProxyClientHeader { - private String method; - private String host; - private int port; - private boolean https; - private boolean complete; - private ByteBuf byteBuf = Unpooled.buffer(); - - private final StringBuilder lineBuf = new StringBuilder(); - - public boolean isComplete() { - return complete; - } - - public String getMethod() { - return method; - } - - public void setMethod(String method) { - this.method = method; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public boolean isHttps() { - return https; - } - - public void setHttps(boolean https) { - this.https = https; - } - - public ByteBuf getByteBuf() { - return byteBuf; - } - - public void setByteBuf(ByteBuf byteBuf) { - this.byteBuf = byteBuf; - } - - public StringBuilder getLineBuf() { - return lineBuf; - } - - public void setComplete(boolean complete) { - this.complete = complete; - } - - public void digest(ByteBuf in) { - while (in.isReadable()) { - if (complete) { - throw new IllegalStateException("already complete"); - } - - String line = readLine(in); - if (line == null) { - return; - } - - if (method == null) { - method = line.split(" ")[0]; // the first word is http method name - https = method.equalsIgnoreCase("CONNECT"); // method CONNECT means https - } - - if (line.startsWith("Host: ") || line.startsWith("host: ")) { - String[] arr = line.split(":"); - host = arr[1].trim(); - if (arr.length == 3) { - port = Integer.parseInt(arr[2]); - } else if (https) { - port = 443; // https - } else { - port = 80; // http - } - } - - if (line.isEmpty()) { - if (host == null || port == 0) { - throw new IllegalStateException("cannot find header \'Host\'"); - } - - byteBuf = byteBuf.asReadOnly(); - complete = true; - break; - } - } - } - - private String readLine(ByteBuf in) { - while (in.isReadable()) { - byte b = in.readByte(); - byteBuf.writeByte(b); - lineBuf.append((char) b); - int len = lineBuf.length(); - if (len >= 2 && lineBuf.substring(len - 2).equals("\r\n")) { - String line = lineBuf.substring(0, len - 2); - lineBuf.delete(0, len); - return line; - } - - } - return null; - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyRemoteHandler.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyRemoteHandler.java deleted file mode 100644 index cf72b251d5fb..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyRemoteHandler.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.proxy; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; - -/** - * Handle data from remote. - * - */ -public class HttpProxyRemoteHandler extends ChannelInboundHandlerAdapter { - private final Logger logger = LoggerFactory.getLogger(HttpProxyRemoteHandler.class); - private final String id; - private Channel clientChannel; - private Channel remoteChannel; - - public HttpProxyRemoteHandler(String id, Channel clientChannel) { - this.id = id; - this.clientChannel = clientChannel; - } - - @Override - public void channelActive(ChannelHandlerContext ctx) { - this.remoteChannel = ctx.channel(); - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) { - clientChannel.writeAndFlush(msg); // just forward - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) { - flushAndClose(clientChannel); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) { - logger.error(id + " error occured", e); - flushAndClose(remoteChannel); - } - - private void flushAndClose(Channel ch) { - if (ch != null && ch.isActive()) { - ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyServer.java b/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyServer.java deleted file mode 100644 index 49d49a86db5a..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/java/com/microsoft/azure/cosmosdb/rx/proxy/HttpProxyServer.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * The MIT License (MIT) - * Copyright (c) 2018 Microsoft Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.microsoft.azure.cosmosdb.rx.proxy; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; - -/** - * A http proxy server. - * - */ -public class HttpProxyServer { - private final Logger logger = LoggerFactory.getLogger(HttpProxyServer.class); - private HttpProxyChannelInitializer httpProxyChannelInitializer; - private int port = 8080; - EventLoopGroup bossGroup; - EventLoopGroup workerGroup; - public HttpProxyServer() { - bossGroup = new NioEventLoopGroup(1); - workerGroup = new NioEventLoopGroup(); - } - - public void start() { - new Thread(() -> { - logger.info("HttpProxyServer started on port: {}", port); - httpProxyChannelInitializer = new HttpProxyChannelInitializer(); - try { - ServerBootstrap bootstrap = new ServerBootstrap(); - bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) - .childHandler(httpProxyChannelInitializer) - .bind(port).sync().channel().closeFuture().sync(); - } catch (InterruptedException e) { - logger.error("Error occurred", e); - } - }).start(); - } - - public void shutDown() { - if(!workerGroup.isShutdown()) { - workerGroup.shutdownGracefully(); - } - - if(!bossGroup.isShutdown()) { - bossGroup.shutdownGracefully(); - } - } -} diff --git a/cosmosdb/data-plane/sdk/src/test/resources/Microsoft.jpg b/cosmosdb/data-plane/sdk/src/test/resources/Microsoft.jpg deleted file mode 100644 index cf6c76bba498..000000000000 Binary files a/cosmosdb/data-plane/sdk/src/test/resources/Microsoft.jpg and /dev/null differ diff --git a/cosmosdb/data-plane/sdk/src/test/resources/cosmosdb-1.png b/cosmosdb/data-plane/sdk/src/test/resources/cosmosdb-1.png deleted file mode 100644 index 60d23806107c..000000000000 Binary files a/cosmosdb/data-plane/sdk/src/test/resources/cosmosdb-1.png and /dev/null differ diff --git a/cosmosdb/data-plane/sdk/src/test/resources/databaseAccount.json b/cosmosdb/data-plane/sdk/src/test/resources/databaseAccount.json deleted file mode 100644 index b514a0dda813..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/resources/databaseAccount.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "_self": "", - "id": "localhost", - "_rid": "localhost", - "media": "//media/", - "addresses": "//addresses/", - "_dbs": "//dbs/", - "writableLocations": [ - { - "name": "South Central US", - "databaseAccountEndpoint": "https://127.0.0.1:8081/" - } - ], - "readableLocations": [ - { - "name": "South Central US", - "databaseAccountEndpoint": "https://127.0.0.1:8081/" - } - ], - "enableMultipleWriteLocations": false, - "userReplicationPolicy": { - "asyncReplication": false, - "minReplicaSetSize": 1, - "maxReplicasetSize": 4 - }, - "userConsistencyPolicy": { - "defaultConsistencyLevel": "Session" - }, - "systemReplicationPolicy": { - "minReplicaSetSize": 1, - "maxReplicasetSize": 4 - }, - "readPolicy": { - "primaryReadCoefficient": 1, - "secondaryReadCoefficient": 1 - }, - "queryEngineConfiguration": "{\"maxSqlQueryInputLength\":262144,\"maxJoinsPerSqlQuery\":5,\"maxLogicalAndPerSqlQuery\":500,\"maxLogicalOrPerSqlQuery\":500,\"maxUdfRefPerSqlQuery\":10,\"maxInExpressionItemsCount\":16000,\"queryMaxInMemorySortDocumentCount\":500,\"maxQueryRequestTimeoutFraction\":0.9,\"sqlAllowNonFiniteNumbers\":false,\"sqlAllowAggregateFunctions\":true,\"sqlAllowSubQuery\":true,\"sqlAllowScalarSubQuery\":true,\"allowNewKeywords\":true,\"sqlAllowLike\":false,\"maxSpatialQueryCells\":12,\"spatialMaxGeometryPointCount\":256,\"sqlAllowTop\":true,\"enableSpatialIndexing\":true}" -} \ No newline at end of file diff --git a/cosmosdb/data-plane/sdk/src/test/resources/emulator-testng.xml b/cosmosdb/data-plane/sdk/src/test/resources/emulator-testng.xml deleted file mode 100644 index 8af636bea2f5..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/resources/emulator-testng.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - diff --git a/cosmosdb/data-plane/sdk/src/test/resources/fast-testng.xml b/cosmosdb/data-plane/sdk/src/test/resources/fast-testng.xml deleted file mode 100644 index b4d5f30b252a..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/resources/fast-testng.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - diff --git a/cosmosdb/data-plane/sdk/src/test/resources/log4j.properties b/cosmosdb/data-plane/sdk/src/test/resources/log4j.properties deleted file mode 100644 index 1f3287c67a55..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/resources/log4j.properties +++ /dev/null @@ -1,15 +0,0 @@ -# this is the log4j configuration for tests - -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -# Set HTTP components' logger to INFO - -log4j.category.io.netty=INFO -log4j.category.io.reactivex=INFO -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%d %5X{pid} [%t] %-5p %c - %m%n diff --git a/cosmosdb/data-plane/sdk/src/test/resources/long-testng.xml b/cosmosdb/data-plane/sdk/src/test/resources/long-testng.xml deleted file mode 100644 index e96812dfbe41..000000000000 --- a/cosmosdb/data-plane/sdk/src/test/resources/long-testng.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - diff --git a/cosmosdb/resource-manager/v2015_04_08/pom.xml b/cosmosdb/resource-manager/v2015_04_08/pom.xml index 23412bcaf098..d4f42ec63e86 100644 --- a/cosmosdb/resource-manager/v2015_04_08/pom.xml +++ b/cosmosdb/resource-manager/v2015_04_08/pom.xml @@ -15,7 +15,7 @@ ../../../pom.management.xml azure-mgmt-cosmosdb - 1.0.0-beta-2 + 1.0.0-beta-3 jar Microsoft Azure SDK for CosmosDB Management This package contains Microsoft CosmosDB Management SDK. @@ -71,6 +71,8 @@ azure-arm-client-runtime test-jar test + + 1.6.5 diff --git a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/ConnectorOffer.java b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/ConnectorOffer.java new file mode 100644 index 000000000000..0c7b491f046e --- /dev/null +++ b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/ConnectorOffer.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.cosmosdb.v2015_04_08; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ConnectorOffer. + */ +public final class ConnectorOffer extends ExpandableStringEnum { + /** Static value Small for ConnectorOffer. */ + public static final ConnectorOffer SMALL = fromString("Small"); + + /** + * Creates or finds a ConnectorOffer from its string representation. + * @param name a name to look for + * @return the corresponding ConnectorOffer + */ + @JsonCreator + public static ConnectorOffer fromString(String name) { + return fromString(name, ConnectorOffer.class); + } + + /** + * @return known ConnectorOffer values + */ + public static Collection values() { + return values(ConnectorOffer.class); + } +} diff --git a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccount.java b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccount.java index be9c08fbd3bb..b344cb239bad 100644 --- a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccount.java +++ b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccount.java @@ -30,6 +30,11 @@ public interface DatabaseAccount extends HasInner, Resourc */ List capabilities(); + /** + * @return the connectorOffer value. + */ + ConnectorOffer connectorOffer(); + /** * @return the consistencyPolicy value. */ @@ -50,6 +55,11 @@ public interface DatabaseAccount extends HasInner, Resourc */ Boolean enableAutomaticFailover(); + /** + * @return the enableCassandraConnector value. + */ + Boolean enableCassandraConnector(); + /** * @return the enableMultipleWriteLocations value. */ @@ -153,6 +163,18 @@ interface WithCapabilities { WithCreate withCapabilities(List capabilities); } + /** + * The stage of the databaseaccount definition allowing to specify ConnectorOffer. + */ + interface WithConnectorOffer { + /** + * Specifies connectorOffer. + * @param connectorOffer The cassandra connector offer type for the Cosmos DB database C* account. Possible values include: 'Small' + * @return the next definition stage + */ + WithCreate withConnectorOffer(ConnectorOffer connectorOffer); + } + /** * The stage of the databaseaccount definition allowing to specify ConsistencyPolicy. */ @@ -177,6 +199,18 @@ interface WithEnableAutomaticFailover { WithCreate withEnableAutomaticFailover(Boolean enableAutomaticFailover); } + /** + * The stage of the databaseaccount definition allowing to specify EnableCassandraConnector. + */ + interface WithEnableCassandraConnector { + /** + * Specifies enableCassandraConnector. + * @param enableCassandraConnector Enables the cassandra connector on the Cosmos DB C* account + * @return the next definition stage + */ + WithCreate withEnableCassandraConnector(Boolean enableCassandraConnector); + } + /** * The stage of the databaseaccount definition allowing to specify EnableMultipleWriteLocations. */ @@ -242,7 +276,7 @@ interface WithVirtualNetworkRules { * the resource to be created (via {@link WithCreate#create()}), but also allows * for any other optional settings to be specified. */ - interface WithCreate extends Creatable, Resource.DefinitionWithTags, DefinitionStages.WithCapabilities, DefinitionStages.WithConsistencyPolicy, DefinitionStages.WithEnableAutomaticFailover, DefinitionStages.WithEnableMultipleWriteLocations, DefinitionStages.WithIpRangeFilter, DefinitionStages.WithIsVirtualNetworkFilterEnabled, DefinitionStages.WithKind, DefinitionStages.WithVirtualNetworkRules { + interface WithCreate extends Creatable, Resource.DefinitionWithTags, DefinitionStages.WithCapabilities, DefinitionStages.WithConnectorOffer, DefinitionStages.WithConsistencyPolicy, DefinitionStages.WithEnableAutomaticFailover, DefinitionStages.WithEnableCassandraConnector, DefinitionStages.WithEnableMultipleWriteLocations, DefinitionStages.WithIpRangeFilter, DefinitionStages.WithIsVirtualNetworkFilterEnabled, DefinitionStages.WithKind, DefinitionStages.WithVirtualNetworkRules { } } /** diff --git a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccountCreateUpdateParameters.java b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccountCreateUpdateParameters.java index 57403672cffa..7240cfbf570b 100644 --- a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccountCreateUpdateParameters.java +++ b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/DatabaseAccountCreateUpdateParameters.java @@ -89,6 +89,19 @@ public class DatabaseAccountCreateUpdateParameters extends Resource { @JsonProperty(value = "properties.enableMultipleWriteLocations") private Boolean enableMultipleWriteLocations; + /** + * Enables the cassandra connector on the Cosmos DB C* account. + */ + @JsonProperty(value = "properties.enableCassandraConnector") + private Boolean enableCassandraConnector; + + /** + * The cassandra connector offer type for the Cosmos DB database C* + * account. Possible values include: 'Small'. + */ + @JsonProperty(value = "properties.connectorOffer") + private ConnectorOffer connectorOffer; + /** * Creates an instance of DatabaseAccountCreateUpdateParameters class. * @param locations an array that contains the georeplication locations enabled for the Cosmos DB account. @@ -297,4 +310,44 @@ public DatabaseAccountCreateUpdateParameters withEnableMultipleWriteLocations(Bo return this; } + /** + * Get enables the cassandra connector on the Cosmos DB C* account. + * + * @return the enableCassandraConnector value + */ + public Boolean enableCassandraConnector() { + return this.enableCassandraConnector; + } + + /** + * Set enables the cassandra connector on the Cosmos DB C* account. + * + * @param enableCassandraConnector the enableCassandraConnector value to set + * @return the DatabaseAccountCreateUpdateParameters object itself. + */ + public DatabaseAccountCreateUpdateParameters withEnableCassandraConnector(Boolean enableCassandraConnector) { + this.enableCassandraConnector = enableCassandraConnector; + return this; + } + + /** + * Get the cassandra connector offer type for the Cosmos DB database C* account. Possible values include: 'Small'. + * + * @return the connectorOffer value + */ + public ConnectorOffer connectorOffer() { + return this.connectorOffer; + } + + /** + * Set the cassandra connector offer type for the Cosmos DB database C* account. Possible values include: 'Small'. + * + * @param connectorOffer the connectorOffer value to set + * @return the DatabaseAccountCreateUpdateParameters object itself. + */ + public DatabaseAccountCreateUpdateParameters withConnectorOffer(ConnectorOffer connectorOffer) { + this.connectorOffer = connectorOffer; + return this; + } + } diff --git a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountImpl.java b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountImpl.java index e5a46bd84c6e..6dc8f71cb170 100644 --- a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountImpl.java +++ b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountImpl.java @@ -15,6 +15,7 @@ import java.util.List; import com.microsoft.azure.management.cosmosdb.v2015_04_08.DatabaseAccountCreateUpdateParameters; import com.microsoft.azure.management.cosmosdb.v2015_04_08.Capability; +import com.microsoft.azure.management.cosmosdb.v2015_04_08.ConnectorOffer; import com.microsoft.azure.management.cosmosdb.v2015_04_08.ConsistencyPolicy; import com.microsoft.azure.management.cosmosdb.v2015_04_08.DatabaseAccountOfferType; import com.microsoft.azure.management.cosmosdb.v2015_04_08.FailoverPolicy; @@ -83,6 +84,11 @@ public List capabilities() { return this.inner().capabilities(); } + @Override + public ConnectorOffer connectorOffer() { + return this.inner().connectorOffer(); + } + @Override public ConsistencyPolicy consistencyPolicy() { return this.inner().consistencyPolicy(); @@ -103,6 +109,11 @@ public Boolean enableAutomaticFailover() { return this.inner().enableAutomaticFailover(); } + @Override + public Boolean enableCassandraConnector() { + return this.inner().enableCassandraConnector(); + } + @Override public Boolean enableMultipleWriteLocations() { return this.inner().enableMultipleWriteLocations(); @@ -160,6 +171,12 @@ public DatabaseAccountImpl withLocations(List locations) { return this; } + @Override + public DatabaseAccountImpl withConnectorOffer(ConnectorOffer connectorOffer) { + this.createParameter.withConnectorOffer(connectorOffer); + return this; + } + @Override public DatabaseAccountImpl withConsistencyPolicy(ConsistencyPolicy consistencyPolicy) { this.createParameter.withConsistencyPolicy(consistencyPolicy); @@ -172,6 +189,12 @@ public DatabaseAccountImpl withEnableAutomaticFailover(Boolean enableAutomaticFa return this; } + @Override + public DatabaseAccountImpl withEnableCassandraConnector(Boolean enableCassandraConnector) { + this.createParameter.withEnableCassandraConnector(enableCassandraConnector); + return this; + } + @Override public DatabaseAccountImpl withEnableMultipleWriteLocations(Boolean enableMultipleWriteLocations) { this.createParameter.withEnableMultipleWriteLocations(enableMultipleWriteLocations); diff --git a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountInner.java b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountInner.java index ea984513227a..f7924f4c005c 100644 --- a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountInner.java +++ b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountInner.java @@ -16,6 +16,7 @@ import com.microsoft.azure.management.cosmosdb.v2015_04_08.Location; import com.microsoft.azure.management.cosmosdb.v2015_04_08.FailoverPolicy; import com.microsoft.azure.management.cosmosdb.v2015_04_08.VirtualNetworkRule; +import com.microsoft.azure.management.cosmosdb.v2015_04_08.ConnectorOffer; import com.fasterxml.jackson.annotation.JsonProperty; import com.microsoft.rest.serializer.JsonFlatten; import com.microsoft.rest.SkipParentValidation; @@ -121,6 +122,19 @@ public class DatabaseAccountInner extends Resource { @JsonProperty(value = "properties.enableMultipleWriteLocations") private Boolean enableMultipleWriteLocations; + /** + * Enables the cassandra connector on the Cosmos DB C* account. + */ + @JsonProperty(value = "properties.enableCassandraConnector") + private Boolean enableCassandraConnector; + + /** + * The cassandra connector offer type for the Cosmos DB database C* + * account. Possible values include: 'Small'. + */ + @JsonProperty(value = "properties.connectorOffer") + private ConnectorOffer connectorOffer; + /** * Get indicates the type of database account. This can only be set at database account creation. Possible values include: 'GlobalDocumentDB', 'MongoDB', 'Parse'. * @@ -346,4 +360,44 @@ public DatabaseAccountInner withEnableMultipleWriteLocations(Boolean enableMulti return this; } + /** + * Get enables the cassandra connector on the Cosmos DB C* account. + * + * @return the enableCassandraConnector value + */ + public Boolean enableCassandraConnector() { + return this.enableCassandraConnector; + } + + /** + * Set enables the cassandra connector on the Cosmos DB C* account. + * + * @param enableCassandraConnector the enableCassandraConnector value to set + * @return the DatabaseAccountInner object itself. + */ + public DatabaseAccountInner withEnableCassandraConnector(Boolean enableCassandraConnector) { + this.enableCassandraConnector = enableCassandraConnector; + return this; + } + + /** + * Get the cassandra connector offer type for the Cosmos DB database C* account. Possible values include: 'Small'. + * + * @return the connectorOffer value + */ + public ConnectorOffer connectorOffer() { + return this.connectorOffer; + } + + /** + * Set the cassandra connector offer type for the Cosmos DB database C* account. Possible values include: 'Small'. + * + * @param connectorOffer the connectorOffer value to set + * @return the DatabaseAccountInner object itself. + */ + public DatabaseAccountInner withConnectorOffer(ConnectorOffer connectorOffer) { + this.connectorOffer = connectorOffer; + return this; + } + } diff --git a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountListKeysResultInner.java b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountListKeysResultInner.java index 8cbe227be29c..463e70c4e4b1 100644 --- a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountListKeysResultInner.java +++ b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountListKeysResultInner.java @@ -9,13 +9,11 @@ package com.microsoft.azure.management.cosmosdb.v2015_04_08.implementation; import com.fasterxml.jackson.annotation.JsonProperty; -import com.microsoft.rest.serializer.JsonFlatten; /** * The access keys for the given database account. */ -@JsonFlatten -public class DatabaseAccountListKeysResultInner { +public class DatabaseAccountListKeysResultInner extends DatabaseAccountListReadOnlyKeysResultInner { /** * Base 64 encoded value of the primary read-write key. */ @@ -28,18 +26,6 @@ public class DatabaseAccountListKeysResultInner { @JsonProperty(value = "secondaryMasterKey", access = JsonProperty.Access.WRITE_ONLY) private String secondaryMasterKey; - /** - * Base 64 encoded value of the primary read-only key. - */ - @JsonProperty(value = "properties.primaryReadonlyMasterKey", access = JsonProperty.Access.WRITE_ONLY) - private String primaryReadonlyMasterKey; - - /** - * Base 64 encoded value of the secondary read-only key. - */ - @JsonProperty(value = "properties.secondaryReadonlyMasterKey", access = JsonProperty.Access.WRITE_ONLY) - private String secondaryReadonlyMasterKey; - /** * Get base 64 encoded value of the primary read-write key. * @@ -58,22 +44,4 @@ public String secondaryMasterKey() { return this.secondaryMasterKey; } - /** - * Get base 64 encoded value of the primary read-only key. - * - * @return the primaryReadonlyMasterKey value - */ - public String primaryReadonlyMasterKey() { - return this.primaryReadonlyMasterKey; - } - - /** - * Get base 64 encoded value of the secondary read-only key. - * - * @return the secondaryReadonlyMasterKey value - */ - public String secondaryReadonlyMasterKey() { - return this.secondaryReadonlyMasterKey; - } - } diff --git a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountsImpl.java b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountsImpl.java index f9f5a9d9338d..1a7827c3b95c 100644 --- a/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountsImpl.java +++ b/cosmosdb/resource-manager/v2015_04_08/src/main/java/com/microsoft/azure/management/cosmosdb/v2015_04_08/implementation/DatabaseAccountsImpl.java @@ -759,10 +759,14 @@ public Throughput call(ThroughputInner inner) { public Observable getSqlContainerAsync(String resourceGroupName, String accountName, String databaseName, String containerName) { DatabaseAccountsInner client = this.inner(); return client.getSqlContainerAsync(resourceGroupName, accountName, databaseName, containerName) - .map(new Func1() { + .flatMap(new Func1>() { @Override - public SqlContainer call(SqlContainerInner inner) { - return wrapSqlContainerModel(inner); + public Observable call(SqlContainerInner inner) { + if (inner == null) { + return Observable.empty(); + } else { + return Observable.just((SqlContainer)wrapSqlContainerModel(inner)); + } } }); } @@ -795,10 +799,14 @@ public Completable deleteSqlContainerAsync(String resourceGroupName, String acco public Observable getMongoDBCollectionAsync(String resourceGroupName, String accountName, String databaseName, String collectionName) { DatabaseAccountsInner client = this.inner(); return client.getMongoDBCollectionAsync(resourceGroupName, accountName, databaseName, collectionName) - .map(new Func1() { + .flatMap(new Func1>() { @Override - public MongoDBCollection call(MongoDBCollectionInner inner) { - return wrapMongoDBCollectionModel(inner); + public Observable call(MongoDBCollectionInner inner) { + if (inner == null) { + return Observable.empty(); + } else { + return Observable.just((MongoDBCollection)wrapMongoDBCollectionModel(inner)); + } } }); } @@ -951,10 +959,14 @@ public Completable deleteCassandraKeyspaceAsync(String resourceGroupName, String public Observable getGremlinGraphAsync(String resourceGroupName, String accountName, String databaseName, String graphName) { DatabaseAccountsInner client = this.inner(); return client.getGremlinGraphAsync(resourceGroupName, accountName, databaseName, graphName) - .map(new Func1() { - @Override - public GremlinGraph call(GremlinGraphInner inner) { - return wrapGremlinGraphModel(inner); + .flatMap(new Func1>() { + @Override + public Observable call(GremlinGraphInner inner) { + if (inner == null) { + return Observable.empty(); + } else { + return Observable.just((GremlinGraph)wrapGremlinGraphModel(inner)); + } } }); } diff --git a/datafactory/resource-manager/v2017_09_01_preview/pom.xml b/datafactory/resource-manager/v2017_09_01_preview/pom.xml new file mode 100644 index 000000000000..859f768e0316 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/pom.xml @@ -0,0 +1,133 @@ + + + 4.0.0 + com.microsoft.azure.datafactory.v2017_09_01_preview + + com.microsoft.azure + azure-arm-parent + 0.0.3-beta + ../../../pom.xml + + azure-mgmt-datafactory + 1.0.0-beta + jar + Microsoft Azure SDK for DataFactory Management + This package contains Microsoft DataFactory Management SDK. + https://github.com/Azure/azure-sdk-for-java + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + UTF-8 + + + + + microsoft + Microsoft + + + + + com.microsoft.azure + azure-client-runtime + + + com.microsoft.azure + azure-arm-client-runtime + + + junit + junit + test + + + com.microsoft.azure + azure-client-authentication + test + + + com.microsoft.azure + azure-mgmt-resources + test + + + com.microsoft.azure + azure-arm-client-runtime + test-jar + test + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + true + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + com.microsoft.azure.management.apigeneration.LangDefinitionProcessor + + + true + true + + true + true + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8 + + *.implementation.*;*.utils.*;com.microsoft.schemas._2003._10.serialization;*.blob.core.search + + + /** +
* Copyright (c) Microsoft Corporation. All rights reserved. +
* Licensed under the MIT License. See License.txt in the project root for +
* license information. +
*/ + ]]> +
+
+
+
+
+
diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Activity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Activity.java new file mode 100644 index 000000000000..82d441390d0b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Activity.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * A pipeline activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Activity") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "Execution", value = ExecutionActivity.class), + @JsonSubTypes.Type(name = "Container", value = ControlActivity.class) +}) +public class Activity { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Activity name. + */ + @JsonProperty(value = "name", required = true) + private String name; + + /** + * Activity description. + */ + @JsonProperty(value = "description") + private String description; + + /** + * Activity depends on condition. + */ + @JsonProperty(value = "dependsOn") + private List dependsOn; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the Activity object itself. + */ + public Activity withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get activity name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set activity name. + * + * @param name the name value to set + * @return the Activity object itself. + */ + public Activity withName(String name) { + this.name = name; + return this; + } + + /** + * Get activity description. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Set activity description. + * + * @param description the description value to set + * @return the Activity object itself. + */ + public Activity withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get activity depends on condition. + * + * @return the dependsOn value + */ + public List dependsOn() { + return this.dependsOn; + } + + /** + * Set activity depends on condition. + * + * @param dependsOn the dependsOn value to set + * @return the Activity object itself. + */ + public Activity withDependsOn(List dependsOn) { + this.dependsOn = dependsOn; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityDependency.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityDependency.java new file mode 100644 index 000000000000..8930842dbbf6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityDependency.java @@ -0,0 +1,97 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Activity dependency information. + */ +public class ActivityDependency { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Activity name. + */ + @JsonProperty(value = "activity", required = true) + private String activity; + + /** + * Match-Condition for the dependency. + */ + @JsonProperty(value = "dependencyConditions", required = true) + private List dependencyConditions; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the ActivityDependency object itself. + */ + public ActivityDependency withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get activity name. + * + * @return the activity value + */ + public String activity() { + return this.activity; + } + + /** + * Set activity name. + * + * @param activity the activity value to set + * @return the ActivityDependency object itself. + */ + public ActivityDependency withActivity(String activity) { + this.activity = activity; + return this; + } + + /** + * Get match-Condition for the dependency. + * + * @return the dependencyConditions value + */ + public List dependencyConditions() { + return this.dependencyConditions; + } + + /** + * Set match-Condition for the dependency. + * + * @param dependencyConditions the dependencyConditions value to set + * @return the ActivityDependency object itself. + */ + public ActivityDependency withDependencyConditions(List dependencyConditions) { + this.dependencyConditions = dependencyConditions; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityPolicy.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityPolicy.java new file mode 100644 index 000000000000..18c4e9d9d911 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityPolicy.java @@ -0,0 +1,152 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Execution policy for an activity. + */ +public class ActivityPolicy { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Specifies the timeout for the activity to run. The default timeout is 7 + * days. Type: string (or Expression with resultType string), pattern: + * ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "timeout") + private Object timeout; + + /** + * Maximum ordinary retry attempts. Default is 0. Type: integer (or + * Expression with resultType integer), minimum: 0. + */ + @JsonProperty(value = "retry") + private Object retry; + + /** + * Interval between each retry attempt (in seconds). The default is 30 sec. + */ + @JsonProperty(value = "retryIntervalInSeconds") + private Integer retryIntervalInSeconds; + + /** + * When set to true, Output from activity is considered as secure and will + * not be logged to monitoring. + */ + @JsonProperty(value = "secureOutput") + private Boolean secureOutput; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the ActivityPolicy object itself. + */ + public ActivityPolicy withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get specifies the timeout for the activity to run. The default timeout is 7 days. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the timeout value + */ + public Object timeout() { + return this.timeout; + } + + /** + * Set specifies the timeout for the activity to run. The default timeout is 7 days. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param timeout the timeout value to set + * @return the ActivityPolicy object itself. + */ + public ActivityPolicy withTimeout(Object timeout) { + this.timeout = timeout; + return this; + } + + /** + * Get maximum ordinary retry attempts. Default is 0. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the retry value + */ + public Object retry() { + return this.retry; + } + + /** + * Set maximum ordinary retry attempts. Default is 0. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param retry the retry value to set + * @return the ActivityPolicy object itself. + */ + public ActivityPolicy withRetry(Object retry) { + this.retry = retry; + return this; + } + + /** + * Get interval between each retry attempt (in seconds). The default is 30 sec. + * + * @return the retryIntervalInSeconds value + */ + public Integer retryIntervalInSeconds() { + return this.retryIntervalInSeconds; + } + + /** + * Set interval between each retry attempt (in seconds). The default is 30 sec. + * + * @param retryIntervalInSeconds the retryIntervalInSeconds value to set + * @return the ActivityPolicy object itself. + */ + public ActivityPolicy withRetryIntervalInSeconds(Integer retryIntervalInSeconds) { + this.retryIntervalInSeconds = retryIntervalInSeconds; + return this; + } + + /** + * Get when set to true, Output from activity is considered as secure and will not be logged to monitoring. + * + * @return the secureOutput value + */ + public Boolean secureOutput() { + return this.secureOutput; + } + + /** + * Set when set to true, Output from activity is considered as secure and will not be logged to monitoring. + * + * @param secureOutput the secureOutput value to set + * @return the ActivityPolicy object itself. + */ + public ActivityPolicy withSecureOutput(Boolean secureOutput) { + this.secureOutput = secureOutput; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityRun.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityRun.java new file mode 100644 index 000000000000..01dfd1cb0924 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityRun.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.ActivityRunInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import org.joda.time.DateTime; +import java.util.Map; + +/** + * Type representing ActivityRun. + */ +public interface ActivityRun extends HasInner, HasManager { + /** + * @return the activityName value. + */ + String activityName(); + + /** + * @return the activityRunEnd value. + */ + DateTime activityRunEnd(); + + /** + * @return the activityRunId value. + */ + String activityRunId(); + + /** + * @return the activityRunStart value. + */ + DateTime activityRunStart(); + + /** + * @return the activityType value. + */ + String activityType(); + + /** + * @return the additionalProperties value. + */ + Map additionalProperties(); + + /** + * @return the durationInMs value. + */ + Integer durationInMs(); + + /** + * @return the error value. + */ + Object error(); + + /** + * @return the input value. + */ + Object input(); + + /** + * @return the linkedServiceName value. + */ + String linkedServiceName(); + + /** + * @return the output value. + */ + Object output(); + + /** + * @return the pipelineName value. + */ + String pipelineName(); + + /** + * @return the pipelineRunId value. + */ + String pipelineRunId(); + + /** + * @return the status value. + */ + String status(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityRuns.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityRuns.java new file mode 100644 index 000000000000..3e4f37dfe2e3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ActivityRuns.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.ActivityRunsInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing ActivityRuns. + */ +public interface ActivityRuns extends HasInner { + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listByPipelineRunAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSLinkedService.java new file mode 100644 index 000000000000..9cd22093a064 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSLinkedService.java @@ -0,0 +1,292 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Amazon Marketplace Web Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AmazonMWS") +@JsonFlatten +public class AmazonMWSLinkedService extends LinkedServiceInner { + /** + * The endpoint of the Amazon MWS server, (i.e. mws.amazonservices.com). + */ + @JsonProperty(value = "typeProperties.endpoint", required = true) + private Object endpoint; + + /** + * The Amazon Marketplace ID you want to retrieve data from. To retrieve + * data from multiple Marketplace IDs, separate them with a comma (,). + * (i.e. A2EUQ1WTGCTBG2). + */ + @JsonProperty(value = "typeProperties.marketplaceID", required = true) + private Object marketplaceID; + + /** + * The Amazon seller ID. + */ + @JsonProperty(value = "typeProperties.sellerID", required = true) + private Object sellerID; + + /** + * The Amazon MWS authentication token. + */ + @JsonProperty(value = "typeProperties.mwsAuthToken") + private SecretBase mwsAuthToken; + + /** + * The access key id used to access data. + */ + @JsonProperty(value = "typeProperties.accessKeyId", required = true) + private Object accessKeyId; + + /** + * The secret key used to access data. + */ + @JsonProperty(value = "typeProperties.secretKey") + private SecretBase secretKey; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the Amazon MWS server, (i.e. mws.amazonservices.com). + * + * @return the endpoint value + */ + public Object endpoint() { + return this.endpoint; + } + + /** + * Set the endpoint of the Amazon MWS server, (i.e. mws.amazonservices.com). + * + * @param endpoint the endpoint value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withEndpoint(Object endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Get the Amazon Marketplace ID you want to retrieve data from. To retrieve data from multiple Marketplace IDs, separate them with a comma (,). (i.e. A2EUQ1WTGCTBG2). + * + * @return the marketplaceID value + */ + public Object marketplaceID() { + return this.marketplaceID; + } + + /** + * Set the Amazon Marketplace ID you want to retrieve data from. To retrieve data from multiple Marketplace IDs, separate them with a comma (,). (i.e. A2EUQ1WTGCTBG2). + * + * @param marketplaceID the marketplaceID value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withMarketplaceID(Object marketplaceID) { + this.marketplaceID = marketplaceID; + return this; + } + + /** + * Get the Amazon seller ID. + * + * @return the sellerID value + */ + public Object sellerID() { + return this.sellerID; + } + + /** + * Set the Amazon seller ID. + * + * @param sellerID the sellerID value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withSellerID(Object sellerID) { + this.sellerID = sellerID; + return this; + } + + /** + * Get the Amazon MWS authentication token. + * + * @return the mwsAuthToken value + */ + public SecretBase mwsAuthToken() { + return this.mwsAuthToken; + } + + /** + * Set the Amazon MWS authentication token. + * + * @param mwsAuthToken the mwsAuthToken value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withMwsAuthToken(SecretBase mwsAuthToken) { + this.mwsAuthToken = mwsAuthToken; + return this; + } + + /** + * Get the access key id used to access data. + * + * @return the accessKeyId value + */ + public Object accessKeyId() { + return this.accessKeyId; + } + + /** + * Set the access key id used to access data. + * + * @param accessKeyId the accessKeyId value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withAccessKeyId(Object accessKeyId) { + this.accessKeyId = accessKeyId; + return this; + } + + /** + * Get the secret key used to access data. + * + * @return the secretKey value + */ + public SecretBase secretKey() { + return this.secretKey; + } + + /** + * Set the secret key used to access data. + * + * @param secretKey the secretKey value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withSecretKey(SecretBase secretKey) { + this.secretKey = secretKey; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AmazonMWSLinkedService object itself. + */ + public AmazonMWSLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSObjectDataset.java new file mode 100644 index 000000000000..866c7965f28d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Amazon Marketplace Web Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AmazonMWSObject") +public class AmazonMWSObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSSource.java new file mode 100644 index 000000000000..57ffe95dd36c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonMWSSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Amazon Marketplace Web Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AmazonMWSSource") +public class AmazonMWSSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the AmazonMWSSource object itself. + */ + public AmazonMWSSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonRedshiftLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonRedshiftLinkedService.java new file mode 100644 index 000000000000..6baeeeb015c4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonRedshiftLinkedService.java @@ -0,0 +1,187 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for Amazon Redshift. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AmazonRedshift") +@JsonFlatten +public class AmazonRedshiftLinkedService extends LinkedServiceInner { + /** + * The name of the Amazon Redshift server. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.server", required = true) + private Object server; + + /** + * The username of the Amazon Redshift source. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password of the Amazon Redshift source. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The database name of the Amazon Redshift source. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.database", required = true) + private Object database; + + /** + * The TCP port number that the Amazon Redshift server uses to listen for + * client connections. The default value is 5439. Type: integer (or + * Expression with resultType integer). + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the name of the Amazon Redshift server. Type: string (or Expression with resultType string). + * + * @return the server value + */ + public Object server() { + return this.server; + } + + /** + * Set the name of the Amazon Redshift server. Type: string (or Expression with resultType string). + * + * @param server the server value to set + * @return the AmazonRedshiftLinkedService object itself. + */ + public AmazonRedshiftLinkedService withServer(Object server) { + this.server = server; + return this; + } + + /** + * Get the username of the Amazon Redshift source. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the username of the Amazon Redshift source. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the AmazonRedshiftLinkedService object itself. + */ + public AmazonRedshiftLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password of the Amazon Redshift source. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password of the Amazon Redshift source. + * + * @param password the password value to set + * @return the AmazonRedshiftLinkedService object itself. + */ + public AmazonRedshiftLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the database name of the Amazon Redshift source. Type: string (or Expression with resultType string). + * + * @return the database value + */ + public Object database() { + return this.database; + } + + /** + * Set the database name of the Amazon Redshift source. Type: string (or Expression with resultType string). + * + * @param database the database value to set + * @return the AmazonRedshiftLinkedService object itself. + */ + public AmazonRedshiftLinkedService withDatabase(Object database) { + this.database = database; + return this; + } + + /** + * Get the TCP port number that the Amazon Redshift server uses to listen for client connections. The default value is 5439. Type: integer (or Expression with resultType integer). + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port number that the Amazon Redshift server uses to listen for client connections. The default value is 5439. Type: integer (or Expression with resultType integer). + * + * @param port the port value to set + * @return the AmazonRedshiftLinkedService object itself. + */ + public AmazonRedshiftLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AmazonRedshiftLinkedService object itself. + */ + public AmazonRedshiftLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonRedshiftSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonRedshiftSource.java new file mode 100644 index 000000000000..c97321276f0b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonRedshiftSource.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for Amazon Redshift Source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AmazonRedshiftSource") +public class AmazonRedshiftSource extends CopySource { + /** + * Database query. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * The Amazon S3 settings needed for the interim Amazon S3 when copying + * from Amazon Redshift with unload. With this, data from Amazon Redshift + * source will be unloaded into S3 first and then copied into the targeted + * sink from the interim S3. + */ + @JsonProperty(value = "redshiftUnloadSettings") + private RedshiftUnloadSettings redshiftUnloadSettings; + + /** + * Get database query. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set database query. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the AmazonRedshiftSource object itself. + */ + public AmazonRedshiftSource withQuery(Object query) { + this.query = query; + return this; + } + + /** + * Get the Amazon S3 settings needed for the interim Amazon S3 when copying from Amazon Redshift with unload. With this, data from Amazon Redshift source will be unloaded into S3 first and then copied into the targeted sink from the interim S3. + * + * @return the redshiftUnloadSettings value + */ + public RedshiftUnloadSettings redshiftUnloadSettings() { + return this.redshiftUnloadSettings; + } + + /** + * Set the Amazon S3 settings needed for the interim Amazon S3 when copying from Amazon Redshift with unload. With this, data from Amazon Redshift source will be unloaded into S3 first and then copied into the targeted sink from the interim S3. + * + * @param redshiftUnloadSettings the redshiftUnloadSettings value to set + * @return the AmazonRedshiftSource object itself. + */ + public AmazonRedshiftSource withRedshiftUnloadSettings(RedshiftUnloadSettings redshiftUnloadSettings) { + this.redshiftUnloadSettings = redshiftUnloadSettings; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonS3Dataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonS3Dataset.java new file mode 100644 index 000000000000..3cb2044c884c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonS3Dataset.java @@ -0,0 +1,184 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * A single Amazon Simple Storage Service (S3) object or a set of S3 objects. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AmazonS3Object") +@JsonFlatten +public class AmazonS3Dataset extends DatasetInner { + /** + * The name of the Amazon S3 bucket. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.bucketName", required = true) + private Object bucketName; + + /** + * The key of the Amazon S3 object. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.key") + private Object key; + + /** + * The prefix filter for the S3 object name. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.prefix") + private Object prefix; + + /** + * The version for the S3 object. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.version") + private Object version; + + /** + * The format of files. + */ + @JsonProperty(value = "typeProperties.format") + private DatasetStorageFormat format; + + /** + * The data compression method used for the Amazon S3 object. + */ + @JsonProperty(value = "typeProperties.compression") + private DatasetCompression compression; + + /** + * Get the name of the Amazon S3 bucket. Type: string (or Expression with resultType string). + * + * @return the bucketName value + */ + public Object bucketName() { + return this.bucketName; + } + + /** + * Set the name of the Amazon S3 bucket. Type: string (or Expression with resultType string). + * + * @param bucketName the bucketName value to set + * @return the AmazonS3Dataset object itself. + */ + public AmazonS3Dataset withBucketName(Object bucketName) { + this.bucketName = bucketName; + return this; + } + + /** + * Get the key of the Amazon S3 object. Type: string (or Expression with resultType string). + * + * @return the key value + */ + public Object key() { + return this.key; + } + + /** + * Set the key of the Amazon S3 object. Type: string (or Expression with resultType string). + * + * @param key the key value to set + * @return the AmazonS3Dataset object itself. + */ + public AmazonS3Dataset withKey(Object key) { + this.key = key; + return this; + } + + /** + * Get the prefix filter for the S3 object name. Type: string (or Expression with resultType string). + * + * @return the prefix value + */ + public Object prefix() { + return this.prefix; + } + + /** + * Set the prefix filter for the S3 object name. Type: string (or Expression with resultType string). + * + * @param prefix the prefix value to set + * @return the AmazonS3Dataset object itself. + */ + public AmazonS3Dataset withPrefix(Object prefix) { + this.prefix = prefix; + return this; + } + + /** + * Get the version for the S3 object. Type: string (or Expression with resultType string). + * + * @return the version value + */ + public Object version() { + return this.version; + } + + /** + * Set the version for the S3 object. Type: string (or Expression with resultType string). + * + * @param version the version value to set + * @return the AmazonS3Dataset object itself. + */ + public AmazonS3Dataset withVersion(Object version) { + this.version = version; + return this; + } + + /** + * Get the format of files. + * + * @return the format value + */ + public DatasetStorageFormat format() { + return this.format; + } + + /** + * Set the format of files. + * + * @param format the format value to set + * @return the AmazonS3Dataset object itself. + */ + public AmazonS3Dataset withFormat(DatasetStorageFormat format) { + this.format = format; + return this; + } + + /** + * Get the data compression method used for the Amazon S3 object. + * + * @return the compression value + */ + public DatasetCompression compression() { + return this.compression; + } + + /** + * Set the data compression method used for the Amazon S3 object. + * + * @param compression the compression value to set + * @return the AmazonS3Dataset object itself. + */ + public AmazonS3Dataset withCompression(DatasetCompression compression) { + this.compression = compression; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonS3LinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonS3LinkedService.java new file mode 100644 index 000000000000..2d1b8e66f400 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AmazonS3LinkedService.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for Amazon S3. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AmazonS3") +@JsonFlatten +public class AmazonS3LinkedService extends LinkedServiceInner { + /** + * The access key identifier of the Amazon S3 Identity and Access + * Management (IAM) user. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.accessKeyId") + private Object accessKeyId; + + /** + * The secret access key of the Amazon S3 Identity and Access Management + * (IAM) user. + */ + @JsonProperty(value = "typeProperties.secretAccessKey") + private SecretBase secretAccessKey; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the access key identifier of the Amazon S3 Identity and Access Management (IAM) user. Type: string (or Expression with resultType string). + * + * @return the accessKeyId value + */ + public Object accessKeyId() { + return this.accessKeyId; + } + + /** + * Set the access key identifier of the Amazon S3 Identity and Access Management (IAM) user. Type: string (or Expression with resultType string). + * + * @param accessKeyId the accessKeyId value to set + * @return the AmazonS3LinkedService object itself. + */ + public AmazonS3LinkedService withAccessKeyId(Object accessKeyId) { + this.accessKeyId = accessKeyId; + return this; + } + + /** + * Get the secret access key of the Amazon S3 Identity and Access Management (IAM) user. + * + * @return the secretAccessKey value + */ + public SecretBase secretAccessKey() { + return this.secretAccessKey; + } + + /** + * Set the secret access key of the Amazon S3 Identity and Access Management (IAM) user. + * + * @param secretAccessKey the secretAccessKey value to set + * @return the AmazonS3LinkedService object itself. + */ + public AmazonS3LinkedService withSecretAccessKey(SecretBase secretAccessKey) { + this.secretAccessKey = secretAccessKey; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AmazonS3LinkedService object itself. + */ + public AmazonS3LinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AvroFormat.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AvroFormat.java new file mode 100644 index 000000000000..4141b44b2770 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AvroFormat.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The data stored in Avro format. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AvroFormat") +public class AvroFormat extends DatasetStorageFormat { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureBatchLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureBatchLinkedService.java new file mode 100644 index 000000000000..5fa1cea622bf --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureBatchLinkedService.java @@ -0,0 +1,185 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure Batch linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureBatch") +@JsonFlatten +public class AzureBatchLinkedService extends LinkedServiceInner { + /** + * The Azure Batch account name. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.accountName", required = true) + private Object accountName; + + /** + * The Azure Batch account access key. + */ + @JsonProperty(value = "typeProperties.accessKey") + private SecretBase accessKey; + + /** + * The Azure Batch URI. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.batchUri", required = true) + private Object batchUri; + + /** + * The Azure Batch pool name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.poolName", required = true) + private Object poolName; + + /** + * The Azure Storage linked service reference. + */ + @JsonProperty(value = "typeProperties.linkedServiceName", required = true) + private LinkedServiceReference linkedServiceName; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the Azure Batch account name. Type: string (or Expression with resultType string). + * + * @return the accountName value + */ + public Object accountName() { + return this.accountName; + } + + /** + * Set the Azure Batch account name. Type: string (or Expression with resultType string). + * + * @param accountName the accountName value to set + * @return the AzureBatchLinkedService object itself. + */ + public AzureBatchLinkedService withAccountName(Object accountName) { + this.accountName = accountName; + return this; + } + + /** + * Get the Azure Batch account access key. + * + * @return the accessKey value + */ + public SecretBase accessKey() { + return this.accessKey; + } + + /** + * Set the Azure Batch account access key. + * + * @param accessKey the accessKey value to set + * @return the AzureBatchLinkedService object itself. + */ + public AzureBatchLinkedService withAccessKey(SecretBase accessKey) { + this.accessKey = accessKey; + return this; + } + + /** + * Get the Azure Batch URI. Type: string (or Expression with resultType string). + * + * @return the batchUri value + */ + public Object batchUri() { + return this.batchUri; + } + + /** + * Set the Azure Batch URI. Type: string (or Expression with resultType string). + * + * @param batchUri the batchUri value to set + * @return the AzureBatchLinkedService object itself. + */ + public AzureBatchLinkedService withBatchUri(Object batchUri) { + this.batchUri = batchUri; + return this; + } + + /** + * Get the Azure Batch pool name. Type: string (or Expression with resultType string). + * + * @return the poolName value + */ + public Object poolName() { + return this.poolName; + } + + /** + * Set the Azure Batch pool name. Type: string (or Expression with resultType string). + * + * @param poolName the poolName value to set + * @return the AzureBatchLinkedService object itself. + */ + public AzureBatchLinkedService withPoolName(Object poolName) { + this.poolName = poolName; + return this; + } + + /** + * Get the Azure Storage linked service reference. + * + * @return the linkedServiceName value + */ + public LinkedServiceReference linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set the Azure Storage linked service reference. + * + * @param linkedServiceName the linkedServiceName value to set + * @return the AzureBatchLinkedService object itself. + */ + public AzureBatchLinkedService withLinkedServiceName(LinkedServiceReference linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureBatchLinkedService object itself. + */ + public AzureBatchLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureBlobDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureBlobDataset.java new file mode 100644 index 000000000000..f02e493f75b3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureBlobDataset.java @@ -0,0 +1,157 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Azure Blob storage. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureBlob") +@JsonFlatten +public class AzureBlobDataset extends DatasetInner { + /** + * The path of the Azure Blob storage. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.folderPath") + private Object folderPath; + + /** + * The root of blob path. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.tableRootLocation") + private Object tableRootLocation; + + /** + * The name of the Azure Blob. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.fileName") + private Object fileName; + + /** + * The format of the Azure Blob storage. + */ + @JsonProperty(value = "typeProperties.format") + private DatasetStorageFormat format; + + /** + * The data compression method used for the blob storage. + */ + @JsonProperty(value = "typeProperties.compression") + private DatasetCompression compression; + + /** + * Get the path of the Azure Blob storage. Type: string (or Expression with resultType string). + * + * @return the folderPath value + */ + public Object folderPath() { + return this.folderPath; + } + + /** + * Set the path of the Azure Blob storage. Type: string (or Expression with resultType string). + * + * @param folderPath the folderPath value to set + * @return the AzureBlobDataset object itself. + */ + public AzureBlobDataset withFolderPath(Object folderPath) { + this.folderPath = folderPath; + return this; + } + + /** + * Get the root of blob path. Type: string (or Expression with resultType string). + * + * @return the tableRootLocation value + */ + public Object tableRootLocation() { + return this.tableRootLocation; + } + + /** + * Set the root of blob path. Type: string (or Expression with resultType string). + * + * @param tableRootLocation the tableRootLocation value to set + * @return the AzureBlobDataset object itself. + */ + public AzureBlobDataset withTableRootLocation(Object tableRootLocation) { + this.tableRootLocation = tableRootLocation; + return this; + } + + /** + * Get the name of the Azure Blob. Type: string (or Expression with resultType string). + * + * @return the fileName value + */ + public Object fileName() { + return this.fileName; + } + + /** + * Set the name of the Azure Blob. Type: string (or Expression with resultType string). + * + * @param fileName the fileName value to set + * @return the AzureBlobDataset object itself. + */ + public AzureBlobDataset withFileName(Object fileName) { + this.fileName = fileName; + return this; + } + + /** + * Get the format of the Azure Blob storage. + * + * @return the format value + */ + public DatasetStorageFormat format() { + return this.format; + } + + /** + * Set the format of the Azure Blob storage. + * + * @param format the format value to set + * @return the AzureBlobDataset object itself. + */ + public AzureBlobDataset withFormat(DatasetStorageFormat format) { + this.format = format; + return this; + } + + /** + * Get the data compression method used for the blob storage. + * + * @return the compression value + */ + public DatasetCompression compression() { + return this.compression; + } + + /** + * Set the data compression method used for the blob storage. + * + * @param compression the compression value to set + * @return the AzureBlobDataset object itself. + */ + public AzureBlobDataset withCompression(DatasetCompression compression) { + this.compression = compression; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeAnalyticsLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeAnalyticsLinkedService.java new file mode 100644 index 000000000000..5011e48a2b50 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeAnalyticsLinkedService.java @@ -0,0 +1,242 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure Data Lake Analytics linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureDataLakeAnalytics") +@JsonFlatten +public class AzureDataLakeAnalyticsLinkedService extends LinkedServiceInner { + /** + * The Azure Data Lake Analytics account name. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.accountName", required = true) + private Object accountName; + + /** + * The ID of the application used to authenticate against the Azure Data + * Lake Analytics account. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.servicePrincipalId") + private Object servicePrincipalId; + + /** + * The Key of the application used to authenticate against the Azure Data + * Lake Analytics account. + */ + @JsonProperty(value = "typeProperties.servicePrincipalKey") + private SecretBase servicePrincipalKey; + + /** + * The name or ID of the tenant to which the service principal belongs. + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tenant", required = true) + private Object tenant; + + /** + * Data Lake Analytics account subscription ID (if different from Data + * Factory account). Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.subscriptionId") + private Object subscriptionId; + + /** + * Data Lake Analytics account resource group name (if different from Data + * Factory account). Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.resourceGroupName") + private Object resourceGroupName; + + /** + * Azure Data Lake Analytics URI Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.dataLakeAnalyticsUri") + private Object dataLakeAnalyticsUri; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the Azure Data Lake Analytics account name. Type: string (or Expression with resultType string). + * + * @return the accountName value + */ + public Object accountName() { + return this.accountName; + } + + /** + * Set the Azure Data Lake Analytics account name. Type: string (or Expression with resultType string). + * + * @param accountName the accountName value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withAccountName(Object accountName) { + this.accountName = accountName; + return this; + } + + /** + * Get the ID of the application used to authenticate against the Azure Data Lake Analytics account. Type: string (or Expression with resultType string). + * + * @return the servicePrincipalId value + */ + public Object servicePrincipalId() { + return this.servicePrincipalId; + } + + /** + * Set the ID of the application used to authenticate against the Azure Data Lake Analytics account. Type: string (or Expression with resultType string). + * + * @param servicePrincipalId the servicePrincipalId value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withServicePrincipalId(Object servicePrincipalId) { + this.servicePrincipalId = servicePrincipalId; + return this; + } + + /** + * Get the Key of the application used to authenticate against the Azure Data Lake Analytics account. + * + * @return the servicePrincipalKey value + */ + public SecretBase servicePrincipalKey() { + return this.servicePrincipalKey; + } + + /** + * Set the Key of the application used to authenticate against the Azure Data Lake Analytics account. + * + * @param servicePrincipalKey the servicePrincipalKey value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withServicePrincipalKey(SecretBase servicePrincipalKey) { + this.servicePrincipalKey = servicePrincipalKey; + return this; + } + + /** + * Get the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @return the tenant value + */ + public Object tenant() { + return this.tenant; + } + + /** + * Set the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @param tenant the tenant value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withTenant(Object tenant) { + this.tenant = tenant; + return this; + } + + /** + * Get data Lake Analytics account subscription ID (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @return the subscriptionId value + */ + public Object subscriptionId() { + return this.subscriptionId; + } + + /** + * Set data Lake Analytics account subscription ID (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @param subscriptionId the subscriptionId value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withSubscriptionId(Object subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /** + * Get data Lake Analytics account resource group name (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @return the resourceGroupName value + */ + public Object resourceGroupName() { + return this.resourceGroupName; + } + + /** + * Set data Lake Analytics account resource group name (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @param resourceGroupName the resourceGroupName value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withResourceGroupName(Object resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + /** + * Get azure Data Lake Analytics URI Type: string (or Expression with resultType string). + * + * @return the dataLakeAnalyticsUri value + */ + public Object dataLakeAnalyticsUri() { + return this.dataLakeAnalyticsUri; + } + + /** + * Set azure Data Lake Analytics URI Type: string (or Expression with resultType string). + * + * @param dataLakeAnalyticsUri the dataLakeAnalyticsUri value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withDataLakeAnalyticsUri(Object dataLakeAnalyticsUri) { + this.dataLakeAnalyticsUri = dataLakeAnalyticsUri; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureDataLakeAnalyticsLinkedService object itself. + */ + public AzureDataLakeAnalyticsLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreDataset.java new file mode 100644 index 000000000000..af8395c336b1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreDataset.java @@ -0,0 +1,131 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Azure Data Lake Store dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureDataLakeStoreFile") +@JsonFlatten +public class AzureDataLakeStoreDataset extends DatasetInner { + /** + * Path to the folder in the Azure Data Lake Store. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.folderPath", required = true) + private Object folderPath; + + /** + * The name of the file in the Azure Data Lake Store. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.fileName") + private Object fileName; + + /** + * The format of the Data Lake Store. + */ + @JsonProperty(value = "typeProperties.format") + private DatasetStorageFormat format; + + /** + * The data compression method used for the item(s) in the Azure Data Lake + * Store. + */ + @JsonProperty(value = "typeProperties.compression") + private DatasetCompression compression; + + /** + * Get path to the folder in the Azure Data Lake Store. Type: string (or Expression with resultType string). + * + * @return the folderPath value + */ + public Object folderPath() { + return this.folderPath; + } + + /** + * Set path to the folder in the Azure Data Lake Store. Type: string (or Expression with resultType string). + * + * @param folderPath the folderPath value to set + * @return the AzureDataLakeStoreDataset object itself. + */ + public AzureDataLakeStoreDataset withFolderPath(Object folderPath) { + this.folderPath = folderPath; + return this; + } + + /** + * Get the name of the file in the Azure Data Lake Store. Type: string (or Expression with resultType string). + * + * @return the fileName value + */ + public Object fileName() { + return this.fileName; + } + + /** + * Set the name of the file in the Azure Data Lake Store. Type: string (or Expression with resultType string). + * + * @param fileName the fileName value to set + * @return the AzureDataLakeStoreDataset object itself. + */ + public AzureDataLakeStoreDataset withFileName(Object fileName) { + this.fileName = fileName; + return this; + } + + /** + * Get the format of the Data Lake Store. + * + * @return the format value + */ + public DatasetStorageFormat format() { + return this.format; + } + + /** + * Set the format of the Data Lake Store. + * + * @param format the format value to set + * @return the AzureDataLakeStoreDataset object itself. + */ + public AzureDataLakeStoreDataset withFormat(DatasetStorageFormat format) { + this.format = format; + return this; + } + + /** + * Get the data compression method used for the item(s) in the Azure Data Lake Store. + * + * @return the compression value + */ + public DatasetCompression compression() { + return this.compression; + } + + /** + * Set the data compression method used for the item(s) in the Azure Data Lake Store. + * + * @param compression the compression value to set + * @return the AzureDataLakeStoreDataset object itself. + */ + public AzureDataLakeStoreDataset withCompression(DatasetCompression compression) { + this.compression = compression; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreLinkedService.java new file mode 100644 index 000000000000..ee162b7d7fd1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreLinkedService.java @@ -0,0 +1,241 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure Data Lake Store linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureDataLakeStore") +@JsonFlatten +public class AzureDataLakeStoreLinkedService extends LinkedServiceInner { + /** + * Data Lake Store service URI. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.dataLakeStoreUri", required = true) + private Object dataLakeStoreUri; + + /** + * The ID of the application used to authenticate against the Azure Data + * Lake Store account. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.servicePrincipalId") + private Object servicePrincipalId; + + /** + * The Key of the application used to authenticate against the Azure Data + * Lake Store account. + */ + @JsonProperty(value = "typeProperties.servicePrincipalKey") + private SecretBase servicePrincipalKey; + + /** + * The name or ID of the tenant to which the service principal belongs. + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tenant") + private Object tenant; + + /** + * Data Lake Store account name. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.accountName") + private Object accountName; + + /** + * Data Lake Store account subscription ID (if different from Data Factory + * account). Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.subscriptionId") + private Object subscriptionId; + + /** + * Data Lake Store account resource group name (if different from Data + * Factory account). Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.resourceGroupName") + private Object resourceGroupName; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get data Lake Store service URI. Type: string (or Expression with resultType string). + * + * @return the dataLakeStoreUri value + */ + public Object dataLakeStoreUri() { + return this.dataLakeStoreUri; + } + + /** + * Set data Lake Store service URI. Type: string (or Expression with resultType string). + * + * @param dataLakeStoreUri the dataLakeStoreUri value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withDataLakeStoreUri(Object dataLakeStoreUri) { + this.dataLakeStoreUri = dataLakeStoreUri; + return this; + } + + /** + * Get the ID of the application used to authenticate against the Azure Data Lake Store account. Type: string (or Expression with resultType string). + * + * @return the servicePrincipalId value + */ + public Object servicePrincipalId() { + return this.servicePrincipalId; + } + + /** + * Set the ID of the application used to authenticate against the Azure Data Lake Store account. Type: string (or Expression with resultType string). + * + * @param servicePrincipalId the servicePrincipalId value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withServicePrincipalId(Object servicePrincipalId) { + this.servicePrincipalId = servicePrincipalId; + return this; + } + + /** + * Get the Key of the application used to authenticate against the Azure Data Lake Store account. + * + * @return the servicePrincipalKey value + */ + public SecretBase servicePrincipalKey() { + return this.servicePrincipalKey; + } + + /** + * Set the Key of the application used to authenticate against the Azure Data Lake Store account. + * + * @param servicePrincipalKey the servicePrincipalKey value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withServicePrincipalKey(SecretBase servicePrincipalKey) { + this.servicePrincipalKey = servicePrincipalKey; + return this; + } + + /** + * Get the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @return the tenant value + */ + public Object tenant() { + return this.tenant; + } + + /** + * Set the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @param tenant the tenant value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withTenant(Object tenant) { + this.tenant = tenant; + return this; + } + + /** + * Get data Lake Store account name. Type: string (or Expression with resultType string). + * + * @return the accountName value + */ + public Object accountName() { + return this.accountName; + } + + /** + * Set data Lake Store account name. Type: string (or Expression with resultType string). + * + * @param accountName the accountName value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withAccountName(Object accountName) { + this.accountName = accountName; + return this; + } + + /** + * Get data Lake Store account subscription ID (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @return the subscriptionId value + */ + public Object subscriptionId() { + return this.subscriptionId; + } + + /** + * Set data Lake Store account subscription ID (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @param subscriptionId the subscriptionId value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withSubscriptionId(Object subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /** + * Get data Lake Store account resource group name (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @return the resourceGroupName value + */ + public Object resourceGroupName() { + return this.resourceGroupName; + } + + /** + * Set data Lake Store account resource group name (if different from Data Factory account). Type: string (or Expression with resultType string). + * + * @param resourceGroupName the resourceGroupName value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withResourceGroupName(Object resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureDataLakeStoreLinkedService object itself. + */ + public AzureDataLakeStoreLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreSink.java new file mode 100644 index 000000000000..3f591e9c2b14 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreSink.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Data Lake Store sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureDataLakeStoreSink") +public class AzureDataLakeStoreSink extends CopySink { + /** + * The type of copy behavior for copy sink. + */ + @JsonProperty(value = "copyBehavior") + private Object copyBehavior; + + /** + * Get the type of copy behavior for copy sink. + * + * @return the copyBehavior value + */ + public Object copyBehavior() { + return this.copyBehavior; + } + + /** + * Set the type of copy behavior for copy sink. + * + * @param copyBehavior the copyBehavior value to set + * @return the AzureDataLakeStoreSink object itself. + */ + public AzureDataLakeStoreSink withCopyBehavior(Object copyBehavior) { + this.copyBehavior = copyBehavior; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreSource.java new file mode 100644 index 000000000000..5890d534e686 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDataLakeStoreSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Data Lake source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureDataLakeStoreSource") +public class AzureDataLakeStoreSource extends CopySource { + /** + * If true, files under the folder path will be read recursively. Default + * is true. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "recursive") + private Object recursive; + + /** + * Get if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @return the recursive value + */ + public Object recursive() { + return this.recursive; + } + + /** + * Set if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @param recursive the recursive value to set + * @return the AzureDataLakeStoreSource object itself. + */ + public AzureDataLakeStoreSource withRecursive(Object recursive) { + this.recursive = recursive; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDatabricksLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDatabricksLinkedService.java new file mode 100644 index 000000000000..490f7f1bdef5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureDatabricksLinkedService.java @@ -0,0 +1,244 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure Databricks linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureDatabricks") +@JsonFlatten +public class AzureDatabricksLinkedService extends LinkedServiceInner { + /** + * <REGION>.azuredatabricks.net, domain name of your Databricks + * deployment. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.domain", required = true) + private Object domain; + + /** + * Access token for databricks REST API. Refer to + * https://docs.azuredatabricks.net/api/latest/authentication.html. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.accessToken", required = true) + private SecretBase accessToken; + + /** + * The id of an existing cluster that will be used for all runs of this + * job. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.existingClusterId") + private Object existingClusterId; + + /** + * The Spark version of new cluster. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.newClusterVersion") + private Object newClusterVersion; + + /** + * Number of worker nodes that new cluster should have. A string formatted + * Int32, like '1' means numOfWorker is 1 or '1:10' means auto-scale from 1 + * as min and 10 as max. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.newClusterNumOfWorker") + private Object newClusterNumOfWorker; + + /** + * The node types of new cluster. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.newClusterNodeType") + private Object newClusterNodeType; + + /** + * a set of optional, user-specified Spark configuration key-value pairs. + */ + @JsonProperty(value = "typeProperties.newClusterSparkConf") + private Map newClusterSparkConf; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get <REGION>.azuredatabricks.net, domain name of your Databricks deployment. Type: string (or Expression with resultType string). + * + * @return the domain value + */ + public Object domain() { + return this.domain; + } + + /** + * Set <REGION>.azuredatabricks.net, domain name of your Databricks deployment. Type: string (or Expression with resultType string). + * + * @param domain the domain value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withDomain(Object domain) { + this.domain = domain; + return this; + } + + /** + * Get access token for databricks REST API. Refer to https://docs.azuredatabricks.net/api/latest/authentication.html. Type: string (or Expression with resultType string). + * + * @return the accessToken value + */ + public SecretBase accessToken() { + return this.accessToken; + } + + /** + * Set access token for databricks REST API. Refer to https://docs.azuredatabricks.net/api/latest/authentication.html. Type: string (or Expression with resultType string). + * + * @param accessToken the accessToken value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withAccessToken(SecretBase accessToken) { + this.accessToken = accessToken; + return this; + } + + /** + * Get the id of an existing cluster that will be used for all runs of this job. Type: string (or Expression with resultType string). + * + * @return the existingClusterId value + */ + public Object existingClusterId() { + return this.existingClusterId; + } + + /** + * Set the id of an existing cluster that will be used for all runs of this job. Type: string (or Expression with resultType string). + * + * @param existingClusterId the existingClusterId value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withExistingClusterId(Object existingClusterId) { + this.existingClusterId = existingClusterId; + return this; + } + + /** + * Get the Spark version of new cluster. Type: string (or Expression with resultType string). + * + * @return the newClusterVersion value + */ + public Object newClusterVersion() { + return this.newClusterVersion; + } + + /** + * Set the Spark version of new cluster. Type: string (or Expression with resultType string). + * + * @param newClusterVersion the newClusterVersion value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withNewClusterVersion(Object newClusterVersion) { + this.newClusterVersion = newClusterVersion; + return this; + } + + /** + * Get number of worker nodes that new cluster should have. A string formatted Int32, like '1' means numOfWorker is 1 or '1:10' means auto-scale from 1 as min and 10 as max. Type: string (or Expression with resultType string). + * + * @return the newClusterNumOfWorker value + */ + public Object newClusterNumOfWorker() { + return this.newClusterNumOfWorker; + } + + /** + * Set number of worker nodes that new cluster should have. A string formatted Int32, like '1' means numOfWorker is 1 or '1:10' means auto-scale from 1 as min and 10 as max. Type: string (or Expression with resultType string). + * + * @param newClusterNumOfWorker the newClusterNumOfWorker value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withNewClusterNumOfWorker(Object newClusterNumOfWorker) { + this.newClusterNumOfWorker = newClusterNumOfWorker; + return this; + } + + /** + * Get the node types of new cluster. Type: string (or Expression with resultType string). + * + * @return the newClusterNodeType value + */ + public Object newClusterNodeType() { + return this.newClusterNodeType; + } + + /** + * Set the node types of new cluster. Type: string (or Expression with resultType string). + * + * @param newClusterNodeType the newClusterNodeType value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withNewClusterNodeType(Object newClusterNodeType) { + this.newClusterNodeType = newClusterNodeType; + return this; + } + + /** + * Get a set of optional, user-specified Spark configuration key-value pairs. + * + * @return the newClusterSparkConf value + */ + public Map newClusterSparkConf() { + return this.newClusterSparkConf; + } + + /** + * Set a set of optional, user-specified Spark configuration key-value pairs. + * + * @param newClusterSparkConf the newClusterSparkConf value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withNewClusterSparkConf(Map newClusterSparkConf) { + this.newClusterSparkConf = newClusterSparkConf; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureDatabricksLinkedService object itself. + */ + public AzureDatabricksLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureKeyVaultLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureKeyVaultLinkedService.java new file mode 100644 index 000000000000..0dae9d58e316 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureKeyVaultLinkedService.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure Key Vault linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureKeyVault") +@JsonFlatten +public class AzureKeyVaultLinkedService extends LinkedServiceInner { + /** + * The base URL of the Azure Key Vault. e.g. https://myakv.vault.azure.net + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.baseUrl", required = true) + private Object baseUrl; + + /** + * Get the base URL of the Azure Key Vault. e.g. https://myakv.vault.azure.net Type: string (or Expression with resultType string). + * + * @return the baseUrl value + */ + public Object baseUrl() { + return this.baseUrl; + } + + /** + * Set the base URL of the Azure Key Vault. e.g. https://myakv.vault.azure.net Type: string (or Expression with resultType string). + * + * @param baseUrl the baseUrl value to set + * @return the AzureKeyVaultLinkedService object itself. + */ + public AzureKeyVaultLinkedService withBaseUrl(Object baseUrl) { + this.baseUrl = baseUrl; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureKeyVaultSecretReference.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureKeyVaultSecretReference.java new file mode 100644 index 000000000000..9e94451faf0e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureKeyVaultSecretReference.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * Azure Key Vault secret reference. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureKeyVaultSecret") +public class AzureKeyVaultSecretReference extends SecretBase { + /** + * The Azure Key Vault linked service reference. + */ + @JsonProperty(value = "store", required = true) + private LinkedServiceReference store; + + /** + * The name of the secret in Azure Key Vault. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "secretName", required = true) + private Object secretName; + + /** + * The version of the secret in Azure Key Vault. The default value is the + * latest version of the secret. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "secretVersion") + private Object secretVersion; + + /** + * Get the Azure Key Vault linked service reference. + * + * @return the store value + */ + public LinkedServiceReference store() { + return this.store; + } + + /** + * Set the Azure Key Vault linked service reference. + * + * @param store the store value to set + * @return the AzureKeyVaultSecretReference object itself. + */ + public AzureKeyVaultSecretReference withStore(LinkedServiceReference store) { + this.store = store; + return this; + } + + /** + * Get the name of the secret in Azure Key Vault. Type: string (or Expression with resultType string). + * + * @return the secretName value + */ + public Object secretName() { + return this.secretName; + } + + /** + * Set the name of the secret in Azure Key Vault. Type: string (or Expression with resultType string). + * + * @param secretName the secretName value to set + * @return the AzureKeyVaultSecretReference object itself. + */ + public AzureKeyVaultSecretReference withSecretName(Object secretName) { + this.secretName = secretName; + return this; + } + + /** + * Get the version of the secret in Azure Key Vault. The default value is the latest version of the secret. Type: string (or Expression with resultType string). + * + * @return the secretVersion value + */ + public Object secretVersion() { + return this.secretVersion; + } + + /** + * Set the version of the secret in Azure Key Vault. The default value is the latest version of the secret. Type: string (or Expression with resultType string). + * + * @param secretVersion the secretVersion value to set + * @return the AzureKeyVaultSecretReference object itself. + */ + public AzureKeyVaultSecretReference withSecretVersion(Object secretVersion) { + this.secretVersion = secretVersion; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLBatchExecutionActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLBatchExecutionActivity.java new file mode 100644 index 000000000000..d2fa4a99973d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLBatchExecutionActivity.java @@ -0,0 +1,111 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Azure ML Batch Execution activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureMLBatchExecution") +@JsonFlatten +public class AzureMLBatchExecutionActivity extends ExecutionActivity { + /** + * Key,Value pairs to be passed to the Azure ML Batch Execution Service + * endpoint. Keys must match the names of web service parameters defined in + * the published Azure ML web service. Values will be passed in the + * GlobalParameters property of the Azure ML batch execution request. + */ + @JsonProperty(value = "typeProperties.globalParameters") + private Map globalParameters; + + /** + * Key,Value pairs, mapping the names of Azure ML endpoint's Web Service + * Outputs to AzureMLWebServiceFile objects specifying the output Blob + * locations. This information will be passed in the WebServiceOutputs + * property of the Azure ML batch execution request. + */ + @JsonProperty(value = "typeProperties.webServiceOutputs") + private Map webServiceOutputs; + + /** + * Key,Value pairs, mapping the names of Azure ML endpoint's Web Service + * Inputs to AzureMLWebServiceFile objects specifying the input Blob + * locations.. This information will be passed in the WebServiceInputs + * property of the Azure ML batch execution request. + */ + @JsonProperty(value = "typeProperties.webServiceInputs") + private Map webServiceInputs; + + /** + * Get key,Value pairs to be passed to the Azure ML Batch Execution Service endpoint. Keys must match the names of web service parameters defined in the published Azure ML web service. Values will be passed in the GlobalParameters property of the Azure ML batch execution request. + * + * @return the globalParameters value + */ + public Map globalParameters() { + return this.globalParameters; + } + + /** + * Set key,Value pairs to be passed to the Azure ML Batch Execution Service endpoint. Keys must match the names of web service parameters defined in the published Azure ML web service. Values will be passed in the GlobalParameters property of the Azure ML batch execution request. + * + * @param globalParameters the globalParameters value to set + * @return the AzureMLBatchExecutionActivity object itself. + */ + public AzureMLBatchExecutionActivity withGlobalParameters(Map globalParameters) { + this.globalParameters = globalParameters; + return this; + } + + /** + * Get key,Value pairs, mapping the names of Azure ML endpoint's Web Service Outputs to AzureMLWebServiceFile objects specifying the output Blob locations. This information will be passed in the WebServiceOutputs property of the Azure ML batch execution request. + * + * @return the webServiceOutputs value + */ + public Map webServiceOutputs() { + return this.webServiceOutputs; + } + + /** + * Set key,Value pairs, mapping the names of Azure ML endpoint's Web Service Outputs to AzureMLWebServiceFile objects specifying the output Blob locations. This information will be passed in the WebServiceOutputs property of the Azure ML batch execution request. + * + * @param webServiceOutputs the webServiceOutputs value to set + * @return the AzureMLBatchExecutionActivity object itself. + */ + public AzureMLBatchExecutionActivity withWebServiceOutputs(Map webServiceOutputs) { + this.webServiceOutputs = webServiceOutputs; + return this; + } + + /** + * Get key,Value pairs, mapping the names of Azure ML endpoint's Web Service Inputs to AzureMLWebServiceFile objects specifying the input Blob locations.. This information will be passed in the WebServiceInputs property of the Azure ML batch execution request. + * + * @return the webServiceInputs value + */ + public Map webServiceInputs() { + return this.webServiceInputs; + } + + /** + * Set key,Value pairs, mapping the names of Azure ML endpoint's Web Service Inputs to AzureMLWebServiceFile objects specifying the input Blob locations.. This information will be passed in the WebServiceInputs property of the Azure ML batch execution request. + * + * @param webServiceInputs the webServiceInputs value to set + * @return the AzureMLBatchExecutionActivity object itself. + */ + public AzureMLBatchExecutionActivity withWebServiceInputs(Map webServiceInputs) { + this.webServiceInputs = webServiceInputs; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLLinkedService.java new file mode 100644 index 000000000000..4ca8a8226867 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLLinkedService.java @@ -0,0 +1,214 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure ML Web Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureML") +@JsonFlatten +public class AzureMLLinkedService extends LinkedServiceInner { + /** + * The Batch Execution REST URL for an Azure ML Web Service endpoint. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.mlEndpoint", required = true) + private Object mlEndpoint; + + /** + * The API key for accessing the Azure ML model endpoint. + */ + @JsonProperty(value = "typeProperties.apiKey", required = true) + private SecretBase apiKey; + + /** + * The Update Resource REST URL for an Azure ML Web Service endpoint. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.updateResourceEndpoint") + private Object updateResourceEndpoint; + + /** + * The ID of the service principal used to authenticate against the + * ARM-based updateResourceEndpoint of an Azure ML web service. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.servicePrincipalId") + private Object servicePrincipalId; + + /** + * The key of the service principal used to authenticate against the + * ARM-based updateResourceEndpoint of an Azure ML web service. + */ + @JsonProperty(value = "typeProperties.servicePrincipalKey") + private SecretBase servicePrincipalKey; + + /** + * The name or ID of the tenant to which the service principal belongs. + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tenant") + private Object tenant; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the Batch Execution REST URL for an Azure ML Web Service endpoint. Type: string (or Expression with resultType string). + * + * @return the mlEndpoint value + */ + public Object mlEndpoint() { + return this.mlEndpoint; + } + + /** + * Set the Batch Execution REST URL for an Azure ML Web Service endpoint. Type: string (or Expression with resultType string). + * + * @param mlEndpoint the mlEndpoint value to set + * @return the AzureMLLinkedService object itself. + */ + public AzureMLLinkedService withMlEndpoint(Object mlEndpoint) { + this.mlEndpoint = mlEndpoint; + return this; + } + + /** + * Get the API key for accessing the Azure ML model endpoint. + * + * @return the apiKey value + */ + public SecretBase apiKey() { + return this.apiKey; + } + + /** + * Set the API key for accessing the Azure ML model endpoint. + * + * @param apiKey the apiKey value to set + * @return the AzureMLLinkedService object itself. + */ + public AzureMLLinkedService withApiKey(SecretBase apiKey) { + this.apiKey = apiKey; + return this; + } + + /** + * Get the Update Resource REST URL for an Azure ML Web Service endpoint. Type: string (or Expression with resultType string). + * + * @return the updateResourceEndpoint value + */ + public Object updateResourceEndpoint() { + return this.updateResourceEndpoint; + } + + /** + * Set the Update Resource REST URL for an Azure ML Web Service endpoint. Type: string (or Expression with resultType string). + * + * @param updateResourceEndpoint the updateResourceEndpoint value to set + * @return the AzureMLLinkedService object itself. + */ + public AzureMLLinkedService withUpdateResourceEndpoint(Object updateResourceEndpoint) { + this.updateResourceEndpoint = updateResourceEndpoint; + return this; + } + + /** + * Get the ID of the service principal used to authenticate against the ARM-based updateResourceEndpoint of an Azure ML web service. Type: string (or Expression with resultType string). + * + * @return the servicePrincipalId value + */ + public Object servicePrincipalId() { + return this.servicePrincipalId; + } + + /** + * Set the ID of the service principal used to authenticate against the ARM-based updateResourceEndpoint of an Azure ML web service. Type: string (or Expression with resultType string). + * + * @param servicePrincipalId the servicePrincipalId value to set + * @return the AzureMLLinkedService object itself. + */ + public AzureMLLinkedService withServicePrincipalId(Object servicePrincipalId) { + this.servicePrincipalId = servicePrincipalId; + return this; + } + + /** + * Get the key of the service principal used to authenticate against the ARM-based updateResourceEndpoint of an Azure ML web service. + * + * @return the servicePrincipalKey value + */ + public SecretBase servicePrincipalKey() { + return this.servicePrincipalKey; + } + + /** + * Set the key of the service principal used to authenticate against the ARM-based updateResourceEndpoint of an Azure ML web service. + * + * @param servicePrincipalKey the servicePrincipalKey value to set + * @return the AzureMLLinkedService object itself. + */ + public AzureMLLinkedService withServicePrincipalKey(SecretBase servicePrincipalKey) { + this.servicePrincipalKey = servicePrincipalKey; + return this; + } + + /** + * Get the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @return the tenant value + */ + public Object tenant() { + return this.tenant; + } + + /** + * Set the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @param tenant the tenant value to set + * @return the AzureMLLinkedService object itself. + */ + public AzureMLLinkedService withTenant(Object tenant) { + this.tenant = tenant; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureMLLinkedService object itself. + */ + public AzureMLLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLUpdateResourceActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLUpdateResourceActivity.java new file mode 100644 index 000000000000..447e9712d1db --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLUpdateResourceActivity.java @@ -0,0 +1,105 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Azure ML Update Resource management activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureMLUpdateResource") +@JsonFlatten +public class AzureMLUpdateResourceActivity extends ExecutionActivity { + /** + * Name of the Trained Model module in the Web Service experiment to be + * updated. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.trainedModelName", required = true) + private Object trainedModelName; + + /** + * Name of Azure Storage linked service holding the .ilearner file that + * will be uploaded by the update operation. + */ + @JsonProperty(value = "typeProperties.trainedModelLinkedServiceName", required = true) + private LinkedServiceReference trainedModelLinkedServiceName; + + /** + * The relative file path in trainedModelLinkedService to represent the + * .ilearner file that will be uploaded by the update operation. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.trainedModelFilePath", required = true) + private Object trainedModelFilePath; + + /** + * Get name of the Trained Model module in the Web Service experiment to be updated. Type: string (or Expression with resultType string). + * + * @return the trainedModelName value + */ + public Object trainedModelName() { + return this.trainedModelName; + } + + /** + * Set name of the Trained Model module in the Web Service experiment to be updated. Type: string (or Expression with resultType string). + * + * @param trainedModelName the trainedModelName value to set + * @return the AzureMLUpdateResourceActivity object itself. + */ + public AzureMLUpdateResourceActivity withTrainedModelName(Object trainedModelName) { + this.trainedModelName = trainedModelName; + return this; + } + + /** + * Get name of Azure Storage linked service holding the .ilearner file that will be uploaded by the update operation. + * + * @return the trainedModelLinkedServiceName value + */ + public LinkedServiceReference trainedModelLinkedServiceName() { + return this.trainedModelLinkedServiceName; + } + + /** + * Set name of Azure Storage linked service holding the .ilearner file that will be uploaded by the update operation. + * + * @param trainedModelLinkedServiceName the trainedModelLinkedServiceName value to set + * @return the AzureMLUpdateResourceActivity object itself. + */ + public AzureMLUpdateResourceActivity withTrainedModelLinkedServiceName(LinkedServiceReference trainedModelLinkedServiceName) { + this.trainedModelLinkedServiceName = trainedModelLinkedServiceName; + return this; + } + + /** + * Get the relative file path in trainedModelLinkedService to represent the .ilearner file that will be uploaded by the update operation. Type: string (or Expression with resultType string). + * + * @return the trainedModelFilePath value + */ + public Object trainedModelFilePath() { + return this.trainedModelFilePath; + } + + /** + * Set the relative file path in trainedModelLinkedService to represent the .ilearner file that will be uploaded by the update operation. Type: string (or Expression with resultType string). + * + * @param trainedModelFilePath the trainedModelFilePath value to set + * @return the AzureMLUpdateResourceActivity object itself. + */ + public AzureMLUpdateResourceActivity withTrainedModelFilePath(Object trainedModelFilePath) { + this.trainedModelFilePath = trainedModelFilePath; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLWebServiceFile.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLWebServiceFile.java new file mode 100644 index 000000000000..e1e5a35f5e91 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMLWebServiceFile.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Azure ML WebService Input/Output file. + */ +public class AzureMLWebServiceFile { + /** + * The relative file path, including container name, in the Azure Blob + * Storage specified by the LinkedService. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "filePath", required = true) + private Object filePath; + + /** + * Reference to an Azure Storage LinkedService, where Azure ML WebService + * Input/Output file located. + */ + @JsonProperty(value = "linkedServiceName", required = true) + private LinkedServiceReference linkedServiceName; + + /** + * Get the relative file path, including container name, in the Azure Blob Storage specified by the LinkedService. Type: string (or Expression with resultType string). + * + * @return the filePath value + */ + public Object filePath() { + return this.filePath; + } + + /** + * Set the relative file path, including container name, in the Azure Blob Storage specified by the LinkedService. Type: string (or Expression with resultType string). + * + * @param filePath the filePath value to set + * @return the AzureMLWebServiceFile object itself. + */ + public AzureMLWebServiceFile withFilePath(Object filePath) { + this.filePath = filePath; + return this; + } + + /** + * Get reference to an Azure Storage LinkedService, where Azure ML WebService Input/Output file located. + * + * @return the linkedServiceName value + */ + public LinkedServiceReference linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set reference to an Azure Storage LinkedService, where Azure ML WebService Input/Output file located. + * + * @param linkedServiceName the linkedServiceName value to set + * @return the AzureMLWebServiceFile object itself. + */ + public AzureMLWebServiceFile withLinkedServiceName(LinkedServiceReference linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlLinkedService.java new file mode 100644 index 000000000000..5d8164e7e457 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure MySQL database linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureMySql") +@JsonFlatten +public class AzureMySqlLinkedService extends LinkedServiceInner { + /** + * The connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the AzureMySqlLinkedService object itself. + */ + public AzureMySqlLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureMySqlLinkedService object itself. + */ + public AzureMySqlLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlSource.java new file mode 100644 index 000000000000..93bfb696cd28 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlSource.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure MySQL source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureMySqlSource") +public class AzureMySqlSource extends CopySource { + /** + * Database query. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get database query. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set database query. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the AzureMySqlSource object itself. + */ + public AzureMySqlSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlTableDataset.java new file mode 100644 index 000000000000..0ddb55d3a276 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureMySqlTableDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Azure MySQL database dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureMySqlTable") +@JsonFlatten +public class AzureMySqlTableDataset extends DatasetInner { + /** + * The Azure MySQL database table name. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.tableName") + private Object tableName; + + /** + * Get the Azure MySQL database table name. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the Azure MySQL database table name. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the AzureMySqlTableDataset object itself. + */ + public AzureMySqlTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlLinkedService.java new file mode 100644 index 000000000000..f5180f2815bc --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure PostgreSQL linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzurePostgreSql") +@JsonFlatten +public class AzurePostgreSqlLinkedService extends LinkedServiceInner { + /** + * An ODBC connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the AzurePostgreSqlLinkedService object itself. + */ + public AzurePostgreSqlLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzurePostgreSqlLinkedService object itself. + */ + public AzurePostgreSqlLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlSource.java new file mode 100644 index 000000000000..3ff27d13695a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure PostgreSQL source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzurePostgreSqlSource") +public class AzurePostgreSqlSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the AzurePostgreSqlSource object itself. + */ + public AzurePostgreSqlSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlTableDataset.java new file mode 100644 index 000000000000..fc6a9f6748da --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzurePostgreSqlTableDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Azure PostgreSQL dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzurePostgreSqlTable") +public class AzurePostgreSqlTableDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureQueueSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureQueueSink.java new file mode 100644 index 000000000000..9068b529db6a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureQueueSink.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Queue sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureQueueSink") +public class AzureQueueSink extends CopySink { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchIndexDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchIndexDataset.java new file mode 100644 index 000000000000..eea64dd01f5c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchIndexDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Azure Search Index. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureSearchIndex") +@JsonFlatten +public class AzureSearchIndexDataset extends DatasetInner { + /** + * The name of the Azure Search Index. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.indexName", required = true) + private Object indexName; + + /** + * Get the name of the Azure Search Index. Type: string (or Expression with resultType string). + * + * @return the indexName value + */ + public Object indexName() { + return this.indexName; + } + + /** + * Set the name of the Azure Search Index. Type: string (or Expression with resultType string). + * + * @param indexName the indexName value to set + * @return the AzureSearchIndexDataset object itself. + */ + public AzureSearchIndexDataset withIndexName(Object indexName) { + this.indexName = indexName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchIndexSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchIndexSink.java new file mode 100644 index 000000000000..9ae8525579a5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchIndexSink.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Search Index sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureSearchIndexSink") +public class AzureSearchIndexSink extends CopySink { + /** + * Specify the write behavior when upserting documents into Azure Search + * Index. + */ + @JsonProperty(value = "writeBehavior") + private Object writeBehavior; + + /** + * Get specify the write behavior when upserting documents into Azure Search Index. + * + * @return the writeBehavior value + */ + public Object writeBehavior() { + return this.writeBehavior; + } + + /** + * Set specify the write behavior when upserting documents into Azure Search Index. + * + * @param writeBehavior the writeBehavior value to set + * @return the AzureSearchIndexSink object itself. + */ + public AzureSearchIndexSink withWriteBehavior(Object writeBehavior) { + this.writeBehavior = writeBehavior; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchLinkedService.java new file mode 100644 index 000000000000..c464e275eaee --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSearchLinkedService.java @@ -0,0 +1,105 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for Windows Azure Search Service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureSearch") +@JsonFlatten +public class AzureSearchLinkedService extends LinkedServiceInner { + /** + * URL for Azure Search service. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.url", required = true) + private Object url; + + /** + * Admin Key for Azure Search service. + */ + @JsonProperty(value = "typeProperties.key") + private SecretBase key; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get uRL for Azure Search service. Type: string (or Expression with resultType string). + * + * @return the url value + */ + public Object url() { + return this.url; + } + + /** + * Set uRL for Azure Search service. Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the AzureSearchLinkedService object itself. + */ + public AzureSearchLinkedService withUrl(Object url) { + this.url = url; + return this; + } + + /** + * Get admin Key for Azure Search service. + * + * @return the key value + */ + public SecretBase key() { + return this.key; + } + + /** + * Set admin Key for Azure Search service. + * + * @param key the key value to set + * @return the AzureSearchLinkedService object itself. + */ + public AzureSearchLinkedService withKey(SecretBase key) { + this.key = key; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureSearchLinkedService object itself. + */ + public AzureSearchLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDWLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDWLinkedService.java new file mode 100644 index 000000000000..3760eec08c19 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDWLinkedService.java @@ -0,0 +1,161 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Azure SQL Data Warehouse linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureSqlDW") +@JsonFlatten +public class AzureSqlDWLinkedService extends LinkedServiceInner { + /** + * The connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private Object connectionString; + + /** + * The ID of the service principal used to authenticate against Azure SQL + * Data Warehouse. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.servicePrincipalId") + private Object servicePrincipalId; + + /** + * The key of the service principal used to authenticate against Azure SQL + * Data Warehouse. + */ + @JsonProperty(value = "typeProperties.servicePrincipalKey") + private SecretBase servicePrincipalKey; + + /** + * The name or ID of the tenant to which the service principal belongs. + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tenant") + private Object tenant; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the AzureSqlDWLinkedService object itself. + */ + public AzureSqlDWLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the ID of the service principal used to authenticate against Azure SQL Data Warehouse. Type: string (or Expression with resultType string). + * + * @return the servicePrincipalId value + */ + public Object servicePrincipalId() { + return this.servicePrincipalId; + } + + /** + * Set the ID of the service principal used to authenticate against Azure SQL Data Warehouse. Type: string (or Expression with resultType string). + * + * @param servicePrincipalId the servicePrincipalId value to set + * @return the AzureSqlDWLinkedService object itself. + */ + public AzureSqlDWLinkedService withServicePrincipalId(Object servicePrincipalId) { + this.servicePrincipalId = servicePrincipalId; + return this; + } + + /** + * Get the key of the service principal used to authenticate against Azure SQL Data Warehouse. + * + * @return the servicePrincipalKey value + */ + public SecretBase servicePrincipalKey() { + return this.servicePrincipalKey; + } + + /** + * Set the key of the service principal used to authenticate against Azure SQL Data Warehouse. + * + * @param servicePrincipalKey the servicePrincipalKey value to set + * @return the AzureSqlDWLinkedService object itself. + */ + public AzureSqlDWLinkedService withServicePrincipalKey(SecretBase servicePrincipalKey) { + this.servicePrincipalKey = servicePrincipalKey; + return this; + } + + /** + * Get the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @return the tenant value + */ + public Object tenant() { + return this.tenant; + } + + /** + * Set the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @param tenant the tenant value to set + * @return the AzureSqlDWLinkedService object itself. + */ + public AzureSqlDWLinkedService withTenant(Object tenant) { + this.tenant = tenant; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureSqlDWLinkedService object itself. + */ + public AzureSqlDWLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDWTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDWTableDataset.java new file mode 100644 index 000000000000..15b048a010eb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDWTableDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Azure SQL Data Warehouse dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureSqlDWTable") +@JsonFlatten +public class AzureSqlDWTableDataset extends DatasetInner { + /** + * The table name of the Azure SQL Data Warehouse. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tableName", required = true) + private Object tableName; + + /** + * Get the table name of the Azure SQL Data Warehouse. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the table name of the Azure SQL Data Warehouse. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the AzureSqlDWTableDataset object itself. + */ + public AzureSqlDWTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDatabaseLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDatabaseLinkedService.java new file mode 100644 index 000000000000..ce76849ac373 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlDatabaseLinkedService.java @@ -0,0 +1,160 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Microsoft Azure SQL Database linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureSqlDatabase") +@JsonFlatten +public class AzureSqlDatabaseLinkedService extends LinkedServiceInner { + /** + * The connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private Object connectionString; + + /** + * The ID of the service principal used to authenticate against Azure SQL + * Database. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.servicePrincipalId") + private Object servicePrincipalId; + + /** + * The key of the service principal used to authenticate against Azure SQL + * Database. + */ + @JsonProperty(value = "typeProperties.servicePrincipalKey") + private SecretBase servicePrincipalKey; + + /** + * The name or ID of the tenant to which the service principal belongs. + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tenant") + private Object tenant; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the AzureSqlDatabaseLinkedService object itself. + */ + public AzureSqlDatabaseLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the ID of the service principal used to authenticate against Azure SQL Database. Type: string (or Expression with resultType string). + * + * @return the servicePrincipalId value + */ + public Object servicePrincipalId() { + return this.servicePrincipalId; + } + + /** + * Set the ID of the service principal used to authenticate against Azure SQL Database. Type: string (or Expression with resultType string). + * + * @param servicePrincipalId the servicePrincipalId value to set + * @return the AzureSqlDatabaseLinkedService object itself. + */ + public AzureSqlDatabaseLinkedService withServicePrincipalId(Object servicePrincipalId) { + this.servicePrincipalId = servicePrincipalId; + return this; + } + + /** + * Get the key of the service principal used to authenticate against Azure SQL Database. + * + * @return the servicePrincipalKey value + */ + public SecretBase servicePrincipalKey() { + return this.servicePrincipalKey; + } + + /** + * Set the key of the service principal used to authenticate against Azure SQL Database. + * + * @param servicePrincipalKey the servicePrincipalKey value to set + * @return the AzureSqlDatabaseLinkedService object itself. + */ + public AzureSqlDatabaseLinkedService withServicePrincipalKey(SecretBase servicePrincipalKey) { + this.servicePrincipalKey = servicePrincipalKey; + return this; + } + + /** + * Get the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @return the tenant value + */ + public Object tenant() { + return this.tenant; + } + + /** + * Set the name or ID of the tenant to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @param tenant the tenant value to set + * @return the AzureSqlDatabaseLinkedService object itself. + */ + public AzureSqlDatabaseLinkedService withTenant(Object tenant) { + this.tenant = tenant; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureSqlDatabaseLinkedService object itself. + */ + public AzureSqlDatabaseLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlTableDataset.java new file mode 100644 index 000000000000..3786d8160477 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureSqlTableDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Azure SQL Server database dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureSqlTable") +@JsonFlatten +public class AzureSqlTableDataset extends DatasetInner { + /** + * The table name of the Azure SQL database. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.tableName", required = true) + private Object tableName; + + /** + * Get the table name of the Azure SQL database. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the table name of the Azure SQL database. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the AzureSqlTableDataset object itself. + */ + public AzureSqlTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureStorageLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureStorageLinkedService.java new file mode 100644 index 000000000000..28401da5afe7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureStorageLinkedService.java @@ -0,0 +1,106 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * The storage account linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureStorage") +@JsonFlatten +public class AzureStorageLinkedService extends LinkedServiceInner { + /** + * The connection string. It is mutually exclusive with sasUri property. + * Type: string, SecureString or AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * SAS URI of the Azure Storage resource. It is mutually exclusive with + * connectionString property. + */ + @JsonProperty(value = "typeProperties.sasUri") + private SecretBase sasUri; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. It is mutually exclusive with sasUri property. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. It is mutually exclusive with sasUri property. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the AzureStorageLinkedService object itself. + */ + public AzureStorageLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get sAS URI of the Azure Storage resource. It is mutually exclusive with connectionString property. + * + * @return the sasUri value + */ + public SecretBase sasUri() { + return this.sasUri; + } + + /** + * Set sAS URI of the Azure Storage resource. It is mutually exclusive with connectionString property. + * + * @param sasUri the sasUri value to set + * @return the AzureStorageLinkedService object itself. + */ + public AzureStorageLinkedService withSasUri(SecretBase sasUri) { + this.sasUri = sasUri; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the AzureStorageLinkedService object itself. + */ + public AzureStorageLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableDataset.java new file mode 100644 index 000000000000..2acdd3474bc0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Azure Table storage dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureTable") +@JsonFlatten +public class AzureTableDataset extends DatasetInner { + /** + * The table name of the Azure Table storage. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.tableName", required = true) + private Object tableName; + + /** + * Get the table name of the Azure Table storage. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the table name of the Azure Table storage. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the AzureTableDataset object itself. + */ + public AzureTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableSink.java new file mode 100644 index 000000000000..1cb5b65e9bcb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableSink.java @@ -0,0 +1,129 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Table sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureTableSink") +public class AzureTableSink extends CopySink { + /** + * Azure Table default partition key value. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "azureTableDefaultPartitionKeyValue") + private Object azureTableDefaultPartitionKeyValue; + + /** + * Azure Table partition key name. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "azureTablePartitionKeyName") + private Object azureTablePartitionKeyName; + + /** + * Azure Table row key name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "azureTableRowKeyName") + private Object azureTableRowKeyName; + + /** + * Azure Table insert type. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "azureTableInsertType") + private Object azureTableInsertType; + + /** + * Get azure Table default partition key value. Type: string (or Expression with resultType string). + * + * @return the azureTableDefaultPartitionKeyValue value + */ + public Object azureTableDefaultPartitionKeyValue() { + return this.azureTableDefaultPartitionKeyValue; + } + + /** + * Set azure Table default partition key value. Type: string (or Expression with resultType string). + * + * @param azureTableDefaultPartitionKeyValue the azureTableDefaultPartitionKeyValue value to set + * @return the AzureTableSink object itself. + */ + public AzureTableSink withAzureTableDefaultPartitionKeyValue(Object azureTableDefaultPartitionKeyValue) { + this.azureTableDefaultPartitionKeyValue = azureTableDefaultPartitionKeyValue; + return this; + } + + /** + * Get azure Table partition key name. Type: string (or Expression with resultType string). + * + * @return the azureTablePartitionKeyName value + */ + public Object azureTablePartitionKeyName() { + return this.azureTablePartitionKeyName; + } + + /** + * Set azure Table partition key name. Type: string (or Expression with resultType string). + * + * @param azureTablePartitionKeyName the azureTablePartitionKeyName value to set + * @return the AzureTableSink object itself. + */ + public AzureTableSink withAzureTablePartitionKeyName(Object azureTablePartitionKeyName) { + this.azureTablePartitionKeyName = azureTablePartitionKeyName; + return this; + } + + /** + * Get azure Table row key name. Type: string (or Expression with resultType string). + * + * @return the azureTableRowKeyName value + */ + public Object azureTableRowKeyName() { + return this.azureTableRowKeyName; + } + + /** + * Set azure Table row key name. Type: string (or Expression with resultType string). + * + * @param azureTableRowKeyName the azureTableRowKeyName value to set + * @return the AzureTableSink object itself. + */ + public AzureTableSink withAzureTableRowKeyName(Object azureTableRowKeyName) { + this.azureTableRowKeyName = azureTableRowKeyName; + return this; + } + + /** + * Get azure Table insert type. Type: string (or Expression with resultType string). + * + * @return the azureTableInsertType value + */ + public Object azureTableInsertType() { + return this.azureTableInsertType; + } + + /** + * Set azure Table insert type. Type: string (or Expression with resultType string). + * + * @param azureTableInsertType the azureTableInsertType value to set + * @return the AzureTableSink object itself. + */ + public AzureTableSink withAzureTableInsertType(Object azureTableInsertType) { + this.azureTableInsertType = azureTableInsertType; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableSource.java new file mode 100644 index 000000000000..0582408f5f7d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/AzureTableSource.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Table source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("AzureTableSource") +public class AzureTableSource extends CopySource { + /** + * Azure Table source query. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "azureTableSourceQuery") + private Object azureTableSourceQuery; + + /** + * Azure Table source ignore table not found. Type: boolean (or Expression + * with resultType boolean). + */ + @JsonProperty(value = "azureTableSourceIgnoreTableNotFound") + private Object azureTableSourceIgnoreTableNotFound; + + /** + * Get azure Table source query. Type: string (or Expression with resultType string). + * + * @return the azureTableSourceQuery value + */ + public Object azureTableSourceQuery() { + return this.azureTableSourceQuery; + } + + /** + * Set azure Table source query. Type: string (or Expression with resultType string). + * + * @param azureTableSourceQuery the azureTableSourceQuery value to set + * @return the AzureTableSource object itself. + */ + public AzureTableSource withAzureTableSourceQuery(Object azureTableSourceQuery) { + this.azureTableSourceQuery = azureTableSourceQuery; + return this; + } + + /** + * Get azure Table source ignore table not found. Type: boolean (or Expression with resultType boolean). + * + * @return the azureTableSourceIgnoreTableNotFound value + */ + public Object azureTableSourceIgnoreTableNotFound() { + return this.azureTableSourceIgnoreTableNotFound; + } + + /** + * Set azure Table source ignore table not found. Type: boolean (or Expression with resultType boolean). + * + * @param azureTableSourceIgnoreTableNotFound the azureTableSourceIgnoreTableNotFound value to set + * @return the AzureTableSource object itself. + */ + public AzureTableSource withAzureTableSourceIgnoreTableNotFound(Object azureTableSourceIgnoreTableNotFound) { + this.azureTableSourceIgnoreTableNotFound = azureTableSourceIgnoreTableNotFound; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobEventTypes.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobEventTypes.java new file mode 100644 index 000000000000..6f130a926306 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobEventTypes.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for BlobEventTypes. + */ +public final class BlobEventTypes extends ExpandableStringEnum { + /** Static value Microsoft.Storage.BlobCreated for BlobEventTypes. */ + public static final BlobEventTypes MICROSOFT_STORAGE_BLOB_CREATED = fromString("Microsoft.Storage.BlobCreated"); + + /** Static value Microsoft.Storage.BlobDeleted for BlobEventTypes. */ + public static final BlobEventTypes MICROSOFT_STORAGE_BLOB_DELETED = fromString("Microsoft.Storage.BlobDeleted"); + + /** + * Creates or finds a BlobEventTypes from its string representation. + * @param name a name to look for + * @return the corresponding BlobEventTypes + */ + @JsonCreator + public static BlobEventTypes fromString(String name) { + return fromString(name, BlobEventTypes.class); + } + + /** + * @return known BlobEventTypes values + */ + public static Collection values() { + return values(BlobEventTypes.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobEventsTrigger.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobEventsTrigger.java new file mode 100644 index 000000000000..62d3d3b31e58 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobEventsTrigger.java @@ -0,0 +1,134 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Trigger that runs every time a Blob event occurs. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("BlobEventsTrigger") +@JsonFlatten +public class BlobEventsTrigger extends MultiplePipelineTrigger { + /** + * The blob path must begin with the pattern provided for trigger to fire. + * For example, '/records/blobs/december/' will only fire the trigger for + * blobs in the december folder under the records container. At least one + * of these must be provided: blobPathBeginsWith, blobPathEndsWith. + */ + @JsonProperty(value = "typeProperties.blobPathBeginsWith") + private String blobPathBeginsWith; + + /** + * The blob path must end with the pattern provided for trigger to fire. + * For example, 'december/boxes.csv' will only fire the trigger for blobs + * named boxes in a december folder. At least one of these must be + * provided: blobPathBeginsWith, blobPathEndsWith. + */ + @JsonProperty(value = "typeProperties.blobPathEndsWith") + private String blobPathEndsWith; + + /** + * The type of events that cause this trigger to fire. + */ + @JsonProperty(value = "typeProperties.events", required = true) + private List events; + + /** + * The ARM resource ID of the Storage Account. + */ + @JsonProperty(value = "typeProperties.scope", required = true) + private String scope; + + /** + * Get the blob path must begin with the pattern provided for trigger to fire. For example, '/records/blobs/december/' will only fire the trigger for blobs in the december folder under the records container. At least one of these must be provided: blobPathBeginsWith, blobPathEndsWith. + * + * @return the blobPathBeginsWith value + */ + public String blobPathBeginsWith() { + return this.blobPathBeginsWith; + } + + /** + * Set the blob path must begin with the pattern provided for trigger to fire. For example, '/records/blobs/december/' will only fire the trigger for blobs in the december folder under the records container. At least one of these must be provided: blobPathBeginsWith, blobPathEndsWith. + * + * @param blobPathBeginsWith the blobPathBeginsWith value to set + * @return the BlobEventsTrigger object itself. + */ + public BlobEventsTrigger withBlobPathBeginsWith(String blobPathBeginsWith) { + this.blobPathBeginsWith = blobPathBeginsWith; + return this; + } + + /** + * Get the blob path must end with the pattern provided for trigger to fire. For example, 'december/boxes.csv' will only fire the trigger for blobs named boxes in a december folder. At least one of these must be provided: blobPathBeginsWith, blobPathEndsWith. + * + * @return the blobPathEndsWith value + */ + public String blobPathEndsWith() { + return this.blobPathEndsWith; + } + + /** + * Set the blob path must end with the pattern provided for trigger to fire. For example, 'december/boxes.csv' will only fire the trigger for blobs named boxes in a december folder. At least one of these must be provided: blobPathBeginsWith, blobPathEndsWith. + * + * @param blobPathEndsWith the blobPathEndsWith value to set + * @return the BlobEventsTrigger object itself. + */ + public BlobEventsTrigger withBlobPathEndsWith(String blobPathEndsWith) { + this.blobPathEndsWith = blobPathEndsWith; + return this; + } + + /** + * Get the type of events that cause this trigger to fire. + * + * @return the events value + */ + public List events() { + return this.events; + } + + /** + * Set the type of events that cause this trigger to fire. + * + * @param events the events value to set + * @return the BlobEventsTrigger object itself. + */ + public BlobEventsTrigger withEvents(List events) { + this.events = events; + return this; + } + + /** + * Get the ARM resource ID of the Storage Account. + * + * @return the scope value + */ + public String scope() { + return this.scope; + } + + /** + * Set the ARM resource ID of the Storage Account. + * + * @param scope the scope value to set + * @return the BlobEventsTrigger object itself. + */ + public BlobEventsTrigger withScope(String scope) { + this.scope = scope; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobSink.java new file mode 100644 index 000000000000..4c6f3ac89df6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobSink.java @@ -0,0 +1,128 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Blob sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("BlobSink") +public class BlobSink extends CopySink { + /** + * Blob writer overwrite files. Type: boolean (or Expression with + * resultType boolean). + */ + @JsonProperty(value = "blobWriterOverwriteFiles") + private Object blobWriterOverwriteFiles; + + /** + * Blob writer date time format. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "blobWriterDateTimeFormat") + private Object blobWriterDateTimeFormat; + + /** + * Blob writer add header. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "blobWriterAddHeader") + private Object blobWriterAddHeader; + + /** + * The type of copy behavior for copy sink. + */ + @JsonProperty(value = "copyBehavior") + private Object copyBehavior; + + /** + * Get blob writer overwrite files. Type: boolean (or Expression with resultType boolean). + * + * @return the blobWriterOverwriteFiles value + */ + public Object blobWriterOverwriteFiles() { + return this.blobWriterOverwriteFiles; + } + + /** + * Set blob writer overwrite files. Type: boolean (or Expression with resultType boolean). + * + * @param blobWriterOverwriteFiles the blobWriterOverwriteFiles value to set + * @return the BlobSink object itself. + */ + public BlobSink withBlobWriterOverwriteFiles(Object blobWriterOverwriteFiles) { + this.blobWriterOverwriteFiles = blobWriterOverwriteFiles; + return this; + } + + /** + * Get blob writer date time format. Type: string (or Expression with resultType string). + * + * @return the blobWriterDateTimeFormat value + */ + public Object blobWriterDateTimeFormat() { + return this.blobWriterDateTimeFormat; + } + + /** + * Set blob writer date time format. Type: string (or Expression with resultType string). + * + * @param blobWriterDateTimeFormat the blobWriterDateTimeFormat value to set + * @return the BlobSink object itself. + */ + public BlobSink withBlobWriterDateTimeFormat(Object blobWriterDateTimeFormat) { + this.blobWriterDateTimeFormat = blobWriterDateTimeFormat; + return this; + } + + /** + * Get blob writer add header. Type: boolean (or Expression with resultType boolean). + * + * @return the blobWriterAddHeader value + */ + public Object blobWriterAddHeader() { + return this.blobWriterAddHeader; + } + + /** + * Set blob writer add header. Type: boolean (or Expression with resultType boolean). + * + * @param blobWriterAddHeader the blobWriterAddHeader value to set + * @return the BlobSink object itself. + */ + public BlobSink withBlobWriterAddHeader(Object blobWriterAddHeader) { + this.blobWriterAddHeader = blobWriterAddHeader; + return this; + } + + /** + * Get the type of copy behavior for copy sink. + * + * @return the copyBehavior value + */ + public Object copyBehavior() { + return this.copyBehavior; + } + + /** + * Set the type of copy behavior for copy sink. + * + * @param copyBehavior the copyBehavior value to set + * @return the BlobSink object itself. + */ + public BlobSink withCopyBehavior(Object copyBehavior) { + this.copyBehavior = copyBehavior; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobSource.java new file mode 100644 index 000000000000..d95dd3cc3d4e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobSource.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Azure Blob source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("BlobSource") +public class BlobSource extends CopySource { + /** + * Treat empty as null. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "treatEmptyAsNull") + private Object treatEmptyAsNull; + + /** + * Number of header lines to skip from each blob. Type: integer (or + * Expression with resultType integer). + */ + @JsonProperty(value = "skipHeaderLineCount") + private Object skipHeaderLineCount; + + /** + * If true, files under the folder path will be read recursively. Default + * is true. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "recursive") + private Object recursive; + + /** + * Get treat empty as null. Type: boolean (or Expression with resultType boolean). + * + * @return the treatEmptyAsNull value + */ + public Object treatEmptyAsNull() { + return this.treatEmptyAsNull; + } + + /** + * Set treat empty as null. Type: boolean (or Expression with resultType boolean). + * + * @param treatEmptyAsNull the treatEmptyAsNull value to set + * @return the BlobSource object itself. + */ + public BlobSource withTreatEmptyAsNull(Object treatEmptyAsNull) { + this.treatEmptyAsNull = treatEmptyAsNull; + return this; + } + + /** + * Get number of header lines to skip from each blob. Type: integer (or Expression with resultType integer). + * + * @return the skipHeaderLineCount value + */ + public Object skipHeaderLineCount() { + return this.skipHeaderLineCount; + } + + /** + * Set number of header lines to skip from each blob. Type: integer (or Expression with resultType integer). + * + * @param skipHeaderLineCount the skipHeaderLineCount value to set + * @return the BlobSource object itself. + */ + public BlobSource withSkipHeaderLineCount(Object skipHeaderLineCount) { + this.skipHeaderLineCount = skipHeaderLineCount; + return this; + } + + /** + * Get if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @return the recursive value + */ + public Object recursive() { + return this.recursive; + } + + /** + * Set if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @param recursive the recursive value to set + * @return the BlobSource object itself. + */ + public BlobSource withRecursive(Object recursive) { + this.recursive = recursive; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobTrigger.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobTrigger.java new file mode 100644 index 000000000000..988f8b01a83f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/BlobTrigger.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Trigger that runs every time the selected Blob container changes. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("BlobTrigger") +@JsonFlatten +public class BlobTrigger extends MultiplePipelineTrigger { + /** + * The path of the container/folder that will trigger the pipeline. + */ + @JsonProperty(value = "typeProperties.folderPath", required = true) + private String folderPath; + + /** + * The max number of parallel files to handle when it is triggered. + */ + @JsonProperty(value = "typeProperties.maxConcurrency", required = true) + private int maxConcurrency; + + /** + * The Azure Storage linked service reference. + */ + @JsonProperty(value = "typeProperties.linkedService", required = true) + private LinkedServiceReference linkedService; + + /** + * Get the path of the container/folder that will trigger the pipeline. + * + * @return the folderPath value + */ + public String folderPath() { + return this.folderPath; + } + + /** + * Set the path of the container/folder that will trigger the pipeline. + * + * @param folderPath the folderPath value to set + * @return the BlobTrigger object itself. + */ + public BlobTrigger withFolderPath(String folderPath) { + this.folderPath = folderPath; + return this; + } + + /** + * Get the max number of parallel files to handle when it is triggered. + * + * @return the maxConcurrency value + */ + public int maxConcurrency() { + return this.maxConcurrency; + } + + /** + * Set the max number of parallel files to handle when it is triggered. + * + * @param maxConcurrency the maxConcurrency value to set + * @return the BlobTrigger object itself. + */ + public BlobTrigger withMaxConcurrency(int maxConcurrency) { + this.maxConcurrency = maxConcurrency; + return this; + } + + /** + * Get the Azure Storage linked service reference. + * + * @return the linkedService value + */ + public LinkedServiceReference linkedService() { + return this.linkedService; + } + + /** + * Set the Azure Storage linked service reference. + * + * @param linkedService the linkedService value to set + * @return the BlobTrigger object itself. + */ + public BlobTrigger withLinkedService(LinkedServiceReference linkedService) { + this.linkedService = linkedService; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraLinkedService.java new file mode 100644 index 000000000000..8276eeaeff1b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraLinkedService.java @@ -0,0 +1,186 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for Cassandra data source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Cassandra") +@JsonFlatten +public class CassandraLinkedService extends LinkedServiceInner { + /** + * Host name for connection. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * AuthenticationType to be used for connection. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.authenticationType") + private Object authenticationType; + + /** + * The port for the connection. Type: integer (or Expression with + * resultType integer). + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * Username for authentication. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * Password for authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get host name for connection. Type: string (or Expression with resultType string). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set host name for connection. Type: string (or Expression with resultType string). + * + * @param host the host value to set + * @return the CassandraLinkedService object itself. + */ + public CassandraLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get authenticationType to be used for connection. Type: string (or Expression with resultType string). + * + * @return the authenticationType value + */ + public Object authenticationType() { + return this.authenticationType; + } + + /** + * Set authenticationType to be used for connection. Type: string (or Expression with resultType string). + * + * @param authenticationType the authenticationType value to set + * @return the CassandraLinkedService object itself. + */ + public CassandraLinkedService withAuthenticationType(Object authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the port for the connection. Type: integer (or Expression with resultType integer). + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the port for the connection. Type: integer (or Expression with resultType integer). + * + * @param port the port value to set + * @return the CassandraLinkedService object itself. + */ + public CassandraLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get username for authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set username for authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the CassandraLinkedService object itself. + */ + public CassandraLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get password for authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for authentication. + * + * @param password the password value to set + * @return the CassandraLinkedService object itself. + */ + public CassandraLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the CassandraLinkedService object itself. + */ + public CassandraLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraSource.java new file mode 100644 index 000000000000..c7a8fa474fa2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraSource.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for a Cassandra database. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CassandraSource") +public class CassandraSource extends CopySource { + /** + * Database query. Should be a SQL-92 query expression or Cassandra Query + * Language (CQL) command. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * The consistency level specifies how many Cassandra servers must respond + * to a read request before returning data to the client application. + * Cassandra checks the specified number of Cassandra servers for data to + * satisfy the read request. Must be one of + * cassandraSourceReadConsistencyLevels. The default value is 'ONE'. It is + * case-insensitive. + */ + @JsonProperty(value = "consistencyLevel") + private Object consistencyLevel; + + /** + * Get database query. Should be a SQL-92 query expression or Cassandra Query Language (CQL) command. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set database query. Should be a SQL-92 query expression or Cassandra Query Language (CQL) command. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the CassandraSource object itself. + */ + public CassandraSource withQuery(Object query) { + this.query = query; + return this; + } + + /** + * Get the consistency level specifies how many Cassandra servers must respond to a read request before returning data to the client application. Cassandra checks the specified number of Cassandra servers for data to satisfy the read request. Must be one of cassandraSourceReadConsistencyLevels. The default value is 'ONE'. It is case-insensitive. + * + * @return the consistencyLevel value + */ + public Object consistencyLevel() { + return this.consistencyLevel; + } + + /** + * Set the consistency level specifies how many Cassandra servers must respond to a read request before returning data to the client application. Cassandra checks the specified number of Cassandra servers for data to satisfy the read request. Must be one of cassandraSourceReadConsistencyLevels. The default value is 'ONE'. It is case-insensitive. + * + * @param consistencyLevel the consistencyLevel value to set + * @return the CassandraSource object itself. + */ + public CassandraSource withConsistencyLevel(Object consistencyLevel) { + this.consistencyLevel = consistencyLevel; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraTableDataset.java new file mode 100644 index 000000000000..d1429a1d4661 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CassandraTableDataset.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Cassandra database dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CassandraTable") +@JsonFlatten +public class CassandraTableDataset extends DatasetInner { + /** + * The table name of the Cassandra database. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.tableName") + private Object tableName; + + /** + * The keyspace of the Cassandra database. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.keyspace") + private Object keyspace; + + /** + * Get the table name of the Cassandra database. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the table name of the Cassandra database. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the CassandraTableDataset object itself. + */ + public CassandraTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + + /** + * Get the keyspace of the Cassandra database. Type: string (or Expression with resultType string). + * + * @return the keyspace value + */ + public Object keyspace() { + return this.keyspace; + } + + /** + * Set the keyspace of the Cassandra database. Type: string (or Expression with resultType string). + * + * @param keyspace the keyspace value to set + * @return the CassandraTableDataset object itself. + */ + public CassandraTableDataset withKeyspace(Object keyspace) { + this.keyspace = keyspace; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurLinkedService.java new file mode 100644 index 000000000000..73318750647e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurLinkedService.java @@ -0,0 +1,213 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Concur Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Concur") +@JsonFlatten +public class ConcurLinkedService extends LinkedServiceInner { + /** + * Application client_id supplied by Concur App Management. + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * The user name that you use to access Concur Service. + */ + @JsonProperty(value = "typeProperties.username", required = true) + private Object username; + + /** + * The password corresponding to the user name that you provided in the + * username field. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get application client_id supplied by Concur App Management. + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set application client_id supplied by Concur App Management. + * + * @param clientId the clientId value to set + * @return the ConcurLinkedService object itself. + */ + public ConcurLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the user name that you use to access Concur Service. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name that you use to access Concur Service. + * + * @param username the username value to set + * @return the ConcurLinkedService object itself. + */ + public ConcurLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name that you provided in the username field. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name that you provided in the username field. + * + * @param password the password value to set + * @return the ConcurLinkedService object itself. + */ + public ConcurLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the ConcurLinkedService object itself. + */ + public ConcurLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the ConcurLinkedService object itself. + */ + public ConcurLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the ConcurLinkedService object itself. + */ + public ConcurLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the ConcurLinkedService object itself. + */ + public ConcurLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurObjectDataset.java new file mode 100644 index 000000000000..f9aa1daf0b60 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Concur Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ConcurObject") +public class ConcurObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurSource.java new file mode 100644 index 000000000000..5c6d2f3bdd21 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ConcurSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Concur Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ConcurSource") +public class ConcurSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the ConcurSource object itself. + */ + public ConcurSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ControlActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ControlActivity.java new file mode 100644 index 000000000000..6538f50b51ab --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ControlActivity.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Base class for all control activities like IfCondition, ForEach , Until. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Container") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "Filter", value = FilterActivity.class), + @JsonSubTypes.Type(name = "Until", value = UntilActivity.class), + @JsonSubTypes.Type(name = "Wait", value = WaitActivity.class), + @JsonSubTypes.Type(name = "ForEach", value = ForEachActivity.class), + @JsonSubTypes.Type(name = "IfCondition", value = IfConditionActivity.class), + @JsonSubTypes.Type(name = "ExecutePipeline", value = ExecutePipelineActivity.class) +}) +public class ControlActivity extends Activity { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopyActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopyActivity.java new file mode 100644 index 000000000000..0555f3b06489 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopyActivity.java @@ -0,0 +1,317 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Copy activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Copy") +@JsonFlatten +public class CopyActivity extends ExecutionActivity { + /** + * Copy activity source. + */ + @JsonProperty(value = "typeProperties.source", required = true) + private CopySource source; + + /** + * Copy activity sink. + */ + @JsonProperty(value = "typeProperties.sink", required = true) + private CopySink sink; + + /** + * Copy activity translator. If not specified, tabular translator is used. + */ + @JsonProperty(value = "typeProperties.translator") + private Object translator; + + /** + * Specifies whether to copy data via an interim staging. Default value is + * false. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "typeProperties.enableStaging") + private Object enableStaging; + + /** + * Specifies interim staging settings when EnableStaging is true. + */ + @JsonProperty(value = "typeProperties.stagingSettings") + private StagingSettings stagingSettings; + + /** + * Maximum number of concurrent sessions opened on the source or sink to + * avoid overloading the data store. Type: integer (or Expression with + * resultType integer), minimum: 0. + */ + @JsonProperty(value = "typeProperties.parallelCopies") + private Object parallelCopies; + + /** + * Maximum number of cloud data movement units that can be used to perform + * this data movement. Type: integer (or Expression with resultType + * integer), minimum: 0. + */ + @JsonProperty(value = "typeProperties.cloudDataMovementUnits") + private Object cloudDataMovementUnits; + + /** + * Whether to skip incompatible row. Default value is false. Type: boolean + * (or Expression with resultType boolean). + */ + @JsonProperty(value = "typeProperties.enableSkipIncompatibleRow") + private Object enableSkipIncompatibleRow; + + /** + * Redirect incompatible row settings when EnableSkipIncompatibleRow is + * true. + */ + @JsonProperty(value = "typeProperties.redirectIncompatibleRowSettings") + private RedirectIncompatibleRowSettings redirectIncompatibleRowSettings; + + /** + * List of inputs for the activity. + */ + @JsonProperty(value = "inputs") + private List inputs; + + /** + * List of outputs for the activity. + */ + @JsonProperty(value = "outputs") + private List outputs; + + /** + * Get copy activity source. + * + * @return the source value + */ + public CopySource source() { + return this.source; + } + + /** + * Set copy activity source. + * + * @param source the source value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withSource(CopySource source) { + this.source = source; + return this; + } + + /** + * Get copy activity sink. + * + * @return the sink value + */ + public CopySink sink() { + return this.sink; + } + + /** + * Set copy activity sink. + * + * @param sink the sink value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withSink(CopySink sink) { + this.sink = sink; + return this; + } + + /** + * Get copy activity translator. If not specified, tabular translator is used. + * + * @return the translator value + */ + public Object translator() { + return this.translator; + } + + /** + * Set copy activity translator. If not specified, tabular translator is used. + * + * @param translator the translator value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withTranslator(Object translator) { + this.translator = translator; + return this; + } + + /** + * Get specifies whether to copy data via an interim staging. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @return the enableStaging value + */ + public Object enableStaging() { + return this.enableStaging; + } + + /** + * Set specifies whether to copy data via an interim staging. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @param enableStaging the enableStaging value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withEnableStaging(Object enableStaging) { + this.enableStaging = enableStaging; + return this; + } + + /** + * Get specifies interim staging settings when EnableStaging is true. + * + * @return the stagingSettings value + */ + public StagingSettings stagingSettings() { + return this.stagingSettings; + } + + /** + * Set specifies interim staging settings when EnableStaging is true. + * + * @param stagingSettings the stagingSettings value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withStagingSettings(StagingSettings stagingSettings) { + this.stagingSettings = stagingSettings; + return this; + } + + /** + * Get maximum number of concurrent sessions opened on the source or sink to avoid overloading the data store. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the parallelCopies value + */ + public Object parallelCopies() { + return this.parallelCopies; + } + + /** + * Set maximum number of concurrent sessions opened on the source or sink to avoid overloading the data store. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param parallelCopies the parallelCopies value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withParallelCopies(Object parallelCopies) { + this.parallelCopies = parallelCopies; + return this; + } + + /** + * Get maximum number of cloud data movement units that can be used to perform this data movement. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the cloudDataMovementUnits value + */ + public Object cloudDataMovementUnits() { + return this.cloudDataMovementUnits; + } + + /** + * Set maximum number of cloud data movement units that can be used to perform this data movement. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param cloudDataMovementUnits the cloudDataMovementUnits value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withCloudDataMovementUnits(Object cloudDataMovementUnits) { + this.cloudDataMovementUnits = cloudDataMovementUnits; + return this; + } + + /** + * Get whether to skip incompatible row. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @return the enableSkipIncompatibleRow value + */ + public Object enableSkipIncompatibleRow() { + return this.enableSkipIncompatibleRow; + } + + /** + * Set whether to skip incompatible row. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @param enableSkipIncompatibleRow the enableSkipIncompatibleRow value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withEnableSkipIncompatibleRow(Object enableSkipIncompatibleRow) { + this.enableSkipIncompatibleRow = enableSkipIncompatibleRow; + return this; + } + + /** + * Get redirect incompatible row settings when EnableSkipIncompatibleRow is true. + * + * @return the redirectIncompatibleRowSettings value + */ + public RedirectIncompatibleRowSettings redirectIncompatibleRowSettings() { + return this.redirectIncompatibleRowSettings; + } + + /** + * Set redirect incompatible row settings when EnableSkipIncompatibleRow is true. + * + * @param redirectIncompatibleRowSettings the redirectIncompatibleRowSettings value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withRedirectIncompatibleRowSettings(RedirectIncompatibleRowSettings redirectIncompatibleRowSettings) { + this.redirectIncompatibleRowSettings = redirectIncompatibleRowSettings; + return this; + } + + /** + * Get list of inputs for the activity. + * + * @return the inputs value + */ + public List inputs() { + return this.inputs; + } + + /** + * Set list of inputs for the activity. + * + * @param inputs the inputs value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withInputs(List inputs) { + this.inputs = inputs; + return this; + } + + /** + * Get list of outputs for the activity. + * + * @return the outputs value + */ + public List outputs() { + return this.outputs; + } + + /** + * Set list of outputs for the activity. + * + * @param outputs the outputs value to set + * @return the CopyActivity object itself. + */ + public CopyActivity withOutputs(List outputs) { + this.outputs = outputs; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopySink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopySink.java new file mode 100644 index 000000000000..94d92848506e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopySink.java @@ -0,0 +1,172 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * A copy activity sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CopySink") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "SalesforceSink", value = SalesforceSink.class), + @JsonSubTypes.Type(name = "DynamicsSink", value = DynamicsSink.class), + @JsonSubTypes.Type(name = "OdbcSink", value = OdbcSink.class), + @JsonSubTypes.Type(name = "AzureSearchIndexSink", value = AzureSearchIndexSink.class), + @JsonSubTypes.Type(name = "AzureDataLakeStoreSink", value = AzureDataLakeStoreSink.class), + @JsonSubTypes.Type(name = "OracleSink", value = OracleSink.class), + @JsonSubTypes.Type(name = "SqlDWSink", value = SqlDWSink.class), + @JsonSubTypes.Type(name = "SqlSink", value = SqlSink.class), + @JsonSubTypes.Type(name = "DocumentDbCollectionSink", value = DocumentDbCollectionSink.class), + @JsonSubTypes.Type(name = "FileSystemSink", value = FileSystemSink.class), + @JsonSubTypes.Type(name = "BlobSink", value = BlobSink.class), + @JsonSubTypes.Type(name = "AzureTableSink", value = AzureTableSink.class), + @JsonSubTypes.Type(name = "AzureQueueSink", value = AzureQueueSink.class), + @JsonSubTypes.Type(name = "SapCloudForCustomerSink", value = SapCloudForCustomerSink.class) +}) +public class CopySink { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Write batch size. Type: integer (or Expression with resultType integer), + * minimum: 0. + */ + @JsonProperty(value = "writeBatchSize") + private Object writeBatchSize; + + /** + * Write batch timeout. Type: string (or Expression with resultType + * string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "writeBatchTimeout") + private Object writeBatchTimeout; + + /** + * Sink retry count. Type: integer (or Expression with resultType integer). + */ + @JsonProperty(value = "sinkRetryCount") + private Object sinkRetryCount; + + /** + * Sink retry wait. Type: string (or Expression with resultType string), + * pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "sinkRetryWait") + private Object sinkRetryWait; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the CopySink object itself. + */ + public CopySink withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get write batch size. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the writeBatchSize value + */ + public Object writeBatchSize() { + return this.writeBatchSize; + } + + /** + * Set write batch size. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param writeBatchSize the writeBatchSize value to set + * @return the CopySink object itself. + */ + public CopySink withWriteBatchSize(Object writeBatchSize) { + this.writeBatchSize = writeBatchSize; + return this; + } + + /** + * Get write batch timeout. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the writeBatchTimeout value + */ + public Object writeBatchTimeout() { + return this.writeBatchTimeout; + } + + /** + * Set write batch timeout. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param writeBatchTimeout the writeBatchTimeout value to set + * @return the CopySink object itself. + */ + public CopySink withWriteBatchTimeout(Object writeBatchTimeout) { + this.writeBatchTimeout = writeBatchTimeout; + return this; + } + + /** + * Get sink retry count. Type: integer (or Expression with resultType integer). + * + * @return the sinkRetryCount value + */ + public Object sinkRetryCount() { + return this.sinkRetryCount; + } + + /** + * Set sink retry count. Type: integer (or Expression with resultType integer). + * + * @param sinkRetryCount the sinkRetryCount value to set + * @return the CopySink object itself. + */ + public CopySink withSinkRetryCount(Object sinkRetryCount) { + this.sinkRetryCount = sinkRetryCount; + return this; + } + + /** + * Get sink retry wait. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the sinkRetryWait value + */ + public Object sinkRetryWait() { + return this.sinkRetryWait; + } + + /** + * Set sink retry wait. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param sinkRetryWait the sinkRetryWait value to set + * @return the CopySink object itself. + */ + public CopySink withSinkRetryWait(Object sinkRetryWait) { + this.sinkRetryWait = sinkRetryWait; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopySource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopySource.java new file mode 100644 index 000000000000..e2975507b90a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CopySource.java @@ -0,0 +1,155 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * A copy activity source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CopySource") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "AmazonRedshiftSource", value = AmazonRedshiftSource.class), + @JsonSubTypes.Type(name = "ResponsysSource", value = ResponsysSource.class), + @JsonSubTypes.Type(name = "SalesforceMarketingCloudSource", value = SalesforceMarketingCloudSource.class), + @JsonSubTypes.Type(name = "VerticaSource", value = VerticaSource.class), + @JsonSubTypes.Type(name = "NetezzaSource", value = NetezzaSource.class), + @JsonSubTypes.Type(name = "ZohoSource", value = ZohoSource.class), + @JsonSubTypes.Type(name = "XeroSource", value = XeroSource.class), + @JsonSubTypes.Type(name = "SquareSource", value = SquareSource.class), + @JsonSubTypes.Type(name = "SparkSource", value = SparkSource.class), + @JsonSubTypes.Type(name = "ShopifySource", value = ShopifySource.class), + @JsonSubTypes.Type(name = "ServiceNowSource", value = ServiceNowSource.class), + @JsonSubTypes.Type(name = "QuickBooksSource", value = QuickBooksSource.class), + @JsonSubTypes.Type(name = "PrestoSource", value = PrestoSource.class), + @JsonSubTypes.Type(name = "PhoenixSource", value = PhoenixSource.class), + @JsonSubTypes.Type(name = "PaypalSource", value = PaypalSource.class), + @JsonSubTypes.Type(name = "MarketoSource", value = MarketoSource.class), + @JsonSubTypes.Type(name = "MariaDBSource", value = MariaDBSource.class), + @JsonSubTypes.Type(name = "MagentoSource", value = MagentoSource.class), + @JsonSubTypes.Type(name = "JiraSource", value = JiraSource.class), + @JsonSubTypes.Type(name = "ImpalaSource", value = ImpalaSource.class), + @JsonSubTypes.Type(name = "HubspotSource", value = HubspotSource.class), + @JsonSubTypes.Type(name = "HiveSource", value = HiveSource.class), + @JsonSubTypes.Type(name = "HBaseSource", value = HBaseSource.class), + @JsonSubTypes.Type(name = "GreenplumSource", value = GreenplumSource.class), + @JsonSubTypes.Type(name = "GoogleBigQuerySource", value = GoogleBigQuerySource.class), + @JsonSubTypes.Type(name = "EloquaSource", value = EloquaSource.class), + @JsonSubTypes.Type(name = "DrillSource", value = DrillSource.class), + @JsonSubTypes.Type(name = "CouchbaseSource", value = CouchbaseSource.class), + @JsonSubTypes.Type(name = "ConcurSource", value = ConcurSource.class), + @JsonSubTypes.Type(name = "AzurePostgreSqlSource", value = AzurePostgreSqlSource.class), + @JsonSubTypes.Type(name = "AmazonMWSSource", value = AmazonMWSSource.class), + @JsonSubTypes.Type(name = "HttpSource", value = HttpSource.class), + @JsonSubTypes.Type(name = "AzureDataLakeStoreSource", value = AzureDataLakeStoreSource.class), + @JsonSubTypes.Type(name = "MongoDbSource", value = MongoDbSource.class), + @JsonSubTypes.Type(name = "CassandraSource", value = CassandraSource.class), + @JsonSubTypes.Type(name = "WebSource", value = WebSource.class), + @JsonSubTypes.Type(name = "OracleSource", value = OracleSource.class), + @JsonSubTypes.Type(name = "AzureMySqlSource", value = AzureMySqlSource.class), + @JsonSubTypes.Type(name = "HdfsSource", value = HdfsSource.class), + @JsonSubTypes.Type(name = "FileSystemSource", value = FileSystemSource.class), + @JsonSubTypes.Type(name = "SqlDWSource", value = SqlDWSource.class), + @JsonSubTypes.Type(name = "SqlSource", value = SqlSource.class), + @JsonSubTypes.Type(name = "SapEccSource", value = SapEccSource.class), + @JsonSubTypes.Type(name = "SapCloudForCustomerSource", value = SapCloudForCustomerSource.class), + @JsonSubTypes.Type(name = "SalesforceSource", value = SalesforceSource.class), + @JsonSubTypes.Type(name = "RelationalSource", value = RelationalSource.class), + @JsonSubTypes.Type(name = "DynamicsSource", value = DynamicsSource.class), + @JsonSubTypes.Type(name = "DocumentDbCollectionSource", value = DocumentDbCollectionSource.class), + @JsonSubTypes.Type(name = "BlobSource", value = BlobSource.class), + @JsonSubTypes.Type(name = "AzureTableSource", value = AzureTableSource.class) +}) +public class CopySource { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Source retry count. Type: integer (or Expression with resultType + * integer). + */ + @JsonProperty(value = "sourceRetryCount") + private Object sourceRetryCount; + + /** + * Source retry wait. Type: string (or Expression with resultType string), + * pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "sourceRetryWait") + private Object sourceRetryWait; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the CopySource object itself. + */ + public CopySource withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get source retry count. Type: integer (or Expression with resultType integer). + * + * @return the sourceRetryCount value + */ + public Object sourceRetryCount() { + return this.sourceRetryCount; + } + + /** + * Set source retry count. Type: integer (or Expression with resultType integer). + * + * @param sourceRetryCount the sourceRetryCount value to set + * @return the CopySource object itself. + */ + public CopySource withSourceRetryCount(Object sourceRetryCount) { + this.sourceRetryCount = sourceRetryCount; + return this; + } + + /** + * Get source retry wait. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the sourceRetryWait value + */ + public Object sourceRetryWait() { + return this.sourceRetryWait; + } + + /** + * Set source retry wait. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param sourceRetryWait the sourceRetryWait value to set + * @return the CopySource object itself. + */ + public CopySource withSourceRetryWait(Object sourceRetryWait) { + this.sourceRetryWait = sourceRetryWait; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CosmosDbLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CosmosDbLinkedService.java new file mode 100644 index 000000000000..e0d5e6d96f0d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CosmosDbLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Microsoft Azure Cosmos Database (CosmosDB) linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CosmosDb") +@JsonFlatten +public class CosmosDbLinkedService extends LinkedServiceInner { + /** + * The connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the CosmosDbLinkedService object itself. + */ + public CosmosDbLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the CosmosDbLinkedService object itself. + */ + public CosmosDbLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseLinkedService.java new file mode 100644 index 000000000000..8e7dc70cc298 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Couchbase server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Couchbase") +@JsonFlatten +public class CouchbaseLinkedService extends LinkedServiceInner { + /** + * An ODBC connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the CouchbaseLinkedService object itself. + */ + public CouchbaseLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the CouchbaseLinkedService object itself. + */ + public CouchbaseLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseSource.java new file mode 100644 index 000000000000..36827fe573c4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Couchbase server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CouchbaseSource") +public class CouchbaseSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the CouchbaseSource object itself. + */ + public CouchbaseSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseTableDataset.java new file mode 100644 index 000000000000..c194dfe24c13 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CouchbaseTableDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Couchbase server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CouchbaseTable") +public class CouchbaseTableDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CreateRunResponse.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CreateRunResponse.java new file mode 100644 index 000000000000..e3e457261ddb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CreateRunResponse.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.CreateRunResponseInner; + +/** + * Type representing CreateRunResponse. + */ +public interface CreateRunResponse extends HasInner, HasManager { + /** + * @return the runId value. + */ + String runId(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomActivity.java new file mode 100644 index 000000000000..8302ce27c79a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomActivity.java @@ -0,0 +1,158 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Custom activity type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Custom") +@JsonFlatten +public class CustomActivity extends ExecutionActivity { + /** + * Command for custom activity Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.command", required = true) + private Object command; + + /** + * Resource linked service reference. + */ + @JsonProperty(value = "typeProperties.resourceLinkedService") + private LinkedServiceReference resourceLinkedService; + + /** + * Folder path for resource files Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.folderPath") + private Object folderPath; + + /** + * Reference objects. + */ + @JsonProperty(value = "typeProperties.referenceObjects") + private CustomActivityReferenceObject referenceObjects; + + /** + * User defined property bag. There is no restriction on the keys or values + * that can be used. The user specified custom activity has the full + * responsibility to consume and interpret the content defined. + */ + @JsonProperty(value = "typeProperties.extendedProperties") + private Map extendedProperties; + + /** + * Get command for custom activity Type: string (or Expression with resultType string). + * + * @return the command value + */ + public Object command() { + return this.command; + } + + /** + * Set command for custom activity Type: string (or Expression with resultType string). + * + * @param command the command value to set + * @return the CustomActivity object itself. + */ + public CustomActivity withCommand(Object command) { + this.command = command; + return this; + } + + /** + * Get resource linked service reference. + * + * @return the resourceLinkedService value + */ + public LinkedServiceReference resourceLinkedService() { + return this.resourceLinkedService; + } + + /** + * Set resource linked service reference. + * + * @param resourceLinkedService the resourceLinkedService value to set + * @return the CustomActivity object itself. + */ + public CustomActivity withResourceLinkedService(LinkedServiceReference resourceLinkedService) { + this.resourceLinkedService = resourceLinkedService; + return this; + } + + /** + * Get folder path for resource files Type: string (or Expression with resultType string). + * + * @return the folderPath value + */ + public Object folderPath() { + return this.folderPath; + } + + /** + * Set folder path for resource files Type: string (or Expression with resultType string). + * + * @param folderPath the folderPath value to set + * @return the CustomActivity object itself. + */ + public CustomActivity withFolderPath(Object folderPath) { + this.folderPath = folderPath; + return this; + } + + /** + * Get reference objects. + * + * @return the referenceObjects value + */ + public CustomActivityReferenceObject referenceObjects() { + return this.referenceObjects; + } + + /** + * Set reference objects. + * + * @param referenceObjects the referenceObjects value to set + * @return the CustomActivity object itself. + */ + public CustomActivity withReferenceObjects(CustomActivityReferenceObject referenceObjects) { + this.referenceObjects = referenceObjects; + return this; + } + + /** + * Get user defined property bag. There is no restriction on the keys or values that can be used. The user specified custom activity has the full responsibility to consume and interpret the content defined. + * + * @return the extendedProperties value + */ + public Map extendedProperties() { + return this.extendedProperties; + } + + /** + * Set user defined property bag. There is no restriction on the keys or values that can be used. The user specified custom activity has the full responsibility to consume and interpret the content defined. + * + * @param extendedProperties the extendedProperties value to set + * @return the CustomActivity object itself. + */ + public CustomActivity withExtendedProperties(Map extendedProperties) { + this.extendedProperties = extendedProperties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomActivityReferenceObject.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomActivityReferenceObject.java new file mode 100644 index 000000000000..494dcbc172d2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomActivityReferenceObject.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Reference objects for custom activity. + */ +public class CustomActivityReferenceObject { + /** + * Linked service references. + */ + @JsonProperty(value = "linkedServices") + private List linkedServices; + + /** + * Dataset references. + */ + @JsonProperty(value = "datasets") + private List datasets; + + /** + * Get linked service references. + * + * @return the linkedServices value + */ + public List linkedServices() { + return this.linkedServices; + } + + /** + * Set linked service references. + * + * @param linkedServices the linkedServices value to set + * @return the CustomActivityReferenceObject object itself. + */ + public CustomActivityReferenceObject withLinkedServices(List linkedServices) { + this.linkedServices = linkedServices; + return this; + } + + /** + * Get dataset references. + * + * @return the datasets value + */ + public List datasets() { + return this.datasets; + } + + /** + * Set dataset references. + * + * @param datasets the datasets value to set + * @return the CustomActivityReferenceObject object itself. + */ + public CustomActivityReferenceObject withDatasets(List datasets) { + this.datasets = datasets; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomDataSourceLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomDataSourceLinkedService.java new file mode 100644 index 000000000000..b8dec1c0b3b0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomDataSourceLinkedService.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Custom linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CustomDataSource") +public class CustomDataSourceLinkedService extends LinkedServiceInner { + /** + * Custom linked service properties. + */ + @JsonProperty(value = "typeProperties", required = true) + private Object typeProperties; + + /** + * Get custom linked service properties. + * + * @return the typeProperties value + */ + public Object typeProperties() { + return this.typeProperties; + } + + /** + * Set custom linked service properties. + * + * @param typeProperties the typeProperties value to set + * @return the CustomDataSourceLinkedService object itself. + */ + public CustomDataSourceLinkedService withTypeProperties(Object typeProperties) { + this.typeProperties = typeProperties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomDataset.java new file mode 100644 index 000000000000..5155a59ba2ab --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/CustomDataset.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The custom dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("CustomDataset") +public class CustomDataset extends DatasetInner { + /** + * Custom dataset properties. + */ + @JsonProperty(value = "typeProperties", required = true) + private Object typeProperties; + + /** + * Get custom dataset properties. + * + * @return the typeProperties value + */ + public Object typeProperties() { + return this.typeProperties; + } + + /** + * Set custom dataset properties. + * + * @param typeProperties the typeProperties value to set + * @return the CustomDataset object itself. + */ + public CustomDataset withTypeProperties(Object typeProperties) { + this.typeProperties = typeProperties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DataLakeAnalyticsUSQLActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DataLakeAnalyticsUSQLActivity.java new file mode 100644 index 000000000000..1c182138ae11 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DataLakeAnalyticsUSQLActivity.java @@ -0,0 +1,214 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Data Lake Analytics U-SQL activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DataLakeAnalyticsU-SQL") +@JsonFlatten +public class DataLakeAnalyticsUSQLActivity extends ExecutionActivity { + /** + * Case-sensitive path to folder that contains the U-SQL script. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.scriptPath", required = true) + private Object scriptPath; + + /** + * Script linked service reference. + */ + @JsonProperty(value = "typeProperties.scriptLinkedService", required = true) + private LinkedServiceReference scriptLinkedService; + + /** + * The maximum number of nodes simultaneously used to run the job. Default + * value is 1. Type: integer (or Expression with resultType integer), + * minimum: 1. + */ + @JsonProperty(value = "typeProperties.degreeOfParallelism") + private Object degreeOfParallelism; + + /** + * Determines which jobs out of all that are queued should be selected to + * run first. The lower the number, the higher the priority. Default value + * is 1000. Type: integer (or Expression with resultType integer), minimum: + * 1. + */ + @JsonProperty(value = "typeProperties.priority") + private Object priority; + + /** + * Parameters for U-SQL job request. + */ + @JsonProperty(value = "typeProperties.parameters") + private Map parameters; + + /** + * Runtime version of the U-SQL engine to use. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.runtimeVersion") + private Object runtimeVersion; + + /** + * Compilation mode of U-SQL. Must be one of these values : Semantic, Full + * and SingleBox. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.compilationMode") + private Object compilationMode; + + /** + * Get case-sensitive path to folder that contains the U-SQL script. Type: string (or Expression with resultType string). + * + * @return the scriptPath value + */ + public Object scriptPath() { + return this.scriptPath; + } + + /** + * Set case-sensitive path to folder that contains the U-SQL script. Type: string (or Expression with resultType string). + * + * @param scriptPath the scriptPath value to set + * @return the DataLakeAnalyticsUSQLActivity object itself. + */ + public DataLakeAnalyticsUSQLActivity withScriptPath(Object scriptPath) { + this.scriptPath = scriptPath; + return this; + } + + /** + * Get script linked service reference. + * + * @return the scriptLinkedService value + */ + public LinkedServiceReference scriptLinkedService() { + return this.scriptLinkedService; + } + + /** + * Set script linked service reference. + * + * @param scriptLinkedService the scriptLinkedService value to set + * @return the DataLakeAnalyticsUSQLActivity object itself. + */ + public DataLakeAnalyticsUSQLActivity withScriptLinkedService(LinkedServiceReference scriptLinkedService) { + this.scriptLinkedService = scriptLinkedService; + return this; + } + + /** + * Get the maximum number of nodes simultaneously used to run the job. Default value is 1. Type: integer (or Expression with resultType integer), minimum: 1. + * + * @return the degreeOfParallelism value + */ + public Object degreeOfParallelism() { + return this.degreeOfParallelism; + } + + /** + * Set the maximum number of nodes simultaneously used to run the job. Default value is 1. Type: integer (or Expression with resultType integer), minimum: 1. + * + * @param degreeOfParallelism the degreeOfParallelism value to set + * @return the DataLakeAnalyticsUSQLActivity object itself. + */ + public DataLakeAnalyticsUSQLActivity withDegreeOfParallelism(Object degreeOfParallelism) { + this.degreeOfParallelism = degreeOfParallelism; + return this; + } + + /** + * Get determines which jobs out of all that are queued should be selected to run first. The lower the number, the higher the priority. Default value is 1000. Type: integer (or Expression with resultType integer), minimum: 1. + * + * @return the priority value + */ + public Object priority() { + return this.priority; + } + + /** + * Set determines which jobs out of all that are queued should be selected to run first. The lower the number, the higher the priority. Default value is 1000. Type: integer (or Expression with resultType integer), minimum: 1. + * + * @param priority the priority value to set + * @return the DataLakeAnalyticsUSQLActivity object itself. + */ + public DataLakeAnalyticsUSQLActivity withPriority(Object priority) { + this.priority = priority; + return this; + } + + /** + * Get parameters for U-SQL job request. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set parameters for U-SQL job request. + * + * @param parameters the parameters value to set + * @return the DataLakeAnalyticsUSQLActivity object itself. + */ + public DataLakeAnalyticsUSQLActivity withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + + /** + * Get runtime version of the U-SQL engine to use. Type: string (or Expression with resultType string). + * + * @return the runtimeVersion value + */ + public Object runtimeVersion() { + return this.runtimeVersion; + } + + /** + * Set runtime version of the U-SQL engine to use. Type: string (or Expression with resultType string). + * + * @param runtimeVersion the runtimeVersion value to set + * @return the DataLakeAnalyticsUSQLActivity object itself. + */ + public DataLakeAnalyticsUSQLActivity withRuntimeVersion(Object runtimeVersion) { + this.runtimeVersion = runtimeVersion; + return this; + } + + /** + * Get compilation mode of U-SQL. Must be one of these values : Semantic, Full and SingleBox. Type: string (or Expression with resultType string). + * + * @return the compilationMode value + */ + public Object compilationMode() { + return this.compilationMode; + } + + /** + * Set compilation mode of U-SQL. Must be one of these values : Semantic, Full and SingleBox. Type: string (or Expression with resultType string). + * + * @param compilationMode the compilationMode value to set + * @return the DataLakeAnalyticsUSQLActivity object itself. + */ + public DataLakeAnalyticsUSQLActivity withCompilationMode(Object compilationMode) { + this.compilationMode = compilationMode; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatabricksNotebookActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatabricksNotebookActivity.java new file mode 100644 index 000000000000..920e92a03576 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatabricksNotebookActivity.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * DatabricksNotebook activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DatabricksNotebook") +@JsonFlatten +public class DatabricksNotebookActivity extends ExecutionActivity { + /** + * The absolute path of the notebook to be run in the Databricks Workspace. + * This path must begin with a slash. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.notebookPath", required = true) + private Object notebookPath; + + /** + * Base parameters to be used for each run of this job.If the notebook + * takes a parameter that is not specified, the default value from the + * notebook will be used. + */ + @JsonProperty(value = "typeProperties.baseParameters") + private Map baseParameters; + + /** + * Get the absolute path of the notebook to be run in the Databricks Workspace. This path must begin with a slash. Type: string (or Expression with resultType string). + * + * @return the notebookPath value + */ + public Object notebookPath() { + return this.notebookPath; + } + + /** + * Set the absolute path of the notebook to be run in the Databricks Workspace. This path must begin with a slash. Type: string (or Expression with resultType string). + * + * @param notebookPath the notebookPath value to set + * @return the DatabricksNotebookActivity object itself. + */ + public DatabricksNotebookActivity withNotebookPath(Object notebookPath) { + this.notebookPath = notebookPath; + return this; + } + + /** + * Get base parameters to be used for each run of this job.If the notebook takes a parameter that is not specified, the default value from the notebook will be used. + * + * @return the baseParameters value + */ + public Map baseParameters() { + return this.baseParameters; + } + + /** + * Set base parameters to be used for each run of this job.If the notebook takes a parameter that is not specified, the default value from the notebook will be used. + * + * @param baseParameters the baseParameters value to set + * @return the DatabricksNotebookActivity object itself. + */ + public DatabricksNotebookActivity withBaseParameters(Map baseParameters) { + this.baseParameters = baseParameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetBZip2Compression.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetBZip2Compression.java new file mode 100644 index 000000000000..93544ae27755 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetBZip2Compression.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The BZip2 compression method used on a dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("BZip2") +public class DatasetBZip2Compression extends DatasetCompression { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetCompression.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetCompression.java new file mode 100644 index 000000000000..3fe22d349f7a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetCompression.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * The compression method used on a dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DatasetCompression") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "ZipDeflate", value = DatasetZipDeflateCompression.class), + @JsonSubTypes.Type(name = "Deflate", value = DatasetDeflateCompression.class), + @JsonSubTypes.Type(name = "GZip", value = DatasetGZipCompression.class), + @JsonSubTypes.Type(name = "BZip2", value = DatasetBZip2Compression.class) +}) +public class DatasetCompression { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the DatasetCompression object itself. + */ + public DatasetCompression withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetDeflateCompression.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetDeflateCompression.java new file mode 100644 index 000000000000..274b0f71133b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetDeflateCompression.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The Deflate compression method used on a dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Deflate") +public class DatasetDeflateCompression extends DatasetCompression { + /** + * The Deflate compression level. + */ + @JsonProperty(value = "level") + private Object level; + + /** + * Get the Deflate compression level. + * + * @return the level value + */ + public Object level() { + return this.level; + } + + /** + * Set the Deflate compression level. + * + * @param level the level value to set + * @return the DatasetDeflateCompression object itself. + */ + public DatasetDeflateCompression withLevel(Object level) { + this.level = level; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetGZipCompression.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetGZipCompression.java new file mode 100644 index 000000000000..a51d35a6523b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetGZipCompression.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The GZip compression method used on a dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("GZip") +public class DatasetGZipCompression extends DatasetCompression { + /** + * The GZip compression level. + */ + @JsonProperty(value = "level") + private Object level; + + /** + * Get the GZip compression level. + * + * @return the level value + */ + public Object level() { + return this.level; + } + + /** + * Set the GZip compression level. + * + * @param level the level value to set + * @return the DatasetGZipCompression object itself. + */ + public DatasetGZipCompression withLevel(Object level) { + this.level = level; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetReference.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetReference.java new file mode 100644 index 000000000000..4aeb1b6df3e1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetReference.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Dataset reference type. + */ +public class DatasetReference { + /** + * Dataset reference type. + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * Reference dataset name. + */ + @JsonProperty(value = "referenceName", required = true) + private String referenceName; + + /** + * Arguments for dataset. + */ + @JsonProperty(value = "parameters") + private Map parameters; + + /** + * Creates an instance of DatasetReference class. + * @param referenceName reference dataset name. + */ + public DatasetReference() { + type = "DatasetReference"; + } + + /** + * Get dataset reference type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set dataset reference type. + * + * @param type the type value to set + * @return the DatasetReference object itself. + */ + public DatasetReference withType(String type) { + this.type = type; + return this; + } + + /** + * Get reference dataset name. + * + * @return the referenceName value + */ + public String referenceName() { + return this.referenceName; + } + + /** + * Set reference dataset name. + * + * @param referenceName the referenceName value to set + * @return the DatasetReference object itself. + */ + public DatasetReference withReferenceName(String referenceName) { + this.referenceName = referenceName; + return this; + } + + /** + * Get arguments for dataset. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set arguments for dataset. + * + * @param parameters the parameters value to set + * @return the DatasetReference object itself. + */ + public DatasetReference withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetResource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetResource.java new file mode 100644 index 000000000000..ea368a4858e6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetResource.java @@ -0,0 +1,149 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetResourceInner; +import com.microsoft.azure.arm.model.Indexable; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; +import java.util.Map; +import java.util.List; + +/** + * Type representing DatasetResource. + */ +public interface DatasetResource extends HasInner, Indexable, Refreshable, Updatable, HasManager { + /** + * @return the etag value. + */ + String etag(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the properties value. + */ + DatasetInner properties(); + + /** + * @return the type value. + */ + String type(); + + /** + * The entirety of the DatasetResource definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithFactory, DefinitionStages.WithIfMatch, DefinitionStages.WithProperties, DefinitionStages.WithCreate { + } + + /** + * Grouping of DatasetResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a DatasetResource definition. + */ + interface Blank extends WithFactory { + } + + /** + * The stage of the datasetresource definition allowing to specify Factory. + */ + interface WithFactory { + /** + * Specifies resourceGroupName, factoryName. + * @param resourceGroupName The resource group name + * @param factoryName The factory name + * @return the next definition stage + */ + WithIfMatch withExistingFactory(String resourceGroupName, String factoryName); + } + + /** + * The stage of the datasetresource definition allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the dataset entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next definition stage + */ + WithProperties withIfMatch(String ifMatch); + } + + /** + * The stage of the datasetresource definition allowing to specify Properties. + */ + interface WithProperties { + /** + * Specifies properties. + * @param properties Dataset properties + * @return the next definition stage + */ + WithCreate withProperties(DatasetInner properties); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable { + } + } + /** + * The template for a DatasetResource update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, UpdateStages.WithIfMatch, UpdateStages.WithProperties { + } + + /** + * Grouping of DatasetResource update stages. + */ + interface UpdateStages { + /** + * The stage of the datasetresource update allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the dataset entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next update stage + */ + Update withIfMatch(String ifMatch); + } + + /** + * The stage of the datasetresource update allowing to specify Properties. + */ + interface WithProperties { + /** + * Specifies properties. + * @param properties Dataset properties + * @return the next update stage + */ + Update withProperties(DatasetInner properties); + } + + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetStorageFormat.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetStorageFormat.java new file mode 100644 index 000000000000..e1b16cb65842 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetStorageFormat.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * The format definition of a storage. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DatasetStorageFormat") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "ParquetFormat", value = ParquetFormat.class), + @JsonSubTypes.Type(name = "OrcFormat", value = OrcFormat.class), + @JsonSubTypes.Type(name = "AvroFormat", value = AvroFormat.class), + @JsonSubTypes.Type(name = "JsonFormat", value = JsonFormat.class), + @JsonSubTypes.Type(name = "TextFormat", value = TextFormat.class) +}) +public class DatasetStorageFormat { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Serializer. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "serializer") + private Object serializer; + + /** + * Deserializer. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "deserializer") + private Object deserializer; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the DatasetStorageFormat object itself. + */ + public DatasetStorageFormat withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get serializer. Type: string (or Expression with resultType string). + * + * @return the serializer value + */ + public Object serializer() { + return this.serializer; + } + + /** + * Set serializer. Type: string (or Expression with resultType string). + * + * @param serializer the serializer value to set + * @return the DatasetStorageFormat object itself. + */ + public DatasetStorageFormat withSerializer(Object serializer) { + this.serializer = serializer; + return this; + } + + /** + * Get deserializer. Type: string (or Expression with resultType string). + * + * @return the deserializer value + */ + public Object deserializer() { + return this.deserializer; + } + + /** + * Set deserializer. Type: string (or Expression with resultType string). + * + * @param deserializer the deserializer value to set + * @return the DatasetStorageFormat object itself. + */ + public DatasetStorageFormat withDeserializer(Object deserializer) { + this.deserializer = deserializer; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetZipDeflateCompression.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetZipDeflateCompression.java new file mode 100644 index 000000000000..a9553708bb46 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DatasetZipDeflateCompression.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The ZipDeflate compression method used on a dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ZipDeflate") +public class DatasetZipDeflateCompression extends DatasetCompression { + /** + * The ZipDeflate compression level. + */ + @JsonProperty(value = "level") + private Object level; + + /** + * Get the ZipDeflate compression level. + * + * @return the level value + */ + public Object level() { + return this.level; + } + + /** + * Set the ZipDeflate compression level. + * + * @param level the level value to set + * @return the DatasetZipDeflateCompression object itself. + */ + public DatasetZipDeflateCompression withLevel(Object level) { + this.level = level; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Datasets.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Datasets.java new file mode 100644 index 000000000000..769dde976149 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Datasets.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import rx.Completable; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetsInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing Datasets. + */ +public interface Datasets extends SupportsCreating, HasInner { + /** + * Gets a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAsync(String resourceGroupName, String factoryName, String datasetName); + + /** + * Lists datasets. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listByFactoryAsync(final String resourceGroupName, final String factoryName); + + /** + * Deletes a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable deleteAsync(String resourceGroupName, String factoryName, String datasetName); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DayOfWeek.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DayOfWeek.java new file mode 100644 index 000000000000..569d54543d40 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DayOfWeek.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for DayOfWeek. + */ +public enum DayOfWeek { + /** Enum value Sunday. */ + SUNDAY("Sunday"), + + /** Enum value Monday. */ + MONDAY("Monday"), + + /** Enum value Tuesday. */ + TUESDAY("Tuesday"), + + /** Enum value Wednesday. */ + WEDNESDAY("Wednesday"), + + /** Enum value Thursday. */ + THURSDAY("Thursday"), + + /** Enum value Friday. */ + FRIDAY("Friday"), + + /** Enum value Saturday. */ + SATURDAY("Saturday"); + + /** The actual serialized value for a DayOfWeek instance. */ + private String value; + + DayOfWeek(String value) { + this.value = value; + } + + /** + * Parses a serialized value to a DayOfWeek instance. + * + * @param value the serialized value to parse. + * @return the parsed DayOfWeek object, or null if unable to parse. + */ + @JsonCreator + public static DayOfWeek fromString(String value) { + DayOfWeek[] items = DayOfWeek.values(); + for (DayOfWeek item : items) { + if (item.toString().equalsIgnoreCase(value)) { + return item; + } + } + return null; + } + + @JsonValue + @Override + public String toString() { + return this.value; + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DaysOfWeek.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DaysOfWeek.java new file mode 100644 index 000000000000..d305767bd604 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DaysOfWeek.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * Defines values for DaysOfWeek. + */ +public enum DaysOfWeek { + /** Enum value Sunday. */ + SUNDAY("Sunday"), + + /** Enum value Monday. */ + MONDAY("Monday"), + + /** Enum value Tuesday. */ + TUESDAY("Tuesday"), + + /** Enum value Wednesday. */ + WEDNESDAY("Wednesday"), + + /** Enum value Thursday. */ + THURSDAY("Thursday"), + + /** Enum value Friday. */ + FRIDAY("Friday"), + + /** Enum value Saturday. */ + SATURDAY("Saturday"); + + /** The actual serialized value for a DaysOfWeek instance. */ + private String value; + + DaysOfWeek(String value) { + this.value = value; + } + + /** + * Parses a serialized value to a DaysOfWeek instance. + * + * @param value the serialized value to parse. + * @return the parsed DaysOfWeek object, or null if unable to parse. + */ + @JsonCreator + public static DaysOfWeek fromString(String value) { + DaysOfWeek[] items = DaysOfWeek.values(); + for (DaysOfWeek item : items) { + if (item.toString().equalsIgnoreCase(value)) { + return item; + } + } + return null; + } + + @JsonValue + @Override + public String toString() { + return this.value; + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Db2AuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Db2AuthenticationType.java new file mode 100644 index 000000000000..0ff77b46e665 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Db2AuthenticationType.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for Db2AuthenticationType. + */ +public final class Db2AuthenticationType extends ExpandableStringEnum { + /** Static value Basic for Db2AuthenticationType. */ + public static final Db2AuthenticationType BASIC = fromString("Basic"); + + /** + * Creates or finds a Db2AuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding Db2AuthenticationType + */ + @JsonCreator + public static Db2AuthenticationType fromString(String name) { + return fromString(name, Db2AuthenticationType.class); + } + + /** + * @return known Db2AuthenticationType values + */ + public static Collection values() { + return values(Db2AuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Db2LinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Db2LinkedService.java new file mode 100644 index 000000000000..241e8b9f4a5c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Db2LinkedService.java @@ -0,0 +1,186 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for DB2 data source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Db2") +@JsonFlatten +public class Db2LinkedService extends LinkedServiceInner { + /** + * Server name for connection. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.server", required = true) + private Object server; + + /** + * Database name for connection. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.database", required = true) + private Object database; + + /** + * AuthenticationType to be used for connection. Possible values include: + * 'Basic'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private Db2AuthenticationType authenticationType; + + /** + * Username for authentication. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * Password for authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get server name for connection. Type: string (or Expression with resultType string). + * + * @return the server value + */ + public Object server() { + return this.server; + } + + /** + * Set server name for connection. Type: string (or Expression with resultType string). + * + * @param server the server value to set + * @return the Db2LinkedService object itself. + */ + public Db2LinkedService withServer(Object server) { + this.server = server; + return this; + } + + /** + * Get database name for connection. Type: string (or Expression with resultType string). + * + * @return the database value + */ + public Object database() { + return this.database; + } + + /** + * Set database name for connection. Type: string (or Expression with resultType string). + * + * @param database the database value to set + * @return the Db2LinkedService object itself. + */ + public Db2LinkedService withDatabase(Object database) { + this.database = database; + return this; + } + + /** + * Get authenticationType to be used for connection. Possible values include: 'Basic'. + * + * @return the authenticationType value + */ + public Db2AuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set authenticationType to be used for connection. Possible values include: 'Basic'. + * + * @param authenticationType the authenticationType value to set + * @return the Db2LinkedService object itself. + */ + public Db2LinkedService withAuthenticationType(Db2AuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get username for authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set username for authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the Db2LinkedService object itself. + */ + public Db2LinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get password for authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for authentication. + * + * @param password the password value to set + * @return the Db2LinkedService object itself. + */ + public Db2LinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the Db2LinkedService object itself. + */ + public Db2LinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DependencyCondition.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DependencyCondition.java new file mode 100644 index 000000000000..5ded9b209034 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DependencyCondition.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for DependencyCondition. + */ +public final class DependencyCondition extends ExpandableStringEnum { + /** Static value Succeeded for DependencyCondition. */ + public static final DependencyCondition SUCCEEDED = fromString("Succeeded"); + + /** Static value Failed for DependencyCondition. */ + public static final DependencyCondition FAILED = fromString("Failed"); + + /** Static value Skipped for DependencyCondition. */ + public static final DependencyCondition SKIPPED = fromString("Skipped"); + + /** Static value Completed for DependencyCondition. */ + public static final DependencyCondition COMPLETED = fromString("Completed"); + + /** + * Creates or finds a DependencyCondition from its string representation. + * @param name a name to look for + * @return the corresponding DependencyCondition + */ + @JsonCreator + public static DependencyCondition fromString(String name) { + return fromString(name, DependencyCondition.class); + } + + /** + * @return known DependencyCondition values + */ + public static Collection values() { + return values(DependencyCondition.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DistcpSettings.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DistcpSettings.java new file mode 100644 index 000000000000..7d1f8996bd22 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DistcpSettings.java @@ -0,0 +1,100 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Distcp settings. + */ +public class DistcpSettings { + /** + * Specifies the Yarn ResourceManager endpoint. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "resourceManagerEndpoint", required = true) + private Object resourceManagerEndpoint; + + /** + * Specifies an existing folder path which will be used to store temp + * Distcp command script. The script file is generated by ADF and will be + * removed after Copy job finished. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "tempScriptPath", required = true) + private Object tempScriptPath; + + /** + * Specifies the Distcp options. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "distcpOptions") + private Object distcpOptions; + + /** + * Get specifies the Yarn ResourceManager endpoint. Type: string (or Expression with resultType string). + * + * @return the resourceManagerEndpoint value + */ + public Object resourceManagerEndpoint() { + return this.resourceManagerEndpoint; + } + + /** + * Set specifies the Yarn ResourceManager endpoint. Type: string (or Expression with resultType string). + * + * @param resourceManagerEndpoint the resourceManagerEndpoint value to set + * @return the DistcpSettings object itself. + */ + public DistcpSettings withResourceManagerEndpoint(Object resourceManagerEndpoint) { + this.resourceManagerEndpoint = resourceManagerEndpoint; + return this; + } + + /** + * Get specifies an existing folder path which will be used to store temp Distcp command script. The script file is generated by ADF and will be removed after Copy job finished. Type: string (or Expression with resultType string). + * + * @return the tempScriptPath value + */ + public Object tempScriptPath() { + return this.tempScriptPath; + } + + /** + * Set specifies an existing folder path which will be used to store temp Distcp command script. The script file is generated by ADF and will be removed after Copy job finished. Type: string (or Expression with resultType string). + * + * @param tempScriptPath the tempScriptPath value to set + * @return the DistcpSettings object itself. + */ + public DistcpSettings withTempScriptPath(Object tempScriptPath) { + this.tempScriptPath = tempScriptPath; + return this; + } + + /** + * Get specifies the Distcp options. Type: string (or Expression with resultType string). + * + * @return the distcpOptions value + */ + public Object distcpOptions() { + return this.distcpOptions; + } + + /** + * Set specifies the Distcp options. Type: string (or Expression with resultType string). + * + * @param distcpOptions the distcpOptions value to set + * @return the DistcpSettings object itself. + */ + public DistcpSettings withDistcpOptions(Object distcpOptions) { + this.distcpOptions = distcpOptions; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionDataset.java new file mode 100644 index 000000000000..f64f948faf88 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Microsoft Azure Document Database Collection dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DocumentDbCollection") +@JsonFlatten +public class DocumentDbCollectionDataset extends DatasetInner { + /** + * Document Database collection name. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.collectionName", required = true) + private Object collectionName; + + /** + * Get document Database collection name. Type: string (or Expression with resultType string). + * + * @return the collectionName value + */ + public Object collectionName() { + return this.collectionName; + } + + /** + * Set document Database collection name. Type: string (or Expression with resultType string). + * + * @param collectionName the collectionName value to set + * @return the DocumentDbCollectionDataset object itself. + */ + public DocumentDbCollectionDataset withCollectionName(Object collectionName) { + this.collectionName = collectionName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionSink.java new file mode 100644 index 000000000000..4972567fc75e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionSink.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Document Database Collection sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DocumentDbCollectionSink") +public class DocumentDbCollectionSink extends CopySink { + /** + * Nested properties separator. Default is . (dot). Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "nestingSeparator") + private Object nestingSeparator; + + /** + * Get nested properties separator. Default is . (dot). Type: string (or Expression with resultType string). + * + * @return the nestingSeparator value + */ + public Object nestingSeparator() { + return this.nestingSeparator; + } + + /** + * Set nested properties separator. Default is . (dot). Type: string (or Expression with resultType string). + * + * @param nestingSeparator the nestingSeparator value to set + * @return the DocumentDbCollectionSink object itself. + */ + public DocumentDbCollectionSink withNestingSeparator(Object nestingSeparator) { + this.nestingSeparator = nestingSeparator; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionSource.java new file mode 100644 index 000000000000..ee4a1a573f51 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DocumentDbCollectionSource.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Document Database Collection source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DocumentDbCollectionSource") +public class DocumentDbCollectionSource extends CopySource { + /** + * Documents query. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Nested properties separator. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "nestingSeparator") + private Object nestingSeparator; + + /** + * Get documents query. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set documents query. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the DocumentDbCollectionSource object itself. + */ + public DocumentDbCollectionSource withQuery(Object query) { + this.query = query; + return this; + } + + /** + * Get nested properties separator. Type: string (or Expression with resultType string). + * + * @return the nestingSeparator value + */ + public Object nestingSeparator() { + return this.nestingSeparator; + } + + /** + * Set nested properties separator. Type: string (or Expression with resultType string). + * + * @param nestingSeparator the nestingSeparator value to set + * @return the DocumentDbCollectionSource object itself. + */ + public DocumentDbCollectionSource withNestingSeparator(Object nestingSeparator) { + this.nestingSeparator = nestingSeparator; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillLinkedService.java new file mode 100644 index 000000000000..5edeb15b225a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Drill server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Drill") +@JsonFlatten +public class DrillLinkedService extends LinkedServiceInner { + /** + * An ODBC connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the DrillLinkedService object itself. + */ + public DrillLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the DrillLinkedService object itself. + */ + public DrillLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillSource.java new file mode 100644 index 000000000000..79d19d044600 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Drill server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DrillSource") +public class DrillSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the DrillSource object itself. + */ + public DrillSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillTableDataset.java new file mode 100644 index 000000000000..c8a72db2dfb6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DrillTableDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Drill server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DrillTable") +public class DrillTableDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsEntityDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsEntityDataset.java new file mode 100644 index 000000000000..665445512ed0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsEntityDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Dynamics entity dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DynamicsEntity") +@JsonFlatten +public class DynamicsEntityDataset extends DatasetInner { + /** + * The logical name of the entity. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.entityName") + private Object entityName; + + /** + * Get the logical name of the entity. Type: string (or Expression with resultType string). + * + * @return the entityName value + */ + public Object entityName() { + return this.entityName; + } + + /** + * Set the logical name of the entity. Type: string (or Expression with resultType string). + * + * @param entityName the entityName value to set + * @return the DynamicsEntityDataset object itself. + */ + public DynamicsEntityDataset withEntityName(Object entityName) { + this.entityName = entityName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsLinkedService.java new file mode 100644 index 000000000000..c23b5ab5c4f1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsLinkedService.java @@ -0,0 +1,274 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Dynamics linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Dynamics") +@JsonFlatten +public class DynamicsLinkedService extends LinkedServiceInner { + /** + * The deployment type of the Dynamics instance. 'Online' for Dynamics + * Online and 'OnPremisesWithIfd' for Dynamics on-premises with Ifd. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.deploymentType", required = true) + private Object deploymentType; + + /** + * The host name of the on-premises Dynamics server. The property is + * required for on-prem and not allowed for online. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.hostName") + private Object hostName; + + /** + * The port of on-premises Dynamics server. The property is required for + * on-prem and not allowed for online. Default is 443. Type: integer (or + * Expression with resultType integer), minimum: 0. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The URL to the Microsoft Dynamics server. The property is required for + * on-line and not allowed for on-prem. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.serviceUri") + private Object serviceUri; + + /** + * The organization name of the Dynamics instance. The property is required + * for on-prem and required for online when there are more than one + * Dynamics instances associated with the user. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.organizationName") + private Object organizationName; + + /** + * The authentication type to connect to Dynamics server. 'Office365' for + * online scenario, 'Ifd' for on-premises with Ifd scenario. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private Object authenticationType; + + /** + * User name to access the Dynamics instance. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.username", required = true) + private Object username; + + /** + * Password to access the Dynamics instance. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the deployment type of the Dynamics instance. 'Online' for Dynamics Online and 'OnPremisesWithIfd' for Dynamics on-premises with Ifd. Type: string (or Expression with resultType string). + * + * @return the deploymentType value + */ + public Object deploymentType() { + return this.deploymentType; + } + + /** + * Set the deployment type of the Dynamics instance. 'Online' for Dynamics Online and 'OnPremisesWithIfd' for Dynamics on-premises with Ifd. Type: string (or Expression with resultType string). + * + * @param deploymentType the deploymentType value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withDeploymentType(Object deploymentType) { + this.deploymentType = deploymentType; + return this; + } + + /** + * Get the host name of the on-premises Dynamics server. The property is required for on-prem and not allowed for online. Type: string (or Expression with resultType string). + * + * @return the hostName value + */ + public Object hostName() { + return this.hostName; + } + + /** + * Set the host name of the on-premises Dynamics server. The property is required for on-prem and not allowed for online. Type: string (or Expression with resultType string). + * + * @param hostName the hostName value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withHostName(Object hostName) { + this.hostName = hostName; + return this; + } + + /** + * Get the port of on-premises Dynamics server. The property is required for on-prem and not allowed for online. Default is 443. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the port of on-premises Dynamics server. The property is required for on-prem and not allowed for online. Default is 443. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param port the port value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the URL to the Microsoft Dynamics server. The property is required for on-line and not allowed for on-prem. Type: string (or Expression with resultType string). + * + * @return the serviceUri value + */ + public Object serviceUri() { + return this.serviceUri; + } + + /** + * Set the URL to the Microsoft Dynamics server. The property is required for on-line and not allowed for on-prem. Type: string (or Expression with resultType string). + * + * @param serviceUri the serviceUri value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withServiceUri(Object serviceUri) { + this.serviceUri = serviceUri; + return this; + } + + /** + * Get the organization name of the Dynamics instance. The property is required for on-prem and required for online when there are more than one Dynamics instances associated with the user. Type: string (or Expression with resultType string). + * + * @return the organizationName value + */ + public Object organizationName() { + return this.organizationName; + } + + /** + * Set the organization name of the Dynamics instance. The property is required for on-prem and required for online when there are more than one Dynamics instances associated with the user. Type: string (or Expression with resultType string). + * + * @param organizationName the organizationName value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withOrganizationName(Object organizationName) { + this.organizationName = organizationName; + return this; + } + + /** + * Get the authentication type to connect to Dynamics server. 'Office365' for online scenario, 'Ifd' for on-premises with Ifd scenario. Type: string (or Expression with resultType string). + * + * @return the authenticationType value + */ + public Object authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to connect to Dynamics server. 'Office365' for online scenario, 'Ifd' for on-premises with Ifd scenario. Type: string (or Expression with resultType string). + * + * @param authenticationType the authenticationType value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withAuthenticationType(Object authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get user name to access the Dynamics instance. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set user name to access the Dynamics instance. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get password to access the Dynamics instance. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password to access the Dynamics instance. + * + * @param password the password value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the DynamicsLinkedService object itself. + */ + public DynamicsLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsSink.java new file mode 100644 index 000000000000..5f59928065ff --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsSink.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Dynamics sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DynamicsSink") +public class DynamicsSink extends CopySink { + /** + * The write behavior for the operation. + */ + @JsonProperty(value = "writeBehavior", required = true) + private Object writeBehavior; + + /** + * The flag indicating whether ignore null values from input dataset + * (except key fields) during write operation. Default is false. Type: + * boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "ignoreNullValues") + private Object ignoreNullValues; + + /** + * Creates an instance of DynamicsSink class. + */ + public DynamicsSink() { + writeBehavior = Upsert; + } + + /** + * Get the write behavior for the operation. + * + * @return the writeBehavior value + */ + public Object writeBehavior() { + return this.writeBehavior; + } + + /** + * Set the write behavior for the operation. + * + * @param writeBehavior the writeBehavior value to set + * @return the DynamicsSink object itself. + */ + public DynamicsSink withWriteBehavior(Object writeBehavior) { + this.writeBehavior = writeBehavior; + return this; + } + + /** + * Get the flag indicating whether ignore null values from input dataset (except key fields) during write operation. Default is false. Type: boolean (or Expression with resultType boolean). + * + * @return the ignoreNullValues value + */ + public Object ignoreNullValues() { + return this.ignoreNullValues; + } + + /** + * Set the flag indicating whether ignore null values from input dataset (except key fields) during write operation. Default is false. Type: boolean (or Expression with resultType boolean). + * + * @param ignoreNullValues the ignoreNullValues value to set + * @return the DynamicsSink object itself. + */ + public DynamicsSink withIgnoreNullValues(Object ignoreNullValues) { + this.ignoreNullValues = ignoreNullValues; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsSource.java new file mode 100644 index 000000000000..8af8422e8ac6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/DynamicsSource.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Dynamics source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("DynamicsSource") +public class DynamicsSource extends CopySource { + /** + * FetchXML is a proprietary query language that is used in Microsoft + * Dynamics (online & on-premises). Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get fetchXML is a proprietary query language that is used in Microsoft Dynamics (online & on-premises). Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set fetchXML is a proprietary query language that is used in Microsoft Dynamics (online & on-premises). Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the DynamicsSource object itself. + */ + public DynamicsSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaLinkedService.java new file mode 100644 index 000000000000..a1f6ed0844c4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaLinkedService.java @@ -0,0 +1,213 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Eloqua server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Eloqua") +@JsonFlatten +public class EloquaLinkedService extends LinkedServiceInner { + /** + * The endpoint of the Eloqua server. (i.e. eloqua.example.com). + */ + @JsonProperty(value = "typeProperties.endpoint", required = true) + private Object endpoint; + + /** + * The site name and user name of your Eloqua account in the form: + * sitename/username. (i.e. Eloqua/Alice). + */ + @JsonProperty(value = "typeProperties.username", required = true) + private Object username; + + /** + * The password corresponding to the user name. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the Eloqua server. (i.e. eloqua.example.com). + * + * @return the endpoint value + */ + public Object endpoint() { + return this.endpoint; + } + + /** + * Set the endpoint of the Eloqua server. (i.e. eloqua.example.com). + * + * @param endpoint the endpoint value to set + * @return the EloquaLinkedService object itself. + */ + public EloquaLinkedService withEndpoint(Object endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Get the site name and user name of your Eloqua account in the form: sitename/username. (i.e. Eloqua/Alice). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the site name and user name of your Eloqua account in the form: sitename/username. (i.e. Eloqua/Alice). + * + * @param username the username value to set + * @return the EloquaLinkedService object itself. + */ + public EloquaLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name. + * + * @param password the password value to set + * @return the EloquaLinkedService object itself. + */ + public EloquaLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the EloquaLinkedService object itself. + */ + public EloquaLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the EloquaLinkedService object itself. + */ + public EloquaLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the EloquaLinkedService object itself. + */ + public EloquaLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the EloquaLinkedService object itself. + */ + public EloquaLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaObjectDataset.java new file mode 100644 index 000000000000..49a893c53b3c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Eloqua server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("EloquaObject") +public class EloquaObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaSource.java new file mode 100644 index 000000000000..f5333245e9b7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EloquaSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Eloqua server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("EloquaSource") +public class EloquaSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the EloquaSource object itself. + */ + public EloquaSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EntityReference.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EntityReference.java new file mode 100644 index 000000000000..fa6153042eaa --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/EntityReference.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The entity reference. + */ +public class EntityReference { + /** + * The type of this referenced entity. Possible values include: + * 'IntegrationRuntimeReference', 'LinkedServiceReference'. + */ + @JsonProperty(value = "type") + private IntegrationRuntimeEntityReferenceType type; + + /** + * The name of this referenced entity. + */ + @JsonProperty(value = "referenceName") + private String referenceName; + + /** + * Get the type of this referenced entity. Possible values include: 'IntegrationRuntimeReference', 'LinkedServiceReference'. + * + * @return the type value + */ + public IntegrationRuntimeEntityReferenceType type() { + return this.type; + } + + /** + * Set the type of this referenced entity. Possible values include: 'IntegrationRuntimeReference', 'LinkedServiceReference'. + * + * @param type the type value to set + * @return the EntityReference object itself. + */ + public EntityReference withType(IntegrationRuntimeEntityReferenceType type) { + this.type = type; + return this; + } + + /** + * Get the name of this referenced entity. + * + * @return the referenceName value + */ + public String referenceName() { + return this.referenceName; + } + + /** + * Set the name of this referenced entity. + * + * @param referenceName the referenceName value to set + * @return the EntityReference object itself. + */ + public EntityReference withReferenceName(String referenceName) { + this.referenceName = referenceName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ErrorResponse.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ErrorResponse.java new file mode 100644 index 000000000000..d75ca77596dd --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ErrorResponse.java @@ -0,0 +1,122 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The object that defines the structure of an Azure Data Factory response. + */ +public class ErrorResponse { + /** + * Error code. + */ + @JsonProperty(value = "code", required = true) + private String code; + + /** + * Error message. + */ + @JsonProperty(value = "message", required = true) + private String message; + + /** + * Property name/path in request associated with error. + */ + @JsonProperty(value = "target") + private String target; + + /** + * Array with additional error details. + */ + @JsonProperty(value = "details") + private List details; + + /** + * Get error code. + * + * @return the code value + */ + public String code() { + return this.code; + } + + /** + * Set error code. + * + * @param code the code value to set + * @return the ErrorResponse object itself. + */ + public ErrorResponse withCode(String code) { + this.code = code; + return this; + } + + /** + * Get error message. + * + * @return the message value + */ + public String message() { + return this.message; + } + + /** + * Set error message. + * + * @param message the message value to set + * @return the ErrorResponse object itself. + */ + public ErrorResponse withMessage(String message) { + this.message = message; + return this; + } + + /** + * Get property name/path in request associated with error. + * + * @return the target value + */ + public String target() { + return this.target; + } + + /** + * Set property name/path in request associated with error. + * + * @param target the target value to set + * @return the ErrorResponse object itself. + */ + public ErrorResponse withTarget(String target) { + this.target = target; + return this; + } + + /** + * Get array with additional error details. + * + * @return the details value + */ + public List details() { + return this.details; + } + + /** + * Set array with additional error details. + * + * @param details the details value to set + * @return the ErrorResponse object itself. + */ + public ErrorResponse withDetails(List details) { + this.details = details; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ErrorResponseException.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ErrorResponseException.java new file mode 100644 index 000000000000..b1e478273a7c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ErrorResponseException.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.rest.RestException; +import okhttp3.ResponseBody; +import retrofit2.Response; + +/** + * Exception thrown for an invalid response with ErrorResponse information. + */ +public class ErrorResponseException extends RestException { + /** + * Initializes a new instance of the ErrorResponseException class. + * + * @param message the exception message or the response content if a message is not available + * @param response the HTTP response + */ + public ErrorResponseException(final String message, final Response response) { + super(message, response); + } + + /** + * Initializes a new instance of the ErrorResponseException class. + * + * @param message the exception message or the response content if a message is not available + * @param response the HTTP response + * @param body the deserialized response body + */ + public ErrorResponseException(final String message, final Response response, final ErrorResponse body) { + super(message, response, body); + } + + @Override + public ErrorResponse body() { + return (ErrorResponse) super.body(); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecutePipelineActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecutePipelineActivity.java new file mode 100644 index 000000000000..c680f6812f61 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecutePipelineActivity.java @@ -0,0 +1,103 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Execute pipeline activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ExecutePipeline") +@JsonFlatten +public class ExecutePipelineActivity extends ControlActivity { + /** + * Pipeline reference. + */ + @JsonProperty(value = "typeProperties.pipeline", required = true) + private PipelineReference pipeline; + + /** + * Pipeline parameters. + */ + @JsonProperty(value = "typeProperties.parameters") + private Map parameters; + + /** + * Defines whether activity execution will wait for the dependent pipeline + * execution to finish. Default is false. + */ + @JsonProperty(value = "typeProperties.waitOnCompletion") + private Boolean waitOnCompletion; + + /** + * Get pipeline reference. + * + * @return the pipeline value + */ + public PipelineReference pipeline() { + return this.pipeline; + } + + /** + * Set pipeline reference. + * + * @param pipeline the pipeline value to set + * @return the ExecutePipelineActivity object itself. + */ + public ExecutePipelineActivity withPipeline(PipelineReference pipeline) { + this.pipeline = pipeline; + return this; + } + + /** + * Get pipeline parameters. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set pipeline parameters. + * + * @param parameters the parameters value to set + * @return the ExecutePipelineActivity object itself. + */ + public ExecutePipelineActivity withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + + /** + * Get defines whether activity execution will wait for the dependent pipeline execution to finish. Default is false. + * + * @return the waitOnCompletion value + */ + public Boolean waitOnCompletion() { + return this.waitOnCompletion; + } + + /** + * Set defines whether activity execution will wait for the dependent pipeline execution to finish. Default is false. + * + * @param waitOnCompletion the waitOnCompletion value to set + * @return the ExecutePipelineActivity object itself. + */ + public ExecutePipelineActivity withWaitOnCompletion(Boolean waitOnCompletion) { + this.waitOnCompletion = waitOnCompletion; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecuteSSISPackageActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecuteSSISPackageActivity.java new file mode 100644 index 000000000000..405e0371c2b2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecuteSSISPackageActivity.java @@ -0,0 +1,339 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Execute SSIS package activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ExecuteSSISPackage") +@JsonFlatten +public class ExecuteSSISPackageActivity extends ExecutionActivity { + /** + * SSIS package location. + */ + @JsonProperty(value = "typeProperties.packageLocation", required = true) + private SSISPackageLocation packageLocation; + + /** + * Specifies the runtime to execute SSIS package. The value should be "x86" + * or "x64". Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.runtime") + private Object runtime; + + /** + * The logging level of SSIS package execution. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.loggingLevel") + private Object loggingLevel; + + /** + * The environment path to execute the SSIS package. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.environmentPath") + private Object environmentPath; + + /** + * The package execution credential. + */ + @JsonProperty(value = "typeProperties.executionCredential") + private SSISExecutionCredential executionCredential; + + /** + * The integration runtime reference. + */ + @JsonProperty(value = "typeProperties.connectVia", required = true) + private IntegrationRuntimeReference connectVia; + + /** + * The project level parameters to execute the SSIS package. + */ + @JsonProperty(value = "typeProperties.projectParameters") + private Map projectParameters; + + /** + * The package level parameters to execute the SSIS package. + */ + @JsonProperty(value = "typeProperties.packageParameters") + private Map packageParameters; + + /** + * The project level connection managers to execute the SSIS package. + */ + @JsonProperty(value = "typeProperties.projectConnectionManagers") + private Map> projectConnectionManagers; + + /** + * The package level connection managers to execute the SSIS package. + */ + @JsonProperty(value = "typeProperties.packageConnectionManagers") + private Map> packageConnectionManagers; + + /** + * The property overrides to execute the SSIS package. + */ + @JsonProperty(value = "typeProperties.propertyOverrides") + private Map propertyOverrides; + + /** + * SSIS package execution log location. + */ + @JsonProperty(value = "typeProperties.logLocation") + private SSISLogLocation logLocation; + + /** + * Get sSIS package location. + * + * @return the packageLocation value + */ + public SSISPackageLocation packageLocation() { + return this.packageLocation; + } + + /** + * Set sSIS package location. + * + * @param packageLocation the packageLocation value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withPackageLocation(SSISPackageLocation packageLocation) { + this.packageLocation = packageLocation; + return this; + } + + /** + * Get specifies the runtime to execute SSIS package. The value should be "x86" or "x64". Type: string (or Expression with resultType string). + * + * @return the runtime value + */ + public Object runtime() { + return this.runtime; + } + + /** + * Set specifies the runtime to execute SSIS package. The value should be "x86" or "x64". Type: string (or Expression with resultType string). + * + * @param runtime the runtime value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withRuntime(Object runtime) { + this.runtime = runtime; + return this; + } + + /** + * Get the logging level of SSIS package execution. Type: string (or Expression with resultType string). + * + * @return the loggingLevel value + */ + public Object loggingLevel() { + return this.loggingLevel; + } + + /** + * Set the logging level of SSIS package execution. Type: string (or Expression with resultType string). + * + * @param loggingLevel the loggingLevel value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withLoggingLevel(Object loggingLevel) { + this.loggingLevel = loggingLevel; + return this; + } + + /** + * Get the environment path to execute the SSIS package. Type: string (or Expression with resultType string). + * + * @return the environmentPath value + */ + public Object environmentPath() { + return this.environmentPath; + } + + /** + * Set the environment path to execute the SSIS package. Type: string (or Expression with resultType string). + * + * @param environmentPath the environmentPath value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withEnvironmentPath(Object environmentPath) { + this.environmentPath = environmentPath; + return this; + } + + /** + * Get the package execution credential. + * + * @return the executionCredential value + */ + public SSISExecutionCredential executionCredential() { + return this.executionCredential; + } + + /** + * Set the package execution credential. + * + * @param executionCredential the executionCredential value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withExecutionCredential(SSISExecutionCredential executionCredential) { + this.executionCredential = executionCredential; + return this; + } + + /** + * Get the integration runtime reference. + * + * @return the connectVia value + */ + public IntegrationRuntimeReference connectVia() { + return this.connectVia; + } + + /** + * Set the integration runtime reference. + * + * @param connectVia the connectVia value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withConnectVia(IntegrationRuntimeReference connectVia) { + this.connectVia = connectVia; + return this; + } + + /** + * Get the project level parameters to execute the SSIS package. + * + * @return the projectParameters value + */ + public Map projectParameters() { + return this.projectParameters; + } + + /** + * Set the project level parameters to execute the SSIS package. + * + * @param projectParameters the projectParameters value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withProjectParameters(Map projectParameters) { + this.projectParameters = projectParameters; + return this; + } + + /** + * Get the package level parameters to execute the SSIS package. + * + * @return the packageParameters value + */ + public Map packageParameters() { + return this.packageParameters; + } + + /** + * Set the package level parameters to execute the SSIS package. + * + * @param packageParameters the packageParameters value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withPackageParameters(Map packageParameters) { + this.packageParameters = packageParameters; + return this; + } + + /** + * Get the project level connection managers to execute the SSIS package. + * + * @return the projectConnectionManagers value + */ + public Map> projectConnectionManagers() { + return this.projectConnectionManagers; + } + + /** + * Set the project level connection managers to execute the SSIS package. + * + * @param projectConnectionManagers the projectConnectionManagers value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withProjectConnectionManagers(Map> projectConnectionManagers) { + this.projectConnectionManagers = projectConnectionManagers; + return this; + } + + /** + * Get the package level connection managers to execute the SSIS package. + * + * @return the packageConnectionManagers value + */ + public Map> packageConnectionManagers() { + return this.packageConnectionManagers; + } + + /** + * Set the package level connection managers to execute the SSIS package. + * + * @param packageConnectionManagers the packageConnectionManagers value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withPackageConnectionManagers(Map> packageConnectionManagers) { + this.packageConnectionManagers = packageConnectionManagers; + return this; + } + + /** + * Get the property overrides to execute the SSIS package. + * + * @return the propertyOverrides value + */ + public Map propertyOverrides() { + return this.propertyOverrides; + } + + /** + * Set the property overrides to execute the SSIS package. + * + * @param propertyOverrides the propertyOverrides value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withPropertyOverrides(Map propertyOverrides) { + this.propertyOverrides = propertyOverrides; + return this; + } + + /** + * Get sSIS package execution log location. + * + * @return the logLocation value + */ + public SSISLogLocation logLocation() { + return this.logLocation; + } + + /** + * Set sSIS package execution log location. + * + * @param logLocation the logLocation value to set + * @return the ExecuteSSISPackageActivity object itself. + */ + public ExecuteSSISPackageActivity withLogLocation(SSISLogLocation logLocation) { + this.logLocation = logLocation; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecutionActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecutionActivity.java new file mode 100644 index 000000000000..7f959932fb4c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ExecutionActivity.java @@ -0,0 +1,92 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Base class for all execution activities. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Execution") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "DatabricksNotebook", value = DatabricksNotebookActivity.class), + @JsonSubTypes.Type(name = "DataLakeAnalyticsU-SQL", value = DataLakeAnalyticsUSQLActivity.class), + @JsonSubTypes.Type(name = "AzureMLUpdateResource", value = AzureMLUpdateResourceActivity.class), + @JsonSubTypes.Type(name = "AzureMLBatchExecution", value = AzureMLBatchExecutionActivity.class), + @JsonSubTypes.Type(name = "GetMetadata", value = GetMetadataActivity.class), + @JsonSubTypes.Type(name = "WebActivity", value = WebActivity.class), + @JsonSubTypes.Type(name = "Lookup", value = LookupActivity.class), + @JsonSubTypes.Type(name = "SqlServerStoredProcedure", value = SqlServerStoredProcedureActivity.class), + @JsonSubTypes.Type(name = "Custom", value = CustomActivity.class), + @JsonSubTypes.Type(name = "ExecuteSSISPackage", value = ExecuteSSISPackageActivity.class), + @JsonSubTypes.Type(name = "HDInsightSpark", value = HDInsightSparkActivity.class), + @JsonSubTypes.Type(name = "HDInsightStreaming", value = HDInsightStreamingActivity.class), + @JsonSubTypes.Type(name = "HDInsightMapReduce", value = HDInsightMapReduceActivity.class), + @JsonSubTypes.Type(name = "HDInsightPig", value = HDInsightPigActivity.class), + @JsonSubTypes.Type(name = "HDInsightHive", value = HDInsightHiveActivity.class), + @JsonSubTypes.Type(name = "Copy", value = CopyActivity.class) +}) +public class ExecutionActivity extends Activity { + /** + * Linked service reference. + */ + @JsonProperty(value = "linkedServiceName") + private LinkedServiceReference linkedServiceName; + + /** + * Activity policy. + */ + @JsonProperty(value = "policy") + private ActivityPolicy policy; + + /** + * Get linked service reference. + * + * @return the linkedServiceName value + */ + public LinkedServiceReference linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set linked service reference. + * + * @param linkedServiceName the linkedServiceName value to set + * @return the ExecutionActivity object itself. + */ + public ExecutionActivity withLinkedServiceName(LinkedServiceReference linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + + /** + * Get activity policy. + * + * @return the policy value + */ + public ActivityPolicy policy() { + return this.policy; + } + + /** + * Set activity policy. + * + * @param policy the policy value to set + * @return the ExecutionActivity object itself. + */ + public ExecutionActivity withPolicy(ActivityPolicy policy) { + this.policy = policy; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Expression.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Expression.java new file mode 100644 index 000000000000..5acb861727ba --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Expression.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Azure Data Factory expression definition. + */ +public class Expression { + /** + * Expression type. + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * Expression value. + */ + @JsonProperty(value = "value", required = true) + private String value; + + /** + * Creates an instance of Expression class. + * @param value expression value. + */ + public Expression() { + type = "Expression"; + } + + /** + * Get expression type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set expression type. + * + * @param type the type value to set + * @return the Expression object itself. + */ + public Expression withType(String type) { + this.type = type; + return this; + } + + /** + * Get expression value. + * + * @return the value value + */ + public String value() { + return this.value; + } + + /** + * Set expression value. + * + * @param value the value value to set + * @return the Expression object itself. + */ + public Expression withValue(String value) { + this.value = value; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Factories.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Factories.java new file mode 100644 index 000000000000..ee48c73a7976 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Factories.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import com.microsoft.azure.arm.resources.collection.SupportsDeletingByResourceGroup; +import com.microsoft.azure.arm.resources.collection.SupportsBatchDeletion; +import com.microsoft.azure.arm.resources.collection.SupportsGettingByResourceGroup; +import rx.Observable; +import com.microsoft.azure.arm.resources.collection.SupportsListingByResourceGroup; +import com.microsoft.azure.arm.collection.SupportsListing; +import rx.Completable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.FactoriesInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing Factories. + */ +public interface Factories extends SupportsCreating, SupportsDeletingByResourceGroup, SupportsBatchDeletion, SupportsGettingByResourceGroup, SupportsListingByResourceGroup, SupportsListing, HasInner { + /** + * Cancel a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable cancelPipelineRunAsync(String resourceGroupName, String factoryName, String runId); + + /** + * Updates a factory's repo information. + * + * @param locationId The location identifier. + * @param factoryRepoUpdate Update factory repo request definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable configureFactoryRepoAsync(String locationId, FactoryRepoUpdate factoryRepoUpdate); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Factory.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Factory.java new file mode 100644 index 000000000000..3c000f290ab7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Factory.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.Resource; +import com.microsoft.azure.arm.resources.models.GroupableResourceCore; +import com.microsoft.azure.arm.resources.models.HasResourceGroup; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import java.util.Map; +import org.joda.time.DateTime; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.FactoryInner; + +/** + * Type representing Factory. + */ +public interface Factory extends HasInner, Resource, GroupableResourceCore, HasResourceGroup, Refreshable, Updatable, HasManager { + /** + * @return the additionalProperties value. + */ + Map additionalProperties(); + + /** + * @return the createTime value. + */ + DateTime createTime(); + + /** + * @return the identity value. + */ + FactoryIdentity identity(); + + /** + * @return the provisioningState value. + */ + String provisioningState(); + + /** + * @return the version value. + */ + String version(); + + /** + * @return the vstsConfiguration value. + */ + FactoryVSTSConfiguration vstsConfiguration(); + + /** + * The entirety of the Factory definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithGroup, DefinitionStages.WithCreate { + } + + /** + * Grouping of Factory definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a Factory definition. + */ + interface Blank extends GroupableResourceCore.DefinitionWithRegion { + } + + /** + * The stage of the Factory definition allowing to specify the resource group. + */ + interface WithGroup extends GroupableResourceCore.DefinitionStages.WithGroup { + } + + /** + * The stage of the factory definition allowing to specify AdditionalProperties. + */ + interface WithAdditionalProperties { + /** + * Specifies additionalProperties. + * @param additionalProperties Unmatched properties from the message are deserialized this collection + * @return the next definition stage + */ + WithCreate withAdditionalProperties(Map additionalProperties); + } + + /** + * The stage of the factory definition allowing to specify Identity. + */ + interface WithIdentity { + /** + * Specifies identity. + * @param identity Managed service identity of the factory + * @return the next definition stage + */ + WithCreate withIdentity(FactoryIdentity identity); + } + + /** + * The stage of the factory definition allowing to specify VstsConfiguration. + */ + interface WithVstsConfiguration { + /** + * Specifies vstsConfiguration. + * @param vstsConfiguration VSTS repo information of the factory + * @return the next definition stage + */ + WithCreate withVstsConfiguration(FactoryVSTSConfiguration vstsConfiguration); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable, Resource.DefinitionWithTags, DefinitionStages.WithAdditionalProperties, DefinitionStages.WithIdentity, DefinitionStages.WithVstsConfiguration { + } + } + /** + * The template for a Factory update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, Resource.UpdateWithTags, UpdateStages.WithIdentity { + } + + /** + * Grouping of Factory update stages. + */ + interface UpdateStages { + /** + * The stage of the factory update allowing to specify Identity. + */ + interface WithIdentity { + /** + * Specifies identity. + * @param identity Managed service identity of the factory + * @return the next update stage + */ + Update withIdentity(FactoryIdentity identity); + } + + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryIdentity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryIdentity.java new file mode 100644 index 000000000000..12024a3fd0f5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryIdentity.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.UUID; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Identity properties of the factory resource. + */ +public class FactoryIdentity { + /** + * The identity type. Currently the only supported type is + * 'SystemAssigned'. + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * The principal id of the identity. + */ + @JsonProperty(value = "principalId", access = JsonProperty.Access.WRITE_ONLY) + private UUID principalId; + + /** + * The client tenant id of the identity. + */ + @JsonProperty(value = "tenantId", access = JsonProperty.Access.WRITE_ONLY) + private UUID tenantId; + + /** + * Creates an instance of FactoryIdentity class. + */ + public FactoryIdentity() { + type = "SystemAssigned"; + } + + /** + * Get the identity type. Currently the only supported type is 'SystemAssigned'. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set the identity type. Currently the only supported type is 'SystemAssigned'. + * + * @param type the type value to set + * @return the FactoryIdentity object itself. + */ + public FactoryIdentity withType(String type) { + this.type = type; + return this; + } + + /** + * Get the principal id of the identity. + * + * @return the principalId value + */ + public UUID principalId() { + return this.principalId; + } + + /** + * Get the client tenant id of the identity. + * + * @return the tenantId value + */ + public UUID tenantId() { + return this.tenantId; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryRepoUpdate.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryRepoUpdate.java new file mode 100644 index 000000000000..543615ca0701 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryRepoUpdate.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Factory's VSTS repo information. + */ +public class FactoryRepoUpdate { + /** + * The factory resource id. + */ + @JsonProperty(value = "factoryResourceId") + private String factoryResourceId; + + /** + * The resource group name. + */ + @JsonProperty(value = "resourceGroupName") + private String resourceGroupName; + + /** + * VSTS repo information of the factory. + */ + @JsonProperty(value = "vstsConfiguration") + private FactoryVSTSConfiguration vstsConfiguration; + + /** + * Get the factory resource id. + * + * @return the factoryResourceId value + */ + public String factoryResourceId() { + return this.factoryResourceId; + } + + /** + * Set the factory resource id. + * + * @param factoryResourceId the factoryResourceId value to set + * @return the FactoryRepoUpdate object itself. + */ + public FactoryRepoUpdate withFactoryResourceId(String factoryResourceId) { + this.factoryResourceId = factoryResourceId; + return this; + } + + /** + * Get the resource group name. + * + * @return the resourceGroupName value + */ + public String resourceGroupName() { + return this.resourceGroupName; + } + + /** + * Set the resource group name. + * + * @param resourceGroupName the resourceGroupName value to set + * @return the FactoryRepoUpdate object itself. + */ + public FactoryRepoUpdate withResourceGroupName(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + /** + * Get vSTS repo information of the factory. + * + * @return the vstsConfiguration value + */ + public FactoryVSTSConfiguration vstsConfiguration() { + return this.vstsConfiguration; + } + + /** + * Set vSTS repo information of the factory. + * + * @param vstsConfiguration the vstsConfiguration value to set + * @return the FactoryRepoUpdate object itself. + */ + public FactoryRepoUpdate withVstsConfiguration(FactoryVSTSConfiguration vstsConfiguration) { + this.vstsConfiguration = vstsConfiguration; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryUpdateParameters.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryUpdateParameters.java new file mode 100644 index 000000000000..3c5a370b064e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryUpdateParameters.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Parameters for updating a factory resource. + */ +public class FactoryUpdateParameters { + /** + * The resource tags. + */ + @JsonProperty(value = "tags") + private Map tags; + + /** + * Managed service identity of the factory. + */ + @JsonProperty(value = "identity") + private FactoryIdentity identity; + + /** + * Get the resource tags. + * + * @return the tags value + */ + public Map tags() { + return this.tags; + } + + /** + * Set the resource tags. + * + * @param tags the tags value to set + * @return the FactoryUpdateParameters object itself. + */ + public FactoryUpdateParameters withTags(Map tags) { + this.tags = tags; + return this; + } + + /** + * Get managed service identity of the factory. + * + * @return the identity value + */ + public FactoryIdentity identity() { + return this.identity; + } + + /** + * Set managed service identity of the factory. + * + * @param identity the identity value to set + * @return the FactoryUpdateParameters object itself. + */ + public FactoryUpdateParameters withIdentity(FactoryIdentity identity) { + this.identity = identity; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryVSTSConfiguration.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryVSTSConfiguration.java new file mode 100644 index 000000000000..d13b5dc79c93 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FactoryVSTSConfiguration.java @@ -0,0 +1,199 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Factory's VSTS repo information. + */ +public class FactoryVSTSConfiguration { + /** + * VSTS account name. + */ + @JsonProperty(value = "accountName") + private String accountName; + + /** + * VSTS project name. + */ + @JsonProperty(value = "projectName") + private String projectName; + + /** + * VSTS repository name. + */ + @JsonProperty(value = "repositoryName") + private String repositoryName; + + /** + * VSTS collaboration branch. + */ + @JsonProperty(value = "collaborationBranch") + private String collaborationBranch; + + /** + * VSTS root folder. + */ + @JsonProperty(value = "rootFolder") + private String rootFolder; + + /** + * VSTS last commit id. + */ + @JsonProperty(value = "lastCommitId") + private String lastCommitId; + + /** + * VSTS tenant id. + */ + @JsonProperty(value = "tenantId") + private String tenantId; + + /** + * Get vSTS account name. + * + * @return the accountName value + */ + public String accountName() { + return this.accountName; + } + + /** + * Set vSTS account name. + * + * @param accountName the accountName value to set + * @return the FactoryVSTSConfiguration object itself. + */ + public FactoryVSTSConfiguration withAccountName(String accountName) { + this.accountName = accountName; + return this; + } + + /** + * Get vSTS project name. + * + * @return the projectName value + */ + public String projectName() { + return this.projectName; + } + + /** + * Set vSTS project name. + * + * @param projectName the projectName value to set + * @return the FactoryVSTSConfiguration object itself. + */ + public FactoryVSTSConfiguration withProjectName(String projectName) { + this.projectName = projectName; + return this; + } + + /** + * Get vSTS repository name. + * + * @return the repositoryName value + */ + public String repositoryName() { + return this.repositoryName; + } + + /** + * Set vSTS repository name. + * + * @param repositoryName the repositoryName value to set + * @return the FactoryVSTSConfiguration object itself. + */ + public FactoryVSTSConfiguration withRepositoryName(String repositoryName) { + this.repositoryName = repositoryName; + return this; + } + + /** + * Get vSTS collaboration branch. + * + * @return the collaborationBranch value + */ + public String collaborationBranch() { + return this.collaborationBranch; + } + + /** + * Set vSTS collaboration branch. + * + * @param collaborationBranch the collaborationBranch value to set + * @return the FactoryVSTSConfiguration object itself. + */ + public FactoryVSTSConfiguration withCollaborationBranch(String collaborationBranch) { + this.collaborationBranch = collaborationBranch; + return this; + } + + /** + * Get vSTS root folder. + * + * @return the rootFolder value + */ + public String rootFolder() { + return this.rootFolder; + } + + /** + * Set vSTS root folder. + * + * @param rootFolder the rootFolder value to set + * @return the FactoryVSTSConfiguration object itself. + */ + public FactoryVSTSConfiguration withRootFolder(String rootFolder) { + this.rootFolder = rootFolder; + return this; + } + + /** + * Get vSTS last commit id. + * + * @return the lastCommitId value + */ + public String lastCommitId() { + return this.lastCommitId; + } + + /** + * Set vSTS last commit id. + * + * @param lastCommitId the lastCommitId value to set + * @return the FactoryVSTSConfiguration object itself. + */ + public FactoryVSTSConfiguration withLastCommitId(String lastCommitId) { + this.lastCommitId = lastCommitId; + return this; + } + + /** + * Get vSTS tenant id. + * + * @return the tenantId value + */ + public String tenantId() { + return this.tenantId; + } + + /** + * Set vSTS tenant id. + * + * @param tenantId the tenantId value to set + * @return the FactoryVSTSConfiguration object itself. + */ + public FactoryVSTSConfiguration withTenantId(String tenantId) { + this.tenantId = tenantId; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileServerLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileServerLinkedService.java new file mode 100644 index 000000000000..e816baa2c0ff --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileServerLinkedService.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * File system linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("FileServer") +@JsonFlatten +public class FileServerLinkedService extends LinkedServiceInner { + /** + * Host name of the server. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * User ID to logon the server. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.userId") + private Object userId; + + /** + * Password to logon the server. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get host name of the server. Type: string (or Expression with resultType string). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set host name of the server. Type: string (or Expression with resultType string). + * + * @param host the host value to set + * @return the FileServerLinkedService object itself. + */ + public FileServerLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get user ID to logon the server. Type: string (or Expression with resultType string). + * + * @return the userId value + */ + public Object userId() { + return this.userId; + } + + /** + * Set user ID to logon the server. Type: string (or Expression with resultType string). + * + * @param userId the userId value to set + * @return the FileServerLinkedService object itself. + */ + public FileServerLinkedService withUserId(Object userId) { + this.userId = userId; + return this; + } + + /** + * Get password to logon the server. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password to logon the server. + * + * @param password the password value to set + * @return the FileServerLinkedService object itself. + */ + public FileServerLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the FileServerLinkedService object itself. + */ + public FileServerLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileShareDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileShareDataset.java new file mode 100644 index 000000000000..82a636a2d7eb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileShareDataset.java @@ -0,0 +1,158 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * An on-premises file system dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("FileShare") +@JsonFlatten +public class FileShareDataset extends DatasetInner { + /** + * The path of the on-premises file system. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.folderPath") + private Object folderPath; + + /** + * The name of the on-premises file system. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.fileName") + private Object fileName; + + /** + * The format of the files. + */ + @JsonProperty(value = "typeProperties.format") + private DatasetStorageFormat format; + + /** + * Specify a filter to be used to select a subset of files in the + * folderPath rather than all files. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.fileFilter") + private Object fileFilter; + + /** + * The data compression method used for the file system. + */ + @JsonProperty(value = "typeProperties.compression") + private DatasetCompression compression; + + /** + * Get the path of the on-premises file system. Type: string (or Expression with resultType string). + * + * @return the folderPath value + */ + public Object folderPath() { + return this.folderPath; + } + + /** + * Set the path of the on-premises file system. Type: string (or Expression with resultType string). + * + * @param folderPath the folderPath value to set + * @return the FileShareDataset object itself. + */ + public FileShareDataset withFolderPath(Object folderPath) { + this.folderPath = folderPath; + return this; + } + + /** + * Get the name of the on-premises file system. Type: string (or Expression with resultType string). + * + * @return the fileName value + */ + public Object fileName() { + return this.fileName; + } + + /** + * Set the name of the on-premises file system. Type: string (or Expression with resultType string). + * + * @param fileName the fileName value to set + * @return the FileShareDataset object itself. + */ + public FileShareDataset withFileName(Object fileName) { + this.fileName = fileName; + return this; + } + + /** + * Get the format of the files. + * + * @return the format value + */ + public DatasetStorageFormat format() { + return this.format; + } + + /** + * Set the format of the files. + * + * @param format the format value to set + * @return the FileShareDataset object itself. + */ + public FileShareDataset withFormat(DatasetStorageFormat format) { + this.format = format; + return this; + } + + /** + * Get specify a filter to be used to select a subset of files in the folderPath rather than all files. Type: string (or Expression with resultType string). + * + * @return the fileFilter value + */ + public Object fileFilter() { + return this.fileFilter; + } + + /** + * Set specify a filter to be used to select a subset of files in the folderPath rather than all files. Type: string (or Expression with resultType string). + * + * @param fileFilter the fileFilter value to set + * @return the FileShareDataset object itself. + */ + public FileShareDataset withFileFilter(Object fileFilter) { + this.fileFilter = fileFilter; + return this; + } + + /** + * Get the data compression method used for the file system. + * + * @return the compression value + */ + public DatasetCompression compression() { + return this.compression; + } + + /** + * Set the data compression method used for the file system. + * + * @param compression the compression value to set + * @return the FileShareDataset object itself. + */ + public FileShareDataset withCompression(DatasetCompression compression) { + this.compression = compression; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileSystemSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileSystemSink.java new file mode 100644 index 000000000000..bd5ff676faf0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileSystemSink.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity file system sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("FileSystemSink") +public class FileSystemSink extends CopySink { + /** + * The type of copy behavior for copy sink. + */ + @JsonProperty(value = "copyBehavior") + private Object copyBehavior; + + /** + * Get the type of copy behavior for copy sink. + * + * @return the copyBehavior value + */ + public Object copyBehavior() { + return this.copyBehavior; + } + + /** + * Set the type of copy behavior for copy sink. + * + * @param copyBehavior the copyBehavior value to set + * @return the FileSystemSink object itself. + */ + public FileSystemSink withCopyBehavior(Object copyBehavior) { + this.copyBehavior = copyBehavior; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileSystemSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileSystemSource.java new file mode 100644 index 000000000000..feca377785c1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FileSystemSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity file system source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("FileSystemSource") +public class FileSystemSource extends CopySource { + /** + * If true, files under the folder path will be read recursively. Default + * is true. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "recursive") + private Object recursive; + + /** + * Get if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @return the recursive value + */ + public Object recursive() { + return this.recursive; + } + + /** + * Set if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @param recursive the recursive value to set + * @return the FileSystemSource object itself. + */ + public FileSystemSource withRecursive(Object recursive) { + this.recursive = recursive; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FilterActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FilterActivity.java new file mode 100644 index 000000000000..102c0a97d05a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FilterActivity.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Filter and return results from input array based on the conditions. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Filter") +@JsonFlatten +public class FilterActivity extends ControlActivity { + /** + * Input array on which filter should be applied. + */ + @JsonProperty(value = "typeProperties.items", required = true) + private Expression items; + + /** + * Condition to be used for filtering the input. + */ + @JsonProperty(value = "typeProperties.condition", required = true) + private Expression condition; + + /** + * Get input array on which filter should be applied. + * + * @return the items value + */ + public Expression items() { + return this.items; + } + + /** + * Set input array on which filter should be applied. + * + * @param items the items value to set + * @return the FilterActivity object itself. + */ + public FilterActivity withItems(Expression items) { + this.items = items; + return this; + } + + /** + * Get condition to be used for filtering the input. + * + * @return the condition value + */ + public Expression condition() { + return this.condition; + } + + /** + * Set condition to be used for filtering the input. + * + * @param condition the condition value to set + * @return the FilterActivity object itself. + */ + public FilterActivity withCondition(Expression condition) { + this.condition = condition; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ForEachActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ForEachActivity.java new file mode 100644 index 000000000000..877c88a81a0e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ForEachActivity.java @@ -0,0 +1,130 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * This activity is used for iterating over a collection and execute given + * activities. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ForEach") +@JsonFlatten +public class ForEachActivity extends ControlActivity { + /** + * Should the loop be executed in sequence or in parallel (max 50). + */ + @JsonProperty(value = "typeProperties.isSequential") + private Boolean isSequential; + + /** + * Batch count to be used for controlling the number of parallel execution + * (when isSequential is set to false). + */ + @JsonProperty(value = "typeProperties.batchCount") + private Integer batchCount; + + /** + * Collection to iterate. + */ + @JsonProperty(value = "typeProperties.items", required = true) + private Expression items; + + /** + * List of activities to execute . + */ + @JsonProperty(value = "typeProperties.activities", required = true) + private List activities; + + /** + * Get should the loop be executed in sequence or in parallel (max 50). + * + * @return the isSequential value + */ + public Boolean isSequential() { + return this.isSequential; + } + + /** + * Set should the loop be executed in sequence or in parallel (max 50). + * + * @param isSequential the isSequential value to set + * @return the ForEachActivity object itself. + */ + public ForEachActivity withIsSequential(Boolean isSequential) { + this.isSequential = isSequential; + return this; + } + + /** + * Get batch count to be used for controlling the number of parallel execution (when isSequential is set to false). + * + * @return the batchCount value + */ + public Integer batchCount() { + return this.batchCount; + } + + /** + * Set batch count to be used for controlling the number of parallel execution (when isSequential is set to false). + * + * @param batchCount the batchCount value to set + * @return the ForEachActivity object itself. + */ + public ForEachActivity withBatchCount(Integer batchCount) { + this.batchCount = batchCount; + return this; + } + + /** + * Get collection to iterate. + * + * @return the items value + */ + public Expression items() { + return this.items; + } + + /** + * Set collection to iterate. + * + * @param items the items value to set + * @return the ForEachActivity object itself. + */ + public ForEachActivity withItems(Expression items) { + this.items = items; + return this; + } + + /** + * Get list of activities to execute . + * + * @return the activities value + */ + public List activities() { + return this.activities; + } + + /** + * Set list of activities to execute . + * + * @param activities the activities value to set + * @return the ForEachActivity object itself. + */ + public ForEachActivity withActivities(List activities) { + this.activities = activities; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FtpAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FtpAuthenticationType.java new file mode 100644 index 000000000000..8488ab3f4553 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FtpAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for FtpAuthenticationType. + */ +public final class FtpAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for FtpAuthenticationType. */ + public static final FtpAuthenticationType BASIC = fromString("Basic"); + + /** Static value Anonymous for FtpAuthenticationType. */ + public static final FtpAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** + * Creates or finds a FtpAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding FtpAuthenticationType + */ + @JsonCreator + public static FtpAuthenticationType fromString(String name) { + return fromString(name, FtpAuthenticationType.class); + } + + /** + * @return known FtpAuthenticationType values + */ + public static Collection values() { + return values(FtpAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FtpServerLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FtpServerLinkedService.java new file mode 100644 index 000000000000..44fd53c24dec --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/FtpServerLinkedService.java @@ -0,0 +1,242 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * A FTP server Linked Service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("FtpServer") +@JsonFlatten +public class FtpServerLinkedService extends LinkedServiceInner { + /** + * Host name of the FTP server. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port number that the FTP server uses to listen for client + * connections. Default value is 21. Type: integer (or Expression with + * resultType integer), minimum: 0. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The authentication type to be used to connect to the FTP server. + * Possible values include: 'Basic', 'Anonymous'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private FtpAuthenticationType authenticationType; + + /** + * Username to logon the FTP server. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password to logon the FTP server. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * If true, connect to the FTP server over SSL/TLS channel. Default value + * is true. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * If true, validate the FTP server SSL certificate when connect over + * SSL/TLS channel. Default value is true. Type: boolean (or Expression + * with resultType boolean). + */ + @JsonProperty(value = "typeProperties.enableServerCertificateValidation") + private Object enableServerCertificateValidation; + + /** + * Get host name of the FTP server. Type: string (or Expression with resultType string). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set host name of the FTP server. Type: string (or Expression with resultType string). + * + * @param host the host value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port number that the FTP server uses to listen for client connections. Default value is 21. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port number that the FTP server uses to listen for client connections. Default value is 21. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param port the port value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the authentication type to be used to connect to the FTP server. Possible values include: 'Basic', 'Anonymous'. + * + * @return the authenticationType value + */ + public FtpAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to be used to connect to the FTP server. Possible values include: 'Basic', 'Anonymous'. + * + * @param authenticationType the authenticationType value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withAuthenticationType(FtpAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get username to logon the FTP server. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set username to logon the FTP server. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password to logon the FTP server. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password to logon the FTP server. + * + * @param password the password value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + + /** + * Get if true, connect to the FTP server over SSL/TLS channel. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set if true, connect to the FTP server over SSL/TLS channel. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param enableSsl the enableSsl value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get if true, validate the FTP server SSL certificate when connect over SSL/TLS channel. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the enableServerCertificateValidation value + */ + public Object enableServerCertificateValidation() { + return this.enableServerCertificateValidation; + } + + /** + * Set if true, validate the FTP server SSL certificate when connect over SSL/TLS channel. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param enableServerCertificateValidation the enableServerCertificateValidation value to set + * @return the FtpServerLinkedService object itself. + */ + public FtpServerLinkedService withEnableServerCertificateValidation(Object enableServerCertificateValidation) { + this.enableServerCertificateValidation = enableServerCertificateValidation; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GetMetadataActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GetMetadataActivity.java new file mode 100644 index 000000000000..21a681d1927c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GetMetadataActivity.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Activity to get metadata of dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("GetMetadata") +@JsonFlatten +public class GetMetadataActivity extends ExecutionActivity { + /** + * GetMetadata activity dataset reference. + */ + @JsonProperty(value = "typeProperties.dataset", required = true) + private DatasetReference dataset; + + /** + * Fields of metadata to get from dataset. + */ + @JsonProperty(value = "typeProperties.fieldList") + private List fieldList; + + /** + * Get getMetadata activity dataset reference. + * + * @return the dataset value + */ + public DatasetReference dataset() { + return this.dataset; + } + + /** + * Set getMetadata activity dataset reference. + * + * @param dataset the dataset value to set + * @return the GetMetadataActivity object itself. + */ + public GetMetadataActivity withDataset(DatasetReference dataset) { + this.dataset = dataset; + return this; + } + + /** + * Get fields of metadata to get from dataset. + * + * @return the fieldList value + */ + public List fieldList() { + return this.fieldList; + } + + /** + * Set fields of metadata to get from dataset. + * + * @param fieldList the fieldList value to set + * @return the GetMetadataActivity object itself. + */ + public GetMetadataActivity withFieldList(List fieldList) { + this.fieldList = fieldList; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryAuthenticationType.java new file mode 100644 index 000000000000..2e6ac25468b7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for GoogleBigQueryAuthenticationType. + */ +public final class GoogleBigQueryAuthenticationType extends ExpandableStringEnum { + /** Static value ServiceAuthentication for GoogleBigQueryAuthenticationType. */ + public static final GoogleBigQueryAuthenticationType SERVICE_AUTHENTICATION = fromString("ServiceAuthentication"); + + /** Static value UserAuthentication for GoogleBigQueryAuthenticationType. */ + public static final GoogleBigQueryAuthenticationType USER_AUTHENTICATION = fromString("UserAuthentication"); + + /** + * Creates or finds a GoogleBigQueryAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding GoogleBigQueryAuthenticationType + */ + @JsonCreator + public static GoogleBigQueryAuthenticationType fromString(String name) { + return fromString(name, GoogleBigQueryAuthenticationType.class); + } + + /** + * @return known GoogleBigQueryAuthenticationType values + */ + public static Collection values() { + return values(GoogleBigQueryAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryLinkedService.java new file mode 100644 index 000000000000..54fa65a89da6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryLinkedService.java @@ -0,0 +1,351 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Google BigQuery service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("GoogleBigQuery") +@JsonFlatten +public class GoogleBigQueryLinkedService extends LinkedServiceInner { + /** + * The default BigQuery project to query against. + */ + @JsonProperty(value = "typeProperties.project", required = true) + private Object project; + + /** + * A comma-separated list of public BigQuery projects to access. + */ + @JsonProperty(value = "typeProperties.additionalProjects") + private Object additionalProjects; + + /** + * Whether to request access to Google Drive. Allowing Google Drive access + * enables support for federated tables that combine BigQuery data with + * data from Google Drive. The default value is false. + */ + @JsonProperty(value = "typeProperties.requestGoogleDriveScope") + private Object requestGoogleDriveScope; + + /** + * The OAuth 2.0 authentication mechanism used for authentication. + * ServiceAuthentication can only be used on self-hosted IR. Possible + * values include: 'ServiceAuthentication', 'UserAuthentication'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private GoogleBigQueryAuthenticationType authenticationType; + + /** + * The refresh token obtained from Google for authorizing access to + * BigQuery for UserAuthentication. + */ + @JsonProperty(value = "typeProperties.refreshToken") + private SecretBase refreshToken; + + /** + * The client id of the google application used to acquire the refresh + * token. + */ + @JsonProperty(value = "typeProperties.clientId") + private SecretBase clientId; + + /** + * The client secret of the google application used to acquire the refresh + * token. + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * The service account email ID that is used for ServiceAuthentication and + * can only be used on self-hosted IR. + */ + @JsonProperty(value = "typeProperties.email") + private Object email; + + /** + * The full path to the .p12 key file that is used to authenticate the + * service account email address and can only be used on self-hosted IR. + */ + @JsonProperty(value = "typeProperties.keyFilePath") + private Object keyFilePath; + + /** + * The full path of the .pem file containing trusted CA certificates for + * verifying the server when connecting over SSL. This property can only be + * set when using SSL on self-hosted IR. The default value is the + * cacerts.pem file installed with the IR. + */ + @JsonProperty(value = "typeProperties.trustedCertPath") + private Object trustedCertPath; + + /** + * Specifies whether to use a CA certificate from the system trust store or + * from a specified PEM file. The default value is false. + */ + @JsonProperty(value = "typeProperties.useSystemTrustStore") + private Object useSystemTrustStore; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the default BigQuery project to query against. + * + * @return the project value + */ + public Object project() { + return this.project; + } + + /** + * Set the default BigQuery project to query against. + * + * @param project the project value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withProject(Object project) { + this.project = project; + return this; + } + + /** + * Get a comma-separated list of public BigQuery projects to access. + * + * @return the additionalProjects value + */ + public Object additionalProjects() { + return this.additionalProjects; + } + + /** + * Set a comma-separated list of public BigQuery projects to access. + * + * @param additionalProjects the additionalProjects value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withAdditionalProjects(Object additionalProjects) { + this.additionalProjects = additionalProjects; + return this; + } + + /** + * Get whether to request access to Google Drive. Allowing Google Drive access enables support for federated tables that combine BigQuery data with data from Google Drive. The default value is false. + * + * @return the requestGoogleDriveScope value + */ + public Object requestGoogleDriveScope() { + return this.requestGoogleDriveScope; + } + + /** + * Set whether to request access to Google Drive. Allowing Google Drive access enables support for federated tables that combine BigQuery data with data from Google Drive. The default value is false. + * + * @param requestGoogleDriveScope the requestGoogleDriveScope value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withRequestGoogleDriveScope(Object requestGoogleDriveScope) { + this.requestGoogleDriveScope = requestGoogleDriveScope; + return this; + } + + /** + * Get the OAuth 2.0 authentication mechanism used for authentication. ServiceAuthentication can only be used on self-hosted IR. Possible values include: 'ServiceAuthentication', 'UserAuthentication'. + * + * @return the authenticationType value + */ + public GoogleBigQueryAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the OAuth 2.0 authentication mechanism used for authentication. ServiceAuthentication can only be used on self-hosted IR. Possible values include: 'ServiceAuthentication', 'UserAuthentication'. + * + * @param authenticationType the authenticationType value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withAuthenticationType(GoogleBigQueryAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the refresh token obtained from Google for authorizing access to BigQuery for UserAuthentication. + * + * @return the refreshToken value + */ + public SecretBase refreshToken() { + return this.refreshToken; + } + + /** + * Set the refresh token obtained from Google for authorizing access to BigQuery for UserAuthentication. + * + * @param refreshToken the refreshToken value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withRefreshToken(SecretBase refreshToken) { + this.refreshToken = refreshToken; + return this; + } + + /** + * Get the client id of the google application used to acquire the refresh token. + * + * @return the clientId value + */ + public SecretBase clientId() { + return this.clientId; + } + + /** + * Set the client id of the google application used to acquire the refresh token. + * + * @param clientId the clientId value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withClientId(SecretBase clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret of the google application used to acquire the refresh token. + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret of the google application used to acquire the refresh token. + * + * @param clientSecret the clientSecret value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get the service account email ID that is used for ServiceAuthentication and can only be used on self-hosted IR. + * + * @return the email value + */ + public Object email() { + return this.email; + } + + /** + * Set the service account email ID that is used for ServiceAuthentication and can only be used on self-hosted IR. + * + * @param email the email value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withEmail(Object email) { + this.email = email; + return this; + } + + /** + * Get the full path to the .p12 key file that is used to authenticate the service account email address and can only be used on self-hosted IR. + * + * @return the keyFilePath value + */ + public Object keyFilePath() { + return this.keyFilePath; + } + + /** + * Set the full path to the .p12 key file that is used to authenticate the service account email address and can only be used on self-hosted IR. + * + * @param keyFilePath the keyFilePath value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withKeyFilePath(Object keyFilePath) { + this.keyFilePath = keyFilePath; + return this; + } + + /** + * Get the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @return the trustedCertPath value + */ + public Object trustedCertPath() { + return this.trustedCertPath; + } + + /** + * Set the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @param trustedCertPath the trustedCertPath value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withTrustedCertPath(Object trustedCertPath) { + this.trustedCertPath = trustedCertPath; + return this; + } + + /** + * Get specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @return the useSystemTrustStore value + */ + public Object useSystemTrustStore() { + return this.useSystemTrustStore; + } + + /** + * Set specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @param useSystemTrustStore the useSystemTrustStore value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withUseSystemTrustStore(Object useSystemTrustStore) { + this.useSystemTrustStore = useSystemTrustStore; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the GoogleBigQueryLinkedService object itself. + */ + public GoogleBigQueryLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryObjectDataset.java new file mode 100644 index 000000000000..01c5aa3300eb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQueryObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Google BigQuery service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("GoogleBigQueryObject") +public class GoogleBigQueryObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQuerySource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQuerySource.java new file mode 100644 index 000000000000..80cc1f31ad98 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GoogleBigQuerySource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Google BigQuery service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("GoogleBigQuerySource") +public class GoogleBigQuerySource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the GoogleBigQuerySource object itself. + */ + public GoogleBigQuerySource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumLinkedService.java new file mode 100644 index 000000000000..c2dc9bcb9c65 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Greenplum Database linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Greenplum") +@JsonFlatten +public class GreenplumLinkedService extends LinkedServiceInner { + /** + * An ODBC connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the GreenplumLinkedService object itself. + */ + public GreenplumLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the GreenplumLinkedService object itself. + */ + public GreenplumLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumSource.java new file mode 100644 index 000000000000..0e83c0e79392 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Greenplum Database source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("GreenplumSource") +public class GreenplumSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the GreenplumSource object itself. + */ + public GreenplumSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumTableDataset.java new file mode 100644 index 000000000000..3723e3389742 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/GreenplumTableDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Greenplum Database dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("GreenplumTable") +public class GreenplumTableDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseAuthenticationType.java new file mode 100644 index 000000000000..fb2e1346dc85 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for HBaseAuthenticationType. + */ +public final class HBaseAuthenticationType extends ExpandableStringEnum { + /** Static value Anonymous for HBaseAuthenticationType. */ + public static final HBaseAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** Static value Basic for HBaseAuthenticationType. */ + public static final HBaseAuthenticationType BASIC = fromString("Basic"); + + /** + * Creates or finds a HBaseAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding HBaseAuthenticationType + */ + @JsonCreator + public static HBaseAuthenticationType fromString(String name) { + return fromString(name, HBaseAuthenticationType.class); + } + + /** + * @return known HBaseAuthenticationType values + */ + public static Collection values() { + return values(HBaseAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseLinkedService.java new file mode 100644 index 000000000000..eb1542114adc --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseLinkedService.java @@ -0,0 +1,322 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * HBase server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HBase") +@JsonFlatten +public class HBaseLinkedService extends LinkedServiceInner { + /** + * The IP address or host name of the HBase server. (i.e. 192.168.222.160). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port that the HBase instance uses to listen for client + * connections. The default value is 9090. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The partial URL corresponding to the HBase server. (i.e. + * /gateway/sandbox/hbase/version). + */ + @JsonProperty(value = "typeProperties.httpPath") + private Object httpPath; + + /** + * The authentication mechanism to use to connect to the HBase server. + * Possible values include: 'Anonymous', 'Basic'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private HBaseAuthenticationType authenticationType; + + /** + * The user name used to connect to the HBase instance. + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password corresponding to the user name. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Specifies whether the connections to the server are encrypted using SSL. + * The default value is false. + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * The full path of the .pem file containing trusted CA certificates for + * verifying the server when connecting over SSL. This property can only be + * set when using SSL on self-hosted IR. The default value is the + * cacerts.pem file installed with the IR. + */ + @JsonProperty(value = "typeProperties.trustedCertPath") + private Object trustedCertPath; + + /** + * Specifies whether to require a CA-issued SSL certificate name to match + * the host name of the server when connecting over SSL. The default value + * is false. + */ + @JsonProperty(value = "typeProperties.allowHostNameCNMismatch") + private Object allowHostNameCNMismatch; + + /** + * Specifies whether to allow self-signed certificates from the server. The + * default value is false. + */ + @JsonProperty(value = "typeProperties.allowSelfSignedServerCert") + private Object allowSelfSignedServerCert; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the IP address or host name of the HBase server. (i.e. 192.168.222.160). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the IP address or host name of the HBase server. (i.e. 192.168.222.160). + * + * @param host the host value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port that the HBase instance uses to listen for client connections. The default value is 9090. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port that the HBase instance uses to listen for client connections. The default value is 9090. + * + * @param port the port value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the partial URL corresponding to the HBase server. (i.e. /gateway/sandbox/hbase/version). + * + * @return the httpPath value + */ + public Object httpPath() { + return this.httpPath; + } + + /** + * Set the partial URL corresponding to the HBase server. (i.e. /gateway/sandbox/hbase/version). + * + * @param httpPath the httpPath value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withHttpPath(Object httpPath) { + this.httpPath = httpPath; + return this; + } + + /** + * Get the authentication mechanism to use to connect to the HBase server. Possible values include: 'Anonymous', 'Basic'. + * + * @return the authenticationType value + */ + public HBaseAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication mechanism to use to connect to the HBase server. Possible values include: 'Anonymous', 'Basic'. + * + * @param authenticationType the authenticationType value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withAuthenticationType(HBaseAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the user name used to connect to the HBase instance. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name used to connect to the HBase instance. + * + * @param username the username value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name. + * + * @param password the password value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @param enableSsl the enableSsl value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @return the trustedCertPath value + */ + public Object trustedCertPath() { + return this.trustedCertPath; + } + + /** + * Set the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @param trustedCertPath the trustedCertPath value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withTrustedCertPath(Object trustedCertPath) { + this.trustedCertPath = trustedCertPath; + return this; + } + + /** + * Get specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @return the allowHostNameCNMismatch value + */ + public Object allowHostNameCNMismatch() { + return this.allowHostNameCNMismatch; + } + + /** + * Set specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @param allowHostNameCNMismatch the allowHostNameCNMismatch value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withAllowHostNameCNMismatch(Object allowHostNameCNMismatch) { + this.allowHostNameCNMismatch = allowHostNameCNMismatch; + return this; + } + + /** + * Get specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @return the allowSelfSignedServerCert value + */ + public Object allowSelfSignedServerCert() { + return this.allowSelfSignedServerCert; + } + + /** + * Set specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @param allowSelfSignedServerCert the allowSelfSignedServerCert value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withAllowSelfSignedServerCert(Object allowSelfSignedServerCert) { + this.allowSelfSignedServerCert = allowSelfSignedServerCert; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the HBaseLinkedService object itself. + */ + public HBaseLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseObjectDataset.java new file mode 100644 index 000000000000..1855d0c47fd6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * HBase server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HBaseObject") +public class HBaseObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseSource.java new file mode 100644 index 000000000000..4138c4ced08b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HBaseSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity HBase server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HBaseSource") +public class HBaseSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the HBaseSource object itself. + */ + public HBaseSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightActivityDebugInfoOption.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightActivityDebugInfoOption.java new file mode 100644 index 000000000000..5513da9a78cd --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightActivityDebugInfoOption.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for HDInsightActivityDebugInfoOption. + */ +public final class HDInsightActivityDebugInfoOption extends ExpandableStringEnum { + /** Static value None for HDInsightActivityDebugInfoOption. */ + public static final HDInsightActivityDebugInfoOption NONE = fromString("None"); + + /** Static value Always for HDInsightActivityDebugInfoOption. */ + public static final HDInsightActivityDebugInfoOption ALWAYS = fromString("Always"); + + /** Static value Failure for HDInsightActivityDebugInfoOption. */ + public static final HDInsightActivityDebugInfoOption FAILURE = fromString("Failure"); + + /** + * Creates or finds a HDInsightActivityDebugInfoOption from its string representation. + * @param name a name to look for + * @return the corresponding HDInsightActivityDebugInfoOption + */ + @JsonCreator + public static HDInsightActivityDebugInfoOption fromString(String name) { + return fromString(name, HDInsightActivityDebugInfoOption.class); + } + + /** + * @return known HDInsightActivityDebugInfoOption values + */ + public static Collection values() { + return values(HDInsightActivityDebugInfoOption.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightHiveActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightHiveActivity.java new file mode 100644 index 000000000000..29512356db33 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightHiveActivity.java @@ -0,0 +1,181 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * HDInsight Hive activity type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HDInsightHive") +@JsonFlatten +public class HDInsightHiveActivity extends ExecutionActivity { + /** + * Storage linked service references. + */ + @JsonProperty(value = "typeProperties.storageLinkedServices") + private List storageLinkedServices; + + /** + * User specified arguments to HDInsightActivity. + */ + @JsonProperty(value = "typeProperties.arguments") + private List arguments; + + /** + * Debug info option. Possible values include: 'None', 'Always', 'Failure'. + */ + @JsonProperty(value = "typeProperties.getDebugInfo") + private HDInsightActivityDebugInfoOption getDebugInfo; + + /** + * Script path. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.scriptPath") + private Object scriptPath; + + /** + * Script linked service reference. + */ + @JsonProperty(value = "typeProperties.scriptLinkedService") + private LinkedServiceReference scriptLinkedService; + + /** + * Allows user to specify defines for Hive job request. + */ + @JsonProperty(value = "typeProperties.defines") + private Map defines; + + /** + * Get storage linked service references. + * + * @return the storageLinkedServices value + */ + public List storageLinkedServices() { + return this.storageLinkedServices; + } + + /** + * Set storage linked service references. + * + * @param storageLinkedServices the storageLinkedServices value to set + * @return the HDInsightHiveActivity object itself. + */ + public HDInsightHiveActivity withStorageLinkedServices(List storageLinkedServices) { + this.storageLinkedServices = storageLinkedServices; + return this; + } + + /** + * Get user specified arguments to HDInsightActivity. + * + * @return the arguments value + */ + public List arguments() { + return this.arguments; + } + + /** + * Set user specified arguments to HDInsightActivity. + * + * @param arguments the arguments value to set + * @return the HDInsightHiveActivity object itself. + */ + public HDInsightHiveActivity withArguments(List arguments) { + this.arguments = arguments; + return this; + } + + /** + * Get debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @return the getDebugInfo value + */ + public HDInsightActivityDebugInfoOption getDebugInfo() { + return this.getDebugInfo; + } + + /** + * Set debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @param getDebugInfo the getDebugInfo value to set + * @return the HDInsightHiveActivity object itself. + */ + public HDInsightHiveActivity withGetDebugInfo(HDInsightActivityDebugInfoOption getDebugInfo) { + this.getDebugInfo = getDebugInfo; + return this; + } + + /** + * Get script path. Type: string (or Expression with resultType string). + * + * @return the scriptPath value + */ + public Object scriptPath() { + return this.scriptPath; + } + + /** + * Set script path. Type: string (or Expression with resultType string). + * + * @param scriptPath the scriptPath value to set + * @return the HDInsightHiveActivity object itself. + */ + public HDInsightHiveActivity withScriptPath(Object scriptPath) { + this.scriptPath = scriptPath; + return this; + } + + /** + * Get script linked service reference. + * + * @return the scriptLinkedService value + */ + public LinkedServiceReference scriptLinkedService() { + return this.scriptLinkedService; + } + + /** + * Set script linked service reference. + * + * @param scriptLinkedService the scriptLinkedService value to set + * @return the HDInsightHiveActivity object itself. + */ + public HDInsightHiveActivity withScriptLinkedService(LinkedServiceReference scriptLinkedService) { + this.scriptLinkedService = scriptLinkedService; + return this; + } + + /** + * Get allows user to specify defines for Hive job request. + * + * @return the defines value + */ + public Map defines() { + return this.defines; + } + + /** + * Set allows user to specify defines for Hive job request. + * + * @param defines the defines value to set + * @return the HDInsightHiveActivity object itself. + */ + public HDInsightHiveActivity withDefines(Map defines) { + this.defines = defines; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightLinkedService.java new file mode 100644 index 000000000000..931991b6f725 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightLinkedService.java @@ -0,0 +1,185 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * HDInsight linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HDInsight") +@JsonFlatten +public class HDInsightLinkedService extends LinkedServiceInner { + /** + * HDInsight cluster URI. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.clusterUri", required = true) + private Object clusterUri; + + /** + * HDInsight cluster user name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * HDInsight cluster password. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The Azure Storage linked service reference. + */ + @JsonProperty(value = "typeProperties.linkedServiceName") + private LinkedServiceReference linkedServiceName; + + /** + * A reference to the Azure SQL linked service that points to the HCatalog + * database. + */ + @JsonProperty(value = "typeProperties.hcatalogLinkedServiceName") + private LinkedServiceReference hcatalogLinkedServiceName; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get hDInsight cluster URI. Type: string (or Expression with resultType string). + * + * @return the clusterUri value + */ + public Object clusterUri() { + return this.clusterUri; + } + + /** + * Set hDInsight cluster URI. Type: string (or Expression with resultType string). + * + * @param clusterUri the clusterUri value to set + * @return the HDInsightLinkedService object itself. + */ + public HDInsightLinkedService withClusterUri(Object clusterUri) { + this.clusterUri = clusterUri; + return this; + } + + /** + * Get hDInsight cluster user name. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set hDInsight cluster user name. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the HDInsightLinkedService object itself. + */ + public HDInsightLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get hDInsight cluster password. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set hDInsight cluster password. + * + * @param password the password value to set + * @return the HDInsightLinkedService object itself. + */ + public HDInsightLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the Azure Storage linked service reference. + * + * @return the linkedServiceName value + */ + public LinkedServiceReference linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set the Azure Storage linked service reference. + * + * @param linkedServiceName the linkedServiceName value to set + * @return the HDInsightLinkedService object itself. + */ + public HDInsightLinkedService withLinkedServiceName(LinkedServiceReference linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + + /** + * Get a reference to the Azure SQL linked service that points to the HCatalog database. + * + * @return the hcatalogLinkedServiceName value + */ + public LinkedServiceReference hcatalogLinkedServiceName() { + return this.hcatalogLinkedServiceName; + } + + /** + * Set a reference to the Azure SQL linked service that points to the HCatalog database. + * + * @param hcatalogLinkedServiceName the hcatalogLinkedServiceName value to set + * @return the HDInsightLinkedService object itself. + */ + public HDInsightLinkedService withHcatalogLinkedServiceName(LinkedServiceReference hcatalogLinkedServiceName) { + this.hcatalogLinkedServiceName = hcatalogLinkedServiceName; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the HDInsightLinkedService object itself. + */ + public HDInsightLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightMapReduceActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightMapReduceActivity.java new file mode 100644 index 000000000000..e7ef7b5a83d0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightMapReduceActivity.java @@ -0,0 +1,233 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * HDInsight MapReduce activity type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HDInsightMapReduce") +@JsonFlatten +public class HDInsightMapReduceActivity extends ExecutionActivity { + /** + * Storage linked service references. + */ + @JsonProperty(value = "typeProperties.storageLinkedServices") + private List storageLinkedServices; + + /** + * User specified arguments to HDInsightActivity. + */ + @JsonProperty(value = "typeProperties.arguments") + private List arguments; + + /** + * Debug info option. Possible values include: 'None', 'Always', 'Failure'. + */ + @JsonProperty(value = "typeProperties.getDebugInfo") + private HDInsightActivityDebugInfoOption getDebugInfo; + + /** + * Class name. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.className", required = true) + private Object className; + + /** + * Jar path. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.jarFilePath", required = true) + private Object jarFilePath; + + /** + * Jar linked service reference. + */ + @JsonProperty(value = "typeProperties.jarLinkedService") + private LinkedServiceReference jarLinkedService; + + /** + * Jar libs. + */ + @JsonProperty(value = "typeProperties.jarLibs") + private List jarLibs; + + /** + * Allows user to specify defines for the MapReduce job request. + */ + @JsonProperty(value = "typeProperties.defines") + private Map defines; + + /** + * Get storage linked service references. + * + * @return the storageLinkedServices value + */ + public List storageLinkedServices() { + return this.storageLinkedServices; + } + + /** + * Set storage linked service references. + * + * @param storageLinkedServices the storageLinkedServices value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withStorageLinkedServices(List storageLinkedServices) { + this.storageLinkedServices = storageLinkedServices; + return this; + } + + /** + * Get user specified arguments to HDInsightActivity. + * + * @return the arguments value + */ + public List arguments() { + return this.arguments; + } + + /** + * Set user specified arguments to HDInsightActivity. + * + * @param arguments the arguments value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withArguments(List arguments) { + this.arguments = arguments; + return this; + } + + /** + * Get debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @return the getDebugInfo value + */ + public HDInsightActivityDebugInfoOption getDebugInfo() { + return this.getDebugInfo; + } + + /** + * Set debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @param getDebugInfo the getDebugInfo value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withGetDebugInfo(HDInsightActivityDebugInfoOption getDebugInfo) { + this.getDebugInfo = getDebugInfo; + return this; + } + + /** + * Get class name. Type: string (or Expression with resultType string). + * + * @return the className value + */ + public Object className() { + return this.className; + } + + /** + * Set class name. Type: string (or Expression with resultType string). + * + * @param className the className value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withClassName(Object className) { + this.className = className; + return this; + } + + /** + * Get jar path. Type: string (or Expression with resultType string). + * + * @return the jarFilePath value + */ + public Object jarFilePath() { + return this.jarFilePath; + } + + /** + * Set jar path. Type: string (or Expression with resultType string). + * + * @param jarFilePath the jarFilePath value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withJarFilePath(Object jarFilePath) { + this.jarFilePath = jarFilePath; + return this; + } + + /** + * Get jar linked service reference. + * + * @return the jarLinkedService value + */ + public LinkedServiceReference jarLinkedService() { + return this.jarLinkedService; + } + + /** + * Set jar linked service reference. + * + * @param jarLinkedService the jarLinkedService value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withJarLinkedService(LinkedServiceReference jarLinkedService) { + this.jarLinkedService = jarLinkedService; + return this; + } + + /** + * Get jar libs. + * + * @return the jarLibs value + */ + public List jarLibs() { + return this.jarLibs; + } + + /** + * Set jar libs. + * + * @param jarLibs the jarLibs value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withJarLibs(List jarLibs) { + this.jarLibs = jarLibs; + return this; + } + + /** + * Get allows user to specify defines for the MapReduce job request. + * + * @return the defines value + */ + public Map defines() { + return this.defines; + } + + /** + * Set allows user to specify defines for the MapReduce job request. + * + * @param defines the defines value to set + * @return the HDInsightMapReduceActivity object itself. + */ + public HDInsightMapReduceActivity withDefines(Map defines) { + this.defines = defines; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightOnDemandLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightOnDemandLinkedService.java new file mode 100644 index 000000000000..f8d24f4ddde2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightOnDemandLinkedService.java @@ -0,0 +1,833 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * HDInsight ondemand linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HDInsightOnDemand") +@JsonFlatten +public class HDInsightOnDemandLinkedService extends LinkedServiceInner { + /** + * Number of worker/data nodes in the cluster. Suggestion value: 4. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clusterSize", required = true) + private Object clusterSize; + + /** + * The allowed idle time for the on-demand HDInsight cluster. Specifies how + * long the on-demand HDInsight cluster stays alive after completion of an + * activity run if there are no other active jobs in the cluster. The + * minimum value is 5 mins. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.timeToLive", required = true) + private Object timeToLive; + + /** + * Version of the HDInsight cluster.  Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.version", required = true) + private Object version; + + /** + * Azure Storage linked service to be used by the on-demand cluster for + * storing and processing data. + */ + @JsonProperty(value = "typeProperties.linkedServiceName", required = true) + private LinkedServiceReference linkedServiceName; + + /** + * The customer’s subscription to host the cluster. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.hostSubscriptionId", required = true) + private Object hostSubscriptionId; + + /** + * The service principal id for the hostSubscriptionId. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.servicePrincipalId") + private Object servicePrincipalId; + + /** + * The key for the service principal id. + */ + @JsonProperty(value = "typeProperties.servicePrincipalKey") + private SecretBase servicePrincipalKey; + + /** + * The Tenant id/name to which the service principal belongs. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tenant", required = true) + private Object tenant; + + /** + * The resource group where the cluster belongs. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clusterResourceGroup", required = true) + private Object clusterResourceGroup; + + /** + * The prefix of cluster name, postfix will be distinct with timestamp. + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clusterNamePrefix") + private Object clusterNamePrefix; + + /** + * The username to access the cluster. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.clusterUserName") + private Object clusterUserName; + + /** + * The password to access the cluster. + */ + @JsonProperty(value = "typeProperties.clusterPassword") + private SecretBase clusterPassword; + + /** + * The username to SSH remotely connect to cluster’s node (for Linux). + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clusterSshUserName") + private Object clusterSshUserName; + + /** + * The password to SSH remotely connect cluster’s node (for Linux). + */ + @JsonProperty(value = "typeProperties.clusterSshPassword") + private SecretBase clusterSshPassword; + + /** + * Specifies additional storage accounts for the HDInsight linked service + * so that the Data Factory service can register them on your behalf. + */ + @JsonProperty(value = "typeProperties.additionalLinkedServiceNames") + private List additionalLinkedServiceNames; + + /** + * The name of Azure SQL linked service that point to the HCatalog + * database. The on-demand HDInsight cluster is created by using the Azure + * SQL database as the metastore. + */ + @JsonProperty(value = "typeProperties.hcatalogLinkedServiceName") + private LinkedServiceReference hcatalogLinkedServiceName; + + /** + * The cluster type. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clusterType") + private Object clusterType; + + /** + * The version of spark if the cluster type is 'spark'. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.sparkVersion") + private Object sparkVersion; + + /** + * Specifies the core configuration parameters (as in core-site.xml) for + * the HDInsight cluster to be created. + */ + @JsonProperty(value = "typeProperties.coreConfiguration") + private Object coreConfiguration; + + /** + * Specifies the HBase configuration parameters (hbase-site.xml) for the + * HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.hBaseConfiguration") + private Object hBaseConfiguration; + + /** + * Specifies the HDFS configuration parameters (hdfs-site.xml) for the + * HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.hdfsConfiguration") + private Object hdfsConfiguration; + + /** + * Specifies the hive configuration parameters (hive-site.xml) for the + * HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.hiveConfiguration") + private Object hiveConfiguration; + + /** + * Specifies the MapReduce configuration parameters (mapred-site.xml) for + * the HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.mapReduceConfiguration") + private Object mapReduceConfiguration; + + /** + * Specifies the Oozie configuration parameters (oozie-site.xml) for the + * HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.oozieConfiguration") + private Object oozieConfiguration; + + /** + * Specifies the Storm configuration parameters (storm-site.xml) for the + * HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.stormConfiguration") + private Object stormConfiguration; + + /** + * Specifies the Yarn configuration parameters (yarn-site.xml) for the + * HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.yarnConfiguration") + private Object yarnConfiguration; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Specifies the size of the head node for the HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.headNodeSize") + private Object headNodeSize; + + /** + * Specifies the size of the data node for the HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.dataNodeSize") + private Object dataNodeSize; + + /** + * Specifies the size of the Zoo Keeper node for the HDInsight cluster. + */ + @JsonProperty(value = "typeProperties.zookeeperNodeSize") + private Object zookeeperNodeSize; + + /** + * Get number of worker/data nodes in the cluster. Suggestion value: 4. Type: string (or Expression with resultType string). + * + * @return the clusterSize value + */ + public Object clusterSize() { + return this.clusterSize; + } + + /** + * Set number of worker/data nodes in the cluster. Suggestion value: 4. Type: string (or Expression with resultType string). + * + * @param clusterSize the clusterSize value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterSize(Object clusterSize) { + this.clusterSize = clusterSize; + return this; + } + + /** + * Get the allowed idle time for the on-demand HDInsight cluster. Specifies how long the on-demand HDInsight cluster stays alive after completion of an activity run if there are no other active jobs in the cluster. The minimum value is 5 mins. Type: string (or Expression with resultType string). + * + * @return the timeToLive value + */ + public Object timeToLive() { + return this.timeToLive; + } + + /** + * Set the allowed idle time for the on-demand HDInsight cluster. Specifies how long the on-demand HDInsight cluster stays alive after completion of an activity run if there are no other active jobs in the cluster. The minimum value is 5 mins. Type: string (or Expression with resultType string). + * + * @param timeToLive the timeToLive value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withTimeToLive(Object timeToLive) { + this.timeToLive = timeToLive; + return this; + } + + /** + * Get version of the HDInsight cluster.  Type: string (or Expression with resultType string). + * + * @return the version value + */ + public Object version() { + return this.version; + } + + /** + * Set version of the HDInsight cluster.  Type: string (or Expression with resultType string). + * + * @param version the version value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withVersion(Object version) { + this.version = version; + return this; + } + + /** + * Get azure Storage linked service to be used by the on-demand cluster for storing and processing data. + * + * @return the linkedServiceName value + */ + public LinkedServiceReference linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set azure Storage linked service to be used by the on-demand cluster for storing and processing data. + * + * @param linkedServiceName the linkedServiceName value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withLinkedServiceName(LinkedServiceReference linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + + /** + * Get the customer’s subscription to host the cluster. Type: string (or Expression with resultType string). + * + * @return the hostSubscriptionId value + */ + public Object hostSubscriptionId() { + return this.hostSubscriptionId; + } + + /** + * Set the customer’s subscription to host the cluster. Type: string (or Expression with resultType string). + * + * @param hostSubscriptionId the hostSubscriptionId value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withHostSubscriptionId(Object hostSubscriptionId) { + this.hostSubscriptionId = hostSubscriptionId; + return this; + } + + /** + * Get the service principal id for the hostSubscriptionId. Type: string (or Expression with resultType string). + * + * @return the servicePrincipalId value + */ + public Object servicePrincipalId() { + return this.servicePrincipalId; + } + + /** + * Set the service principal id for the hostSubscriptionId. Type: string (or Expression with resultType string). + * + * @param servicePrincipalId the servicePrincipalId value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withServicePrincipalId(Object servicePrincipalId) { + this.servicePrincipalId = servicePrincipalId; + return this; + } + + /** + * Get the key for the service principal id. + * + * @return the servicePrincipalKey value + */ + public SecretBase servicePrincipalKey() { + return this.servicePrincipalKey; + } + + /** + * Set the key for the service principal id. + * + * @param servicePrincipalKey the servicePrincipalKey value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withServicePrincipalKey(SecretBase servicePrincipalKey) { + this.servicePrincipalKey = servicePrincipalKey; + return this; + } + + /** + * Get the Tenant id/name to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @return the tenant value + */ + public Object tenant() { + return this.tenant; + } + + /** + * Set the Tenant id/name to which the service principal belongs. Type: string (or Expression with resultType string). + * + * @param tenant the tenant value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withTenant(Object tenant) { + this.tenant = tenant; + return this; + } + + /** + * Get the resource group where the cluster belongs. Type: string (or Expression with resultType string). + * + * @return the clusterResourceGroup value + */ + public Object clusterResourceGroup() { + return this.clusterResourceGroup; + } + + /** + * Set the resource group where the cluster belongs. Type: string (or Expression with resultType string). + * + * @param clusterResourceGroup the clusterResourceGroup value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterResourceGroup(Object clusterResourceGroup) { + this.clusterResourceGroup = clusterResourceGroup; + return this; + } + + /** + * Get the prefix of cluster name, postfix will be distinct with timestamp. Type: string (or Expression with resultType string). + * + * @return the clusterNamePrefix value + */ + public Object clusterNamePrefix() { + return this.clusterNamePrefix; + } + + /** + * Set the prefix of cluster name, postfix will be distinct with timestamp. Type: string (or Expression with resultType string). + * + * @param clusterNamePrefix the clusterNamePrefix value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterNamePrefix(Object clusterNamePrefix) { + this.clusterNamePrefix = clusterNamePrefix; + return this; + } + + /** + * Get the username to access the cluster. Type: string (or Expression with resultType string). + * + * @return the clusterUserName value + */ + public Object clusterUserName() { + return this.clusterUserName; + } + + /** + * Set the username to access the cluster. Type: string (or Expression with resultType string). + * + * @param clusterUserName the clusterUserName value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterUserName(Object clusterUserName) { + this.clusterUserName = clusterUserName; + return this; + } + + /** + * Get the password to access the cluster. + * + * @return the clusterPassword value + */ + public SecretBase clusterPassword() { + return this.clusterPassword; + } + + /** + * Set the password to access the cluster. + * + * @param clusterPassword the clusterPassword value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterPassword(SecretBase clusterPassword) { + this.clusterPassword = clusterPassword; + return this; + } + + /** + * Get the username to SSH remotely connect to cluster’s node (for Linux). Type: string (or Expression with resultType string). + * + * @return the clusterSshUserName value + */ + public Object clusterSshUserName() { + return this.clusterSshUserName; + } + + /** + * Set the username to SSH remotely connect to cluster’s node (for Linux). Type: string (or Expression with resultType string). + * + * @param clusterSshUserName the clusterSshUserName value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterSshUserName(Object clusterSshUserName) { + this.clusterSshUserName = clusterSshUserName; + return this; + } + + /** + * Get the password to SSH remotely connect cluster’s node (for Linux). + * + * @return the clusterSshPassword value + */ + public SecretBase clusterSshPassword() { + return this.clusterSshPassword; + } + + /** + * Set the password to SSH remotely connect cluster’s node (for Linux). + * + * @param clusterSshPassword the clusterSshPassword value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterSshPassword(SecretBase clusterSshPassword) { + this.clusterSshPassword = clusterSshPassword; + return this; + } + + /** + * Get specifies additional storage accounts for the HDInsight linked service so that the Data Factory service can register them on your behalf. + * + * @return the additionalLinkedServiceNames value + */ + public List additionalLinkedServiceNames() { + return this.additionalLinkedServiceNames; + } + + /** + * Set specifies additional storage accounts for the HDInsight linked service so that the Data Factory service can register them on your behalf. + * + * @param additionalLinkedServiceNames the additionalLinkedServiceNames value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withAdditionalLinkedServiceNames(List additionalLinkedServiceNames) { + this.additionalLinkedServiceNames = additionalLinkedServiceNames; + return this; + } + + /** + * Get the name of Azure SQL linked service that point to the HCatalog database. The on-demand HDInsight cluster is created by using the Azure SQL database as the metastore. + * + * @return the hcatalogLinkedServiceName value + */ + public LinkedServiceReference hcatalogLinkedServiceName() { + return this.hcatalogLinkedServiceName; + } + + /** + * Set the name of Azure SQL linked service that point to the HCatalog database. The on-demand HDInsight cluster is created by using the Azure SQL database as the metastore. + * + * @param hcatalogLinkedServiceName the hcatalogLinkedServiceName value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withHcatalogLinkedServiceName(LinkedServiceReference hcatalogLinkedServiceName) { + this.hcatalogLinkedServiceName = hcatalogLinkedServiceName; + return this; + } + + /** + * Get the cluster type. Type: string (or Expression with resultType string). + * + * @return the clusterType value + */ + public Object clusterType() { + return this.clusterType; + } + + /** + * Set the cluster type. Type: string (or Expression with resultType string). + * + * @param clusterType the clusterType value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withClusterType(Object clusterType) { + this.clusterType = clusterType; + return this; + } + + /** + * Get the version of spark if the cluster type is 'spark'. Type: string (or Expression with resultType string). + * + * @return the sparkVersion value + */ + public Object sparkVersion() { + return this.sparkVersion; + } + + /** + * Set the version of spark if the cluster type is 'spark'. Type: string (or Expression with resultType string). + * + * @param sparkVersion the sparkVersion value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withSparkVersion(Object sparkVersion) { + this.sparkVersion = sparkVersion; + return this; + } + + /** + * Get specifies the core configuration parameters (as in core-site.xml) for the HDInsight cluster to be created. + * + * @return the coreConfiguration value + */ + public Object coreConfiguration() { + return this.coreConfiguration; + } + + /** + * Set specifies the core configuration parameters (as in core-site.xml) for the HDInsight cluster to be created. + * + * @param coreConfiguration the coreConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withCoreConfiguration(Object coreConfiguration) { + this.coreConfiguration = coreConfiguration; + return this; + } + + /** + * Get specifies the HBase configuration parameters (hbase-site.xml) for the HDInsight cluster. + * + * @return the hBaseConfiguration value + */ + public Object hBaseConfiguration() { + return this.hBaseConfiguration; + } + + /** + * Set specifies the HBase configuration parameters (hbase-site.xml) for the HDInsight cluster. + * + * @param hBaseConfiguration the hBaseConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withHBaseConfiguration(Object hBaseConfiguration) { + this.hBaseConfiguration = hBaseConfiguration; + return this; + } + + /** + * Get specifies the HDFS configuration parameters (hdfs-site.xml) for the HDInsight cluster. + * + * @return the hdfsConfiguration value + */ + public Object hdfsConfiguration() { + return this.hdfsConfiguration; + } + + /** + * Set specifies the HDFS configuration parameters (hdfs-site.xml) for the HDInsight cluster. + * + * @param hdfsConfiguration the hdfsConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withHdfsConfiguration(Object hdfsConfiguration) { + this.hdfsConfiguration = hdfsConfiguration; + return this; + } + + /** + * Get specifies the hive configuration parameters (hive-site.xml) for the HDInsight cluster. + * + * @return the hiveConfiguration value + */ + public Object hiveConfiguration() { + return this.hiveConfiguration; + } + + /** + * Set specifies the hive configuration parameters (hive-site.xml) for the HDInsight cluster. + * + * @param hiveConfiguration the hiveConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withHiveConfiguration(Object hiveConfiguration) { + this.hiveConfiguration = hiveConfiguration; + return this; + } + + /** + * Get specifies the MapReduce configuration parameters (mapred-site.xml) for the HDInsight cluster. + * + * @return the mapReduceConfiguration value + */ + public Object mapReduceConfiguration() { + return this.mapReduceConfiguration; + } + + /** + * Set specifies the MapReduce configuration parameters (mapred-site.xml) for the HDInsight cluster. + * + * @param mapReduceConfiguration the mapReduceConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withMapReduceConfiguration(Object mapReduceConfiguration) { + this.mapReduceConfiguration = mapReduceConfiguration; + return this; + } + + /** + * Get specifies the Oozie configuration parameters (oozie-site.xml) for the HDInsight cluster. + * + * @return the oozieConfiguration value + */ + public Object oozieConfiguration() { + return this.oozieConfiguration; + } + + /** + * Set specifies the Oozie configuration parameters (oozie-site.xml) for the HDInsight cluster. + * + * @param oozieConfiguration the oozieConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withOozieConfiguration(Object oozieConfiguration) { + this.oozieConfiguration = oozieConfiguration; + return this; + } + + /** + * Get specifies the Storm configuration parameters (storm-site.xml) for the HDInsight cluster. + * + * @return the stormConfiguration value + */ + public Object stormConfiguration() { + return this.stormConfiguration; + } + + /** + * Set specifies the Storm configuration parameters (storm-site.xml) for the HDInsight cluster. + * + * @param stormConfiguration the stormConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withStormConfiguration(Object stormConfiguration) { + this.stormConfiguration = stormConfiguration; + return this; + } + + /** + * Get specifies the Yarn configuration parameters (yarn-site.xml) for the HDInsight cluster. + * + * @return the yarnConfiguration value + */ + public Object yarnConfiguration() { + return this.yarnConfiguration; + } + + /** + * Set specifies the Yarn configuration parameters (yarn-site.xml) for the HDInsight cluster. + * + * @param yarnConfiguration the yarnConfiguration value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withYarnConfiguration(Object yarnConfiguration) { + this.yarnConfiguration = yarnConfiguration; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + + /** + * Get specifies the size of the head node for the HDInsight cluster. + * + * @return the headNodeSize value + */ + public Object headNodeSize() { + return this.headNodeSize; + } + + /** + * Set specifies the size of the head node for the HDInsight cluster. + * + * @param headNodeSize the headNodeSize value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withHeadNodeSize(Object headNodeSize) { + this.headNodeSize = headNodeSize; + return this; + } + + /** + * Get specifies the size of the data node for the HDInsight cluster. + * + * @return the dataNodeSize value + */ + public Object dataNodeSize() { + return this.dataNodeSize; + } + + /** + * Set specifies the size of the data node for the HDInsight cluster. + * + * @param dataNodeSize the dataNodeSize value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withDataNodeSize(Object dataNodeSize) { + this.dataNodeSize = dataNodeSize; + return this; + } + + /** + * Get specifies the size of the Zoo Keeper node for the HDInsight cluster. + * + * @return the zookeeperNodeSize value + */ + public Object zookeeperNodeSize() { + return this.zookeeperNodeSize; + } + + /** + * Set specifies the size of the Zoo Keeper node for the HDInsight cluster. + * + * @param zookeeperNodeSize the zookeeperNodeSize value to set + * @return the HDInsightOnDemandLinkedService object itself. + */ + public HDInsightOnDemandLinkedService withZookeeperNodeSize(Object zookeeperNodeSize) { + this.zookeeperNodeSize = zookeeperNodeSize; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightPigActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightPigActivity.java new file mode 100644 index 000000000000..186e521b124a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightPigActivity.java @@ -0,0 +1,181 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * HDInsight Pig activity type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HDInsightPig") +@JsonFlatten +public class HDInsightPigActivity extends ExecutionActivity { + /** + * Storage linked service references. + */ + @JsonProperty(value = "typeProperties.storageLinkedServices") + private List storageLinkedServices; + + /** + * User specified arguments to HDInsightActivity. + */ + @JsonProperty(value = "typeProperties.arguments") + private List arguments; + + /** + * Debug info option. Possible values include: 'None', 'Always', 'Failure'. + */ + @JsonProperty(value = "typeProperties.getDebugInfo") + private HDInsightActivityDebugInfoOption getDebugInfo; + + /** + * Script path. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.scriptPath") + private Object scriptPath; + + /** + * Script linked service reference. + */ + @JsonProperty(value = "typeProperties.scriptLinkedService") + private LinkedServiceReference scriptLinkedService; + + /** + * Allows user to specify defines for Pig job request. + */ + @JsonProperty(value = "typeProperties.defines") + private Map defines; + + /** + * Get storage linked service references. + * + * @return the storageLinkedServices value + */ + public List storageLinkedServices() { + return this.storageLinkedServices; + } + + /** + * Set storage linked service references. + * + * @param storageLinkedServices the storageLinkedServices value to set + * @return the HDInsightPigActivity object itself. + */ + public HDInsightPigActivity withStorageLinkedServices(List storageLinkedServices) { + this.storageLinkedServices = storageLinkedServices; + return this; + } + + /** + * Get user specified arguments to HDInsightActivity. + * + * @return the arguments value + */ + public List arguments() { + return this.arguments; + } + + /** + * Set user specified arguments to HDInsightActivity. + * + * @param arguments the arguments value to set + * @return the HDInsightPigActivity object itself. + */ + public HDInsightPigActivity withArguments(List arguments) { + this.arguments = arguments; + return this; + } + + /** + * Get debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @return the getDebugInfo value + */ + public HDInsightActivityDebugInfoOption getDebugInfo() { + return this.getDebugInfo; + } + + /** + * Set debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @param getDebugInfo the getDebugInfo value to set + * @return the HDInsightPigActivity object itself. + */ + public HDInsightPigActivity withGetDebugInfo(HDInsightActivityDebugInfoOption getDebugInfo) { + this.getDebugInfo = getDebugInfo; + return this; + } + + /** + * Get script path. Type: string (or Expression with resultType string). + * + * @return the scriptPath value + */ + public Object scriptPath() { + return this.scriptPath; + } + + /** + * Set script path. Type: string (or Expression with resultType string). + * + * @param scriptPath the scriptPath value to set + * @return the HDInsightPigActivity object itself. + */ + public HDInsightPigActivity withScriptPath(Object scriptPath) { + this.scriptPath = scriptPath; + return this; + } + + /** + * Get script linked service reference. + * + * @return the scriptLinkedService value + */ + public LinkedServiceReference scriptLinkedService() { + return this.scriptLinkedService; + } + + /** + * Set script linked service reference. + * + * @param scriptLinkedService the scriptLinkedService value to set + * @return the HDInsightPigActivity object itself. + */ + public HDInsightPigActivity withScriptLinkedService(LinkedServiceReference scriptLinkedService) { + this.scriptLinkedService = scriptLinkedService; + return this; + } + + /** + * Get allows user to specify defines for Pig job request. + * + * @return the defines value + */ + public Map defines() { + return this.defines; + } + + /** + * Set allows user to specify defines for Pig job request. + * + * @param defines the defines value to set + * @return the HDInsightPigActivity object itself. + */ + public HDInsightPigActivity withDefines(Map defines) { + this.defines = defines; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightSparkActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightSparkActivity.java new file mode 100644 index 000000000000..759491ecbfc4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightSparkActivity.java @@ -0,0 +1,237 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * HDInsight Spark activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HDInsightSpark") +@JsonFlatten +public class HDInsightSparkActivity extends ExecutionActivity { + /** + * The root path in 'sparkJobLinkedService' for all the job’s files. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.rootPath", required = true) + private Object rootPath; + + /** + * The relative path to the root folder of the code/package to be executed. + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.entryFilePath", required = true) + private Object entryFilePath; + + /** + * The user-specified arguments to HDInsightSparkActivity. + */ + @JsonProperty(value = "typeProperties.arguments") + private List arguments; + + /** + * Debug info option. Possible values include: 'None', 'Always', 'Failure'. + */ + @JsonProperty(value = "typeProperties.getDebugInfo") + private HDInsightActivityDebugInfoOption getDebugInfo; + + /** + * The storage linked service for uploading the entry file and + * dependencies, and for receiving logs. + */ + @JsonProperty(value = "typeProperties.sparkJobLinkedService") + private LinkedServiceReference sparkJobLinkedService; + + /** + * The application's Java/Spark main class. + */ + @JsonProperty(value = "typeProperties.className") + private String className; + + /** + * The user to impersonate that will execute the job. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.proxyUser") + private Object proxyUser; + + /** + * Spark configuration property. + */ + @JsonProperty(value = "typeProperties.sparkConfig") + private Map sparkConfig; + + /** + * Get the root path in 'sparkJobLinkedService' for all the job’s files. Type: string (or Expression with resultType string). + * + * @return the rootPath value + */ + public Object rootPath() { + return this.rootPath; + } + + /** + * Set the root path in 'sparkJobLinkedService' for all the job’s files. Type: string (or Expression with resultType string). + * + * @param rootPath the rootPath value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withRootPath(Object rootPath) { + this.rootPath = rootPath; + return this; + } + + /** + * Get the relative path to the root folder of the code/package to be executed. Type: string (or Expression with resultType string). + * + * @return the entryFilePath value + */ + public Object entryFilePath() { + return this.entryFilePath; + } + + /** + * Set the relative path to the root folder of the code/package to be executed. Type: string (or Expression with resultType string). + * + * @param entryFilePath the entryFilePath value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withEntryFilePath(Object entryFilePath) { + this.entryFilePath = entryFilePath; + return this; + } + + /** + * Get the user-specified arguments to HDInsightSparkActivity. + * + * @return the arguments value + */ + public List arguments() { + return this.arguments; + } + + /** + * Set the user-specified arguments to HDInsightSparkActivity. + * + * @param arguments the arguments value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withArguments(List arguments) { + this.arguments = arguments; + return this; + } + + /** + * Get debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @return the getDebugInfo value + */ + public HDInsightActivityDebugInfoOption getDebugInfo() { + return this.getDebugInfo; + } + + /** + * Set debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @param getDebugInfo the getDebugInfo value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withGetDebugInfo(HDInsightActivityDebugInfoOption getDebugInfo) { + this.getDebugInfo = getDebugInfo; + return this; + } + + /** + * Get the storage linked service for uploading the entry file and dependencies, and for receiving logs. + * + * @return the sparkJobLinkedService value + */ + public LinkedServiceReference sparkJobLinkedService() { + return this.sparkJobLinkedService; + } + + /** + * Set the storage linked service for uploading the entry file and dependencies, and for receiving logs. + * + * @param sparkJobLinkedService the sparkJobLinkedService value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withSparkJobLinkedService(LinkedServiceReference sparkJobLinkedService) { + this.sparkJobLinkedService = sparkJobLinkedService; + return this; + } + + /** + * Get the application's Java/Spark main class. + * + * @return the className value + */ + public String className() { + return this.className; + } + + /** + * Set the application's Java/Spark main class. + * + * @param className the className value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withClassName(String className) { + this.className = className; + return this; + } + + /** + * Get the user to impersonate that will execute the job. Type: string (or Expression with resultType string). + * + * @return the proxyUser value + */ + public Object proxyUser() { + return this.proxyUser; + } + + /** + * Set the user to impersonate that will execute the job. Type: string (or Expression with resultType string). + * + * @param proxyUser the proxyUser value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withProxyUser(Object proxyUser) { + this.proxyUser = proxyUser; + return this; + } + + /** + * Get spark configuration property. + * + * @return the sparkConfig value + */ + public Map sparkConfig() { + return this.sparkConfig; + } + + /** + * Set spark configuration property. + * + * @param sparkConfig the sparkConfig value to set + * @return the HDInsightSparkActivity object itself. + */ + public HDInsightSparkActivity withSparkConfig(Map sparkConfig) { + this.sparkConfig = sparkConfig; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightStreamingActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightStreamingActivity.java new file mode 100644 index 000000000000..63ad0de77f90 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HDInsightStreamingActivity.java @@ -0,0 +1,340 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * HDInsight streaming activity type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HDInsightStreaming") +@JsonFlatten +public class HDInsightStreamingActivity extends ExecutionActivity { + /** + * Storage linked service references. + */ + @JsonProperty(value = "typeProperties.storageLinkedServices") + private List storageLinkedServices; + + /** + * User specified arguments to HDInsightActivity. + */ + @JsonProperty(value = "typeProperties.arguments") + private List arguments; + + /** + * Debug info option. Possible values include: 'None', 'Always', 'Failure'. + */ + @JsonProperty(value = "typeProperties.getDebugInfo") + private HDInsightActivityDebugInfoOption getDebugInfo; + + /** + * Mapper executable name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.mapper", required = true) + private Object mapper; + + /** + * Reducer executable name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.reducer", required = true) + private Object reducer; + + /** + * Input blob path. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.input", required = true) + private Object input; + + /** + * Output blob path. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.output", required = true) + private Object output; + + /** + * Paths to streaming job files. Can be directories. + */ + @JsonProperty(value = "typeProperties.filePaths", required = true) + private List filePaths; + + /** + * Linked service reference where the files are located. + */ + @JsonProperty(value = "typeProperties.fileLinkedService") + private LinkedServiceReference fileLinkedService; + + /** + * Combiner executable name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.combiner") + private Object combiner; + + /** + * Command line environment values. + */ + @JsonProperty(value = "typeProperties.commandEnvironment") + private List commandEnvironment; + + /** + * Allows user to specify defines for streaming job request. + */ + @JsonProperty(value = "typeProperties.defines") + private Map defines; + + /** + * Get storage linked service references. + * + * @return the storageLinkedServices value + */ + public List storageLinkedServices() { + return this.storageLinkedServices; + } + + /** + * Set storage linked service references. + * + * @param storageLinkedServices the storageLinkedServices value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withStorageLinkedServices(List storageLinkedServices) { + this.storageLinkedServices = storageLinkedServices; + return this; + } + + /** + * Get user specified arguments to HDInsightActivity. + * + * @return the arguments value + */ + public List arguments() { + return this.arguments; + } + + /** + * Set user specified arguments to HDInsightActivity. + * + * @param arguments the arguments value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withArguments(List arguments) { + this.arguments = arguments; + return this; + } + + /** + * Get debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @return the getDebugInfo value + */ + public HDInsightActivityDebugInfoOption getDebugInfo() { + return this.getDebugInfo; + } + + /** + * Set debug info option. Possible values include: 'None', 'Always', 'Failure'. + * + * @param getDebugInfo the getDebugInfo value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withGetDebugInfo(HDInsightActivityDebugInfoOption getDebugInfo) { + this.getDebugInfo = getDebugInfo; + return this; + } + + /** + * Get mapper executable name. Type: string (or Expression with resultType string). + * + * @return the mapper value + */ + public Object mapper() { + return this.mapper; + } + + /** + * Set mapper executable name. Type: string (or Expression with resultType string). + * + * @param mapper the mapper value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withMapper(Object mapper) { + this.mapper = mapper; + return this; + } + + /** + * Get reducer executable name. Type: string (or Expression with resultType string). + * + * @return the reducer value + */ + public Object reducer() { + return this.reducer; + } + + /** + * Set reducer executable name. Type: string (or Expression with resultType string). + * + * @param reducer the reducer value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withReducer(Object reducer) { + this.reducer = reducer; + return this; + } + + /** + * Get input blob path. Type: string (or Expression with resultType string). + * + * @return the input value + */ + public Object input() { + return this.input; + } + + /** + * Set input blob path. Type: string (or Expression with resultType string). + * + * @param input the input value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withInput(Object input) { + this.input = input; + return this; + } + + /** + * Get output blob path. Type: string (or Expression with resultType string). + * + * @return the output value + */ + public Object output() { + return this.output; + } + + /** + * Set output blob path. Type: string (or Expression with resultType string). + * + * @param output the output value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withOutput(Object output) { + this.output = output; + return this; + } + + /** + * Get paths to streaming job files. Can be directories. + * + * @return the filePaths value + */ + public List filePaths() { + return this.filePaths; + } + + /** + * Set paths to streaming job files. Can be directories. + * + * @param filePaths the filePaths value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withFilePaths(List filePaths) { + this.filePaths = filePaths; + return this; + } + + /** + * Get linked service reference where the files are located. + * + * @return the fileLinkedService value + */ + public LinkedServiceReference fileLinkedService() { + return this.fileLinkedService; + } + + /** + * Set linked service reference where the files are located. + * + * @param fileLinkedService the fileLinkedService value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withFileLinkedService(LinkedServiceReference fileLinkedService) { + this.fileLinkedService = fileLinkedService; + return this; + } + + /** + * Get combiner executable name. Type: string (or Expression with resultType string). + * + * @return the combiner value + */ + public Object combiner() { + return this.combiner; + } + + /** + * Set combiner executable name. Type: string (or Expression with resultType string). + * + * @param combiner the combiner value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withCombiner(Object combiner) { + this.combiner = combiner; + return this; + } + + /** + * Get command line environment values. + * + * @return the commandEnvironment value + */ + public List commandEnvironment() { + return this.commandEnvironment; + } + + /** + * Set command line environment values. + * + * @param commandEnvironment the commandEnvironment value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withCommandEnvironment(List commandEnvironment) { + this.commandEnvironment = commandEnvironment; + return this; + } + + /** + * Get allows user to specify defines for streaming job request. + * + * @return the defines value + */ + public Map defines() { + return this.defines; + } + + /** + * Set allows user to specify defines for streaming job request. + * + * @param defines the defines value to set + * @return the HDInsightStreamingActivity object itself. + */ + public HDInsightStreamingActivity withDefines(Map defines) { + this.defines = defines; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HdfsLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HdfsLinkedService.java new file mode 100644 index 000000000000..1341ca9feab6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HdfsLinkedService.java @@ -0,0 +1,161 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Hadoop Distributed File System (HDFS) linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Hdfs") +@JsonFlatten +public class HdfsLinkedService extends LinkedServiceInner { + /** + * The URL of the HDFS service endpoint, e.g. + * http://myhostname:50070/webhdfs/v1 . Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.url", required = true) + private Object url; + + /** + * Type of authentication used to connect to the HDFS. Possible values are: + * Anonymous and Windows. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.authenticationType") + private Object authenticationType; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * User name for Windows authentication. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password for Windows authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Get the URL of the HDFS service endpoint, e.g. http://myhostname:50070/webhdfs/v1 . Type: string (or Expression with resultType string). + * + * @return the url value + */ + public Object url() { + return this.url; + } + + /** + * Set the URL of the HDFS service endpoint, e.g. http://myhostname:50070/webhdfs/v1 . Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the HdfsLinkedService object itself. + */ + public HdfsLinkedService withUrl(Object url) { + this.url = url; + return this; + } + + /** + * Get type of authentication used to connect to the HDFS. Possible values are: Anonymous and Windows. Type: string (or Expression with resultType string). + * + * @return the authenticationType value + */ + public Object authenticationType() { + return this.authenticationType; + } + + /** + * Set type of authentication used to connect to the HDFS. Possible values are: Anonymous and Windows. Type: string (or Expression with resultType string). + * + * @param authenticationType the authenticationType value to set + * @return the HdfsLinkedService object itself. + */ + public HdfsLinkedService withAuthenticationType(Object authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the HdfsLinkedService object itself. + */ + public HdfsLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + + /** + * Get user name for Windows authentication. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set user name for Windows authentication. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the HdfsLinkedService object itself. + */ + public HdfsLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password for Windows authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for Windows authentication. + * + * @param password the password value to set + * @return the HdfsLinkedService object itself. + */ + public HdfsLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HdfsSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HdfsSource.java new file mode 100644 index 000000000000..87af345fafa8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HdfsSource.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity HDFS source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HdfsSource") +public class HdfsSource extends CopySource { + /** + * If true, files under the folder path will be read recursively. Default + * is true. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "recursive") + private Object recursive; + + /** + * Specifies Distcp-related settings. + */ + @JsonProperty(value = "distcpSettings") + private DistcpSettings distcpSettings; + + /** + * Get if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @return the recursive value + */ + public Object recursive() { + return this.recursive; + } + + /** + * Set if true, files under the folder path will be read recursively. Default is true. Type: boolean (or Expression with resultType boolean). + * + * @param recursive the recursive value to set + * @return the HdfsSource object itself. + */ + public HdfsSource withRecursive(Object recursive) { + this.recursive = recursive; + return this; + } + + /** + * Get specifies Distcp-related settings. + * + * @return the distcpSettings value + */ + public DistcpSettings distcpSettings() { + return this.distcpSettings; + } + + /** + * Set specifies Distcp-related settings. + * + * @param distcpSettings the distcpSettings value to set + * @return the HdfsSource object itself. + */ + public HdfsSource withDistcpSettings(DistcpSettings distcpSettings) { + this.distcpSettings = distcpSettings; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveAuthenticationType.java new file mode 100644 index 000000000000..77298c27cc5d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveAuthenticationType.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for HiveAuthenticationType. + */ +public final class HiveAuthenticationType extends ExpandableStringEnum { + /** Static value Anonymous for HiveAuthenticationType. */ + public static final HiveAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** Static value Username for HiveAuthenticationType. */ + public static final HiveAuthenticationType USERNAME = fromString("Username"); + + /** Static value UsernameAndPassword for HiveAuthenticationType. */ + public static final HiveAuthenticationType USERNAME_AND_PASSWORD = fromString("UsernameAndPassword"); + + /** Static value WindowsAzureHDInsightService for HiveAuthenticationType. */ + public static final HiveAuthenticationType WINDOWS_AZURE_HDINSIGHT_SERVICE = fromString("WindowsAzureHDInsightService"); + + /** + * Creates or finds a HiveAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding HiveAuthenticationType + */ + @JsonCreator + public static HiveAuthenticationType fromString(String name) { + return fromString(name, HiveAuthenticationType.class); + } + + /** + * @return known HiveAuthenticationType values + */ + public static Collection values() { + return values(HiveAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveLinkedService.java new file mode 100644 index 000000000000..d5dd90b4d585 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveLinkedService.java @@ -0,0 +1,483 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Hive Server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Hive") +@JsonFlatten +public class HiveLinkedService extends LinkedServiceInner { + /** + * IP address or host name of the Hive server, separated by ';' for + * multiple hosts (only when serviceDiscoveryMode is enable). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port that the Hive server uses to listen for client connections. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The type of Hive server. Possible values include: 'HiveServer1', + * 'HiveServer2', 'HiveThriftServer'. + */ + @JsonProperty(value = "typeProperties.serverType") + private HiveServerType serverType; + + /** + * The transport protocol to use in the Thrift layer. Possible values + * include: 'Binary', 'SASL', 'HTTP '. + */ + @JsonProperty(value = "typeProperties.thriftTransportProtocol") + private HiveThriftTransportProtocol thriftTransportProtocol; + + /** + * The authentication method used to access the Hive server. Possible + * values include: 'Anonymous', 'Username', 'UsernameAndPassword', + * 'WindowsAzureHDInsightService'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private HiveAuthenticationType authenticationType; + + /** + * true to indicate using the ZooKeeper service, false not. + */ + @JsonProperty(value = "typeProperties.serviceDiscoveryMode") + private Object serviceDiscoveryMode; + + /** + * The namespace on ZooKeeper under which Hive Server 2 nodes are added. + */ + @JsonProperty(value = "typeProperties.zooKeeperNameSpace") + private Object zooKeeperNameSpace; + + /** + * Specifies whether the driver uses native HiveQL queries,or converts them + * into an equivalent form in HiveQL. + */ + @JsonProperty(value = "typeProperties.useNativeQuery") + private Object useNativeQuery; + + /** + * The user name that you use to access Hive Server. + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password corresponding to the user name that you provided in the + * Username field. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The partial URL corresponding to the Hive server. + */ + @JsonProperty(value = "typeProperties.httpPath") + private Object httpPath; + + /** + * Specifies whether the connections to the server are encrypted using SSL. + * The default value is false. + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * The full path of the .pem file containing trusted CA certificates for + * verifying the server when connecting over SSL. This property can only be + * set when using SSL on self-hosted IR. The default value is the + * cacerts.pem file installed with the IR. + */ + @JsonProperty(value = "typeProperties.trustedCertPath") + private Object trustedCertPath; + + /** + * Specifies whether to use a CA certificate from the system trust store or + * from a specified PEM file. The default value is false. + */ + @JsonProperty(value = "typeProperties.useSystemTrustStore") + private Object useSystemTrustStore; + + /** + * Specifies whether to require a CA-issued SSL certificate name to match + * the host name of the server when connecting over SSL. The default value + * is false. + */ + @JsonProperty(value = "typeProperties.allowHostNameCNMismatch") + private Object allowHostNameCNMismatch; + + /** + * Specifies whether to allow self-signed certificates from the server. The + * default value is false. + */ + @JsonProperty(value = "typeProperties.allowSelfSignedServerCert") + private Object allowSelfSignedServerCert; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get iP address or host name of the Hive server, separated by ';' for multiple hosts (only when serviceDiscoveryMode is enable). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set iP address or host name of the Hive server, separated by ';' for multiple hosts (only when serviceDiscoveryMode is enable). + * + * @param host the host value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port that the Hive server uses to listen for client connections. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port that the Hive server uses to listen for client connections. + * + * @param port the port value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the type of Hive server. Possible values include: 'HiveServer1', 'HiveServer2', 'HiveThriftServer'. + * + * @return the serverType value + */ + public HiveServerType serverType() { + return this.serverType; + } + + /** + * Set the type of Hive server. Possible values include: 'HiveServer1', 'HiveServer2', 'HiveThriftServer'. + * + * @param serverType the serverType value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withServerType(HiveServerType serverType) { + this.serverType = serverType; + return this; + } + + /** + * Get the transport protocol to use in the Thrift layer. Possible values include: 'Binary', 'SASL', 'HTTP '. + * + * @return the thriftTransportProtocol value + */ + public HiveThriftTransportProtocol thriftTransportProtocol() { + return this.thriftTransportProtocol; + } + + /** + * Set the transport protocol to use in the Thrift layer. Possible values include: 'Binary', 'SASL', 'HTTP '. + * + * @param thriftTransportProtocol the thriftTransportProtocol value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withThriftTransportProtocol(HiveThriftTransportProtocol thriftTransportProtocol) { + this.thriftTransportProtocol = thriftTransportProtocol; + return this; + } + + /** + * Get the authentication method used to access the Hive server. Possible values include: 'Anonymous', 'Username', 'UsernameAndPassword', 'WindowsAzureHDInsightService'. + * + * @return the authenticationType value + */ + public HiveAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication method used to access the Hive server. Possible values include: 'Anonymous', 'Username', 'UsernameAndPassword', 'WindowsAzureHDInsightService'. + * + * @param authenticationType the authenticationType value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withAuthenticationType(HiveAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get true to indicate using the ZooKeeper service, false not. + * + * @return the serviceDiscoveryMode value + */ + public Object serviceDiscoveryMode() { + return this.serviceDiscoveryMode; + } + + /** + * Set true to indicate using the ZooKeeper service, false not. + * + * @param serviceDiscoveryMode the serviceDiscoveryMode value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withServiceDiscoveryMode(Object serviceDiscoveryMode) { + this.serviceDiscoveryMode = serviceDiscoveryMode; + return this; + } + + /** + * Get the namespace on ZooKeeper under which Hive Server 2 nodes are added. + * + * @return the zooKeeperNameSpace value + */ + public Object zooKeeperNameSpace() { + return this.zooKeeperNameSpace; + } + + /** + * Set the namespace on ZooKeeper under which Hive Server 2 nodes are added. + * + * @param zooKeeperNameSpace the zooKeeperNameSpace value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withZooKeeperNameSpace(Object zooKeeperNameSpace) { + this.zooKeeperNameSpace = zooKeeperNameSpace; + return this; + } + + /** + * Get specifies whether the driver uses native HiveQL queries,or converts them into an equivalent form in HiveQL. + * + * @return the useNativeQuery value + */ + public Object useNativeQuery() { + return this.useNativeQuery; + } + + /** + * Set specifies whether the driver uses native HiveQL queries,or converts them into an equivalent form in HiveQL. + * + * @param useNativeQuery the useNativeQuery value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withUseNativeQuery(Object useNativeQuery) { + this.useNativeQuery = useNativeQuery; + return this; + } + + /** + * Get the user name that you use to access Hive Server. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name that you use to access Hive Server. + * + * @param username the username value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name that you provided in the Username field. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name that you provided in the Username field. + * + * @param password the password value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the partial URL corresponding to the Hive server. + * + * @return the httpPath value + */ + public Object httpPath() { + return this.httpPath; + } + + /** + * Set the partial URL corresponding to the Hive server. + * + * @param httpPath the httpPath value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withHttpPath(Object httpPath) { + this.httpPath = httpPath; + return this; + } + + /** + * Get specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @param enableSsl the enableSsl value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @return the trustedCertPath value + */ + public Object trustedCertPath() { + return this.trustedCertPath; + } + + /** + * Set the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @param trustedCertPath the trustedCertPath value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withTrustedCertPath(Object trustedCertPath) { + this.trustedCertPath = trustedCertPath; + return this; + } + + /** + * Get specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @return the useSystemTrustStore value + */ + public Object useSystemTrustStore() { + return this.useSystemTrustStore; + } + + /** + * Set specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @param useSystemTrustStore the useSystemTrustStore value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withUseSystemTrustStore(Object useSystemTrustStore) { + this.useSystemTrustStore = useSystemTrustStore; + return this; + } + + /** + * Get specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @return the allowHostNameCNMismatch value + */ + public Object allowHostNameCNMismatch() { + return this.allowHostNameCNMismatch; + } + + /** + * Set specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @param allowHostNameCNMismatch the allowHostNameCNMismatch value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withAllowHostNameCNMismatch(Object allowHostNameCNMismatch) { + this.allowHostNameCNMismatch = allowHostNameCNMismatch; + return this; + } + + /** + * Get specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @return the allowSelfSignedServerCert value + */ + public Object allowSelfSignedServerCert() { + return this.allowSelfSignedServerCert; + } + + /** + * Set specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @param allowSelfSignedServerCert the allowSelfSignedServerCert value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withAllowSelfSignedServerCert(Object allowSelfSignedServerCert) { + this.allowSelfSignedServerCert = allowSelfSignedServerCert; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the HiveLinkedService object itself. + */ + public HiveLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveObjectDataset.java new file mode 100644 index 000000000000..9fcdc7226a75 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Hive Server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HiveObject") +public class HiveObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveServerType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveServerType.java new file mode 100644 index 000000000000..fd45a8a51a89 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveServerType.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for HiveServerType. + */ +public final class HiveServerType extends ExpandableStringEnum { + /** Static value HiveServer1 for HiveServerType. */ + public static final HiveServerType HIVE_SERVER1 = fromString("HiveServer1"); + + /** Static value HiveServer2 for HiveServerType. */ + public static final HiveServerType HIVE_SERVER2 = fromString("HiveServer2"); + + /** Static value HiveThriftServer for HiveServerType. */ + public static final HiveServerType HIVE_THRIFT_SERVER = fromString("HiveThriftServer"); + + /** + * Creates or finds a HiveServerType from its string representation. + * @param name a name to look for + * @return the corresponding HiveServerType + */ + @JsonCreator + public static HiveServerType fromString(String name) { + return fromString(name, HiveServerType.class); + } + + /** + * @return known HiveServerType values + */ + public static Collection values() { + return values(HiveServerType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveSource.java new file mode 100644 index 000000000000..bc959c92de74 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Hive Server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HiveSource") +public class HiveSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the HiveSource object itself. + */ + public HiveSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveThriftTransportProtocol.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveThriftTransportProtocol.java new file mode 100644 index 000000000000..406d905b79cc --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HiveThriftTransportProtocol.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for HiveThriftTransportProtocol. + */ +public final class HiveThriftTransportProtocol extends ExpandableStringEnum { + /** Static value Binary for HiveThriftTransportProtocol. */ + public static final HiveThriftTransportProtocol BINARY = fromString("Binary"); + + /** Static value SASL for HiveThriftTransportProtocol. */ + public static final HiveThriftTransportProtocol SASL = fromString("SASL"); + + /** Static value HTTP for HiveThriftTransportProtocol. */ + public static final HiveThriftTransportProtocol HTTP_ = fromString("HTTP "); + + /** + * Creates or finds a HiveThriftTransportProtocol from its string representation. + * @param name a name to look for + * @return the corresponding HiveThriftTransportProtocol + */ + @JsonCreator + public static HiveThriftTransportProtocol fromString(String name) { + return fromString(name, HiveThriftTransportProtocol.class); + } + + /** + * @return known HiveThriftTransportProtocol values + */ + public static Collection values() { + return values(HiveThriftTransportProtocol.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpAuthenticationType.java new file mode 100644 index 000000000000..807acd12e904 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpAuthenticationType.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for HttpAuthenticationType. + */ +public final class HttpAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for HttpAuthenticationType. */ + public static final HttpAuthenticationType BASIC = fromString("Basic"); + + /** Static value Anonymous for HttpAuthenticationType. */ + public static final HttpAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** Static value Digest for HttpAuthenticationType. */ + public static final HttpAuthenticationType DIGEST = fromString("Digest"); + + /** Static value Windows for HttpAuthenticationType. */ + public static final HttpAuthenticationType WINDOWS = fromString("Windows"); + + /** Static value ClientCertificate for HttpAuthenticationType. */ + public static final HttpAuthenticationType CLIENT_CERTIFICATE = fromString("ClientCertificate"); + + /** + * Creates or finds a HttpAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding HttpAuthenticationType + */ + @JsonCreator + public static HttpAuthenticationType fromString(String name) { + return fromString(name, HttpAuthenticationType.class); + } + + /** + * @return known HttpAuthenticationType values + */ + public static Collection values() { + return values(HttpAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpDataset.java new file mode 100644 index 000000000000..f4278994b524 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpDataset.java @@ -0,0 +1,191 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * A file in an HTTP web server. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HttpFile") +@JsonFlatten +public class HttpDataset extends DatasetInner { + /** + * The relative URL based on the URL in the HttpLinkedService refers to an + * HTTP file Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.relativeUrl") + private Object relativeUrl; + + /** + * The HTTP method for the HTTP request. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.requestMethod") + private Object requestMethod; + + /** + * The body for the HTTP request. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.requestBody") + private Object requestBody; + + /** + * The headers for the HTTP Request. e.g. + * request-header-name-1:request-header-value-1 + * ... + * request-header-name-n:request-header-value-n Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.additionalHeaders") + private Object additionalHeaders; + + /** + * The format of files. + */ + @JsonProperty(value = "typeProperties.format") + private DatasetStorageFormat format; + + /** + * The data compression method used on files. + */ + @JsonProperty(value = "typeProperties.compression") + private DatasetCompression compression; + + /** + * Get the relative URL based on the URL in the HttpLinkedService refers to an HTTP file Type: string (or Expression with resultType string). + * + * @return the relativeUrl value + */ + public Object relativeUrl() { + return this.relativeUrl; + } + + /** + * Set the relative URL based on the URL in the HttpLinkedService refers to an HTTP file Type: string (or Expression with resultType string). + * + * @param relativeUrl the relativeUrl value to set + * @return the HttpDataset object itself. + */ + public HttpDataset withRelativeUrl(Object relativeUrl) { + this.relativeUrl = relativeUrl; + return this; + } + + /** + * Get the HTTP method for the HTTP request. Type: string (or Expression with resultType string). + * + * @return the requestMethod value + */ + public Object requestMethod() { + return this.requestMethod; + } + + /** + * Set the HTTP method for the HTTP request. Type: string (or Expression with resultType string). + * + * @param requestMethod the requestMethod value to set + * @return the HttpDataset object itself. + */ + public HttpDataset withRequestMethod(Object requestMethod) { + this.requestMethod = requestMethod; + return this; + } + + /** + * Get the body for the HTTP request. Type: string (or Expression with resultType string). + * + * @return the requestBody value + */ + public Object requestBody() { + return this.requestBody; + } + + /** + * Set the body for the HTTP request. Type: string (or Expression with resultType string). + * + * @param requestBody the requestBody value to set + * @return the HttpDataset object itself. + */ + public HttpDataset withRequestBody(Object requestBody) { + this.requestBody = requestBody; + return this; + } + + /** + * Get the headers for the HTTP Request. e.g. request-header-name-1:request-header-value-1 + ... + request-header-name-n:request-header-value-n Type: string (or Expression with resultType string). + * + * @return the additionalHeaders value + */ + public Object additionalHeaders() { + return this.additionalHeaders; + } + + /** + * Set the headers for the HTTP Request. e.g. request-header-name-1:request-header-value-1 + ... + request-header-name-n:request-header-value-n Type: string (or Expression with resultType string). + * + * @param additionalHeaders the additionalHeaders value to set + * @return the HttpDataset object itself. + */ + public HttpDataset withAdditionalHeaders(Object additionalHeaders) { + this.additionalHeaders = additionalHeaders; + return this; + } + + /** + * Get the format of files. + * + * @return the format value + */ + public DatasetStorageFormat format() { + return this.format; + } + + /** + * Set the format of files. + * + * @param format the format value to set + * @return the HttpDataset object itself. + */ + public HttpDataset withFormat(DatasetStorageFormat format) { + this.format = format; + return this; + } + + /** + * Get the data compression method used on files. + * + * @return the compression value + */ + public DatasetCompression compression() { + return this.compression; + } + + /** + * Set the data compression method used on files. + * + * @param compression the compression value to set + * @return the HttpDataset object itself. + */ + public HttpDataset withCompression(DatasetCompression compression) { + this.compression = compression; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpLinkedService.java new file mode 100644 index 000000000000..5654f32237db --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpLinkedService.java @@ -0,0 +1,247 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for an HTTP source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HttpServer") +@JsonFlatten +public class HttpLinkedService extends LinkedServiceInner { + /** + * The base URL of the HTTP endpoint, e.g. http://www.microsoft.com. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.url", required = true) + private Object url; + + /** + * The authentication type to be used to connect to the HTTP server. + * Possible values include: 'Basic', 'Anonymous', 'Digest', 'Windows', + * 'ClientCertificate'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private HttpAuthenticationType authenticationType; + + /** + * User name for Basic, Digest, or Windows authentication. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password for Basic, Digest, Windows, or ClientCertificate with + * EmbeddedCertData authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Base64 encoded certificate data for ClientCertificate authentication. + * For on-premises copy with ClientCertificate authentication, either + * CertThumbprint or EmbeddedCertData/Password should be specified. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.embeddedCertData") + private Object embeddedCertData; + + /** + * Thumbprint of certificate for ClientCertificate authentication. Only + * valid for on-premises copy. For on-premises copy with ClientCertificate + * authentication, either CertThumbprint or EmbeddedCertData/Password + * should be specified. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.certThumbprint") + private Object certThumbprint; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * If true, validate the HTTPS server SSL certificate. Default value is + * true. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "typeProperties.enableServerCertificateValidation") + private Object enableServerCertificateValidation; + + /** + * Get the base URL of the HTTP endpoint, e.g. http://www.microsoft.com. Type: string (or Expression with resultType string). + * + * @return the url value + */ + public Object url() { + return this.url; + } + + /** + * Set the base URL of the HTTP endpoint, e.g. http://www.microsoft.com. Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withUrl(Object url) { + this.url = url; + return this; + } + + /** + * Get the authentication type to be used to connect to the HTTP server. Possible values include: 'Basic', 'Anonymous', 'Digest', 'Windows', 'ClientCertificate'. + * + * @return the authenticationType value + */ + public HttpAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to be used to connect to the HTTP server. Possible values include: 'Basic', 'Anonymous', 'Digest', 'Windows', 'ClientCertificate'. + * + * @param authenticationType the authenticationType value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withAuthenticationType(HttpAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get user name for Basic, Digest, or Windows authentication. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set user name for Basic, Digest, or Windows authentication. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password for Basic, Digest, Windows, or ClientCertificate with EmbeddedCertData authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for Basic, Digest, Windows, or ClientCertificate with EmbeddedCertData authentication. + * + * @param password the password value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get base64 encoded certificate data for ClientCertificate authentication. For on-premises copy with ClientCertificate authentication, either CertThumbprint or EmbeddedCertData/Password should be specified. Type: string (or Expression with resultType string). + * + * @return the embeddedCertData value + */ + public Object embeddedCertData() { + return this.embeddedCertData; + } + + /** + * Set base64 encoded certificate data for ClientCertificate authentication. For on-premises copy with ClientCertificate authentication, either CertThumbprint or EmbeddedCertData/Password should be specified. Type: string (or Expression with resultType string). + * + * @param embeddedCertData the embeddedCertData value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withEmbeddedCertData(Object embeddedCertData) { + this.embeddedCertData = embeddedCertData; + return this; + } + + /** + * Get thumbprint of certificate for ClientCertificate authentication. Only valid for on-premises copy. For on-premises copy with ClientCertificate authentication, either CertThumbprint or EmbeddedCertData/Password should be specified. Type: string (or Expression with resultType string). + * + * @return the certThumbprint value + */ + public Object certThumbprint() { + return this.certThumbprint; + } + + /** + * Set thumbprint of certificate for ClientCertificate authentication. Only valid for on-premises copy. For on-premises copy with ClientCertificate authentication, either CertThumbprint or EmbeddedCertData/Password should be specified. Type: string (or Expression with resultType string). + * + * @param certThumbprint the certThumbprint value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withCertThumbprint(Object certThumbprint) { + this.certThumbprint = certThumbprint; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + + /** + * Get if true, validate the HTTPS server SSL certificate. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the enableServerCertificateValidation value + */ + public Object enableServerCertificateValidation() { + return this.enableServerCertificateValidation; + } + + /** + * Set if true, validate the HTTPS server SSL certificate. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param enableServerCertificateValidation the enableServerCertificateValidation value to set + * @return the HttpLinkedService object itself. + */ + public HttpLinkedService withEnableServerCertificateValidation(Object enableServerCertificateValidation) { + this.enableServerCertificateValidation = enableServerCertificateValidation; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpSource.java new file mode 100644 index 000000000000..66364181d696 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HttpSource.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for an HTTP file. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HttpSource") +public class HttpSource extends CopySource { + /** + * Specifies the timeout for a HTTP client to get HTTP response from HTTP + * server. The default value is equivalent to + * System.Net.HttpWebRequest.Timeout. Type: string (or Expression with + * resultType string), pattern: + * ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "httpRequestTimeout") + private Object httpRequestTimeout; + + /** + * Get specifies the timeout for a HTTP client to get HTTP response from HTTP server. The default value is equivalent to System.Net.HttpWebRequest.Timeout. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the httpRequestTimeout value + */ + public Object httpRequestTimeout() { + return this.httpRequestTimeout; + } + + /** + * Set specifies the timeout for a HTTP client to get HTTP response from HTTP server. The default value is equivalent to System.Net.HttpWebRequest.Timeout. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param httpRequestTimeout the httpRequestTimeout value to set + * @return the HttpSource object itself. + */ + public HttpSource withHttpRequestTimeout(Object httpRequestTimeout) { + this.httpRequestTimeout = httpRequestTimeout; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotLinkedService.java new file mode 100644 index 000000000000..fe5110099dc8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotLinkedService.java @@ -0,0 +1,240 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Hubspot Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Hubspot") +@JsonFlatten +public class HubspotLinkedService extends LinkedServiceInner { + /** + * The client ID associated with your Hubspot application. + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * The client secret associated with your Hubspot application. + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * The access token obtained when initially authenticating your OAuth + * integration. + */ + @JsonProperty(value = "typeProperties.accessToken") + private SecretBase accessToken; + + /** + * The refresh token obtained when initially authenticating your OAuth + * integration. + */ + @JsonProperty(value = "typeProperties.refreshToken") + private SecretBase refreshToken; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the client ID associated with your Hubspot application. + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set the client ID associated with your Hubspot application. + * + * @param clientId the clientId value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret associated with your Hubspot application. + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret associated with your Hubspot application. + * + * @param clientSecret the clientSecret value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get the access token obtained when initially authenticating your OAuth integration. + * + * @return the accessToken value + */ + public SecretBase accessToken() { + return this.accessToken; + } + + /** + * Set the access token obtained when initially authenticating your OAuth integration. + * + * @param accessToken the accessToken value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withAccessToken(SecretBase accessToken) { + this.accessToken = accessToken; + return this; + } + + /** + * Get the refresh token obtained when initially authenticating your OAuth integration. + * + * @return the refreshToken value + */ + public SecretBase refreshToken() { + return this.refreshToken; + } + + /** + * Set the refresh token obtained when initially authenticating your OAuth integration. + * + * @param refreshToken the refreshToken value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withRefreshToken(SecretBase refreshToken) { + this.refreshToken = refreshToken; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the HubspotLinkedService object itself. + */ + public HubspotLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotObjectDataset.java new file mode 100644 index 000000000000..91f81745a8b5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Hubspot Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HubspotObject") +public class HubspotObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotSource.java new file mode 100644 index 000000000000..5f77c2fc5a82 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/HubspotSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Hubspot Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("HubspotSource") +public class HubspotSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the HubspotSource object itself. + */ + public HubspotSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IfConditionActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IfConditionActivity.java new file mode 100644 index 000000000000..c07a3fdd78a9 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IfConditionActivity.java @@ -0,0 +1,110 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * This activity evaluates a boolean expression and executes either the + * activities under the ifTrueActivities property or the ifFalseActivities + * property depending on the result of the expression. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("IfCondition") +@JsonFlatten +public class IfConditionActivity extends ControlActivity { + /** + * An expression that would evaluate to Boolean. This is used to determine + * the block of activities (ifTrueActivities or ifFalseActivities) that + * will be executed. + */ + @JsonProperty(value = "typeProperties.expression", required = true) + private Expression expression; + + /** + * List of activities to execute if expression is evaluated to true. This + * is an optional property and if not provided, the activity will exit + * without any action. + */ + @JsonProperty(value = "typeProperties.ifTrueActivities") + private List ifTrueActivities; + + /** + * List of activities to execute if expression is evaluated to false. This + * is an optional property and if not provided, the activity will exit + * without any action. + */ + @JsonProperty(value = "typeProperties.ifFalseActivities") + private List ifFalseActivities; + + /** + * Get an expression that would evaluate to Boolean. This is used to determine the block of activities (ifTrueActivities or ifFalseActivities) that will be executed. + * + * @return the expression value + */ + public Expression expression() { + return this.expression; + } + + /** + * Set an expression that would evaluate to Boolean. This is used to determine the block of activities (ifTrueActivities or ifFalseActivities) that will be executed. + * + * @param expression the expression value to set + * @return the IfConditionActivity object itself. + */ + public IfConditionActivity withExpression(Expression expression) { + this.expression = expression; + return this; + } + + /** + * Get list of activities to execute if expression is evaluated to true. This is an optional property and if not provided, the activity will exit without any action. + * + * @return the ifTrueActivities value + */ + public List ifTrueActivities() { + return this.ifTrueActivities; + } + + /** + * Set list of activities to execute if expression is evaluated to true. This is an optional property and if not provided, the activity will exit without any action. + * + * @param ifTrueActivities the ifTrueActivities value to set + * @return the IfConditionActivity object itself. + */ + public IfConditionActivity withIfTrueActivities(List ifTrueActivities) { + this.ifTrueActivities = ifTrueActivities; + return this; + } + + /** + * Get list of activities to execute if expression is evaluated to false. This is an optional property and if not provided, the activity will exit without any action. + * + * @return the ifFalseActivities value + */ + public List ifFalseActivities() { + return this.ifFalseActivities; + } + + /** + * Set list of activities to execute if expression is evaluated to false. This is an optional property and if not provided, the activity will exit without any action. + * + * @param ifFalseActivities the ifFalseActivities value to set + * @return the IfConditionActivity object itself. + */ + public IfConditionActivity withIfFalseActivities(List ifFalseActivities) { + this.ifFalseActivities = ifFalseActivities; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaAuthenticationType.java new file mode 100644 index 000000000000..ede8f96bde80 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaAuthenticationType.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ImpalaAuthenticationType. + */ +public final class ImpalaAuthenticationType extends ExpandableStringEnum { + /** Static value Anonymous for ImpalaAuthenticationType. */ + public static final ImpalaAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** Static value SASLUsername for ImpalaAuthenticationType. */ + public static final ImpalaAuthenticationType SASLUSERNAME = fromString("SASLUsername"); + + /** Static value UsernameAndPassword for ImpalaAuthenticationType. */ + public static final ImpalaAuthenticationType USERNAME_AND_PASSWORD = fromString("UsernameAndPassword"); + + /** + * Creates or finds a ImpalaAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding ImpalaAuthenticationType + */ + @JsonCreator + public static ImpalaAuthenticationType fromString(String name) { + return fromString(name, ImpalaAuthenticationType.class); + } + + /** + * @return known ImpalaAuthenticationType values + */ + public static Collection values() { + return values(ImpalaAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaLinkedService.java new file mode 100644 index 000000000000..ac8daabd4b6c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaLinkedService.java @@ -0,0 +1,325 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Impala server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Impala") +@JsonFlatten +public class ImpalaLinkedService extends LinkedServiceInner { + /** + * The IP address or host name of the Impala server. (i.e. + * 192.168.222.160). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port that the Impala server uses to listen for client + * connections. The default value is 21050. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The authentication type to use. Possible values include: 'Anonymous', + * 'SASLUsername', 'UsernameAndPassword'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private ImpalaAuthenticationType authenticationType; + + /** + * The user name used to access the Impala server. The default value is + * anonymous when using SASLUsername. + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password corresponding to the user name when using + * UsernameAndPassword. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Specifies whether the connections to the server are encrypted using SSL. + * The default value is false. + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * The full path of the .pem file containing trusted CA certificates for + * verifying the server when connecting over SSL. This property can only be + * set when using SSL on self-hosted IR. The default value is the + * cacerts.pem file installed with the IR. + */ + @JsonProperty(value = "typeProperties.trustedCertPath") + private Object trustedCertPath; + + /** + * Specifies whether to use a CA certificate from the system trust store or + * from a specified PEM file. The default value is false. + */ + @JsonProperty(value = "typeProperties.useSystemTrustStore") + private Object useSystemTrustStore; + + /** + * Specifies whether to require a CA-issued SSL certificate name to match + * the host name of the server when connecting over SSL. The default value + * is false. + */ + @JsonProperty(value = "typeProperties.allowHostNameCNMismatch") + private Object allowHostNameCNMismatch; + + /** + * Specifies whether to allow self-signed certificates from the server. The + * default value is false. + */ + @JsonProperty(value = "typeProperties.allowSelfSignedServerCert") + private Object allowSelfSignedServerCert; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the IP address or host name of the Impala server. (i.e. 192.168.222.160). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the IP address or host name of the Impala server. (i.e. 192.168.222.160). + * + * @param host the host value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port that the Impala server uses to listen for client connections. The default value is 21050. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port that the Impala server uses to listen for client connections. The default value is 21050. + * + * @param port the port value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the authentication type to use. Possible values include: 'Anonymous', 'SASLUsername', 'UsernameAndPassword'. + * + * @return the authenticationType value + */ + public ImpalaAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to use. Possible values include: 'Anonymous', 'SASLUsername', 'UsernameAndPassword'. + * + * @param authenticationType the authenticationType value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withAuthenticationType(ImpalaAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the user name used to access the Impala server. The default value is anonymous when using SASLUsername. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name used to access the Impala server. The default value is anonymous when using SASLUsername. + * + * @param username the username value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name when using UsernameAndPassword. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name when using UsernameAndPassword. + * + * @param password the password value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @param enableSsl the enableSsl value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @return the trustedCertPath value + */ + public Object trustedCertPath() { + return this.trustedCertPath; + } + + /** + * Set the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @param trustedCertPath the trustedCertPath value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withTrustedCertPath(Object trustedCertPath) { + this.trustedCertPath = trustedCertPath; + return this; + } + + /** + * Get specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @return the useSystemTrustStore value + */ + public Object useSystemTrustStore() { + return this.useSystemTrustStore; + } + + /** + * Set specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @param useSystemTrustStore the useSystemTrustStore value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withUseSystemTrustStore(Object useSystemTrustStore) { + this.useSystemTrustStore = useSystemTrustStore; + return this; + } + + /** + * Get specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @return the allowHostNameCNMismatch value + */ + public Object allowHostNameCNMismatch() { + return this.allowHostNameCNMismatch; + } + + /** + * Set specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @param allowHostNameCNMismatch the allowHostNameCNMismatch value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withAllowHostNameCNMismatch(Object allowHostNameCNMismatch) { + this.allowHostNameCNMismatch = allowHostNameCNMismatch; + return this; + } + + /** + * Get specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @return the allowSelfSignedServerCert value + */ + public Object allowSelfSignedServerCert() { + return this.allowSelfSignedServerCert; + } + + /** + * Set specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @param allowSelfSignedServerCert the allowSelfSignedServerCert value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withAllowSelfSignedServerCert(Object allowSelfSignedServerCert) { + this.allowSelfSignedServerCert = allowSelfSignedServerCert; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the ImpalaLinkedService object itself. + */ + public ImpalaLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaObjectDataset.java new file mode 100644 index 000000000000..d3ccc0174f6a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Impala server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ImpalaObject") +public class ImpalaObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaSource.java new file mode 100644 index 000000000000..ac5dea283c30 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ImpalaSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Impala server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ImpalaSource") +public class ImpalaSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the ImpalaSource object itself. + */ + public ImpalaSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAuthKeyName.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAuthKeyName.java new file mode 100644 index 000000000000..b2463bdd80eb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAuthKeyName.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeAuthKeyName. + */ +public final class IntegrationRuntimeAuthKeyName extends ExpandableStringEnum { + /** Static value authKey1 for IntegrationRuntimeAuthKeyName. */ + public static final IntegrationRuntimeAuthKeyName AUTH_KEY1 = fromString("authKey1"); + + /** Static value authKey2 for IntegrationRuntimeAuthKeyName. */ + public static final IntegrationRuntimeAuthKeyName AUTH_KEY2 = fromString("authKey2"); + + /** + * Creates or finds a IntegrationRuntimeAuthKeyName from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeAuthKeyName + */ + @JsonCreator + public static IntegrationRuntimeAuthKeyName fromString(String name) { + return fromString(name, IntegrationRuntimeAuthKeyName.class); + } + + /** + * @return known IntegrationRuntimeAuthKeyName values + */ + public static Collection values() { + return values(IntegrationRuntimeAuthKeyName.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAuthKeys.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAuthKeys.java new file mode 100644 index 000000000000..fcb8244be493 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAuthKeys.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeAuthKeysInner; + +/** + * Type representing IntegrationRuntimeAuthKeys. + */ +public interface IntegrationRuntimeAuthKeys extends HasInner, HasManager { + /** + * @return the authKey1 value. + */ + String authKey1(); + + /** + * @return the authKey2 value. + */ + String authKey2(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAutoUpdate.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAutoUpdate.java new file mode 100644 index 000000000000..e99036ecb812 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeAutoUpdate.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeAutoUpdate. + */ +public final class IntegrationRuntimeAutoUpdate extends ExpandableStringEnum { + /** Static value On for IntegrationRuntimeAutoUpdate. */ + public static final IntegrationRuntimeAutoUpdate ON = fromString("On"); + + /** Static value Off for IntegrationRuntimeAutoUpdate. */ + public static final IntegrationRuntimeAutoUpdate OFF = fromString("Off"); + + /** + * Creates or finds a IntegrationRuntimeAutoUpdate from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeAutoUpdate + */ + @JsonCreator + public static IntegrationRuntimeAutoUpdate fromString(String name) { + return fromString(name, IntegrationRuntimeAutoUpdate.class); + } + + /** + * @return known IntegrationRuntimeAutoUpdate values + */ + public static Collection values() { + return values(IntegrationRuntimeAutoUpdate.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeComputeProperties.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeComputeProperties.java new file mode 100644 index 000000000000..c04931976094 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeComputeProperties.java @@ -0,0 +1,177 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The compute resource properties for managed integration runtime. + */ +public class IntegrationRuntimeComputeProperties { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The location for managed integration runtime. The supported regions + * could be found on + * https://docs.microsoft.com/en-us/azure/data-factory/data-factory-data-movement-activities. + */ + @JsonProperty(value = "location") + private String location; + + /** + * The node size requirement to managed integration runtime. + */ + @JsonProperty(value = "nodeSize") + private String nodeSize; + + /** + * The required number of nodes for managed integration runtime. + */ + @JsonProperty(value = "numberOfNodes") + private Integer numberOfNodes; + + /** + * Maximum parallel executions count per node for managed integration + * runtime. + */ + @JsonProperty(value = "maxParallelExecutionsPerNode") + private Integer maxParallelExecutionsPerNode; + + /** + * VNet properties for managed integration runtime. + */ + @JsonProperty(value = "vNetProperties") + private IntegrationRuntimeVNetProperties vNetProperties; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeComputeProperties object itself. + */ + public IntegrationRuntimeComputeProperties withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the location for managed integration runtime. The supported regions could be found on https://docs.microsoft.com/en-us/azure/data-factory/data-factory-data-movement-activities. + * + * @return the location value + */ + public String location() { + return this.location; + } + + /** + * Set the location for managed integration runtime. The supported regions could be found on https://docs.microsoft.com/en-us/azure/data-factory/data-factory-data-movement-activities. + * + * @param location the location value to set + * @return the IntegrationRuntimeComputeProperties object itself. + */ + public IntegrationRuntimeComputeProperties withLocation(String location) { + this.location = location; + return this; + } + + /** + * Get the node size requirement to managed integration runtime. + * + * @return the nodeSize value + */ + public String nodeSize() { + return this.nodeSize; + } + + /** + * Set the node size requirement to managed integration runtime. + * + * @param nodeSize the nodeSize value to set + * @return the IntegrationRuntimeComputeProperties object itself. + */ + public IntegrationRuntimeComputeProperties withNodeSize(String nodeSize) { + this.nodeSize = nodeSize; + return this; + } + + /** + * Get the required number of nodes for managed integration runtime. + * + * @return the numberOfNodes value + */ + public Integer numberOfNodes() { + return this.numberOfNodes; + } + + /** + * Set the required number of nodes for managed integration runtime. + * + * @param numberOfNodes the numberOfNodes value to set + * @return the IntegrationRuntimeComputeProperties object itself. + */ + public IntegrationRuntimeComputeProperties withNumberOfNodes(Integer numberOfNodes) { + this.numberOfNodes = numberOfNodes; + return this; + } + + /** + * Get maximum parallel executions count per node for managed integration runtime. + * + * @return the maxParallelExecutionsPerNode value + */ + public Integer maxParallelExecutionsPerNode() { + return this.maxParallelExecutionsPerNode; + } + + /** + * Set maximum parallel executions count per node for managed integration runtime. + * + * @param maxParallelExecutionsPerNode the maxParallelExecutionsPerNode value to set + * @return the IntegrationRuntimeComputeProperties object itself. + */ + public IntegrationRuntimeComputeProperties withMaxParallelExecutionsPerNode(Integer maxParallelExecutionsPerNode) { + this.maxParallelExecutionsPerNode = maxParallelExecutionsPerNode; + return this; + } + + /** + * Get vNet properties for managed integration runtime. + * + * @return the vNetProperties value + */ + public IntegrationRuntimeVNetProperties vNetProperties() { + return this.vNetProperties; + } + + /** + * Set vNet properties for managed integration runtime. + * + * @param vNetProperties the vNetProperties value to set + * @return the IntegrationRuntimeComputeProperties object itself. + */ + public IntegrationRuntimeComputeProperties withVNetProperties(IntegrationRuntimeVNetProperties vNetProperties) { + this.vNetProperties = vNetProperties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeConnectionInfo.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeConnectionInfo.java new file mode 100644 index 000000000000..e3e21ccdcb07 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeConnectionInfo.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeConnectionInfoInner; +import java.util.Map; + +/** + * Type representing IntegrationRuntimeConnectionInfo. + */ +public interface IntegrationRuntimeConnectionInfo extends HasInner, HasManager { + /** + * @return the additionalProperties value. + */ + Map additionalProperties(); + + /** + * @return the hostServiceUri value. + */ + String hostServiceUri(); + + /** + * @return the identityCertThumbprint value. + */ + String identityCertThumbprint(); + + /** + * @return the isIdentityCertExprired value. + */ + Boolean isIdentityCertExprired(); + + /** + * @return the publicKey value. + */ + String publicKey(); + + /** + * @return the serviceToken value. + */ + String serviceToken(); + + /** + * @return the version value. + */ + String version(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeCustomSetupScriptProperties.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeCustomSetupScriptProperties.java new file mode 100644 index 000000000000..0243b58a5239 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeCustomSetupScriptProperties.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Custom setup script properties for a managed dedicated integration runtime. + */ +public class IntegrationRuntimeCustomSetupScriptProperties { + /** + * The URI of the Azure blob container that contains the custom setup + * script. + */ + @JsonProperty(value = "blobContainerUri") + private String blobContainerUri; + + /** + * The SAS token of the Azure blob container. + */ + @JsonProperty(value = "sasToken") + private SecureString sasToken; + + /** + * Get the URI of the Azure blob container that contains the custom setup script. + * + * @return the blobContainerUri value + */ + public String blobContainerUri() { + return this.blobContainerUri; + } + + /** + * Set the URI of the Azure blob container that contains the custom setup script. + * + * @param blobContainerUri the blobContainerUri value to set + * @return the IntegrationRuntimeCustomSetupScriptProperties object itself. + */ + public IntegrationRuntimeCustomSetupScriptProperties withBlobContainerUri(String blobContainerUri) { + this.blobContainerUri = blobContainerUri; + return this; + } + + /** + * Get the SAS token of the Azure blob container. + * + * @return the sasToken value + */ + public SecureString sasToken() { + return this.sasToken; + } + + /** + * Set the SAS token of the Azure blob container. + * + * @param sasToken the sasToken value to set + * @return the IntegrationRuntimeCustomSetupScriptProperties object itself. + */ + public IntegrationRuntimeCustomSetupScriptProperties withSasToken(SecureString sasToken) { + this.sasToken = sasToken; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeDataProxyProperties.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeDataProxyProperties.java new file mode 100644 index 000000000000..4eb61b68697f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeDataProxyProperties.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Data proxy properties for a managed dedicated integration runtime. + */ +public class IntegrationRuntimeDataProxyProperties { + /** + * The self-hosted integration runtime reference. + */ + @JsonProperty(value = "connectVia") + private EntityReference connectVia; + + /** + * The staging linked service reference. + */ + @JsonProperty(value = "stagingLinkedService") + private EntityReference stagingLinkedService; + + /** + * The path to contain the staged data in the Blob storage. + */ + @JsonProperty(value = "path") + private String path; + + /** + * Get the self-hosted integration runtime reference. + * + * @return the connectVia value + */ + public EntityReference connectVia() { + return this.connectVia; + } + + /** + * Set the self-hosted integration runtime reference. + * + * @param connectVia the connectVia value to set + * @return the IntegrationRuntimeDataProxyProperties object itself. + */ + public IntegrationRuntimeDataProxyProperties withConnectVia(EntityReference connectVia) { + this.connectVia = connectVia; + return this; + } + + /** + * Get the staging linked service reference. + * + * @return the stagingLinkedService value + */ + public EntityReference stagingLinkedService() { + return this.stagingLinkedService; + } + + /** + * Set the staging linked service reference. + * + * @param stagingLinkedService the stagingLinkedService value to set + * @return the IntegrationRuntimeDataProxyProperties object itself. + */ + public IntegrationRuntimeDataProxyProperties withStagingLinkedService(EntityReference stagingLinkedService) { + this.stagingLinkedService = stagingLinkedService; + return this; + } + + /** + * Get the path to contain the staged data in the Blob storage. + * + * @return the path value + */ + public String path() { + return this.path; + } + + /** + * Set the path to contain the staged data in the Blob storage. + * + * @param path the path value to set + * @return the IntegrationRuntimeDataProxyProperties object itself. + */ + public IntegrationRuntimeDataProxyProperties withPath(String path) { + this.path = path; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeEdition.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeEdition.java new file mode 100644 index 000000000000..ca4e1d289212 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeEdition.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeEdition. + */ +public final class IntegrationRuntimeEdition extends ExpandableStringEnum { + /** Static value Standard for IntegrationRuntimeEdition. */ + public static final IntegrationRuntimeEdition STANDARD = fromString("Standard"); + + /** Static value Enterprise for IntegrationRuntimeEdition. */ + public static final IntegrationRuntimeEdition ENTERPRISE = fromString("Enterprise"); + + /** + * Creates or finds a IntegrationRuntimeEdition from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeEdition + */ + @JsonCreator + public static IntegrationRuntimeEdition fromString(String name) { + return fromString(name, IntegrationRuntimeEdition.class); + } + + /** + * @return known IntegrationRuntimeEdition values + */ + public static Collection values() { + return values(IntegrationRuntimeEdition.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeEntityReferenceType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeEntityReferenceType.java new file mode 100644 index 000000000000..3941603fea45 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeEntityReferenceType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeEntityReferenceType. + */ +public final class IntegrationRuntimeEntityReferenceType extends ExpandableStringEnum { + /** Static value IntegrationRuntimeReference for IntegrationRuntimeEntityReferenceType. */ + public static final IntegrationRuntimeEntityReferenceType INTEGRATION_RUNTIME_REFERENCE = fromString("IntegrationRuntimeReference"); + + /** Static value LinkedServiceReference for IntegrationRuntimeEntityReferenceType. */ + public static final IntegrationRuntimeEntityReferenceType LINKED_SERVICE_REFERENCE = fromString("LinkedServiceReference"); + + /** + * Creates or finds a IntegrationRuntimeEntityReferenceType from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeEntityReferenceType + */ + @JsonCreator + public static IntegrationRuntimeEntityReferenceType fromString(String name) { + return fromString(name, IntegrationRuntimeEntityReferenceType.class); + } + + /** + * @return known IntegrationRuntimeEntityReferenceType values + */ + public static Collection values() { + return values(IntegrationRuntimeEntityReferenceType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeInternalChannelEncryptionMode.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeInternalChannelEncryptionMode.java new file mode 100644 index 000000000000..3d4ef2ade799 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeInternalChannelEncryptionMode.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeInternalChannelEncryptionMode. + */ +public final class IntegrationRuntimeInternalChannelEncryptionMode extends ExpandableStringEnum { + /** Static value NotSet for IntegrationRuntimeInternalChannelEncryptionMode. */ + public static final IntegrationRuntimeInternalChannelEncryptionMode NOT_SET = fromString("NotSet"); + + /** Static value SslEncrypted for IntegrationRuntimeInternalChannelEncryptionMode. */ + public static final IntegrationRuntimeInternalChannelEncryptionMode SSL_ENCRYPTED = fromString("SslEncrypted"); + + /** Static value NotEncrypted for IntegrationRuntimeInternalChannelEncryptionMode. */ + public static final IntegrationRuntimeInternalChannelEncryptionMode NOT_ENCRYPTED = fromString("NotEncrypted"); + + /** + * Creates or finds a IntegrationRuntimeInternalChannelEncryptionMode from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeInternalChannelEncryptionMode + */ + @JsonCreator + public static IntegrationRuntimeInternalChannelEncryptionMode fromString(String name) { + return fromString(name, IntegrationRuntimeInternalChannelEncryptionMode.class); + } + + /** + * @return known IntegrationRuntimeInternalChannelEncryptionMode values + */ + public static Collection values() { + return values(IntegrationRuntimeInternalChannelEncryptionMode.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeLicenseType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeLicenseType.java new file mode 100644 index 000000000000..f3c0b2312fef --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeLicenseType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeLicenseType. + */ +public final class IntegrationRuntimeLicenseType extends ExpandableStringEnum { + /** Static value BasePrice for IntegrationRuntimeLicenseType. */ + public static final IntegrationRuntimeLicenseType BASE_PRICE = fromString("BasePrice"); + + /** Static value LicenseIncluded for IntegrationRuntimeLicenseType. */ + public static final IntegrationRuntimeLicenseType LICENSE_INCLUDED = fromString("LicenseIncluded"); + + /** + * Creates or finds a IntegrationRuntimeLicenseType from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeLicenseType + */ + @JsonCreator + public static IntegrationRuntimeLicenseType fromString(String name) { + return fromString(name, IntegrationRuntimeLicenseType.class); + } + + /** + * @return known IntegrationRuntimeLicenseType values + */ + public static Collection values() { + return values(IntegrationRuntimeLicenseType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeMonitoringData.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeMonitoringData.java new file mode 100644 index 000000000000..f77780d31942 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeMonitoringData.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeMonitoringDataInner; +import java.util.List; + +/** + * Type representing IntegrationRuntimeMonitoringData. + */ +public interface IntegrationRuntimeMonitoringData extends HasInner, HasManager { + /** + * @return the name value. + */ + String name(); + + /** + * @return the nodes value. + */ + List nodes(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodeIpAddress.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodeIpAddress.java new file mode 100644 index 000000000000..deeb5481d869 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodeIpAddress.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeNodeIpAddressInner; + +/** + * Type representing IntegrationRuntimeNodeIpAddress. + */ +public interface IntegrationRuntimeNodeIpAddress extends HasInner, HasManager { + /** + * @return the ipAddress value. + */ + String ipAddress(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodeMonitoringData.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodeMonitoringData.java new file mode 100644 index 000000000000..d6bb33badb40 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodeMonitoringData.java @@ -0,0 +1,164 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Monitoring data for integration runtime node. + */ +public class IntegrationRuntimeNodeMonitoringData { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Name of the integration runtime node. + */ + @JsonProperty(value = "nodeName", access = JsonProperty.Access.WRITE_ONLY) + private String nodeName; + + /** + * Available memory (MB) on the integration runtime node. + */ + @JsonProperty(value = "availableMemoryInMB", access = JsonProperty.Access.WRITE_ONLY) + private Integer availableMemoryInMB; + + /** + * CPU percentage on the integration runtime node. + */ + @JsonProperty(value = "cpuUtilization", access = JsonProperty.Access.WRITE_ONLY) + private Double cpuUtilization; + + /** + * Maximum concurrent jobs on the integration runtime node. + */ + @JsonProperty(value = "concurrentJobsLimit", access = JsonProperty.Access.WRITE_ONLY) + private Integer concurrentJobsLimit; + + /** + * The number of jobs currently running on the integration runtime node. + */ + @JsonProperty(value = "concurrentJobsRunning", access = JsonProperty.Access.WRITE_ONLY) + private Integer concurrentJobsRunning; + + /** + * The maximum concurrent jobs in this integration runtime. + */ + @JsonProperty(value = "maxConcurrentJobs", access = JsonProperty.Access.WRITE_ONLY) + private Integer maxConcurrentJobs; + + /** + * Sent bytes on the integration runtime node. + */ + @JsonProperty(value = "sentBytes", access = JsonProperty.Access.WRITE_ONLY) + private Double sentBytes; + + /** + * Received bytes on the integration runtime node. + */ + @JsonProperty(value = "receivedBytes", access = JsonProperty.Access.WRITE_ONLY) + private Double receivedBytes; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeNodeMonitoringData object itself. + */ + public IntegrationRuntimeNodeMonitoringData withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get name of the integration runtime node. + * + * @return the nodeName value + */ + public String nodeName() { + return this.nodeName; + } + + /** + * Get available memory (MB) on the integration runtime node. + * + * @return the availableMemoryInMB value + */ + public Integer availableMemoryInMB() { + return this.availableMemoryInMB; + } + + /** + * Get cPU percentage on the integration runtime node. + * + * @return the cpuUtilization value + */ + public Double cpuUtilization() { + return this.cpuUtilization; + } + + /** + * Get maximum concurrent jobs on the integration runtime node. + * + * @return the concurrentJobsLimit value + */ + public Integer concurrentJobsLimit() { + return this.concurrentJobsLimit; + } + + /** + * Get the number of jobs currently running on the integration runtime node. + * + * @return the concurrentJobsRunning value + */ + public Integer concurrentJobsRunning() { + return this.concurrentJobsRunning; + } + + /** + * Get the maximum concurrent jobs in this integration runtime. + * + * @return the maxConcurrentJobs value + */ + public Integer maxConcurrentJobs() { + return this.maxConcurrentJobs; + } + + /** + * Get sent bytes on the integration runtime node. + * + * @return the sentBytes value + */ + public Double sentBytes() { + return this.sentBytes; + } + + /** + * Get received bytes on the integration runtime node. + * + * @return the receivedBytes value + */ + public Double receivedBytes() { + return this.receivedBytes; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodes.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodes.java new file mode 100644 index 000000000000..82e2fd04d22b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeNodes.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import rx.Completable; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeNodesInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing IntegrationRuntimeNodes. + */ +public interface IntegrationRuntimeNodes extends HasInner { + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName); + + /** + * Get the IP address of self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getIpAddressAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName); + + /** + * Deletes a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable deleteAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeReference.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeReference.java new file mode 100644 index 000000000000..7b65702f4ff8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeReference.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Integration runtime reference type. + */ +public class IntegrationRuntimeReference { + /** + * Type of integration runtime. + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * Reference integration runtime name. + */ + @JsonProperty(value = "referenceName", required = true) + private String referenceName; + + /** + * Arguments for integration runtime. + */ + @JsonProperty(value = "parameters") + private Map parameters; + + /** + * Creates an instance of IntegrationRuntimeReference class. + * @param referenceName reference integration runtime name. + */ + public IntegrationRuntimeReference() { + type = "IntegrationRuntimeReference"; + } + + /** + * Get type of integration runtime. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set type of integration runtime. + * + * @param type the type value to set + * @return the IntegrationRuntimeReference object itself. + */ + public IntegrationRuntimeReference withType(String type) { + this.type = type; + return this; + } + + /** + * Get reference integration runtime name. + * + * @return the referenceName value + */ + public String referenceName() { + return this.referenceName; + } + + /** + * Set reference integration runtime name. + * + * @param referenceName the referenceName value to set + * @return the IntegrationRuntimeReference object itself. + */ + public IntegrationRuntimeReference withReferenceName(String referenceName) { + this.referenceName = referenceName; + return this; + } + + /** + * Get arguments for integration runtime. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set arguments for integration runtime. + * + * @param parameters the parameters value to set + * @return the IntegrationRuntimeReference object itself. + */ + public IntegrationRuntimeReference withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeRegenerateKeyParameters.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeRegenerateKeyParameters.java new file mode 100644 index 000000000000..d042a50a13f8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeRegenerateKeyParameters.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Parameters to regenerate the authentication key. + */ +public class IntegrationRuntimeRegenerateKeyParameters { + /** + * The name of the authentication key to regenerate. Possible values + * include: 'authKey1', 'authKey2'. + */ + @JsonProperty(value = "keyName") + private IntegrationRuntimeAuthKeyName keyName; + + /** + * Get the name of the authentication key to regenerate. Possible values include: 'authKey1', 'authKey2'. + * + * @return the keyName value + */ + public IntegrationRuntimeAuthKeyName keyName() { + return this.keyName; + } + + /** + * Set the name of the authentication key to regenerate. Possible values include: 'authKey1', 'authKey2'. + * + * @param keyName the keyName value to set + * @return the IntegrationRuntimeRegenerateKeyParameters object itself. + */ + public IntegrationRuntimeRegenerateKeyParameters withKeyName(IntegrationRuntimeAuthKeyName keyName) { + this.keyName = keyName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeRemoveNodeRequest.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeRemoveNodeRequest.java new file mode 100644 index 000000000000..9c6014c770f8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeRemoveNodeRequest.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Request to remove a node. + */ +public class IntegrationRuntimeRemoveNodeRequest { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The name of the node to be removed. + */ + @JsonProperty(value = "nodeName") + private String nodeName; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeRemoveNodeRequest object itself. + */ + public IntegrationRuntimeRemoveNodeRequest withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the name of the node to be removed. + * + * @return the nodeName value + */ + public String nodeName() { + return this.nodeName; + } + + /** + * Set the name of the node to be removed. + * + * @param nodeName the nodeName value to set + * @return the IntegrationRuntimeRemoveNodeRequest object itself. + */ + public IntegrationRuntimeRemoveNodeRequest withNodeName(String nodeName) { + this.nodeName = nodeName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeResource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeResource.java new file mode 100644 index 000000000000..af9f088ce07b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeResource.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeResourceInner; +import com.microsoft.azure.arm.model.Indexable; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeInner; +import java.util.Map; + +/** + * Type representing IntegrationRuntimeResource. + */ +public interface IntegrationRuntimeResource extends HasInner, Indexable, Refreshable, Updatable, HasManager { + /** + * @return the etag value. + */ + String etag(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the properties value. + */ + IntegrationRuntimeInner properties(); + + /** + * @return the type value. + */ + String type(); + + /** + * The entirety of the IntegrationRuntimeResource definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithFactory, DefinitionStages.WithIfMatch, DefinitionStages.WithProperties, DefinitionStages.WithCreate { + } + + /** + * Grouping of IntegrationRuntimeResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a IntegrationRuntimeResource definition. + */ + interface Blank extends WithFactory { + } + + /** + * The stage of the integrationruntimeresource definition allowing to specify Factory. + */ + interface WithFactory { + /** + * Specifies resourceGroupName, factoryName. + * @param resourceGroupName The resource group name + * @param factoryName The factory name + * @return the next definition stage + */ + WithIfMatch withExistingFactory(String resourceGroupName, String factoryName); + } + + /** + * The stage of the integrationruntimeresource definition allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the integration runtime entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next definition stage + */ + WithProperties withIfMatch(String ifMatch); + } + + /** + * The stage of the integrationruntimeresource definition allowing to specify Properties. + */ + interface WithProperties { + /** + * Specifies properties. + * @param properties Integration runtime properties + * @return the next definition stage + */ + WithCreate withProperties(IntegrationRuntimeInner properties); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable { + } + } + /** + * The template for a IntegrationRuntimeResource update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, UpdateStages.WithAutoUpdate, UpdateStages.WithUpdateDelayOffset { + } + + /** + * Grouping of IntegrationRuntimeResource update stages. + */ + interface UpdateStages { + /** + * The stage of the integrationruntimeresource update allowing to specify AutoUpdate. + */ + interface WithAutoUpdate { + /** + * Specifies autoUpdate. + * @param autoUpdate Enables or disables the auto-update feature of the self-hosted integration runtime. See https://go.microsoft.com/fwlink/?linkid=854189. Possible values include: 'On', 'Off' + * @return the next update stage + */ + Update withAutoUpdate(IntegrationRuntimeAutoUpdate autoUpdate); + } + + /** + * The stage of the integrationruntimeresource update allowing to specify UpdateDelayOffset. + */ + interface WithUpdateDelayOffset { + /** + * Specifies updateDelayOffset. + * @param updateDelayOffset The time offset (in hours) in the day, e.g., PT03H is 3 hours. The integration runtime auto update will happen on that time + * @return the next update stage + */ + Update withUpdateDelayOffset(String updateDelayOffset); + } + + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeSsisCatalogInfo.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeSsisCatalogInfo.java new file mode 100644 index 000000000000..ea0c4e1565a1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeSsisCatalogInfo.java @@ -0,0 +1,150 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Catalog information for managed dedicated integration runtime. + */ +public class IntegrationRuntimeSsisCatalogInfo { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The catalog database server URL. + */ + @JsonProperty(value = "catalogServerEndpoint") + private String catalogServerEndpoint; + + /** + * The administrator user name of catalog database. + */ + @JsonProperty(value = "catalogAdminUserName") + private String catalogAdminUserName; + + /** + * The password of the administrator user account of the catalog database. + */ + @JsonProperty(value = "catalogAdminPassword") + private SecureString catalogAdminPassword; + + /** + * The pricing tier for the catalog database. The valid values could be + * found in + * https://azure.microsoft.com/en-us/pricing/details/sql-database/. + */ + @JsonProperty(value = "catalogPricingTier") + private String catalogPricingTier; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeSsisCatalogInfo object itself. + */ + public IntegrationRuntimeSsisCatalogInfo withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the catalog database server URL. + * + * @return the catalogServerEndpoint value + */ + public String catalogServerEndpoint() { + return this.catalogServerEndpoint; + } + + /** + * Set the catalog database server URL. + * + * @param catalogServerEndpoint the catalogServerEndpoint value to set + * @return the IntegrationRuntimeSsisCatalogInfo object itself. + */ + public IntegrationRuntimeSsisCatalogInfo withCatalogServerEndpoint(String catalogServerEndpoint) { + this.catalogServerEndpoint = catalogServerEndpoint; + return this; + } + + /** + * Get the administrator user name of catalog database. + * + * @return the catalogAdminUserName value + */ + public String catalogAdminUserName() { + return this.catalogAdminUserName; + } + + /** + * Set the administrator user name of catalog database. + * + * @param catalogAdminUserName the catalogAdminUserName value to set + * @return the IntegrationRuntimeSsisCatalogInfo object itself. + */ + public IntegrationRuntimeSsisCatalogInfo withCatalogAdminUserName(String catalogAdminUserName) { + this.catalogAdminUserName = catalogAdminUserName; + return this; + } + + /** + * Get the password of the administrator user account of the catalog database. + * + * @return the catalogAdminPassword value + */ + public SecureString catalogAdminPassword() { + return this.catalogAdminPassword; + } + + /** + * Set the password of the administrator user account of the catalog database. + * + * @param catalogAdminPassword the catalogAdminPassword value to set + * @return the IntegrationRuntimeSsisCatalogInfo object itself. + */ + public IntegrationRuntimeSsisCatalogInfo withCatalogAdminPassword(SecureString catalogAdminPassword) { + this.catalogAdminPassword = catalogAdminPassword; + return this; + } + + /** + * Get the pricing tier for the catalog database. The valid values could be found in https://azure.microsoft.com/en-us/pricing/details/sql-database/. + * + * @return the catalogPricingTier value + */ + public String catalogPricingTier() { + return this.catalogPricingTier; + } + + /** + * Set the pricing tier for the catalog database. The valid values could be found in https://azure.microsoft.com/en-us/pricing/details/sql-database/. + * + * @param catalogPricingTier the catalogPricingTier value to set + * @return the IntegrationRuntimeSsisCatalogInfo object itself. + */ + public IntegrationRuntimeSsisCatalogInfo withCatalogPricingTier(String catalogPricingTier) { + this.catalogPricingTier = catalogPricingTier; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeSsisProperties.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeSsisProperties.java new file mode 100644 index 000000000000..cc01a8c39582 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeSsisProperties.java @@ -0,0 +1,177 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SSIS properties for managed integration runtime. + */ +public class IntegrationRuntimeSsisProperties { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Catalog information for managed dedicated integration runtime. + */ + @JsonProperty(value = "catalogInfo") + private IntegrationRuntimeSsisCatalogInfo catalogInfo; + + /** + * License type for bringing your own license scenario. Possible values + * include: 'BasePrice', 'LicenseIncluded'. + */ + @JsonProperty(value = "licenseType") + private IntegrationRuntimeLicenseType licenseType; + + /** + * Custom setup script properties for a managed dedicated integration + * runtime. + */ + @JsonProperty(value = "customSetupScriptProperties") + private IntegrationRuntimeCustomSetupScriptProperties customSetupScriptProperties; + + /** + * Data proxy properties for a managed dedicated integration runtime. + */ + @JsonProperty(value = "dataProxyProperties") + private IntegrationRuntimeDataProxyProperties dataProxyProperties; + + /** + * The edition for the SSIS Integration Runtime. Possible values include: + * 'Standard', 'Enterprise'. + */ + @JsonProperty(value = "edition") + private IntegrationRuntimeEdition edition; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeSsisProperties object itself. + */ + public IntegrationRuntimeSsisProperties withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get catalog information for managed dedicated integration runtime. + * + * @return the catalogInfo value + */ + public IntegrationRuntimeSsisCatalogInfo catalogInfo() { + return this.catalogInfo; + } + + /** + * Set catalog information for managed dedicated integration runtime. + * + * @param catalogInfo the catalogInfo value to set + * @return the IntegrationRuntimeSsisProperties object itself. + */ + public IntegrationRuntimeSsisProperties withCatalogInfo(IntegrationRuntimeSsisCatalogInfo catalogInfo) { + this.catalogInfo = catalogInfo; + return this; + } + + /** + * Get license type for bringing your own license scenario. Possible values include: 'BasePrice', 'LicenseIncluded'. + * + * @return the licenseType value + */ + public IntegrationRuntimeLicenseType licenseType() { + return this.licenseType; + } + + /** + * Set license type for bringing your own license scenario. Possible values include: 'BasePrice', 'LicenseIncluded'. + * + * @param licenseType the licenseType value to set + * @return the IntegrationRuntimeSsisProperties object itself. + */ + public IntegrationRuntimeSsisProperties withLicenseType(IntegrationRuntimeLicenseType licenseType) { + this.licenseType = licenseType; + return this; + } + + /** + * Get custom setup script properties for a managed dedicated integration runtime. + * + * @return the customSetupScriptProperties value + */ + public IntegrationRuntimeCustomSetupScriptProperties customSetupScriptProperties() { + return this.customSetupScriptProperties; + } + + /** + * Set custom setup script properties for a managed dedicated integration runtime. + * + * @param customSetupScriptProperties the customSetupScriptProperties value to set + * @return the IntegrationRuntimeSsisProperties object itself. + */ + public IntegrationRuntimeSsisProperties withCustomSetupScriptProperties(IntegrationRuntimeCustomSetupScriptProperties customSetupScriptProperties) { + this.customSetupScriptProperties = customSetupScriptProperties; + return this; + } + + /** + * Get data proxy properties for a managed dedicated integration runtime. + * + * @return the dataProxyProperties value + */ + public IntegrationRuntimeDataProxyProperties dataProxyProperties() { + return this.dataProxyProperties; + } + + /** + * Set data proxy properties for a managed dedicated integration runtime. + * + * @param dataProxyProperties the dataProxyProperties value to set + * @return the IntegrationRuntimeSsisProperties object itself. + */ + public IntegrationRuntimeSsisProperties withDataProxyProperties(IntegrationRuntimeDataProxyProperties dataProxyProperties) { + this.dataProxyProperties = dataProxyProperties; + return this; + } + + /** + * Get the edition for the SSIS Integration Runtime. Possible values include: 'Standard', 'Enterprise'. + * + * @return the edition value + */ + public IntegrationRuntimeEdition edition() { + return this.edition; + } + + /** + * Set the edition for the SSIS Integration Runtime. Possible values include: 'Standard', 'Enterprise'. + * + * @param edition the edition value to set + * @return the IntegrationRuntimeSsisProperties object itself. + */ + public IntegrationRuntimeSsisProperties withEdition(IntegrationRuntimeEdition edition) { + this.edition = edition; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeState.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeState.java new file mode 100644 index 000000000000..9f4041c5481f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeState.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeState. + */ +public final class IntegrationRuntimeState extends ExpandableStringEnum { + /** Static value Initial for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState INITIAL = fromString("Initial"); + + /** Static value Stopped for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState STOPPED = fromString("Stopped"); + + /** Static value Started for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState STARTED = fromString("Started"); + + /** Static value Starting for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState STARTING = fromString("Starting"); + + /** Static value Stopping for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState STOPPING = fromString("Stopping"); + + /** Static value NeedRegistration for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState NEED_REGISTRATION = fromString("NeedRegistration"); + + /** Static value Online for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState ONLINE = fromString("Online"); + + /** Static value Limited for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState LIMITED = fromString("Limited"); + + /** Static value Offline for IntegrationRuntimeState. */ + public static final IntegrationRuntimeState OFFLINE = fromString("Offline"); + + /** + * Creates or finds a IntegrationRuntimeState from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeState + */ + @JsonCreator + public static IntegrationRuntimeState fromString(String name) { + return fromString(name, IntegrationRuntimeState.class); + } + + /** + * @return known IntegrationRuntimeState values + */ + public static Collection values() { + return values(IntegrationRuntimeState.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatus.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatus.java new file mode 100644 index 000000000000..5a67931b7f14 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatus.java @@ -0,0 +1,85 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Integration runtime status. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("IntegrationRuntimeStatus") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "SelfHosted", value = SelfHostedIntegrationRuntimeStatus.class), + @JsonSubTypes.Type(name = "Managed", value = ManagedIntegrationRuntimeStatus.class) +}) +public class IntegrationRuntimeStatus { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The data factory name which the integration runtime belong to. + */ + @JsonProperty(value = "dataFactoryName", access = JsonProperty.Access.WRITE_ONLY) + private String dataFactoryName; + + /** + * The state of integration runtime. Possible values include: 'Initial', + * 'Stopped', 'Started', 'Starting', 'Stopping', 'NeedRegistration', + * 'Online', 'Limited', 'Offline'. + */ + @JsonProperty(value = "state", access = JsonProperty.Access.WRITE_ONLY) + private IntegrationRuntimeState state; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeStatus object itself. + */ + public IntegrationRuntimeStatus withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the data factory name which the integration runtime belong to. + * + * @return the dataFactoryName value + */ + public String dataFactoryName() { + return this.dataFactoryName; + } + + /** + * Get the state of integration runtime. Possible values include: 'Initial', 'Stopped', 'Started', 'Starting', 'Stopping', 'NeedRegistration', 'Online', 'Limited', 'Offline'. + * + * @return the state value + */ + public IntegrationRuntimeState state() { + return this.state; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatusListResponse.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatusListResponse.java new file mode 100644 index 000000000000..39a1e8fb8812 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatusListResponse.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeStatusResponseInner; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A list of integration runtime status. + */ +public class IntegrationRuntimeStatusListResponse { + /** + * List of integration runtime status. + */ + @JsonProperty(value = "value", required = true) + private List value; + + /** + * The link to the next page of results, if any remaining results exist. + */ + @JsonProperty(value = "nextLink") + private String nextLink; + + /** + * Get list of integration runtime status. + * + * @return the value value + */ + public List value() { + return this.value; + } + + /** + * Set list of integration runtime status. + * + * @param value the value value to set + * @return the IntegrationRuntimeStatusListResponse object itself. + */ + public IntegrationRuntimeStatusListResponse withValue(List value) { + this.value = value; + return this; + } + + /** + * Get the link to the next page of results, if any remaining results exist. + * + * @return the nextLink value + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Set the link to the next page of results, if any remaining results exist. + * + * @param nextLink the nextLink value to set + * @return the IntegrationRuntimeStatusListResponse object itself. + */ + public IntegrationRuntimeStatusListResponse withNextLink(String nextLink) { + this.nextLink = nextLink; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatusResponse.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatusResponse.java new file mode 100644 index 000000000000..ea9d67089c3c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeStatusResponse.java @@ -0,0 +1,30 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeStatusResponseInner; + +/** + * Type representing IntegrationRuntimeStatusResponse. + */ +public interface IntegrationRuntimeStatusResponse extends HasInner, HasManager { + /** + * @return the name value. + */ + String name(); + + /** + * @return the properties value. + */ + IntegrationRuntimeStatus properties(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeType.java new file mode 100644 index 000000000000..ae3c530ccf3b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeType. + */ +public final class IntegrationRuntimeType extends ExpandableStringEnum { + /** Static value Managed for IntegrationRuntimeType. */ + public static final IntegrationRuntimeType MANAGED = fromString("Managed"); + + /** Static value SelfHosted for IntegrationRuntimeType. */ + public static final IntegrationRuntimeType SELF_HOSTED = fromString("SelfHosted"); + + /** + * Creates or finds a IntegrationRuntimeType from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeType + */ + @JsonCreator + public static IntegrationRuntimeType fromString(String name) { + return fromString(name, IntegrationRuntimeType.class); + } + + /** + * @return known IntegrationRuntimeType values + */ + public static Collection values() { + return values(IntegrationRuntimeType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeUpdateResult.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeUpdateResult.java new file mode 100644 index 000000000000..4a2659619fd7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeUpdateResult.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for IntegrationRuntimeUpdateResult. + */ +public final class IntegrationRuntimeUpdateResult extends ExpandableStringEnum { + /** Static value Succeed for IntegrationRuntimeUpdateResult. */ + public static final IntegrationRuntimeUpdateResult SUCCEED = fromString("Succeed"); + + /** Static value Fail for IntegrationRuntimeUpdateResult. */ + public static final IntegrationRuntimeUpdateResult FAIL = fromString("Fail"); + + /** + * Creates or finds a IntegrationRuntimeUpdateResult from its string representation. + * @param name a name to look for + * @return the corresponding IntegrationRuntimeUpdateResult + */ + @JsonCreator + public static IntegrationRuntimeUpdateResult fromString(String name) { + return fromString(name, IntegrationRuntimeUpdateResult.class); + } + + /** + * @return known IntegrationRuntimeUpdateResult values + */ + public static Collection values() { + return values(IntegrationRuntimeUpdateResult.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeVNetProperties.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeVNetProperties.java new file mode 100644 index 000000000000..e09713e775ec --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimeVNetProperties.java @@ -0,0 +1,96 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * VNet properties for managed integration runtime. + */ +public class IntegrationRuntimeVNetProperties { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The ID of the VNet that this integration runtime will join. + */ + @JsonProperty(value = "vNetId") + private String vNetId; + + /** + * The name of the subnet this integration runtime will join. + */ + @JsonProperty(value = "subnet") + private String subnet; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeVNetProperties object itself. + */ + public IntegrationRuntimeVNetProperties withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the ID of the VNet that this integration runtime will join. + * + * @return the vNetId value + */ + public String vNetId() { + return this.vNetId; + } + + /** + * Set the ID of the VNet that this integration runtime will join. + * + * @param vNetId the vNetId value to set + * @return the IntegrationRuntimeVNetProperties object itself. + */ + public IntegrationRuntimeVNetProperties withVNetId(String vNetId) { + this.vNetId = vNetId; + return this; + } + + /** + * Get the name of the subnet this integration runtime will join. + * + * @return the subnet value + */ + public String subnet() { + return this.subnet; + } + + /** + * Set the name of the subnet this integration runtime will join. + * + * @param subnet the subnet value to set + * @return the IntegrationRuntimeVNetProperties object itself. + */ + public IntegrationRuntimeVNetProperties withSubnet(String subnet) { + this.subnet = subnet; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimes.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimes.java new file mode 100644 index 000000000000..2c7a4d762f94 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/IntegrationRuntimes.java @@ -0,0 +1,164 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import rx.Completable; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimesInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing IntegrationRuntimes. + */ +public interface IntegrationRuntimes extends SupportsCreating, HasInner { + /** + * Gets detailed status information for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getStatusAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Gets the on-premises integration runtime connection information for encrypting the on-premises data source credentials. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getConnectionInfoAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable regenerateAuthKeyAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Retrieves the authentication keys for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listAuthKeysAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable startAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable stopAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Remove a node from integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param removeNodeParameters The name of the node to be removed from an integration runtime. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable removeNodeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeRemoveNodeRequest removeNodeParameters); + + /** + * Force the integration runtime to synchronize credentials across integration runtime nodes, and this will override the credentials across all worker nodes with those available on the dispatcher node. If you already have the latest credential backup file, you should manually import it (preferred) on any self-hosted integration runtime node than using this API directly. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable syncCredentialsAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Get the integration runtime monitoring data, which includes the monitor data for all the nodes under this integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getMonitoringDataAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Upgrade self-hosted integration runtime to latest version if availability. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable upgradeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Gets an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + + /** + * Lists integration runtimes. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listByFactoryAsync(final String resourceGroupName, final String factoryName); + + /** + * Deletes an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable deleteAsync(String resourceGroupName, String factoryName, String integrationRuntimeName); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraLinkedService.java new file mode 100644 index 000000000000..d5f8950d618b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraLinkedService.java @@ -0,0 +1,242 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Jira Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Jira") +@JsonFlatten +public class JiraLinkedService extends LinkedServiceInner { + /** + * The IP address or host name of the Jira service. (e.g. + * jira.example.com). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port that the Jira server uses to listen for client connections. + * The default value is 443 if connecting through HTTPS, or 8080 if + * connecting through HTTP. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The user name that you use to access Jira Service. + */ + @JsonProperty(value = "typeProperties.username", required = true) + private Object username; + + /** + * The password corresponding to the user name that you provided in the + * username field. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the IP address or host name of the Jira service. (e.g. jira.example.com). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the IP address or host name of the Jira service. (e.g. jira.example.com). + * + * @param host the host value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port that the Jira server uses to listen for client connections. The default value is 443 if connecting through HTTPS, or 8080 if connecting through HTTP. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port that the Jira server uses to listen for client connections. The default value is 443 if connecting through HTTPS, or 8080 if connecting through HTTP. + * + * @param port the port value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the user name that you use to access Jira Service. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name that you use to access Jira Service. + * + * @param username the username value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name that you provided in the username field. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name that you provided in the username field. + * + * @param password the password value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the JiraLinkedService object itself. + */ + public JiraLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraObjectDataset.java new file mode 100644 index 000000000000..1cc278ee99e5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Jira Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("JiraObject") +public class JiraObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraSource.java new file mode 100644 index 000000000000..c889694a34e0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JiraSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Jira Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("JiraSource") +public class JiraSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the JiraSource object itself. + */ + public JiraSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JsonFormat.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JsonFormat.java new file mode 100644 index 000000000000..63033b3e5162 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JsonFormat.java @@ -0,0 +1,166 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The data stored in JSON format. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("JsonFormat") +public class JsonFormat extends DatasetStorageFormat { + /** + * File pattern of JSON. To be more specific, the way of separating a + * collection of JSON objects. The default value is 'setOfObjects'. It is + * case-sensitive. Possible values include: 'setOfObjects', + * 'arrayOfObjects'. + */ + @JsonProperty(value = "filePattern") + private JsonFormatFilePattern filePattern; + + /** + * The character used to separate nesting levels. Default value is '.' + * (dot). Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "nestingSeparator") + private Object nestingSeparator; + + /** + * The code page name of the preferred encoding. If not provided, the + * default value is 'utf-8', unless the byte order mark (BOM) denotes + * another Unicode encoding. The full list of supported values can be found + * in the 'Name' column of the table of encodings in the following + * reference: https://go.microsoft.com/fwlink/?linkid=861078. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "encodingName") + private Object encodingName; + + /** + * The JSONPath of the JSON array element to be flattened. Example: + * "$.ArrayPath". Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "jsonNodeReference") + private Object jsonNodeReference; + + /** + * The JSONPath definition for each column mapping with a customized column + * name to extract data from JSON file. For fields under root object, start + * with "$"; for fields inside the array chosen by jsonNodeReference + * property, start from the array element. Example: {"Column1": + * "$.Column1Path", "Column2": "Column2PathInArray"}. Type: object (or + * Expression with resultType object). + */ + @JsonProperty(value = "jsonPathDefinition") + private Object jsonPathDefinition; + + /** + * Get file pattern of JSON. To be more specific, the way of separating a collection of JSON objects. The default value is 'setOfObjects'. It is case-sensitive. Possible values include: 'setOfObjects', 'arrayOfObjects'. + * + * @return the filePattern value + */ + public JsonFormatFilePattern filePattern() { + return this.filePattern; + } + + /** + * Set file pattern of JSON. To be more specific, the way of separating a collection of JSON objects. The default value is 'setOfObjects'. It is case-sensitive. Possible values include: 'setOfObjects', 'arrayOfObjects'. + * + * @param filePattern the filePattern value to set + * @return the JsonFormat object itself. + */ + public JsonFormat withFilePattern(JsonFormatFilePattern filePattern) { + this.filePattern = filePattern; + return this; + } + + /** + * Get the character used to separate nesting levels. Default value is '.' (dot). Type: string (or Expression with resultType string). + * + * @return the nestingSeparator value + */ + public Object nestingSeparator() { + return this.nestingSeparator; + } + + /** + * Set the character used to separate nesting levels. Default value is '.' (dot). Type: string (or Expression with resultType string). + * + * @param nestingSeparator the nestingSeparator value to set + * @return the JsonFormat object itself. + */ + public JsonFormat withNestingSeparator(Object nestingSeparator) { + this.nestingSeparator = nestingSeparator; + return this; + } + + /** + * Get the code page name of the preferred encoding. If not provided, the default value is 'utf-8', unless the byte order mark (BOM) denotes another Unicode encoding. The full list of supported values can be found in the 'Name' column of the table of encodings in the following reference: https://go.microsoft.com/fwlink/?linkid=861078. Type: string (or Expression with resultType string). + * + * @return the encodingName value + */ + public Object encodingName() { + return this.encodingName; + } + + /** + * Set the code page name of the preferred encoding. If not provided, the default value is 'utf-8', unless the byte order mark (BOM) denotes another Unicode encoding. The full list of supported values can be found in the 'Name' column of the table of encodings in the following reference: https://go.microsoft.com/fwlink/?linkid=861078. Type: string (or Expression with resultType string). + * + * @param encodingName the encodingName value to set + * @return the JsonFormat object itself. + */ + public JsonFormat withEncodingName(Object encodingName) { + this.encodingName = encodingName; + return this; + } + + /** + * Get the JSONPath of the JSON array element to be flattened. Example: "$.ArrayPath". Type: string (or Expression with resultType string). + * + * @return the jsonNodeReference value + */ + public Object jsonNodeReference() { + return this.jsonNodeReference; + } + + /** + * Set the JSONPath of the JSON array element to be flattened. Example: "$.ArrayPath". Type: string (or Expression with resultType string). + * + * @param jsonNodeReference the jsonNodeReference value to set + * @return the JsonFormat object itself. + */ + public JsonFormat withJsonNodeReference(Object jsonNodeReference) { + this.jsonNodeReference = jsonNodeReference; + return this; + } + + /** + * Get the JSONPath definition for each column mapping with a customized column name to extract data from JSON file. For fields under root object, start with "$"; for fields inside the array chosen by jsonNodeReference property, start from the array element. Example: {"Column1": "$.Column1Path", "Column2": "Column2PathInArray"}. Type: object (or Expression with resultType object). + * + * @return the jsonPathDefinition value + */ + public Object jsonPathDefinition() { + return this.jsonPathDefinition; + } + + /** + * Set the JSONPath definition for each column mapping with a customized column name to extract data from JSON file. For fields under root object, start with "$"; for fields inside the array chosen by jsonNodeReference property, start from the array element. Example: {"Column1": "$.Column1Path", "Column2": "Column2PathInArray"}. Type: object (or Expression with resultType object). + * + * @param jsonPathDefinition the jsonPathDefinition value to set + * @return the JsonFormat object itself. + */ + public JsonFormat withJsonPathDefinition(Object jsonPathDefinition) { + this.jsonPathDefinition = jsonPathDefinition; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JsonFormatFilePattern.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JsonFormatFilePattern.java new file mode 100644 index 000000000000..9417eb59a2f3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/JsonFormatFilePattern.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for JsonFormatFilePattern. + */ +public final class JsonFormatFilePattern extends ExpandableStringEnum { + /** Static value setOfObjects for JsonFormatFilePattern. */ + public static final JsonFormatFilePattern SET_OF_OBJECTS = fromString("setOfObjects"); + + /** Static value arrayOfObjects for JsonFormatFilePattern. */ + public static final JsonFormatFilePattern ARRAY_OF_OBJECTS = fromString("arrayOfObjects"); + + /** + * Creates or finds a JsonFormatFilePattern from its string representation. + * @param name a name to look for + * @return the corresponding JsonFormatFilePattern + */ + @JsonCreator + public static JsonFormatFilePattern fromString(String name) { + return fromString(name, JsonFormatFilePattern.class); + } + + /** + * @return known JsonFormatFilePattern values + */ + public static Collection values() { + return values(JsonFormatFilePattern.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntime.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntime.java new file mode 100644 index 000000000000..4b5ed8ef575d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntime.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import org.joda.time.DateTime; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The linked integration runtime information. + */ +public class LinkedIntegrationRuntime { + /** + * The name of the linked integration runtime. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The subscription ID for which the linked integration runtime belong to. + */ + @JsonProperty(value = "subscriptionId", access = JsonProperty.Access.WRITE_ONLY) + private String subscriptionId; + + /** + * The name of the data factory for which the linked integration runtime + * belong to. + */ + @JsonProperty(value = "dataFactoryName", access = JsonProperty.Access.WRITE_ONLY) + private String dataFactoryName; + + /** + * The location of the data factory for which the linked integration + * runtime belong to. + */ + @JsonProperty(value = "dataFactoryLocation", access = JsonProperty.Access.WRITE_ONLY) + private String dataFactoryLocation; + + /** + * The creating time of the linked integration runtime. + */ + @JsonProperty(value = "createTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime createTime; + + /** + * Get the name of the linked integration runtime. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the subscription ID for which the linked integration runtime belong to. + * + * @return the subscriptionId value + */ + public String subscriptionId() { + return this.subscriptionId; + } + + /** + * Get the name of the data factory for which the linked integration runtime belong to. + * + * @return the dataFactoryName value + */ + public String dataFactoryName() { + return this.dataFactoryName; + } + + /** + * Get the location of the data factory for which the linked integration runtime belong to. + * + * @return the dataFactoryLocation value + */ + public String dataFactoryLocation() { + return this.dataFactoryLocation; + } + + /** + * Get the creating time of the linked integration runtime. + * + * @return the createTime value + */ + public DateTime createTime() { + return this.createTime; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeKey.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeKey.java new file mode 100644 index 000000000000..c92ae3747415 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeKey.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The base definition of a secret type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "authorizationType") +@JsonTypeName("Key") +public class LinkedIntegrationRuntimeKey extends LinkedIntegrationRuntimeProperties { + /** + * Type of the secret. + */ + @JsonProperty(value = "key", required = true) + private SecureString key; + + /** + * Get type of the secret. + * + * @return the key value + */ + public SecureString key() { + return this.key; + } + + /** + * Set type of the secret. + * + * @param key the key value to set + * @return the LinkedIntegrationRuntimeKey object itself. + */ + public LinkedIntegrationRuntimeKey withKey(SecureString key) { + this.key = key; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeProperties.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeProperties.java new file mode 100644 index 000000000000..9e7572b7853f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeProperties.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * The base definition of a secret type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "authorizationType") +@JsonTypeName("LinkedIntegrationRuntimeProperties") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "RBAC", value = LinkedIntegrationRuntimeRbac.class), + @JsonSubTypes.Type(name = "Key", value = LinkedIntegrationRuntimeKey.class) +}) +public class LinkedIntegrationRuntimeProperties { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeRbac.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeRbac.java new file mode 100644 index 000000000000..509ff731728b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedIntegrationRuntimeRbac.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The base definition of a secret type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "authorizationType") +@JsonTypeName("RBAC") +public class LinkedIntegrationRuntimeRbac extends LinkedIntegrationRuntimeProperties { + /** + * The resource ID of the integration runtime to be shared. + */ + @JsonProperty(value = "resourceId", required = true) + private String resourceId; + + /** + * Get the resource ID of the integration runtime to be shared. + * + * @return the resourceId value + */ + public String resourceId() { + return this.resourceId; + } + + /** + * Set the resource ID of the integration runtime to be shared. + * + * @param resourceId the resourceId value to set + * @return the LinkedIntegrationRuntimeRbac object itself. + */ + public LinkedIntegrationRuntimeRbac withResourceId(String resourceId) { + this.resourceId = resourceId; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServiceReference.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServiceReference.java new file mode 100644 index 000000000000..4a5228e483cf --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServiceReference.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Linked service reference type. + */ +public class LinkedServiceReference { + /** + * Linked service reference type. + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * Reference LinkedService name. + */ + @JsonProperty(value = "referenceName", required = true) + private String referenceName; + + /** + * Arguments for LinkedService. + */ + @JsonProperty(value = "parameters") + private Map parameters; + + /** + * Creates an instance of LinkedServiceReference class. + * @param referenceName reference LinkedService name. + */ + public LinkedServiceReference() { + type = "LinkedServiceReference"; + } + + /** + * Get linked service reference type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set linked service reference type. + * + * @param type the type value to set + * @return the LinkedServiceReference object itself. + */ + public LinkedServiceReference withType(String type) { + this.type = type; + return this; + } + + /** + * Get reference LinkedService name. + * + * @return the referenceName value + */ + public String referenceName() { + return this.referenceName; + } + + /** + * Set reference LinkedService name. + * + * @param referenceName the referenceName value to set + * @return the LinkedServiceReference object itself. + */ + public LinkedServiceReference withReferenceName(String referenceName) { + this.referenceName = referenceName; + return this; + } + + /** + * Get arguments for LinkedService. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set arguments for LinkedService. + * + * @param parameters the parameters value to set + * @return the LinkedServiceReference object itself. + */ + public LinkedServiceReference withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServiceResource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServiceResource.java new file mode 100644 index 000000000000..75b18ab169e2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServiceResource.java @@ -0,0 +1,149 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceResourceInner; +import com.microsoft.azure.arm.model.Indexable; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; +import java.util.Map; +import java.util.List; + +/** + * Type representing LinkedServiceResource. + */ +public interface LinkedServiceResource extends HasInner, Indexable, Refreshable, Updatable, HasManager { + /** + * @return the etag value. + */ + String etag(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the properties value. + */ + LinkedServiceInner properties(); + + /** + * @return the type value. + */ + String type(); + + /** + * The entirety of the LinkedServiceResource definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithFactory, DefinitionStages.WithIfMatch, DefinitionStages.WithProperties, DefinitionStages.WithCreate { + } + + /** + * Grouping of LinkedServiceResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a LinkedServiceResource definition. + */ + interface Blank extends WithFactory { + } + + /** + * The stage of the linkedserviceresource definition allowing to specify Factory. + */ + interface WithFactory { + /** + * Specifies resourceGroupName, factoryName. + * @param resourceGroupName The resource group name + * @param factoryName The factory name + * @return the next definition stage + */ + WithIfMatch withExistingFactory(String resourceGroupName, String factoryName); + } + + /** + * The stage of the linkedserviceresource definition allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the linkedService entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next definition stage + */ + WithProperties withIfMatch(String ifMatch); + } + + /** + * The stage of the linkedserviceresource definition allowing to specify Properties. + */ + interface WithProperties { + /** + * Specifies properties. + * @param properties Properties of linked service + * @return the next definition stage + */ + WithCreate withProperties(LinkedServiceInner properties); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable { + } + } + /** + * The template for a LinkedServiceResource update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, UpdateStages.WithIfMatch, UpdateStages.WithProperties { + } + + /** + * Grouping of LinkedServiceResource update stages. + */ + interface UpdateStages { + /** + * The stage of the linkedserviceresource update allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the linkedService entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next update stage + */ + Update withIfMatch(String ifMatch); + } + + /** + * The stage of the linkedserviceresource update allowing to specify Properties. + */ + interface WithProperties { + /** + * Specifies properties. + * @param properties Properties of linked service + * @return the next update stage + */ + Update withProperties(LinkedServiceInner properties); + } + + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServices.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServices.java new file mode 100644 index 000000000000..6a35053edf42 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LinkedServices.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import rx.Completable; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServicesInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing LinkedServices. + */ +public interface LinkedServices extends SupportsCreating, HasInner { + /** + * Gets a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAsync(String resourceGroupName, String factoryName, String linkedServiceName); + + /** + * Lists linked services. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listByFactoryAsync(final String resourceGroupName, final String factoryName); + + /** + * Deletes a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable deleteAsync(String resourceGroupName, String factoryName, String linkedServiceName); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LookupActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LookupActivity.java new file mode 100644 index 000000000000..c5f55e929672 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/LookupActivity.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Lookup activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Lookup") +@JsonFlatten +public class LookupActivity extends ExecutionActivity { + /** + * Dataset-specific source properties, same as copy activity source. + */ + @JsonProperty(value = "typeProperties.source", required = true) + private CopySource source; + + /** + * Lookup activity dataset reference. + */ + @JsonProperty(value = "typeProperties.dataset", required = true) + private DatasetReference dataset; + + /** + * Whether to return first row or all rows. Default value is true. Type: + * boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "typeProperties.firstRowOnly") + private Object firstRowOnly; + + /** + * Get dataset-specific source properties, same as copy activity source. + * + * @return the source value + */ + public CopySource source() { + return this.source; + } + + /** + * Set dataset-specific source properties, same as copy activity source. + * + * @param source the source value to set + * @return the LookupActivity object itself. + */ + public LookupActivity withSource(CopySource source) { + this.source = source; + return this; + } + + /** + * Get lookup activity dataset reference. + * + * @return the dataset value + */ + public DatasetReference dataset() { + return this.dataset; + } + + /** + * Set lookup activity dataset reference. + * + * @param dataset the dataset value to set + * @return the LookupActivity object itself. + */ + public LookupActivity withDataset(DatasetReference dataset) { + this.dataset = dataset; + return this; + } + + /** + * Get whether to return first row or all rows. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the firstRowOnly value + */ + public Object firstRowOnly() { + return this.firstRowOnly; + } + + /** + * Set whether to return first row or all rows. Default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param firstRowOnly the firstRowOnly value to set + * @return the LookupActivity object itself. + */ + public LookupActivity withFirstRowOnly(Object firstRowOnly) { + this.firstRowOnly = firstRowOnly; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoLinkedService.java new file mode 100644 index 000000000000..324edd07b8e1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoLinkedService.java @@ -0,0 +1,186 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Magento server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Magento") +@JsonFlatten +public class MagentoLinkedService extends LinkedServiceInner { + /** + * The URL of the Magento instance. (i.e. 192.168.222.110/magento3). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The access token from Magento. + */ + @JsonProperty(value = "typeProperties.accessToken") + private SecretBase accessToken; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the URL of the Magento instance. (i.e. 192.168.222.110/magento3). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the URL of the Magento instance. (i.e. 192.168.222.110/magento3). + * + * @param host the host value to set + * @return the MagentoLinkedService object itself. + */ + public MagentoLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the access token from Magento. + * + * @return the accessToken value + */ + public SecretBase accessToken() { + return this.accessToken; + } + + /** + * Set the access token from Magento. + * + * @param accessToken the accessToken value to set + * @return the MagentoLinkedService object itself. + */ + public MagentoLinkedService withAccessToken(SecretBase accessToken) { + this.accessToken = accessToken; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the MagentoLinkedService object itself. + */ + public MagentoLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the MagentoLinkedService object itself. + */ + public MagentoLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the MagentoLinkedService object itself. + */ + public MagentoLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the MagentoLinkedService object itself. + */ + public MagentoLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoObjectDataset.java new file mode 100644 index 000000000000..3f3def8dd8a0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Magento server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MagentoObject") +public class MagentoObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoSource.java new file mode 100644 index 000000000000..3320650ff5a4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MagentoSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Magento server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MagentoSource") +public class MagentoSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the MagentoSource object itself. + */ + public MagentoSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntime.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntime.java new file mode 100644 index 000000000000..a4920a8e888f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntime.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeInner; + +/** + * Managed integration runtime, including managed elastic and managed dedicated + * integration runtimes. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Managed") +@JsonFlatten +public class ManagedIntegrationRuntime extends IntegrationRuntimeInner { + /** + * Integration runtime state, only valid for managed dedicated integration + * runtime. Possible values include: 'Initial', 'Stopped', 'Started', + * 'Starting', 'Stopping', 'NeedRegistration', 'Online', 'Limited', + * 'Offline'. + */ + @JsonProperty(value = "state", access = JsonProperty.Access.WRITE_ONLY) + private IntegrationRuntimeState state; + + /** + * The compute resource for managed integration runtime. + */ + @JsonProperty(value = "typeProperties.computeProperties") + private IntegrationRuntimeComputeProperties computeProperties; + + /** + * SSIS properties for managed integration runtime. + */ + @JsonProperty(value = "typeProperties.ssisProperties") + private IntegrationRuntimeSsisProperties ssisProperties; + + /** + * Get integration runtime state, only valid for managed dedicated integration runtime. Possible values include: 'Initial', 'Stopped', 'Started', 'Starting', 'Stopping', 'NeedRegistration', 'Online', 'Limited', 'Offline'. + * + * @return the state value + */ + public IntegrationRuntimeState state() { + return this.state; + } + + /** + * Get the compute resource for managed integration runtime. + * + * @return the computeProperties value + */ + public IntegrationRuntimeComputeProperties computeProperties() { + return this.computeProperties; + } + + /** + * Set the compute resource for managed integration runtime. + * + * @param computeProperties the computeProperties value to set + * @return the ManagedIntegrationRuntime object itself. + */ + public ManagedIntegrationRuntime withComputeProperties(IntegrationRuntimeComputeProperties computeProperties) { + this.computeProperties = computeProperties; + return this; + } + + /** + * Get sSIS properties for managed integration runtime. + * + * @return the ssisProperties value + */ + public IntegrationRuntimeSsisProperties ssisProperties() { + return this.ssisProperties; + } + + /** + * Set sSIS properties for managed integration runtime. + * + * @param ssisProperties the ssisProperties value to set + * @return the ManagedIntegrationRuntime object itself. + */ + public ManagedIntegrationRuntime withSsisProperties(IntegrationRuntimeSsisProperties ssisProperties) { + this.ssisProperties = ssisProperties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeError.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeError.java new file mode 100644 index 000000000000..8afe66233b0c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeError.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import org.joda.time.DateTime; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Error definition for managed integration runtime. + */ +public class ManagedIntegrationRuntimeError { + /** + * The time when the error occurred. + */ + @JsonProperty(value = "time", access = JsonProperty.Access.WRITE_ONLY) + private DateTime time; + + /** + * Error code. + */ + @JsonProperty(value = "code", access = JsonProperty.Access.WRITE_ONLY) + private String code; + + /** + * Managed integration runtime error parameters. + */ + @JsonProperty(value = "parameters", access = JsonProperty.Access.WRITE_ONLY) + private List parameters; + + /** + * Error message. + */ + @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) + private String message; + + /** + * Get the time when the error occurred. + * + * @return the time value + */ + public DateTime time() { + return this.time; + } + + /** + * Get error code. + * + * @return the code value + */ + public String code() { + return this.code; + } + + /** + * Get managed integration runtime error parameters. + * + * @return the parameters value + */ + public List parameters() { + return this.parameters; + } + + /** + * Get error message. + * + * @return the message value + */ + public String message() { + return this.message; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeNode.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeNode.java new file mode 100644 index 000000000000..6ebb14619e02 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeNode.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Properties of integration runtime node. + */ +public class ManagedIntegrationRuntimeNode { + /** + * The managed integration runtime node id. + */ + @JsonProperty(value = "nodeId", access = JsonProperty.Access.WRITE_ONLY) + private String nodeId; + + /** + * The managed integration runtime node status. Possible values include: + * 'Starting', 'Available', 'Recycling', 'Unavailable'. + */ + @JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY) + private ManagedIntegrationRuntimeNodeStatus status; + + /** + * The errors that occurred on this integration runtime node. + */ + @JsonProperty(value = "errors") + private List errors; + + /** + * Get the managed integration runtime node id. + * + * @return the nodeId value + */ + public String nodeId() { + return this.nodeId; + } + + /** + * Get the managed integration runtime node status. Possible values include: 'Starting', 'Available', 'Recycling', 'Unavailable'. + * + * @return the status value + */ + public ManagedIntegrationRuntimeNodeStatus status() { + return this.status; + } + + /** + * Get the errors that occurred on this integration runtime node. + * + * @return the errors value + */ + public List errors() { + return this.errors; + } + + /** + * Set the errors that occurred on this integration runtime node. + * + * @param errors the errors value to set + * @return the ManagedIntegrationRuntimeNode object itself. + */ + public ManagedIntegrationRuntimeNode withErrors(List errors) { + this.errors = errors; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeNodeStatus.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeNodeStatus.java new file mode 100644 index 000000000000..d80ac2c96ffe --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeNodeStatus.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ManagedIntegrationRuntimeNodeStatus. + */ +public final class ManagedIntegrationRuntimeNodeStatus extends ExpandableStringEnum { + /** Static value Starting for ManagedIntegrationRuntimeNodeStatus. */ + public static final ManagedIntegrationRuntimeNodeStatus STARTING = fromString("Starting"); + + /** Static value Available for ManagedIntegrationRuntimeNodeStatus. */ + public static final ManagedIntegrationRuntimeNodeStatus AVAILABLE = fromString("Available"); + + /** Static value Recycling for ManagedIntegrationRuntimeNodeStatus. */ + public static final ManagedIntegrationRuntimeNodeStatus RECYCLING = fromString("Recycling"); + + /** Static value Unavailable for ManagedIntegrationRuntimeNodeStatus. */ + public static final ManagedIntegrationRuntimeNodeStatus UNAVAILABLE = fromString("Unavailable"); + + /** + * Creates or finds a ManagedIntegrationRuntimeNodeStatus from its string representation. + * @param name a name to look for + * @return the corresponding ManagedIntegrationRuntimeNodeStatus + */ + @JsonCreator + public static ManagedIntegrationRuntimeNodeStatus fromString(String name) { + return fromString(name, ManagedIntegrationRuntimeNodeStatus.class); + } + + /** + * @return known ManagedIntegrationRuntimeNodeStatus values + */ + public static Collection values() { + return values(ManagedIntegrationRuntimeNodeStatus.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeOperationResult.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeOperationResult.java new file mode 100644 index 000000000000..04784a221d83 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeOperationResult.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import org.joda.time.DateTime; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Properties of managed integration runtime operation result. + */ +public class ManagedIntegrationRuntimeOperationResult { + /** + * The operation type. Could be start or stop. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * The start time of the operation. + */ + @JsonProperty(value = "startTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime startTime; + + /** + * The operation result. + */ + @JsonProperty(value = "result", access = JsonProperty.Access.WRITE_ONLY) + private String result; + + /** + * The error code. + */ + @JsonProperty(value = "errorCode", access = JsonProperty.Access.WRITE_ONLY) + private String errorCode; + + /** + * Managed integration runtime error parameters. + */ + @JsonProperty(value = "parameters", access = JsonProperty.Access.WRITE_ONLY) + private List parameters; + + /** + * The activity id for the operation request. + */ + @JsonProperty(value = "activityId", access = JsonProperty.Access.WRITE_ONLY) + private String activityId; + + /** + * Get the operation type. Could be start or stop. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get the start time of the operation. + * + * @return the startTime value + */ + public DateTime startTime() { + return this.startTime; + } + + /** + * Get the operation result. + * + * @return the result value + */ + public String result() { + return this.result; + } + + /** + * Get the error code. + * + * @return the errorCode value + */ + public String errorCode() { + return this.errorCode; + } + + /** + * Get managed integration runtime error parameters. + * + * @return the parameters value + */ + public List parameters() { + return this.parameters; + } + + /** + * Get the activity id for the operation request. + * + * @return the activityId value + */ + public String activityId() { + return this.activityId; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeStatus.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeStatus.java new file mode 100644 index 000000000000..de8244645552 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ManagedIntegrationRuntimeStatus.java @@ -0,0 +1,86 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import org.joda.time.DateTime; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Managed integration runtime status. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Managed") +@JsonFlatten +public class ManagedIntegrationRuntimeStatus extends IntegrationRuntimeStatus { + /** + * The time at which the integration runtime was created, in ISO8601 + * format. + */ + @JsonProperty(value = "typeProperties.createTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime createTime; + + /** + * The list of nodes for managed integration runtime. + */ + @JsonProperty(value = "typeProperties.nodes", access = JsonProperty.Access.WRITE_ONLY) + private List nodes; + + /** + * The errors that occurred on this integration runtime. + */ + @JsonProperty(value = "typeProperties.otherErrors", access = JsonProperty.Access.WRITE_ONLY) + private List otherErrors; + + /** + * The last operation result that occurred on this integration runtime. + */ + @JsonProperty(value = "typeProperties.lastOperation", access = JsonProperty.Access.WRITE_ONLY) + private ManagedIntegrationRuntimeOperationResult lastOperation; + + /** + * Get the time at which the integration runtime was created, in ISO8601 format. + * + * @return the createTime value + */ + public DateTime createTime() { + return this.createTime; + } + + /** + * Get the list of nodes for managed integration runtime. + * + * @return the nodes value + */ + public List nodes() { + return this.nodes; + } + + /** + * Get the errors that occurred on this integration runtime. + * + * @return the otherErrors value + */ + public List otherErrors() { + return this.otherErrors; + } + + /** + * Get the last operation result that occurred on this integration runtime. + * + * @return the lastOperation value + */ + public ManagedIntegrationRuntimeOperationResult lastOperation() { + return this.lastOperation; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBLinkedService.java new file mode 100644 index 000000000000..7d8084caa4ab --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * MariaDB server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MariaDB") +@JsonFlatten +public class MariaDBLinkedService extends LinkedServiceInner { + /** + * An ODBC connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the MariaDBLinkedService object itself. + */ + public MariaDBLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the MariaDBLinkedService object itself. + */ + public MariaDBLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBSource.java new file mode 100644 index 000000000000..ab6ad006ddf8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity MariaDB server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MariaDBSource") +public class MariaDBSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the MariaDBSource object itself. + */ + public MariaDBSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBTableDataset.java new file mode 100644 index 000000000000..82e9deab925c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MariaDBTableDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * MariaDB server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MariaDBTable") +public class MariaDBTableDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoLinkedService.java new file mode 100644 index 000000000000..21ba905aad42 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoLinkedService.java @@ -0,0 +1,212 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Marketo server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Marketo") +@JsonFlatten +public class MarketoLinkedService extends LinkedServiceInner { + /** + * The endpoint of the Marketo server. (i.e. 123-ABC-321.mktorest.com). + */ + @JsonProperty(value = "typeProperties.endpoint", required = true) + private Object endpoint; + + /** + * The client Id of your Marketo service. + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * The client secret of your Marketo service. + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the Marketo server. (i.e. 123-ABC-321.mktorest.com). + * + * @return the endpoint value + */ + public Object endpoint() { + return this.endpoint; + } + + /** + * Set the endpoint of the Marketo server. (i.e. 123-ABC-321.mktorest.com). + * + * @param endpoint the endpoint value to set + * @return the MarketoLinkedService object itself. + */ + public MarketoLinkedService withEndpoint(Object endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Get the client Id of your Marketo service. + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set the client Id of your Marketo service. + * + * @param clientId the clientId value to set + * @return the MarketoLinkedService object itself. + */ + public MarketoLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret of your Marketo service. + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret of your Marketo service. + * + * @param clientSecret the clientSecret value to set + * @return the MarketoLinkedService object itself. + */ + public MarketoLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the MarketoLinkedService object itself. + */ + public MarketoLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the MarketoLinkedService object itself. + */ + public MarketoLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the MarketoLinkedService object itself. + */ + public MarketoLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the MarketoLinkedService object itself. + */ + public MarketoLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoObjectDataset.java new file mode 100644 index 000000000000..363a98f2a51b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Marketo server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MarketoObject") +public class MarketoObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoSource.java new file mode 100644 index 000000000000..a5afe9824332 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MarketoSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Marketo server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MarketoSource") +public class MarketoSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the MarketoSource object itself. + */ + public MarketoSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbAuthenticationType.java new file mode 100644 index 000000000000..86b078b74645 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for MongoDbAuthenticationType. + */ +public final class MongoDbAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for MongoDbAuthenticationType. */ + public static final MongoDbAuthenticationType BASIC = fromString("Basic"); + + /** Static value Anonymous for MongoDbAuthenticationType. */ + public static final MongoDbAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** + * Creates or finds a MongoDbAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding MongoDbAuthenticationType + */ + @JsonCreator + public static MongoDbAuthenticationType fromString(String name) { + return fromString(name, MongoDbAuthenticationType.class); + } + + /** + * @return known MongoDbAuthenticationType values + */ + public static Collection values() { + return values(MongoDbAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbCollectionDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbCollectionDataset.java new file mode 100644 index 000000000000..b662336edcaa --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbCollectionDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The MongoDB database dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MongoDbCollection") +@JsonFlatten +public class MongoDbCollectionDataset extends DatasetInner { + /** + * The table name of the MongoDB database. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.collectionName", required = true) + private Object collectionName; + + /** + * Get the table name of the MongoDB database. Type: string (or Expression with resultType string). + * + * @return the collectionName value + */ + public Object collectionName() { + return this.collectionName; + } + + /** + * Set the table name of the MongoDB database. Type: string (or Expression with resultType string). + * + * @param collectionName the collectionName value to set + * @return the MongoDbCollectionDataset object itself. + */ + public MongoDbCollectionDataset withCollectionName(Object collectionName) { + this.collectionName = collectionName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbLinkedService.java new file mode 100644 index 000000000000..14286a18c373 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbLinkedService.java @@ -0,0 +1,297 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for MongoDb data source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MongoDb") +@JsonFlatten +public class MongoDbLinkedService extends LinkedServiceInner { + /** + * The IP address or server name of the MongoDB server. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.server", required = true) + private Object server; + + /** + * The authentication type to be used to connect to the MongoDB database. + * Possible values include: 'Basic', 'Anonymous'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private MongoDbAuthenticationType authenticationType; + + /** + * The name of the MongoDB database that you want to access. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.databaseName", required = true) + private Object databaseName; + + /** + * Username for authentication. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * Password for authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Database to verify the username and password. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.authSource") + private Object authSource; + + /** + * The TCP port number that the MongoDB server uses to listen for client + * connections. The default value is 27017. Type: integer (or Expression + * with resultType integer), minimum: 0. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * Specifies whether the connections to the server are encrypted using SSL. + * The default value is false. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * Specifies whether to allow self-signed certificates from the server. The + * default value is false. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "typeProperties.allowSelfSignedServerCert") + private Object allowSelfSignedServerCert; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the IP address or server name of the MongoDB server. Type: string (or Expression with resultType string). + * + * @return the server value + */ + public Object server() { + return this.server; + } + + /** + * Set the IP address or server name of the MongoDB server. Type: string (or Expression with resultType string). + * + * @param server the server value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withServer(Object server) { + this.server = server; + return this; + } + + /** + * Get the authentication type to be used to connect to the MongoDB database. Possible values include: 'Basic', 'Anonymous'. + * + * @return the authenticationType value + */ + public MongoDbAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to be used to connect to the MongoDB database. Possible values include: 'Basic', 'Anonymous'. + * + * @param authenticationType the authenticationType value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withAuthenticationType(MongoDbAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the name of the MongoDB database that you want to access. Type: string (or Expression with resultType string). + * + * @return the databaseName value + */ + public Object databaseName() { + return this.databaseName; + } + + /** + * Set the name of the MongoDB database that you want to access. Type: string (or Expression with resultType string). + * + * @param databaseName the databaseName value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withDatabaseName(Object databaseName) { + this.databaseName = databaseName; + return this; + } + + /** + * Get username for authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set username for authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get password for authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for authentication. + * + * @param password the password value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get database to verify the username and password. Type: string (or Expression with resultType string). + * + * @return the authSource value + */ + public Object authSource() { + return this.authSource; + } + + /** + * Set database to verify the username and password. Type: string (or Expression with resultType string). + * + * @param authSource the authSource value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withAuthSource(Object authSource) { + this.authSource = authSource; + return this; + } + + /** + * Get the TCP port number that the MongoDB server uses to listen for client connections. The default value is 27017. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port number that the MongoDB server uses to listen for client connections. The default value is 27017. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param port the port value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get specifies whether the connections to the server are encrypted using SSL. The default value is false. Type: boolean (or Expression with resultType boolean). + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set specifies whether the connections to the server are encrypted using SSL. The default value is false. Type: boolean (or Expression with resultType boolean). + * + * @param enableSsl the enableSsl value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get specifies whether to allow self-signed certificates from the server. The default value is false. Type: boolean (or Expression with resultType boolean). + * + * @return the allowSelfSignedServerCert value + */ + public Object allowSelfSignedServerCert() { + return this.allowSelfSignedServerCert; + } + + /** + * Set specifies whether to allow self-signed certificates from the server. The default value is false. Type: boolean (or Expression with resultType boolean). + * + * @param allowSelfSignedServerCert the allowSelfSignedServerCert value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withAllowSelfSignedServerCert(Object allowSelfSignedServerCert) { + this.allowSelfSignedServerCert = allowSelfSignedServerCert; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the MongoDbLinkedService object itself. + */ + public MongoDbLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbSource.java new file mode 100644 index 000000000000..81bbb0e4427f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MongoDbSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for a MongoDB database. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MongoDbSource") +public class MongoDbSource extends CopySource { + /** + * Database query. Should be a SQL-92 query expression. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get database query. Should be a SQL-92 query expression. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set database query. Should be a SQL-92 query expression. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the MongoDbSource object itself. + */ + public MongoDbSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MultiplePipelineTrigger.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MultiplePipelineTrigger.java new file mode 100644 index 000000000000..18ca5c96f769 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MultiplePipelineTrigger.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.TriggerInner; + +/** + * Base class for all triggers that support one to many model for trigger to + * pipeline. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MultiplePipelineTrigger") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "BlobEventsTrigger", value = BlobEventsTrigger.class), + @JsonSubTypes.Type(name = "BlobTrigger", value = BlobTrigger.class), + @JsonSubTypes.Type(name = "ScheduleTrigger", value = ScheduleTrigger.class) +}) +public class MultiplePipelineTrigger extends TriggerInner { + /** + * Pipelines that need to be started. + */ + @JsonProperty(value = "pipelines") + private List pipelines; + + /** + * Get pipelines that need to be started. + * + * @return the pipelines value + */ + public List pipelines() { + return this.pipelines; + } + + /** + * Set pipelines that need to be started. + * + * @param pipelines the pipelines value to set + * @return the MultiplePipelineTrigger object itself. + */ + public MultiplePipelineTrigger withPipelines(List pipelines) { + this.pipelines = pipelines; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MySqlLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MySqlLinkedService.java new file mode 100644 index 000000000000..47aae9f0e42e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/MySqlLinkedService.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for MySQL data source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("MySql") +@JsonFlatten +public class MySqlLinkedService extends LinkedServiceInner { + /** + * The connection string. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private SecretBase connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. + * + * @return the connectionString value + */ + public SecretBase connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. + * + * @param connectionString the connectionString value to set + * @return the MySqlLinkedService object itself. + */ + public MySqlLinkedService withConnectionString(SecretBase connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the MySqlLinkedService object itself. + */ + public MySqlLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaLinkedService.java new file mode 100644 index 000000000000..cc37285b7a3e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Netezza linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Netezza") +@JsonFlatten +public class NetezzaLinkedService extends LinkedServiceInner { + /** + * An ODBC connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the NetezzaLinkedService object itself. + */ + public NetezzaLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the NetezzaLinkedService object itself. + */ + public NetezzaLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaSource.java new file mode 100644 index 000000000000..941b41b05eed --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Netezza source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("NetezzaSource") +public class NetezzaSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the NetezzaSource object itself. + */ + public NetezzaSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaTableDataset.java new file mode 100644 index 000000000000..a6a1a126a63d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/NetezzaTableDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Netezza dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("NetezzaTable") +public class NetezzaTableDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataAuthenticationType.java new file mode 100644 index 000000000000..1e6bcdecf1b2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ODataAuthenticationType. + */ +public final class ODataAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for ODataAuthenticationType. */ + public static final ODataAuthenticationType BASIC = fromString("Basic"); + + /** Static value Anonymous for ODataAuthenticationType. */ + public static final ODataAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** + * Creates or finds a ODataAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding ODataAuthenticationType + */ + @JsonCreator + public static ODataAuthenticationType fromString(String name) { + return fromString(name, ODataAuthenticationType.class); + } + + /** + * @return known ODataAuthenticationType values + */ + public static Collection values() { + return values(ODataAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataLinkedService.java new file mode 100644 index 000000000000..9306b69b480e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataLinkedService.java @@ -0,0 +1,159 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Open Data Protocol (OData) linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("OData") +@JsonFlatten +public class ODataLinkedService extends LinkedServiceInner { + /** + * The URL of the OData service endpoint. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.url", required = true) + private Object url; + + /** + * Type of authentication used to connect to the OData service. Possible + * values include: 'Basic', 'Anonymous'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private ODataAuthenticationType authenticationType; + + /** + * User name of the OData service. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password of the OData service. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the URL of the OData service endpoint. Type: string (or Expression with resultType string). + * + * @return the url value + */ + public Object url() { + return this.url; + } + + /** + * Set the URL of the OData service endpoint. Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the ODataLinkedService object itself. + */ + public ODataLinkedService withUrl(Object url) { + this.url = url; + return this; + } + + /** + * Get type of authentication used to connect to the OData service. Possible values include: 'Basic', 'Anonymous'. + * + * @return the authenticationType value + */ + public ODataAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set type of authentication used to connect to the OData service. Possible values include: 'Basic', 'Anonymous'. + * + * @param authenticationType the authenticationType value to set + * @return the ODataLinkedService object itself. + */ + public ODataLinkedService withAuthenticationType(ODataAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get user name of the OData service. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set user name of the OData service. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the ODataLinkedService object itself. + */ + public ODataLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password of the OData service. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password of the OData service. + * + * @param password the password value to set + * @return the ODataLinkedService object itself. + */ + public ODataLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the ODataLinkedService object itself. + */ + public ODataLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataResourceDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataResourceDataset.java new file mode 100644 index 000000000000..c7e80c59e400 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ODataResourceDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Open Data Protocol (OData) resource dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ODataResource") +@JsonFlatten +public class ODataResourceDataset extends DatasetInner { + /** + * The OData resource path. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.path") + private Object path; + + /** + * Get the OData resource path. Type: string (or Expression with resultType string). + * + * @return the path value + */ + public Object path() { + return this.path; + } + + /** + * Set the OData resource path. Type: string (or Expression with resultType string). + * + * @param path the path value to set + * @return the ODataResourceDataset object itself. + */ + public ODataResourceDataset withPath(Object path) { + this.path = path; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OdbcLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OdbcLinkedService.java new file mode 100644 index 000000000000..275d880d4335 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OdbcLinkedService.java @@ -0,0 +1,188 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Open Database Connectivity (ODBC) linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Odbc") +@JsonFlatten +public class OdbcLinkedService extends LinkedServiceInner { + /** + * The non-access credential portion of the connection string as well as an + * optional encrypted credential. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private Object connectionString; + + /** + * Type of authentication used to connect to the ODBC data store. Possible + * values are: Anonymous and Basic. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.authenticationType") + private Object authenticationType; + + /** + * The access credential portion of the connection string specified in + * driver-specific property-value format. + */ + @JsonProperty(value = "typeProperties.credential") + private SecretBase credential; + + /** + * User name for Basic authentication. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password for Basic authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the non-access credential portion of the connection string as well as an optional encrypted credential. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the non-access credential portion of the connection string as well as an optional encrypted credential. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the OdbcLinkedService object itself. + */ + public OdbcLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get type of authentication used to connect to the ODBC data store. Possible values are: Anonymous and Basic. Type: string (or Expression with resultType string). + * + * @return the authenticationType value + */ + public Object authenticationType() { + return this.authenticationType; + } + + /** + * Set type of authentication used to connect to the ODBC data store. Possible values are: Anonymous and Basic. Type: string (or Expression with resultType string). + * + * @param authenticationType the authenticationType value to set + * @return the OdbcLinkedService object itself. + */ + public OdbcLinkedService withAuthenticationType(Object authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the access credential portion of the connection string specified in driver-specific property-value format. + * + * @return the credential value + */ + public SecretBase credential() { + return this.credential; + } + + /** + * Set the access credential portion of the connection string specified in driver-specific property-value format. + * + * @param credential the credential value to set + * @return the OdbcLinkedService object itself. + */ + public OdbcLinkedService withCredential(SecretBase credential) { + this.credential = credential; + return this; + } + + /** + * Get user name for Basic authentication. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set user name for Basic authentication. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the OdbcLinkedService object itself. + */ + public OdbcLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password for Basic authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for Basic authentication. + * + * @param password the password value to set + * @return the OdbcLinkedService object itself. + */ + public OdbcLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the OdbcLinkedService object itself. + */ + public OdbcLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OdbcSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OdbcSink.java new file mode 100644 index 000000000000..d4ff6470ef96 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OdbcSink.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity ODBC sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("OdbcSink") +public class OdbcSink extends CopySink { + /** + * A query to execute before starting the copy. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "preCopyScript") + private Object preCopyScript; + + /** + * Get a query to execute before starting the copy. Type: string (or Expression with resultType string). + * + * @return the preCopyScript value + */ + public Object preCopyScript() { + return this.preCopyScript; + } + + /** + * Set a query to execute before starting the copy. Type: string (or Expression with resultType string). + * + * @param preCopyScript the preCopyScript value to set + * @return the OdbcSink object itself. + */ + public OdbcSink withPreCopyScript(Object preCopyScript) { + this.preCopyScript = preCopyScript; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationDisplay.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationDisplay.java new file mode 100644 index 000000000000..3fe9e26de07b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationDisplay.java @@ -0,0 +1,121 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Metadata associated with the operation. + */ +public class OperationDisplay { + /** + * The description of the operation. + */ + @JsonProperty(value = "description") + private String description; + + /** + * The name of the provider. + */ + @JsonProperty(value = "provider") + private String provider; + + /** + * The name of the resource type on which the operation is performed. + */ + @JsonProperty(value = "resource") + private String resource; + + /** + * The type of operation: get, read, delete, etc. + */ + @JsonProperty(value = "operation") + private String operation; + + /** + * Get the description of the operation. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Set the description of the operation. + * + * @param description the description value to set + * @return the OperationDisplay object itself. + */ + public OperationDisplay withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get the name of the provider. + * + * @return the provider value + */ + public String provider() { + return this.provider; + } + + /** + * Set the name of the provider. + * + * @param provider the provider value to set + * @return the OperationDisplay object itself. + */ + public OperationDisplay withProvider(String provider) { + this.provider = provider; + return this; + } + + /** + * Get the name of the resource type on which the operation is performed. + * + * @return the resource value + */ + public String resource() { + return this.resource; + } + + /** + * Set the name of the resource type on which the operation is performed. + * + * @param resource the resource value to set + * @return the OperationDisplay object itself. + */ + public OperationDisplay withResource(String resource) { + this.resource = resource; + return this; + } + + /** + * Get the type of operation: get, read, delete, etc. + * + * @return the operation value + */ + public String operation() { + return this.operation; + } + + /** + * Set the type of operation: get, read, delete, etc. + * + * @param operation the operation value to set + * @return the OperationDisplay object itself. + */ + public OperationDisplay withOperation(String operation) { + this.operation = operation; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationListResponse.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationListResponse.java new file mode 100644 index 000000000000..83a84546f52f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationListResponse.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.OperationListResponseInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.OperationInner; +import java.util.List; + +/** + * Type representing OperationListResponse. + */ +public interface OperationListResponse extends HasInner, HasManager { + /** + * @return the nextLink value. + */ + String nextLink(); + + /** + * @return the value value. + */ + List value(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationLogSpecification.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationLogSpecification.java new file mode 100644 index 000000000000..42a211304754 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationLogSpecification.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Details about an operation related to logs. + */ +public class OperationLogSpecification { + /** + * The name of the log category. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Localized display name. + */ + @JsonProperty(value = "displayName") + private String displayName; + + /** + * Blobs created in the customer storage account, per hour. + */ + @JsonProperty(value = "blobDuration") + private String blobDuration; + + /** + * Get the name of the log category. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set the name of the log category. + * + * @param name the name value to set + * @return the OperationLogSpecification object itself. + */ + public OperationLogSpecification withName(String name) { + this.name = name; + return this; + } + + /** + * Get localized display name. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set localized display name. + * + * @param displayName the displayName value to set + * @return the OperationLogSpecification object itself. + */ + public OperationLogSpecification withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get blobs created in the customer storage account, per hour. + * + * @return the blobDuration value + */ + public String blobDuration() { + return this.blobDuration; + } + + /** + * Set blobs created in the customer storage account, per hour. + * + * @param blobDuration the blobDuration value to set + * @return the OperationLogSpecification object itself. + */ + public OperationLogSpecification withBlobDuration(String blobDuration) { + this.blobDuration = blobDuration; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationMetricAvailability.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationMetricAvailability.java new file mode 100644 index 000000000000..c75c1ff53d11 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationMetricAvailability.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Defines how often data for a metric becomes available. + */ +public class OperationMetricAvailability { + /** + * The granularity for the metric. + */ + @JsonProperty(value = "timeGrain") + private String timeGrain; + + /** + * Blob created in the customer storage account, per hour. + */ + @JsonProperty(value = "blobDuration") + private String blobDuration; + + /** + * Get the granularity for the metric. + * + * @return the timeGrain value + */ + public String timeGrain() { + return this.timeGrain; + } + + /** + * Set the granularity for the metric. + * + * @param timeGrain the timeGrain value to set + * @return the OperationMetricAvailability object itself. + */ + public OperationMetricAvailability withTimeGrain(String timeGrain) { + this.timeGrain = timeGrain; + return this; + } + + /** + * Get blob created in the customer storage account, per hour. + * + * @return the blobDuration value + */ + public String blobDuration() { + return this.blobDuration; + } + + /** + * Set blob created in the customer storage account, per hour. + * + * @param blobDuration the blobDuration value to set + * @return the OperationMetricAvailability object itself. + */ + public OperationMetricAvailability withBlobDuration(String blobDuration) { + this.blobDuration = blobDuration; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationMetricSpecification.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationMetricSpecification.java new file mode 100644 index 000000000000..aa16b3fd3b68 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationMetricSpecification.java @@ -0,0 +1,252 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Details about an operation related to metrics. + */ +public class OperationMetricSpecification { + /** + * The name of the metric. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Localized display name of the metric. + */ + @JsonProperty(value = "displayName") + private String displayName; + + /** + * The description of the metric. + */ + @JsonProperty(value = "displayDescription") + private String displayDescription; + + /** + * The unit that the metric is measured in. + */ + @JsonProperty(value = "unit") + private String unit; + + /** + * The type of metric aggregation. + */ + @JsonProperty(value = "aggregationType") + private String aggregationType; + + /** + * Whether or not the service is using regional MDM accounts. + */ + @JsonProperty(value = "enableRegionalMdmAccount") + private String enableRegionalMdmAccount; + + /** + * The name of the MDM account. + */ + @JsonProperty(value = "sourceMdmAccount") + private String sourceMdmAccount; + + /** + * The name of the MDM namespace. + */ + @JsonProperty(value = "sourceMdmNamespace") + private String sourceMdmNamespace; + + /** + * Defines how often data for metrics becomes available. + */ + @JsonProperty(value = "availabilities") + private List availabilities; + + /** + * Get the name of the metric. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set the name of the metric. + * + * @param name the name value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withName(String name) { + this.name = name; + return this; + } + + /** + * Get localized display name of the metric. + * + * @return the displayName value + */ + public String displayName() { + return this.displayName; + } + + /** + * Set localized display name of the metric. + * + * @param displayName the displayName value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + /** + * Get the description of the metric. + * + * @return the displayDescription value + */ + public String displayDescription() { + return this.displayDescription; + } + + /** + * Set the description of the metric. + * + * @param displayDescription the displayDescription value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withDisplayDescription(String displayDescription) { + this.displayDescription = displayDescription; + return this; + } + + /** + * Get the unit that the metric is measured in. + * + * @return the unit value + */ + public String unit() { + return this.unit; + } + + /** + * Set the unit that the metric is measured in. + * + * @param unit the unit value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withUnit(String unit) { + this.unit = unit; + return this; + } + + /** + * Get the type of metric aggregation. + * + * @return the aggregationType value + */ + public String aggregationType() { + return this.aggregationType; + } + + /** + * Set the type of metric aggregation. + * + * @param aggregationType the aggregationType value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withAggregationType(String aggregationType) { + this.aggregationType = aggregationType; + return this; + } + + /** + * Get whether or not the service is using regional MDM accounts. + * + * @return the enableRegionalMdmAccount value + */ + public String enableRegionalMdmAccount() { + return this.enableRegionalMdmAccount; + } + + /** + * Set whether or not the service is using regional MDM accounts. + * + * @param enableRegionalMdmAccount the enableRegionalMdmAccount value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withEnableRegionalMdmAccount(String enableRegionalMdmAccount) { + this.enableRegionalMdmAccount = enableRegionalMdmAccount; + return this; + } + + /** + * Get the name of the MDM account. + * + * @return the sourceMdmAccount value + */ + public String sourceMdmAccount() { + return this.sourceMdmAccount; + } + + /** + * Set the name of the MDM account. + * + * @param sourceMdmAccount the sourceMdmAccount value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withSourceMdmAccount(String sourceMdmAccount) { + this.sourceMdmAccount = sourceMdmAccount; + return this; + } + + /** + * Get the name of the MDM namespace. + * + * @return the sourceMdmNamespace value + */ + public String sourceMdmNamespace() { + return this.sourceMdmNamespace; + } + + /** + * Set the name of the MDM namespace. + * + * @param sourceMdmNamespace the sourceMdmNamespace value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withSourceMdmNamespace(String sourceMdmNamespace) { + this.sourceMdmNamespace = sourceMdmNamespace; + return this; + } + + /** + * Get defines how often data for metrics becomes available. + * + * @return the availabilities value + */ + public List availabilities() { + return this.availabilities; + } + + /** + * Set defines how often data for metrics becomes available. + * + * @param availabilities the availabilities value to set + * @return the OperationMetricSpecification object itself. + */ + public OperationMetricSpecification withAvailabilities(List availabilities) { + this.availabilities = availabilities; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationServiceSpecification.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationServiceSpecification.java new file mode 100644 index 000000000000..c76a280fe0fc --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OperationServiceSpecification.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Details about a service operation. + */ +public class OperationServiceSpecification { + /** + * Details about operations related to logs. + */ + @JsonProperty(value = "logSpecifications") + private List logSpecifications; + + /** + * Details about operations related to metrics. + */ + @JsonProperty(value = "metricSpecifications") + private List metricSpecifications; + + /** + * Get details about operations related to logs. + * + * @return the logSpecifications value + */ + public List logSpecifications() { + return this.logSpecifications; + } + + /** + * Set details about operations related to logs. + * + * @param logSpecifications the logSpecifications value to set + * @return the OperationServiceSpecification object itself. + */ + public OperationServiceSpecification withLogSpecifications(List logSpecifications) { + this.logSpecifications = logSpecifications; + return this; + } + + /** + * Get details about operations related to metrics. + * + * @return the metricSpecifications value + */ + public List metricSpecifications() { + return this.metricSpecifications; + } + + /** + * Set details about operations related to metrics. + * + * @param metricSpecifications the metricSpecifications value to set + * @return the OperationServiceSpecification object itself. + */ + public OperationServiceSpecification withMetricSpecifications(List metricSpecifications) { + this.metricSpecifications = metricSpecifications; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Operations.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Operations.java new file mode 100644 index 000000000000..9a456cc018cb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Operations.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.OperationsInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing Operations. + */ +public interface Operations extends HasInner { + /** + * Lists the available Azure Data Factory API operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listAsync(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleLinkedService.java new file mode 100644 index 000000000000..73506b7e1078 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Oracle database. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Oracle") +@JsonFlatten +public class OracleLinkedService extends LinkedServiceInner { + /** + * The connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the OracleLinkedService object itself. + */ + public OracleLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the OracleLinkedService object itself. + */ + public OracleLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleSink.java new file mode 100644 index 000000000000..5257a223371a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleSink.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Oracle sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("OracleSink") +public class OracleSink extends CopySink { + /** + * SQL pre-copy script. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "preCopyScript") + private Object preCopyScript; + + /** + * Get sQL pre-copy script. Type: string (or Expression with resultType string). + * + * @return the preCopyScript value + */ + public Object preCopyScript() { + return this.preCopyScript; + } + + /** + * Set sQL pre-copy script. Type: string (or Expression with resultType string). + * + * @param preCopyScript the preCopyScript value to set + * @return the OracleSink object itself. + */ + public OracleSink withPreCopyScript(Object preCopyScript) { + this.preCopyScript = preCopyScript; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleSource.java new file mode 100644 index 000000000000..6380ced71a7a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleSource.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Oracle source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("OracleSource") +public class OracleSource extends CopySource { + /** + * Oracle reader query. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "oracleReaderQuery") + private Object oracleReaderQuery; + + /** + * Query timeout. Type: string (or Expression with resultType string), + * pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "queryTimeout") + private Object queryTimeout; + + /** + * Get oracle reader query. Type: string (or Expression with resultType string). + * + * @return the oracleReaderQuery value + */ + public Object oracleReaderQuery() { + return this.oracleReaderQuery; + } + + /** + * Set oracle reader query. Type: string (or Expression with resultType string). + * + * @param oracleReaderQuery the oracleReaderQuery value to set + * @return the OracleSource object itself. + */ + public OracleSource withOracleReaderQuery(Object oracleReaderQuery) { + this.oracleReaderQuery = oracleReaderQuery; + return this; + } + + /** + * Get query timeout. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the queryTimeout value + */ + public Object queryTimeout() { + return this.queryTimeout; + } + + /** + * Set query timeout. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param queryTimeout the queryTimeout value to set + * @return the OracleSource object itself. + */ + public OracleSource withQueryTimeout(Object queryTimeout) { + this.queryTimeout = queryTimeout; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleTableDataset.java new file mode 100644 index 000000000000..45fdfd0f0b30 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OracleTableDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The on-premises Oracle database dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("OracleTable") +@JsonFlatten +public class OracleTableDataset extends DatasetInner { + /** + * The table name of the on-premises Oracle database. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.tableName", required = true) + private Object tableName; + + /** + * Get the table name of the on-premises Oracle database. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the table name of the on-premises Oracle database. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the OracleTableDataset object itself. + */ + public OracleTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OrcFormat.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OrcFormat.java new file mode 100644 index 000000000000..ce4c0e8388ef --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/OrcFormat.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The data stored in Optimized Row Columnar (ORC) format. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("OrcFormat") +public class OrcFormat extends DatasetStorageFormat { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParameterSpecification.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParameterSpecification.java new file mode 100644 index 000000000000..d15bf0ecb16e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParameterSpecification.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Definition of a single parameter for an entity. + */ +public class ParameterSpecification { + /** + * Parameter type. Possible values include: 'Object', 'String', 'Int', + * 'Float', 'Bool', 'Array', 'SecureString'. + */ + @JsonProperty(value = "type", required = true) + private ParameterType type; + + /** + * Default value of parameter. + */ + @JsonProperty(value = "defaultValue") + private Object defaultValue; + + /** + * Get parameter type. Possible values include: 'Object', 'String', 'Int', 'Float', 'Bool', 'Array', 'SecureString'. + * + * @return the type value + */ + public ParameterType type() { + return this.type; + } + + /** + * Set parameter type. Possible values include: 'Object', 'String', 'Int', 'Float', 'Bool', 'Array', 'SecureString'. + * + * @param type the type value to set + * @return the ParameterSpecification object itself. + */ + public ParameterSpecification withType(ParameterType type) { + this.type = type; + return this; + } + + /** + * Get default value of parameter. + * + * @return the defaultValue value + */ + public Object defaultValue() { + return this.defaultValue; + } + + /** + * Set default value of parameter. + * + * @param defaultValue the defaultValue value to set + * @return the ParameterSpecification object itself. + */ + public ParameterSpecification withDefaultValue(Object defaultValue) { + this.defaultValue = defaultValue; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParameterType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParameterType.java new file mode 100644 index 000000000000..9d0d46295b92 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParameterType.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ParameterType. + */ +public final class ParameterType extends ExpandableStringEnum { + /** Static value Object for ParameterType. */ + public static final ParameterType OBJECT = fromString("Object"); + + /** Static value String for ParameterType. */ + public static final ParameterType STRING = fromString("String"); + + /** Static value Int for ParameterType. */ + public static final ParameterType INT = fromString("Int"); + + /** Static value Float for ParameterType. */ + public static final ParameterType FLOAT = fromString("Float"); + + /** Static value Bool for ParameterType. */ + public static final ParameterType BOOL = fromString("Bool"); + + /** Static value Array for ParameterType. */ + public static final ParameterType ARRAY = fromString("Array"); + + /** Static value SecureString for ParameterType. */ + public static final ParameterType SECURE_STRING = fromString("SecureString"); + + /** + * Creates or finds a ParameterType from its string representation. + * @param name a name to look for + * @return the corresponding ParameterType + */ + @JsonCreator + public static ParameterType fromString(String name) { + return fromString(name, ParameterType.class); + } + + /** + * @return known ParameterType values + */ + public static Collection values() { + return values(ParameterType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParquetFormat.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParquetFormat.java new file mode 100644 index 000000000000..afde3f764dc3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ParquetFormat.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The data stored in Parquet format. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ParquetFormat") +public class ParquetFormat extends DatasetStorageFormat { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalLinkedService.java new file mode 100644 index 000000000000..a9bbf319c446 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalLinkedService.java @@ -0,0 +1,212 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Paypal Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Paypal") +@JsonFlatten +public class PaypalLinkedService extends LinkedServiceInner { + /** + * The URL of the PayPal instance. (i.e. api.sandbox.paypal.com). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The client ID associated with your PayPal application. + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * The client secret associated with your PayPal application. + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the URL of the PayPal instance. (i.e. api.sandbox.paypal.com). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the URL of the PayPal instance. (i.e. api.sandbox.paypal.com). + * + * @param host the host value to set + * @return the PaypalLinkedService object itself. + */ + public PaypalLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the client ID associated with your PayPal application. + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set the client ID associated with your PayPal application. + * + * @param clientId the clientId value to set + * @return the PaypalLinkedService object itself. + */ + public PaypalLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret associated with your PayPal application. + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret associated with your PayPal application. + * + * @param clientSecret the clientSecret value to set + * @return the PaypalLinkedService object itself. + */ + public PaypalLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the PaypalLinkedService object itself. + */ + public PaypalLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the PaypalLinkedService object itself. + */ + public PaypalLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the PaypalLinkedService object itself. + */ + public PaypalLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the PaypalLinkedService object itself. + */ + public PaypalLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalObjectDataset.java new file mode 100644 index 000000000000..7ee5b4ce5436 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Paypal Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("PaypalObject") +public class PaypalObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalSource.java new file mode 100644 index 000000000000..4e1a8380af94 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PaypalSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Paypal Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("PaypalSource") +public class PaypalSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the PaypalSource object itself. + */ + public PaypalSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixAuthenticationType.java new file mode 100644 index 000000000000..910b15074755 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixAuthenticationType.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for PhoenixAuthenticationType. + */ +public final class PhoenixAuthenticationType extends ExpandableStringEnum { + /** Static value Anonymous for PhoenixAuthenticationType. */ + public static final PhoenixAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** Static value UsernameAndPassword for PhoenixAuthenticationType. */ + public static final PhoenixAuthenticationType USERNAME_AND_PASSWORD = fromString("UsernameAndPassword"); + + /** Static value WindowsAzureHDInsightService for PhoenixAuthenticationType. */ + public static final PhoenixAuthenticationType WINDOWS_AZURE_HDINSIGHT_SERVICE = fromString("WindowsAzureHDInsightService"); + + /** + * Creates or finds a PhoenixAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding PhoenixAuthenticationType + */ + @JsonCreator + public static PhoenixAuthenticationType fromString(String name) { + return fromString(name, PhoenixAuthenticationType.class); + } + + /** + * @return known PhoenixAuthenticationType values + */ + public static Collection values() { + return values(PhoenixAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixLinkedService.java new file mode 100644 index 000000000000..a4a0c1c5f9f7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixLinkedService.java @@ -0,0 +1,352 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Phoenix server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Phoenix") +@JsonFlatten +public class PhoenixLinkedService extends LinkedServiceInner { + /** + * The IP address or host name of the Phoenix server. (i.e. + * 192.168.222.160). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port that the Phoenix server uses to listen for client + * connections. The default value is 8765. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The partial URL corresponding to the Phoenix server. (i.e. + * /gateway/sandbox/phoenix/version). The default value is hbasephoenix if + * using WindowsAzureHDInsightService. + */ + @JsonProperty(value = "typeProperties.httpPath") + private Object httpPath; + + /** + * The authentication mechanism used to connect to the Phoenix server. + * Possible values include: 'Anonymous', 'UsernameAndPassword', + * 'WindowsAzureHDInsightService'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private PhoenixAuthenticationType authenticationType; + + /** + * The user name used to connect to the Phoenix server. + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password corresponding to the user name. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Specifies whether the connections to the server are encrypted using SSL. + * The default value is false. + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * The full path of the .pem file containing trusted CA certificates for + * verifying the server when connecting over SSL. This property can only be + * set when using SSL on self-hosted IR. The default value is the + * cacerts.pem file installed with the IR. + */ + @JsonProperty(value = "typeProperties.trustedCertPath") + private Object trustedCertPath; + + /** + * Specifies whether to use a CA certificate from the system trust store or + * from a specified PEM file. The default value is false. + */ + @JsonProperty(value = "typeProperties.useSystemTrustStore") + private Object useSystemTrustStore; + + /** + * Specifies whether to require a CA-issued SSL certificate name to match + * the host name of the server when connecting over SSL. The default value + * is false. + */ + @JsonProperty(value = "typeProperties.allowHostNameCNMismatch") + private Object allowHostNameCNMismatch; + + /** + * Specifies whether to allow self-signed certificates from the server. The + * default value is false. + */ + @JsonProperty(value = "typeProperties.allowSelfSignedServerCert") + private Object allowSelfSignedServerCert; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the IP address or host name of the Phoenix server. (i.e. 192.168.222.160). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the IP address or host name of the Phoenix server. (i.e. 192.168.222.160). + * + * @param host the host value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port that the Phoenix server uses to listen for client connections. The default value is 8765. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port that the Phoenix server uses to listen for client connections. The default value is 8765. + * + * @param port the port value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the partial URL corresponding to the Phoenix server. (i.e. /gateway/sandbox/phoenix/version). The default value is hbasephoenix if using WindowsAzureHDInsightService. + * + * @return the httpPath value + */ + public Object httpPath() { + return this.httpPath; + } + + /** + * Set the partial URL corresponding to the Phoenix server. (i.e. /gateway/sandbox/phoenix/version). The default value is hbasephoenix if using WindowsAzureHDInsightService. + * + * @param httpPath the httpPath value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withHttpPath(Object httpPath) { + this.httpPath = httpPath; + return this; + } + + /** + * Get the authentication mechanism used to connect to the Phoenix server. Possible values include: 'Anonymous', 'UsernameAndPassword', 'WindowsAzureHDInsightService'. + * + * @return the authenticationType value + */ + public PhoenixAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication mechanism used to connect to the Phoenix server. Possible values include: 'Anonymous', 'UsernameAndPassword', 'WindowsAzureHDInsightService'. + * + * @param authenticationType the authenticationType value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withAuthenticationType(PhoenixAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the user name used to connect to the Phoenix server. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name used to connect to the Phoenix server. + * + * @param username the username value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name. + * + * @param password the password value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @param enableSsl the enableSsl value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @return the trustedCertPath value + */ + public Object trustedCertPath() { + return this.trustedCertPath; + } + + /** + * Set the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @param trustedCertPath the trustedCertPath value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withTrustedCertPath(Object trustedCertPath) { + this.trustedCertPath = trustedCertPath; + return this; + } + + /** + * Get specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @return the useSystemTrustStore value + */ + public Object useSystemTrustStore() { + return this.useSystemTrustStore; + } + + /** + * Set specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @param useSystemTrustStore the useSystemTrustStore value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withUseSystemTrustStore(Object useSystemTrustStore) { + this.useSystemTrustStore = useSystemTrustStore; + return this; + } + + /** + * Get specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @return the allowHostNameCNMismatch value + */ + public Object allowHostNameCNMismatch() { + return this.allowHostNameCNMismatch; + } + + /** + * Set specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @param allowHostNameCNMismatch the allowHostNameCNMismatch value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withAllowHostNameCNMismatch(Object allowHostNameCNMismatch) { + this.allowHostNameCNMismatch = allowHostNameCNMismatch; + return this; + } + + /** + * Get specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @return the allowSelfSignedServerCert value + */ + public Object allowSelfSignedServerCert() { + return this.allowSelfSignedServerCert; + } + + /** + * Set specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @param allowSelfSignedServerCert the allowSelfSignedServerCert value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withAllowSelfSignedServerCert(Object allowSelfSignedServerCert) { + this.allowSelfSignedServerCert = allowSelfSignedServerCert; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the PhoenixLinkedService object itself. + */ + public PhoenixLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixObjectDataset.java new file mode 100644 index 000000000000..0006100a7879 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Phoenix server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("PhoenixObject") +public class PhoenixObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixSource.java new file mode 100644 index 000000000000..0578bd4fd517 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PhoenixSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Phoenix server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("PhoenixSource") +public class PhoenixSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the PhoenixSource object itself. + */ + public PhoenixSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineReference.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineReference.java new file mode 100644 index 000000000000..3a8da61c76f1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineReference.java @@ -0,0 +1,103 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Pipeline reference type. + */ +public class PipelineReference { + /** + * Pipeline reference type. + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * Reference pipeline name. + */ + @JsonProperty(value = "referenceName", required = true) + private String referenceName; + + /** + * Reference name. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Creates an instance of PipelineReference class. + * @param referenceName reference pipeline name. + */ + public PipelineReference() { + type = "PipelineReference"; + } + + /** + * Get pipeline reference type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set pipeline reference type. + * + * @param type the type value to set + * @return the PipelineReference object itself. + */ + public PipelineReference withType(String type) { + this.type = type; + return this; + } + + /** + * Get reference pipeline name. + * + * @return the referenceName value + */ + public String referenceName() { + return this.referenceName; + } + + /** + * Set reference pipeline name. + * + * @param referenceName the referenceName value to set + * @return the PipelineReference object itself. + */ + public PipelineReference withReferenceName(String referenceName) { + this.referenceName = referenceName; + return this; + } + + /** + * Get reference name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set reference name. + * + * @param name the name value to set + * @return the PipelineReference object itself. + */ + public PipelineReference withName(String name) { + this.name = name; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineResource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineResource.java new file mode 100644 index 000000000000..4a9d1a5c8627 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineResource.java @@ -0,0 +1,293 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.PipelineResourceInner; +import com.microsoft.azure.arm.model.Indexable; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import java.util.Map; +import java.util.List; + +/** + * Type representing PipelineResource. + */ +public interface PipelineResource extends HasInner, Indexable, Refreshable, Updatable, HasManager { + /** + * @return the activities value. + */ + List activities(); + + /** + * @return the additionalProperties value. + */ + Map additionalProperties(); + + /** + * @return the annotations value. + */ + List annotations(); + + /** + * @return the concurrency value. + */ + Integer concurrency(); + + /** + * @return the description value. + */ + String description(); + + /** + * @return the etag value. + */ + String etag(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the parameters value. + */ + Map parameters(); + + /** + * @return the type value. + */ + String type(); + + /** + * The entirety of the PipelineResource definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithFactory, DefinitionStages.WithIfMatch, DefinitionStages.WithCreate { + } + + /** + * Grouping of PipelineResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a PipelineResource definition. + */ + interface Blank extends WithFactory { + } + + /** + * The stage of the pipelineresource definition allowing to specify Factory. + */ + interface WithFactory { + /** + * Specifies resourceGroupName, factoryName. + * @param resourceGroupName The resource group name + * @param factoryName The factory name + * @return the next definition stage + */ + WithIfMatch withExistingFactory(String resourceGroupName, String factoryName); + } + + /** + * The stage of the pipelineresource definition allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the pipeline entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next definition stage + */ + WithCreate withIfMatch(String ifMatch); + } + + /** + * The stage of the pipelineresource definition allowing to specify Activities. + */ + interface WithActivities { + /** + * Specifies activities. + * @param activities List of activities in pipeline + * @return the next definition stage + */ + WithCreate withActivities(List activities); + } + + /** + * The stage of the pipelineresource definition allowing to specify AdditionalProperties. + */ + interface WithAdditionalProperties { + /** + * Specifies additionalProperties. + * @param additionalProperties Unmatched properties from the message are deserialized this collection + * @return the next definition stage + */ + WithCreate withAdditionalProperties(Map additionalProperties); + } + + /** + * The stage of the pipelineresource definition allowing to specify Annotations. + */ + interface WithAnnotations { + /** + * Specifies annotations. + * @param annotations List of tags that can be used for describing the Pipeline + * @return the next definition stage + */ + WithCreate withAnnotations(List annotations); + } + + /** + * The stage of the pipelineresource definition allowing to specify Concurrency. + */ + interface WithConcurrency { + /** + * Specifies concurrency. + * @param concurrency The max number of concurrent runs for the pipeline + * @return the next definition stage + */ + WithCreate withConcurrency(Integer concurrency); + } + + /** + * The stage of the pipelineresource definition allowing to specify Description. + */ + interface WithDescription { + /** + * Specifies description. + * @param description The description of the pipeline + * @return the next definition stage + */ + WithCreate withDescription(String description); + } + + /** + * The stage of the pipelineresource definition allowing to specify Parameters. + */ + interface WithParameters { + /** + * Specifies parameters. + * @param parameters List of parameters for pipeline + * @return the next definition stage + */ + WithCreate withParameters(Map parameters); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable, DefinitionStages.WithActivities, DefinitionStages.WithAdditionalProperties, DefinitionStages.WithAnnotations, DefinitionStages.WithConcurrency, DefinitionStages.WithDescription, DefinitionStages.WithParameters { + } + } + /** + * The template for a PipelineResource update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, UpdateStages.WithIfMatch, UpdateStages.WithActivities, UpdateStages.WithAdditionalProperties, UpdateStages.WithAnnotations, UpdateStages.WithConcurrency, UpdateStages.WithDescription, UpdateStages.WithParameters { + } + + /** + * Grouping of PipelineResource update stages. + */ + interface UpdateStages { + /** + * The stage of the pipelineresource update allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the pipeline entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next update stage + */ + Update withIfMatch(String ifMatch); + } + + /** + * The stage of the pipelineresource update allowing to specify Activities. + */ + interface WithActivities { + /** + * Specifies activities. + * @param activities List of activities in pipeline + * @return the next update stage + */ + Update withActivities(List activities); + } + + /** + * The stage of the pipelineresource update allowing to specify AdditionalProperties. + */ + interface WithAdditionalProperties { + /** + * Specifies additionalProperties. + * @param additionalProperties Unmatched properties from the message are deserialized this collection + * @return the next update stage + */ + Update withAdditionalProperties(Map additionalProperties); + } + + /** + * The stage of the pipelineresource update allowing to specify Annotations. + */ + interface WithAnnotations { + /** + * Specifies annotations. + * @param annotations List of tags that can be used for describing the Pipeline + * @return the next update stage + */ + Update withAnnotations(List annotations); + } + + /** + * The stage of the pipelineresource update allowing to specify Concurrency. + */ + interface WithConcurrency { + /** + * Specifies concurrency. + * @param concurrency The max number of concurrent runs for the pipeline + * @return the next update stage + */ + Update withConcurrency(Integer concurrency); + } + + /** + * The stage of the pipelineresource update allowing to specify Description. + */ + interface WithDescription { + /** + * Specifies description. + * @param description The description of the pipeline + * @return the next update stage + */ + Update withDescription(String description); + } + + /** + * The stage of the pipelineresource update allowing to specify Parameters. + */ + interface WithParameters { + /** + * Specifies parameters. + * @param parameters List of parameters for pipeline + * @return the next update stage + */ + Update withParameters(Map parameters); + } + + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRun.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRun.java new file mode 100644 index 000000000000..4ac78eda66e7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRun.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.PipelineRunInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import java.util.Map; +import org.joda.time.DateTime; + +/** + * Type representing PipelineRun. + */ +public interface PipelineRun extends HasInner, HasManager { + /** + * @return the additionalProperties value. + */ + Map additionalProperties(); + + /** + * @return the durationInMs value. + */ + Integer durationInMs(); + + /** + * @return the invokedBy value. + */ + PipelineRunInvokedBy invokedBy(); + + /** + * @return the lastUpdated value. + */ + DateTime lastUpdated(); + + /** + * @return the message value. + */ + String message(); + + /** + * @return the parameters value. + */ + Map parameters(); + + /** + * @return the pipelineName value. + */ + String pipelineName(); + + /** + * @return the runEnd value. + */ + DateTime runEnd(); + + /** + * @return the runId value. + */ + String runId(); + + /** + * @return the runStart value. + */ + DateTime runStart(); + + /** + * @return the status value. + */ + String status(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunFilterParameters.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunFilterParameters.java new file mode 100644 index 000000000000..c04b844926a6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunFilterParameters.java @@ -0,0 +1,152 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import org.joda.time.DateTime; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Query parameters for listing pipeline runs. + */ +public class PipelineRunFilterParameters { + /** + * The continuation token for getting the next page of results. Null for + * first page. + */ + @JsonProperty(value = "continuationToken") + private String continuationToken; + + /** + * The time at or after which the pipeline run event was updated in 'ISO + * 8601' format. + */ + @JsonProperty(value = "lastUpdatedAfter", required = true) + private DateTime lastUpdatedAfter; + + /** + * The time at or before which the pipeline run event was updated in 'ISO + * 8601' format. + */ + @JsonProperty(value = "lastUpdatedBefore", required = true) + private DateTime lastUpdatedBefore; + + /** + * List of filters. + */ + @JsonProperty(value = "filters") + private List filters; + + /** + * List of OrderBy option. + */ + @JsonProperty(value = "orderBy") + private List orderBy; + + /** + * Get the continuation token for getting the next page of results. Null for first page. + * + * @return the continuationToken value + */ + public String continuationToken() { + return this.continuationToken; + } + + /** + * Set the continuation token for getting the next page of results. Null for first page. + * + * @param continuationToken the continuationToken value to set + * @return the PipelineRunFilterParameters object itself. + */ + public PipelineRunFilterParameters withContinuationToken(String continuationToken) { + this.continuationToken = continuationToken; + return this; + } + + /** + * Get the time at or after which the pipeline run event was updated in 'ISO 8601' format. + * + * @return the lastUpdatedAfter value + */ + public DateTime lastUpdatedAfter() { + return this.lastUpdatedAfter; + } + + /** + * Set the time at or after which the pipeline run event was updated in 'ISO 8601' format. + * + * @param lastUpdatedAfter the lastUpdatedAfter value to set + * @return the PipelineRunFilterParameters object itself. + */ + public PipelineRunFilterParameters withLastUpdatedAfter(DateTime lastUpdatedAfter) { + this.lastUpdatedAfter = lastUpdatedAfter; + return this; + } + + /** + * Get the time at or before which the pipeline run event was updated in 'ISO 8601' format. + * + * @return the lastUpdatedBefore value + */ + public DateTime lastUpdatedBefore() { + return this.lastUpdatedBefore; + } + + /** + * Set the time at or before which the pipeline run event was updated in 'ISO 8601' format. + * + * @param lastUpdatedBefore the lastUpdatedBefore value to set + * @return the PipelineRunFilterParameters object itself. + */ + public PipelineRunFilterParameters withLastUpdatedBefore(DateTime lastUpdatedBefore) { + this.lastUpdatedBefore = lastUpdatedBefore; + return this; + } + + /** + * Get list of filters. + * + * @return the filters value + */ + public List filters() { + return this.filters; + } + + /** + * Set list of filters. + * + * @param filters the filters value to set + * @return the PipelineRunFilterParameters object itself. + */ + public PipelineRunFilterParameters withFilters(List filters) { + this.filters = filters; + return this; + } + + /** + * Get list of OrderBy option. + * + * @return the orderBy value + */ + public List orderBy() { + return this.orderBy; + } + + /** + * Set list of OrderBy option. + * + * @param orderBy the orderBy value to set + * @return the PipelineRunFilterParameters object itself. + */ + public PipelineRunFilterParameters withOrderBy(List orderBy) { + this.orderBy = orderBy; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunInvokedBy.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunInvokedBy.java new file mode 100644 index 000000000000..746e0f07baaf --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunInvokedBy.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Provides entity name and id that started the pipeline run. + */ +public class PipelineRunInvokedBy { + /** + * Name of the entity that started the pipeline run. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The ID of the entity that started the run. + */ + @JsonProperty(value = "id", access = JsonProperty.Access.WRITE_ONLY) + private String id; + + /** + * Get name of the entity that started the pipeline run. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the ID of the entity that started the run. + * + * @return the id value + */ + public String id() { + return this.id; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilter.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilter.java new file mode 100644 index 000000000000..e0007fe5915b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilter.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Query filter option for listing pipeline runs. + */ +public class PipelineRunQueryFilter { + /** + * Parameter name to be used for filter. Possible values include: + * 'PipelineName', 'Status', 'RunStart', 'RunEnd'. + */ + @JsonProperty(value = "operand", required = true) + private PipelineRunQueryFilterOperand operand; + + /** + * Operator to be used for filter. Possible values include: 'Equals', + * 'NotEquals', 'In', 'NotIn'. + */ + @JsonProperty(value = "operator", required = true) + private PipelineRunQueryFilterOperator operator; + + /** + * List of filter values. + */ + @JsonProperty(value = "values", required = true) + private List values; + + /** + * Get parameter name to be used for filter. Possible values include: 'PipelineName', 'Status', 'RunStart', 'RunEnd'. + * + * @return the operand value + */ + public PipelineRunQueryFilterOperand operand() { + return this.operand; + } + + /** + * Set parameter name to be used for filter. Possible values include: 'PipelineName', 'Status', 'RunStart', 'RunEnd'. + * + * @param operand the operand value to set + * @return the PipelineRunQueryFilter object itself. + */ + public PipelineRunQueryFilter withOperand(PipelineRunQueryFilterOperand operand) { + this.operand = operand; + return this; + } + + /** + * Get operator to be used for filter. Possible values include: 'Equals', 'NotEquals', 'In', 'NotIn'. + * + * @return the operator value + */ + public PipelineRunQueryFilterOperator operator() { + return this.operator; + } + + /** + * Set operator to be used for filter. Possible values include: 'Equals', 'NotEquals', 'In', 'NotIn'. + * + * @param operator the operator value to set + * @return the PipelineRunQueryFilter object itself. + */ + public PipelineRunQueryFilter withOperator(PipelineRunQueryFilterOperator operator) { + this.operator = operator; + return this; + } + + /** + * Get list of filter values. + * + * @return the values value + */ + public List values() { + return this.values; + } + + /** + * Set list of filter values. + * + * @param values the values value to set + * @return the PipelineRunQueryFilter object itself. + */ + public PipelineRunQueryFilter withValues(List values) { + this.values = values; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilterOperand.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilterOperand.java new file mode 100644 index 000000000000..ee9a96a4694c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilterOperand.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for PipelineRunQueryFilterOperand. + */ +public final class PipelineRunQueryFilterOperand extends ExpandableStringEnum { + /** Static value PipelineName for PipelineRunQueryFilterOperand. */ + public static final PipelineRunQueryFilterOperand PIPELINE_NAME = fromString("PipelineName"); + + /** Static value Status for PipelineRunQueryFilterOperand. */ + public static final PipelineRunQueryFilterOperand STATUS = fromString("Status"); + + /** Static value RunStart for PipelineRunQueryFilterOperand. */ + public static final PipelineRunQueryFilterOperand RUN_START = fromString("RunStart"); + + /** Static value RunEnd for PipelineRunQueryFilterOperand. */ + public static final PipelineRunQueryFilterOperand RUN_END = fromString("RunEnd"); + + /** + * Creates or finds a PipelineRunQueryFilterOperand from its string representation. + * @param name a name to look for + * @return the corresponding PipelineRunQueryFilterOperand + */ + @JsonCreator + public static PipelineRunQueryFilterOperand fromString(String name) { + return fromString(name, PipelineRunQueryFilterOperand.class); + } + + /** + * @return known PipelineRunQueryFilterOperand values + */ + public static Collection values() { + return values(PipelineRunQueryFilterOperand.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilterOperator.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilterOperator.java new file mode 100644 index 000000000000..af713a8d8c32 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryFilterOperator.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for PipelineRunQueryFilterOperator. + */ +public final class PipelineRunQueryFilterOperator extends ExpandableStringEnum { + /** Static value Equals for PipelineRunQueryFilterOperator. */ + public static final PipelineRunQueryFilterOperator EQUALS = fromString("Equals"); + + /** Static value NotEquals for PipelineRunQueryFilterOperator. */ + public static final PipelineRunQueryFilterOperator NOT_EQUALS = fromString("NotEquals"); + + /** Static value In for PipelineRunQueryFilterOperator. */ + public static final PipelineRunQueryFilterOperator IN = fromString("In"); + + /** Static value NotIn for PipelineRunQueryFilterOperator. */ + public static final PipelineRunQueryFilterOperator NOT_IN = fromString("NotIn"); + + /** + * Creates or finds a PipelineRunQueryFilterOperator from its string representation. + * @param name a name to look for + * @return the corresponding PipelineRunQueryFilterOperator + */ + @JsonCreator + public static PipelineRunQueryFilterOperator fromString(String name) { + return fromString(name, PipelineRunQueryFilterOperator.class); + } + + /** + * @return known PipelineRunQueryFilterOperator values + */ + public static Collection values() { + return values(PipelineRunQueryFilterOperator.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrder.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrder.java new file mode 100644 index 000000000000..50588bce5412 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrder.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for PipelineRunQueryOrder. + */ +public final class PipelineRunQueryOrder extends ExpandableStringEnum { + /** Static value ASC for PipelineRunQueryOrder. */ + public static final PipelineRunQueryOrder ASC = fromString("ASC"); + + /** Static value DESC for PipelineRunQueryOrder. */ + public static final PipelineRunQueryOrder DESC = fromString("DESC"); + + /** + * Creates or finds a PipelineRunQueryOrder from its string representation. + * @param name a name to look for + * @return the corresponding PipelineRunQueryOrder + */ + @JsonCreator + public static PipelineRunQueryOrder fromString(String name) { + return fromString(name, PipelineRunQueryOrder.class); + } + + /** + * @return known PipelineRunQueryOrder values + */ + public static Collection values() { + return values(PipelineRunQueryOrder.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrderBy.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrderBy.java new file mode 100644 index 000000000000..d84c8b8a3396 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrderBy.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * An object to provide order by options for listing pipeline runs. + */ +public class PipelineRunQueryOrderBy { + /** + * Parameter name to be used for order by. Possible values include: + * 'RunStart', 'RunEnd'. + */ + @JsonProperty(value = "orderBy", required = true) + private PipelineRunQueryOrderByField orderBy; + + /** + * Sorting order of the parameter. Possible values include: 'ASC', 'DESC'. + */ + @JsonProperty(value = "order", required = true) + private PipelineRunQueryOrder order; + + /** + * Get parameter name to be used for order by. Possible values include: 'RunStart', 'RunEnd'. + * + * @return the orderBy value + */ + public PipelineRunQueryOrderByField orderBy() { + return this.orderBy; + } + + /** + * Set parameter name to be used for order by. Possible values include: 'RunStart', 'RunEnd'. + * + * @param orderBy the orderBy value to set + * @return the PipelineRunQueryOrderBy object itself. + */ + public PipelineRunQueryOrderBy withOrderBy(PipelineRunQueryOrderByField orderBy) { + this.orderBy = orderBy; + return this; + } + + /** + * Get sorting order of the parameter. Possible values include: 'ASC', 'DESC'. + * + * @return the order value + */ + public PipelineRunQueryOrder order() { + return this.order; + } + + /** + * Set sorting order of the parameter. Possible values include: 'ASC', 'DESC'. + * + * @param order the order value to set + * @return the PipelineRunQueryOrderBy object itself. + */ + public PipelineRunQueryOrderBy withOrder(PipelineRunQueryOrder order) { + this.order = order; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrderByField.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrderByField.java new file mode 100644 index 000000000000..af1bec151e2a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryOrderByField.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for PipelineRunQueryOrderByField. + */ +public final class PipelineRunQueryOrderByField extends ExpandableStringEnum { + /** Static value RunStart for PipelineRunQueryOrderByField. */ + public static final PipelineRunQueryOrderByField RUN_START = fromString("RunStart"); + + /** Static value RunEnd for PipelineRunQueryOrderByField. */ + public static final PipelineRunQueryOrderByField RUN_END = fromString("RunEnd"); + + /** + * Creates or finds a PipelineRunQueryOrderByField from its string representation. + * @param name a name to look for + * @return the corresponding PipelineRunQueryOrderByField + */ + @JsonCreator + public static PipelineRunQueryOrderByField fromString(String name) { + return fromString(name, PipelineRunQueryOrderByField.class); + } + + /** + * @return known PipelineRunQueryOrderByField values + */ + public static Collection values() { + return values(PipelineRunQueryOrderByField.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryResponse.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryResponse.java new file mode 100644 index 000000000000..6a6908e7946b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRunQueryResponse.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.PipelineRunQueryResponseInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.PipelineRunInner; +import java.util.List; + +/** + * Type representing PipelineRunQueryResponse. + */ +public interface PipelineRunQueryResponse extends HasInner, HasManager { + /** + * @return the continuationToken value. + */ + String continuationToken(); + + /** + * @return the value value. + */ + List value(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRuns.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRuns.java new file mode 100644 index 000000000000..5aa234f89c51 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PipelineRuns.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.PipelineRunsInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing PipelineRuns. + */ +public interface PipelineRuns extends HasInner { + /** + * Get a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAsync(String resourceGroupName, String factoryName, String runId); + + /** + * Query pipeline runs in the factory based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param filterParameters Parameters to filter the pipeline run. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable queryByFactoryAsync(String resourceGroupName, String factoryName, PipelineRunFilterParameters filterParameters); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Pipelines.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Pipelines.java new file mode 100644 index 000000000000..f08ceacad2eb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Pipelines.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import rx.Completable; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.PipelinesInner; +import com.microsoft.azure.arm.model.HasInner; + +/** + * Type representing Pipelines. + */ +public interface Pipelines extends SupportsCreating, HasInner { + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable createRunAsync(String resourceGroupName, String factoryName, String pipelineName); + + /** + * Gets a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAsync(String resourceGroupName, String factoryName, String pipelineName); + + /** + * Lists pipelines. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listByFactoryAsync(final String resourceGroupName, final String factoryName); + + /** + * Deletes a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable deleteAsync(String resourceGroupName, String factoryName, String pipelineName); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PolybaseSettings.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PolybaseSettings.java new file mode 100644 index 000000000000..1596e04b134a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PolybaseSettings.java @@ -0,0 +1,154 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * PolyBase settings. + */ +public class PolybaseSettings { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Reject type. + */ + @JsonProperty(value = "rejectType") + private Object rejectType; + + /** + * Specifies the value or the percentage of rows that can be rejected + * before the query fails. Type: number (or Expression with resultType + * number), minimum: 0. + */ + @JsonProperty(value = "rejectValue") + private Object rejectValue; + + /** + * Determines the number of rows to attempt to retrieve before the PolyBase + * recalculates the percentage of rejected rows. Type: integer (or + * Expression with resultType integer), minimum: 0. + */ + @JsonProperty(value = "rejectSampleValue") + private Object rejectSampleValue; + + /** + * Specifies how to handle missing values in delimited text files when + * PolyBase retrieves data from the text file. Type: boolean (or Expression + * with resultType boolean). + */ + @JsonProperty(value = "useTypeDefault") + private Object useTypeDefault; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the PolybaseSettings object itself. + */ + public PolybaseSettings withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get reject type. + * + * @return the rejectType value + */ + public Object rejectType() { + return this.rejectType; + } + + /** + * Set reject type. + * + * @param rejectType the rejectType value to set + * @return the PolybaseSettings object itself. + */ + public PolybaseSettings withRejectType(Object rejectType) { + this.rejectType = rejectType; + return this; + } + + /** + * Get specifies the value or the percentage of rows that can be rejected before the query fails. Type: number (or Expression with resultType number), minimum: 0. + * + * @return the rejectValue value + */ + public Object rejectValue() { + return this.rejectValue; + } + + /** + * Set specifies the value or the percentage of rows that can be rejected before the query fails. Type: number (or Expression with resultType number), minimum: 0. + * + * @param rejectValue the rejectValue value to set + * @return the PolybaseSettings object itself. + */ + public PolybaseSettings withRejectValue(Object rejectValue) { + this.rejectValue = rejectValue; + return this; + } + + /** + * Get determines the number of rows to attempt to retrieve before the PolyBase recalculates the percentage of rejected rows. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the rejectSampleValue value + */ + public Object rejectSampleValue() { + return this.rejectSampleValue; + } + + /** + * Set determines the number of rows to attempt to retrieve before the PolyBase recalculates the percentage of rejected rows. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param rejectSampleValue the rejectSampleValue value to set + * @return the PolybaseSettings object itself. + */ + public PolybaseSettings withRejectSampleValue(Object rejectSampleValue) { + this.rejectSampleValue = rejectSampleValue; + return this; + } + + /** + * Get specifies how to handle missing values in delimited text files when PolyBase retrieves data from the text file. Type: boolean (or Expression with resultType boolean). + * + * @return the useTypeDefault value + */ + public Object useTypeDefault() { + return this.useTypeDefault; + } + + /** + * Set specifies how to handle missing values in delimited text files when PolyBase retrieves data from the text file. Type: boolean (or Expression with resultType boolean). + * + * @param useTypeDefault the useTypeDefault value to set + * @return the PolybaseSettings object itself. + */ + public PolybaseSettings withUseTypeDefault(Object useTypeDefault) { + this.useTypeDefault = useTypeDefault; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PostgreSqlLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PostgreSqlLinkedService.java new file mode 100644 index 000000000000..bac655e46c64 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PostgreSqlLinkedService.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for PostgreSQL data source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("PostgreSql") +@JsonFlatten +public class PostgreSqlLinkedService extends LinkedServiceInner { + /** + * The connection string. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private SecretBase connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. + * + * @return the connectionString value + */ + public SecretBase connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. + * + * @param connectionString the connectionString value to set + * @return the PostgreSqlLinkedService object itself. + */ + public PostgreSqlLinkedService withConnectionString(SecretBase connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the PostgreSqlLinkedService object itself. + */ + public PostgreSqlLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoAuthenticationType.java new file mode 100644 index 000000000000..701d1cce296b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for PrestoAuthenticationType. + */ +public final class PrestoAuthenticationType extends ExpandableStringEnum { + /** Static value Anonymous for PrestoAuthenticationType. */ + public static final PrestoAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** Static value LDAP for PrestoAuthenticationType. */ + public static final PrestoAuthenticationType LDAP = fromString("LDAP"); + + /** + * Creates or finds a PrestoAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding PrestoAuthenticationType + */ + @JsonCreator + public static PrestoAuthenticationType fromString(String name) { + return fromString(name, PrestoAuthenticationType.class); + } + + /** + * @return known PrestoAuthenticationType values + */ + public static Collection values() { + return values(PrestoAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoLinkedService.java new file mode 100644 index 000000000000..15e8b7cf40ce --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoLinkedService.java @@ -0,0 +1,403 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Presto server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Presto") +@JsonFlatten +public class PrestoLinkedService extends LinkedServiceInner { + /** + * The IP address or host name of the Presto server. (i.e. + * 192.168.222.160). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The version of the Presto server. (i.e. 0.148-t). + */ + @JsonProperty(value = "typeProperties.serverVersion", required = true) + private Object serverVersion; + + /** + * The catalog context for all request against the server. + */ + @JsonProperty(value = "typeProperties.catalog", required = true) + private Object catalog; + + /** + * The TCP port that the Presto server uses to listen for client + * connections. The default value is 8080. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The authentication mechanism used to connect to the Presto server. + * Possible values include: 'Anonymous', 'LDAP'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private PrestoAuthenticationType authenticationType; + + /** + * The user name used to connect to the Presto server. + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password corresponding to the user name. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * Specifies whether the connections to the server are encrypted using SSL. + * The default value is false. + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * The full path of the .pem file containing trusted CA certificates for + * verifying the server when connecting over SSL. This property can only be + * set when using SSL on self-hosted IR. The default value is the + * cacerts.pem file installed with the IR. + */ + @JsonProperty(value = "typeProperties.trustedCertPath") + private Object trustedCertPath; + + /** + * Specifies whether to use a CA certificate from the system trust store or + * from a specified PEM file. The default value is false. + */ + @JsonProperty(value = "typeProperties.useSystemTrustStore") + private Object useSystemTrustStore; + + /** + * Specifies whether to require a CA-issued SSL certificate name to match + * the host name of the server when connecting over SSL. The default value + * is false. + */ + @JsonProperty(value = "typeProperties.allowHostNameCNMismatch") + private Object allowHostNameCNMismatch; + + /** + * Specifies whether to allow self-signed certificates from the server. The + * default value is false. + */ + @JsonProperty(value = "typeProperties.allowSelfSignedServerCert") + private Object allowSelfSignedServerCert; + + /** + * The local time zone used by the connection. Valid values for this option + * are specified in the IANA Time Zone Database. The default value is the + * system time zone. + */ + @JsonProperty(value = "typeProperties.timeZoneID") + private Object timeZoneID; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the IP address or host name of the Presto server. (i.e. 192.168.222.160). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the IP address or host name of the Presto server. (i.e. 192.168.222.160). + * + * @param host the host value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the version of the Presto server. (i.e. 0.148-t). + * + * @return the serverVersion value + */ + public Object serverVersion() { + return this.serverVersion; + } + + /** + * Set the version of the Presto server. (i.e. 0.148-t). + * + * @param serverVersion the serverVersion value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withServerVersion(Object serverVersion) { + this.serverVersion = serverVersion; + return this; + } + + /** + * Get the catalog context for all request against the server. + * + * @return the catalog value + */ + public Object catalog() { + return this.catalog; + } + + /** + * Set the catalog context for all request against the server. + * + * @param catalog the catalog value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withCatalog(Object catalog) { + this.catalog = catalog; + return this; + } + + /** + * Get the TCP port that the Presto server uses to listen for client connections. The default value is 8080. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port that the Presto server uses to listen for client connections. The default value is 8080. + * + * @param port the port value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the authentication mechanism used to connect to the Presto server. Possible values include: 'Anonymous', 'LDAP'. + * + * @return the authenticationType value + */ + public PrestoAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication mechanism used to connect to the Presto server. Possible values include: 'Anonymous', 'LDAP'. + * + * @param authenticationType the authenticationType value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withAuthenticationType(PrestoAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the user name used to connect to the Presto server. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name used to connect to the Presto server. + * + * @param username the username value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name. + * + * @param password the password value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @param enableSsl the enableSsl value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @return the trustedCertPath value + */ + public Object trustedCertPath() { + return this.trustedCertPath; + } + + /** + * Set the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @param trustedCertPath the trustedCertPath value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withTrustedCertPath(Object trustedCertPath) { + this.trustedCertPath = trustedCertPath; + return this; + } + + /** + * Get specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @return the useSystemTrustStore value + */ + public Object useSystemTrustStore() { + return this.useSystemTrustStore; + } + + /** + * Set specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @param useSystemTrustStore the useSystemTrustStore value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withUseSystemTrustStore(Object useSystemTrustStore) { + this.useSystemTrustStore = useSystemTrustStore; + return this; + } + + /** + * Get specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @return the allowHostNameCNMismatch value + */ + public Object allowHostNameCNMismatch() { + return this.allowHostNameCNMismatch; + } + + /** + * Set specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @param allowHostNameCNMismatch the allowHostNameCNMismatch value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withAllowHostNameCNMismatch(Object allowHostNameCNMismatch) { + this.allowHostNameCNMismatch = allowHostNameCNMismatch; + return this; + } + + /** + * Get specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @return the allowSelfSignedServerCert value + */ + public Object allowSelfSignedServerCert() { + return this.allowSelfSignedServerCert; + } + + /** + * Set specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @param allowSelfSignedServerCert the allowSelfSignedServerCert value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withAllowSelfSignedServerCert(Object allowSelfSignedServerCert) { + this.allowSelfSignedServerCert = allowSelfSignedServerCert; + return this; + } + + /** + * Get the local time zone used by the connection. Valid values for this option are specified in the IANA Time Zone Database. The default value is the system time zone. + * + * @return the timeZoneID value + */ + public Object timeZoneID() { + return this.timeZoneID; + } + + /** + * Set the local time zone used by the connection. Valid values for this option are specified in the IANA Time Zone Database. The default value is the system time zone. + * + * @param timeZoneID the timeZoneID value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withTimeZoneID(Object timeZoneID) { + this.timeZoneID = timeZoneID; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the PrestoLinkedService object itself. + */ + public PrestoLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoObjectDataset.java new file mode 100644 index 000000000000..4a426e7b2294 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Presto server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("PrestoObject") +public class PrestoObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoSource.java new file mode 100644 index 000000000000..3a4b558cded8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/PrestoSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Presto server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("PrestoSource") +public class PrestoSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the PrestoSource object itself. + */ + public PrestoSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksLinkedService.java new file mode 100644 index 000000000000..778f7d7c24bb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksLinkedService.java @@ -0,0 +1,235 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * QuickBooks server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("QuickBooks") +@JsonFlatten +public class QuickBooksLinkedService extends LinkedServiceInner { + /** + * The endpoint of the QuickBooks server. (i.e. quickbooks.api.intuit.com). + */ + @JsonProperty(value = "typeProperties.endpoint", required = true) + private Object endpoint; + + /** + * The company ID of the QuickBooks company to authorize. + */ + @JsonProperty(value = "typeProperties.companyId", required = true) + private Object companyId; + + /** + * The consumer key for OAuth 1.0 authentication. + */ + @JsonProperty(value = "typeProperties.consumerKey", required = true) + private Object consumerKey; + + /** + * The consumer secret for OAuth 1.0 authentication. + */ + @JsonProperty(value = "typeProperties.consumerSecret", required = true) + private SecretBase consumerSecret; + + /** + * The access token for OAuth 1.0 authentication. + */ + @JsonProperty(value = "typeProperties.accessToken", required = true) + private SecretBase accessToken; + + /** + * The access token secret for OAuth 1.0 authentication. + */ + @JsonProperty(value = "typeProperties.accessTokenSecret", required = true) + private SecretBase accessTokenSecret; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the QuickBooks server. (i.e. quickbooks.api.intuit.com). + * + * @return the endpoint value + */ + public Object endpoint() { + return this.endpoint; + } + + /** + * Set the endpoint of the QuickBooks server. (i.e. quickbooks.api.intuit.com). + * + * @param endpoint the endpoint value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withEndpoint(Object endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Get the company ID of the QuickBooks company to authorize. + * + * @return the companyId value + */ + public Object companyId() { + return this.companyId; + } + + /** + * Set the company ID of the QuickBooks company to authorize. + * + * @param companyId the companyId value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withCompanyId(Object companyId) { + this.companyId = companyId; + return this; + } + + /** + * Get the consumer key for OAuth 1.0 authentication. + * + * @return the consumerKey value + */ + public Object consumerKey() { + return this.consumerKey; + } + + /** + * Set the consumer key for OAuth 1.0 authentication. + * + * @param consumerKey the consumerKey value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withConsumerKey(Object consumerKey) { + this.consumerKey = consumerKey; + return this; + } + + /** + * Get the consumer secret for OAuth 1.0 authentication. + * + * @return the consumerSecret value + */ + public SecretBase consumerSecret() { + return this.consumerSecret; + } + + /** + * Set the consumer secret for OAuth 1.0 authentication. + * + * @param consumerSecret the consumerSecret value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withConsumerSecret(SecretBase consumerSecret) { + this.consumerSecret = consumerSecret; + return this; + } + + /** + * Get the access token for OAuth 1.0 authentication. + * + * @return the accessToken value + */ + public SecretBase accessToken() { + return this.accessToken; + } + + /** + * Set the access token for OAuth 1.0 authentication. + * + * @param accessToken the accessToken value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withAccessToken(SecretBase accessToken) { + this.accessToken = accessToken; + return this; + } + + /** + * Get the access token secret for OAuth 1.0 authentication. + * + * @return the accessTokenSecret value + */ + public SecretBase accessTokenSecret() { + return this.accessTokenSecret; + } + + /** + * Set the access token secret for OAuth 1.0 authentication. + * + * @param accessTokenSecret the accessTokenSecret value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withAccessTokenSecret(SecretBase accessTokenSecret) { + this.accessTokenSecret = accessTokenSecret; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the QuickBooksLinkedService object itself. + */ + public QuickBooksLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksObjectDataset.java new file mode 100644 index 000000000000..4ac22bf83144 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * QuickBooks server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("QuickBooksObject") +public class QuickBooksObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksSource.java new file mode 100644 index 000000000000..698f13af76bd --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/QuickBooksSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity QuickBooks server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("QuickBooksSource") +public class QuickBooksSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the QuickBooksSource object itself. + */ + public QuickBooksSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceFrequency.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceFrequency.java new file mode 100644 index 000000000000..a2eead4f6a74 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceFrequency.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for RecurrenceFrequency. + */ +public final class RecurrenceFrequency extends ExpandableStringEnum { + /** Static value NotSpecified for RecurrenceFrequency. */ + public static final RecurrenceFrequency NOT_SPECIFIED = fromString("NotSpecified"); + + /** Static value Minute for RecurrenceFrequency. */ + public static final RecurrenceFrequency MINUTE = fromString("Minute"); + + /** Static value Hour for RecurrenceFrequency. */ + public static final RecurrenceFrequency HOUR = fromString("Hour"); + + /** Static value Day for RecurrenceFrequency. */ + public static final RecurrenceFrequency DAY = fromString("Day"); + + /** Static value Week for RecurrenceFrequency. */ + public static final RecurrenceFrequency WEEK = fromString("Week"); + + /** Static value Month for RecurrenceFrequency. */ + public static final RecurrenceFrequency MONTH = fromString("Month"); + + /** Static value Year for RecurrenceFrequency. */ + public static final RecurrenceFrequency YEAR = fromString("Year"); + + /** + * Creates or finds a RecurrenceFrequency from its string representation. + * @param name a name to look for + * @return the corresponding RecurrenceFrequency + */ + @JsonCreator + public static RecurrenceFrequency fromString(String name) { + return fromString(name, RecurrenceFrequency.class); + } + + /** + * @return known RecurrenceFrequency values + */ + public static Collection values() { + return values(RecurrenceFrequency.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceSchedule.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceSchedule.java new file mode 100644 index 000000000000..9059c8d5f0c6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceSchedule.java @@ -0,0 +1,175 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The recurrence schedule. + */ +public class RecurrenceSchedule { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The minutes. + */ + @JsonProperty(value = "minutes") + private List minutes; + + /** + * The hours. + */ + @JsonProperty(value = "hours") + private List hours; + + /** + * The days of the week. + */ + @JsonProperty(value = "weekDays") + private List weekDays; + + /** + * The month days. + */ + @JsonProperty(value = "monthDays") + private List monthDays; + + /** + * The monthly occurrences. + */ + @JsonProperty(value = "monthlyOccurrences") + private List monthlyOccurrences; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the RecurrenceSchedule object itself. + */ + public RecurrenceSchedule withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the minutes. + * + * @return the minutes value + */ + public List minutes() { + return this.minutes; + } + + /** + * Set the minutes. + * + * @param minutes the minutes value to set + * @return the RecurrenceSchedule object itself. + */ + public RecurrenceSchedule withMinutes(List minutes) { + this.minutes = minutes; + return this; + } + + /** + * Get the hours. + * + * @return the hours value + */ + public List hours() { + return this.hours; + } + + /** + * Set the hours. + * + * @param hours the hours value to set + * @return the RecurrenceSchedule object itself. + */ + public RecurrenceSchedule withHours(List hours) { + this.hours = hours; + return this; + } + + /** + * Get the days of the week. + * + * @return the weekDays value + */ + public List weekDays() { + return this.weekDays; + } + + /** + * Set the days of the week. + * + * @param weekDays the weekDays value to set + * @return the RecurrenceSchedule object itself. + */ + public RecurrenceSchedule withWeekDays(List weekDays) { + this.weekDays = weekDays; + return this; + } + + /** + * Get the month days. + * + * @return the monthDays value + */ + public List monthDays() { + return this.monthDays; + } + + /** + * Set the month days. + * + * @param monthDays the monthDays value to set + * @return the RecurrenceSchedule object itself. + */ + public RecurrenceSchedule withMonthDays(List monthDays) { + this.monthDays = monthDays; + return this; + } + + /** + * Get the monthly occurrences. + * + * @return the monthlyOccurrences value + */ + public List monthlyOccurrences() { + return this.monthlyOccurrences; + } + + /** + * Set the monthly occurrences. + * + * @param monthlyOccurrences the monthlyOccurrences value to set + * @return the RecurrenceSchedule object itself. + */ + public RecurrenceSchedule withMonthlyOccurrences(List monthlyOccurrences) { + this.monthlyOccurrences = monthlyOccurrences; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceScheduleOccurrence.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceScheduleOccurrence.java new file mode 100644 index 000000000000..8fd83c26e9e4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RecurrenceScheduleOccurrence.java @@ -0,0 +1,97 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The recurrence schedule occurrence. + */ +public class RecurrenceScheduleOccurrence { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The day of the week. Possible values include: 'Sunday', 'Monday', + * 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'. + */ + @JsonProperty(value = "day") + private DayOfWeek day; + + /** + * The occurrence. + */ + @JsonProperty(value = "occurrence") + private Integer occurrence; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the RecurrenceScheduleOccurrence object itself. + */ + public RecurrenceScheduleOccurrence withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the day of the week. Possible values include: 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'. + * + * @return the day value + */ + public DayOfWeek day() { + return this.day; + } + + /** + * Set the day of the week. Possible values include: 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'. + * + * @param day the day value to set + * @return the RecurrenceScheduleOccurrence object itself. + */ + public RecurrenceScheduleOccurrence withDay(DayOfWeek day) { + this.day = day; + return this; + } + + /** + * Get the occurrence. + * + * @return the occurrence value + */ + public Integer occurrence() { + return this.occurrence; + } + + /** + * Set the occurrence. + * + * @param occurrence the occurrence value to set + * @return the RecurrenceScheduleOccurrence object itself. + */ + public RecurrenceScheduleOccurrence withOccurrence(Integer occurrence) { + this.occurrence = occurrence; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RedirectIncompatibleRowSettings.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RedirectIncompatibleRowSettings.java new file mode 100644 index 000000000000..246b96dd741e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RedirectIncompatibleRowSettings.java @@ -0,0 +1,100 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Redirect incompatible row settings. + */ +public class RedirectIncompatibleRowSettings { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Name of the Azure Storage, Storage SAS, or Azure Data Lake Store linked + * service used for redirecting incompatible row. Must be specified if + * redirectIncompatibleRowSettings is specified. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "linkedServiceName", required = true) + private Object linkedServiceName; + + /** + * The path for storing the redirect incompatible row data. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "path") + private Object path; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the RedirectIncompatibleRowSettings object itself. + */ + public RedirectIncompatibleRowSettings withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get name of the Azure Storage, Storage SAS, or Azure Data Lake Store linked service used for redirecting incompatible row. Must be specified if redirectIncompatibleRowSettings is specified. Type: string (or Expression with resultType string). + * + * @return the linkedServiceName value + */ + public Object linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set name of the Azure Storage, Storage SAS, or Azure Data Lake Store linked service used for redirecting incompatible row. Must be specified if redirectIncompatibleRowSettings is specified. Type: string (or Expression with resultType string). + * + * @param linkedServiceName the linkedServiceName value to set + * @return the RedirectIncompatibleRowSettings object itself. + */ + public RedirectIncompatibleRowSettings withLinkedServiceName(Object linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + + /** + * Get the path for storing the redirect incompatible row data. Type: string (or Expression with resultType string). + * + * @return the path value + */ + public Object path() { + return this.path; + } + + /** + * Set the path for storing the redirect incompatible row data. Type: string (or Expression with resultType string). + * + * @param path the path value to set + * @return the RedirectIncompatibleRowSettings object itself. + */ + public RedirectIncompatibleRowSettings withPath(Object path) { + this.path = path; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RedshiftUnloadSettings.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RedshiftUnloadSettings.java new file mode 100644 index 000000000000..62a75ce3cab6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RedshiftUnloadSettings.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The Amazon S3 settings needed for the interim Amazon S3 when copying from + * Amazon Redshift with unload. With this, data from Amazon Redshift source + * will be unloaded into S3 first and then copied into the targeted sink from + * the interim S3. + */ +public class RedshiftUnloadSettings { + /** + * The name of the Amazon S3 linked service which will be used for the + * unload operation when copying from the Amazon Redshift source. + */ + @JsonProperty(value = "s3LinkedServiceName", required = true) + private LinkedServiceReference s3LinkedServiceName; + + /** + * The bucket of the interim Amazon S3 which will be used to store the + * unloaded data from Amazon Redshift source. The bucket must be in the + * same region as the Amazon Redshift source. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "bucketName", required = true) + private Object bucketName; + + /** + * Get the name of the Amazon S3 linked service which will be used for the unload operation when copying from the Amazon Redshift source. + * + * @return the s3LinkedServiceName value + */ + public LinkedServiceReference s3LinkedServiceName() { + return this.s3LinkedServiceName; + } + + /** + * Set the name of the Amazon S3 linked service which will be used for the unload operation when copying from the Amazon Redshift source. + * + * @param s3LinkedServiceName the s3LinkedServiceName value to set + * @return the RedshiftUnloadSettings object itself. + */ + public RedshiftUnloadSettings withS3LinkedServiceName(LinkedServiceReference s3LinkedServiceName) { + this.s3LinkedServiceName = s3LinkedServiceName; + return this; + } + + /** + * Get the bucket of the interim Amazon S3 which will be used to store the unloaded data from Amazon Redshift source. The bucket must be in the same region as the Amazon Redshift source. Type: string (or Expression with resultType string). + * + * @return the bucketName value + */ + public Object bucketName() { + return this.bucketName; + } + + /** + * Set the bucket of the interim Amazon S3 which will be used to store the unloaded data from Amazon Redshift source. The bucket must be in the same region as the Amazon Redshift source. Type: string (or Expression with resultType string). + * + * @param bucketName the bucketName value to set + * @return the RedshiftUnloadSettings object itself. + */ + public RedshiftUnloadSettings withBucketName(Object bucketName) { + this.bucketName = bucketName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RelationalSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RelationalSource.java new file mode 100644 index 000000000000..c8fa7fa63ab1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RelationalSource.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for various relational databases. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("RelationalSource") +public class RelationalSource extends CopySource { + /** + * Database query. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get database query. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set database query. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the RelationalSource object itself. + */ + public RelationalSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RelationalTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RelationalTableDataset.java new file mode 100644 index 000000000000..2ee249b9eb5b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RelationalTableDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The relational table dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("RelationalTable") +@JsonFlatten +public class RelationalTableDataset extends DatasetInner { + /** + * The relational table name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.tableName") + private Object tableName; + + /** + * Get the relational table name. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the relational table name. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the RelationalTableDataset object itself. + */ + public RelationalTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysLinkedService.java new file mode 100644 index 000000000000..27479e683b35 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysLinkedService.java @@ -0,0 +1,217 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Responsys linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Responsys") +@JsonFlatten +public class ResponsysLinkedService extends LinkedServiceInner { + /** + * The endpoint of the Responsys server. + */ + @JsonProperty(value = "typeProperties.endpoint", required = true) + private Object endpoint; + + /** + * The client ID associated with the Responsys application. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * The client secret associated with the Responsys application. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. Type: boolean (or Expression with + * resultType boolean). + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the Responsys server. + * + * @return the endpoint value + */ + public Object endpoint() { + return this.endpoint; + } + + /** + * Set the endpoint of the Responsys server. + * + * @param endpoint the endpoint value to set + * @return the ResponsysLinkedService object itself. + */ + public ResponsysLinkedService withEndpoint(Object endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Get the client ID associated with the Responsys application. Type: string (or Expression with resultType string). + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set the client ID associated with the Responsys application. Type: string (or Expression with resultType string). + * + * @param clientId the clientId value to set + * @return the ResponsysLinkedService object itself. + */ + public ResponsysLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret associated with the Responsys application. Type: string (or Expression with resultType string). + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret associated with the Responsys application. Type: string (or Expression with resultType string). + * + * @param clientSecret the clientSecret value to set + * @return the ResponsysLinkedService object itself. + */ + public ResponsysLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the ResponsysLinkedService object itself. + */ + public ResponsysLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param useHostVerification the useHostVerification value to set + * @return the ResponsysLinkedService object itself. + */ + public ResponsysLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param usePeerVerification the usePeerVerification value to set + * @return the ResponsysLinkedService object itself. + */ + public ResponsysLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the ResponsysLinkedService object itself. + */ + public ResponsysLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysObjectDataset.java new file mode 100644 index 000000000000..053a643958e9 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Responsys dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ResponsysObject") +public class ResponsysObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysSource.java new file mode 100644 index 000000000000..406312ed516e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ResponsysSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Responsys source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ResponsysSource") +public class ResponsysSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the ResponsysSource object itself. + */ + public ResponsysSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RetryPolicy.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RetryPolicy.java new file mode 100644 index 000000000000..6a7b69de4071 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/RetryPolicy.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Execution policy for an activity. + */ +public class RetryPolicy { + /** + * Maximum ordinary retry attempts. Default is 0. Type: integer (or + * Expression with resultType integer), minimum: 0. + */ + @JsonProperty(value = "count") + private Object count; + + /** + * Interval between retries in seconds. Default is 30. + */ + @JsonProperty(value = "intervalInSeconds") + private Integer intervalInSeconds; + + /** + * Get maximum ordinary retry attempts. Default is 0. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the count value + */ + public Object count() { + return this.count; + } + + /** + * Set maximum ordinary retry attempts. Default is 0. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param count the count value to set + * @return the RetryPolicy object itself. + */ + public RetryPolicy withCount(Object count) { + this.count = count; + return this; + } + + /** + * Get interval between retries in seconds. Default is 30. + * + * @return the intervalInSeconds value + */ + public Integer intervalInSeconds() { + return this.intervalInSeconds; + } + + /** + * Set interval between retries in seconds. Default is 30. + * + * @param intervalInSeconds the intervalInSeconds value to set + * @return the RetryPolicy object itself. + */ + public RetryPolicy withIntervalInSeconds(Integer intervalInSeconds) { + this.intervalInSeconds = intervalInSeconds; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISAccessCredential.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISAccessCredential.java new file mode 100644 index 000000000000..ce79f81e919f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISAccessCredential.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SSIS access credential. + */ +public class SSISAccessCredential { + /** + * Domain for windows authentication. + */ + @JsonProperty(value = "domain", required = true) + private Object domain; + + /** + * UseName for windows authentication. + */ + @JsonProperty(value = "userName", required = true) + private Object userName; + + /** + * Password for windows authentication. + */ + @JsonProperty(value = "password", required = true) + private SecretBase password; + + /** + * Get domain for windows authentication. + * + * @return the domain value + */ + public Object domain() { + return this.domain; + } + + /** + * Set domain for windows authentication. + * + * @param domain the domain value to set + * @return the SSISAccessCredential object itself. + */ + public SSISAccessCredential withDomain(Object domain) { + this.domain = domain; + return this; + } + + /** + * Get useName for windows authentication. + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set useName for windows authentication. + * + * @param userName the userName value to set + * @return the SSISAccessCredential object itself. + */ + public SSISAccessCredential withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password for windows authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for windows authentication. + * + * @param password the password value to set + * @return the SSISAccessCredential object itself. + */ + public SSISAccessCredential withPassword(SecretBase password) { + this.password = password; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISExecutionCredential.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISExecutionCredential.java new file mode 100644 index 000000000000..d1e5cc0931b7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISExecutionCredential.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SSIS package execution credential. + */ +public class SSISExecutionCredential { + /** + * Domain for windows authentication. + */ + @JsonProperty(value = "domain", required = true) + private Object domain; + + /** + * UseName for windows authentication. + */ + @JsonProperty(value = "userName", required = true) + private Object userName; + + /** + * Password for windows authentication. + */ + @JsonProperty(value = "password", required = true) + private SecureString password; + + /** + * Get domain for windows authentication. + * + * @return the domain value + */ + public Object domain() { + return this.domain; + } + + /** + * Set domain for windows authentication. + * + * @param domain the domain value to set + * @return the SSISExecutionCredential object itself. + */ + public SSISExecutionCredential withDomain(Object domain) { + this.domain = domain; + return this; + } + + /** + * Get useName for windows authentication. + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set useName for windows authentication. + * + * @param userName the userName value to set + * @return the SSISExecutionCredential object itself. + */ + public SSISExecutionCredential withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password for windows authentication. + * + * @return the password value + */ + public SecureString password() { + return this.password; + } + + /** + * Set password for windows authentication. + * + * @param password the password value to set + * @return the SSISExecutionCredential object itself. + */ + public SSISExecutionCredential withPassword(SecureString password) { + this.password = password; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISExecutionParameter.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISExecutionParameter.java new file mode 100644 index 000000000000..4e276c59042f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISExecutionParameter.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SSIS execution parameter. + */ +public class SSISExecutionParameter { + /** + * SSIS package execution parameter value. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "value", required = true) + private Object value; + + /** + * Get sSIS package execution parameter value. Type: string (or Expression with resultType string). + * + * @return the value value + */ + public Object value() { + return this.value; + } + + /** + * Set sSIS package execution parameter value. Type: string (or Expression with resultType string). + * + * @param value the value value to set + * @return the SSISExecutionParameter object itself. + */ + public SSISExecutionParameter withValue(Object value) { + this.value = value; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISLogLocation.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISLogLocation.java new file mode 100644 index 000000000000..eb7930fdddab --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISLogLocation.java @@ -0,0 +1,134 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * SSIS package execution log location. + */ +@JsonFlatten +public class SSISLogLocation { + /** + * The SSIS package execution log path. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "logPath", required = true) + private Object logPath; + + /** + * The type of SSIS log location. + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * The package execution log access credential. + */ + @JsonProperty(value = "typeProperties.accessCredential") + private SSISAccessCredential accessCredential; + + /** + * Specifies the interval to refresh log. The default interval is 5 + * minutes. Type: string (or Expression with resultType string), pattern: + * ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "typeProperties.logRefreshInterval") + private Object logRefreshInterval; + + /** + * Creates an instance of SSISLogLocation class. + * @param logPath the SSIS package execution log path. Type: string (or Expression with resultType string). + */ + public SSISLogLocation() { + type = "File"; + } + + /** + * Get the SSIS package execution log path. Type: string (or Expression with resultType string). + * + * @return the logPath value + */ + public Object logPath() { + return this.logPath; + } + + /** + * Set the SSIS package execution log path. Type: string (or Expression with resultType string). + * + * @param logPath the logPath value to set + * @return the SSISLogLocation object itself. + */ + public SSISLogLocation withLogPath(Object logPath) { + this.logPath = logPath; + return this; + } + + /** + * Get the type of SSIS log location. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set the type of SSIS log location. + * + * @param type the type value to set + * @return the SSISLogLocation object itself. + */ + public SSISLogLocation withType(String type) { + this.type = type; + return this; + } + + /** + * Get the package execution log access credential. + * + * @return the accessCredential value + */ + public SSISAccessCredential accessCredential() { + return this.accessCredential; + } + + /** + * Set the package execution log access credential. + * + * @param accessCredential the accessCredential value to set + * @return the SSISLogLocation object itself. + */ + public SSISLogLocation withAccessCredential(SSISAccessCredential accessCredential) { + this.accessCredential = accessCredential; + return this; + } + + /** + * Get specifies the interval to refresh log. The default interval is 5 minutes. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the logRefreshInterval value + */ + public Object logRefreshInterval() { + return this.logRefreshInterval; + } + + /** + * Set specifies the interval to refresh log. The default interval is 5 minutes. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param logRefreshInterval the logRefreshInterval value to set + * @return the SSISLogLocation object itself. + */ + public SSISLogLocation withLogRefreshInterval(Object logRefreshInterval) { + this.logRefreshInterval = logRefreshInterval; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISPackageLocation.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISPackageLocation.java new file mode 100644 index 000000000000..7e60e7089e21 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISPackageLocation.java @@ -0,0 +1,152 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * SSIS package location. + */ +@JsonFlatten +public class SSISPackageLocation { + /** + * The SSIS package path. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "packagePath", required = true) + private Object packagePath; + + /** + * The type of SSIS package location. Possible values include: 'SSISDB', + * 'File'. + */ + @JsonProperty(value = "type") + private SsisPackageLocationType type; + + /** + * Password of the package. + */ + @JsonProperty(value = "typeProperties.packagePassword") + private SecretBase packagePassword; + + /** + * The package access credential. + */ + @JsonProperty(value = "typeProperties.accessCredential") + private SSISAccessCredential accessCredential; + + /** + * The configuration file of the package execution. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.configurationPath") + private Object configurationPath; + + /** + * Get the SSIS package path. Type: string (or Expression with resultType string). + * + * @return the packagePath value + */ + public Object packagePath() { + return this.packagePath; + } + + /** + * Set the SSIS package path. Type: string (or Expression with resultType string). + * + * @param packagePath the packagePath value to set + * @return the SSISPackageLocation object itself. + */ + public SSISPackageLocation withPackagePath(Object packagePath) { + this.packagePath = packagePath; + return this; + } + + /** + * Get the type of SSIS package location. Possible values include: 'SSISDB', 'File'. + * + * @return the type value + */ + public SsisPackageLocationType type() { + return this.type; + } + + /** + * Set the type of SSIS package location. Possible values include: 'SSISDB', 'File'. + * + * @param type the type value to set + * @return the SSISPackageLocation object itself. + */ + public SSISPackageLocation withType(SsisPackageLocationType type) { + this.type = type; + return this; + } + + /** + * Get password of the package. + * + * @return the packagePassword value + */ + public SecretBase packagePassword() { + return this.packagePassword; + } + + /** + * Set password of the package. + * + * @param packagePassword the packagePassword value to set + * @return the SSISPackageLocation object itself. + */ + public SSISPackageLocation withPackagePassword(SecretBase packagePassword) { + this.packagePassword = packagePassword; + return this; + } + + /** + * Get the package access credential. + * + * @return the accessCredential value + */ + public SSISAccessCredential accessCredential() { + return this.accessCredential; + } + + /** + * Set the package access credential. + * + * @param accessCredential the accessCredential value to set + * @return the SSISPackageLocation object itself. + */ + public SSISPackageLocation withAccessCredential(SSISAccessCredential accessCredential) { + this.accessCredential = accessCredential; + return this; + } + + /** + * Get the configuration file of the package execution. Type: string (or Expression with resultType string). + * + * @return the configurationPath value + */ + public Object configurationPath() { + return this.configurationPath; + } + + /** + * Set the configuration file of the package execution. Type: string (or Expression with resultType string). + * + * @param configurationPath the configurationPath value to set + * @return the SSISPackageLocation object itself. + */ + public SSISPackageLocation withConfigurationPath(Object configurationPath) { + this.configurationPath = configurationPath; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISPropertyOverride.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISPropertyOverride.java new file mode 100644 index 000000000000..227d1b21bd37 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SSISPropertyOverride.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SSIS property override. + */ +public class SSISPropertyOverride { + /** + * SSIS package property override value. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "value", required = true) + private Object value; + + /** + * Whether SSIS package property override value is sensitive data. Value + * will be encrypted in SSISDB if it is true. + */ + @JsonProperty(value = "isSensitive") + private Boolean isSensitive; + + /** + * Get sSIS package property override value. Type: string (or Expression with resultType string). + * + * @return the value value + */ + public Object value() { + return this.value; + } + + /** + * Set sSIS package property override value. Type: string (or Expression with resultType string). + * + * @param value the value value to set + * @return the SSISPropertyOverride object itself. + */ + public SSISPropertyOverride withValue(Object value) { + this.value = value; + return this; + } + + /** + * Get whether SSIS package property override value is sensitive data. Value will be encrypted in SSISDB if it is true. + * + * @return the isSensitive value + */ + public Boolean isSensitive() { + return this.isSensitive; + } + + /** + * Set whether SSIS package property override value is sensitive data. Value will be encrypted in SSISDB if it is true. + * + * @param isSensitive the isSensitive value to set + * @return the SSISPropertyOverride object itself. + */ + public SSISPropertyOverride withIsSensitive(Boolean isSensitive) { + this.isSensitive = isSensitive; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceLinkedService.java new file mode 100644 index 000000000000..9ba7690a7082 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceLinkedService.java @@ -0,0 +1,161 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for Salesforce. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Salesforce") +@JsonFlatten +public class SalesforceLinkedService extends LinkedServiceInner { + /** + * The URL of Salesforce instance. Default is + * 'https://login.salesforce.com'. To copy data from sandbox, specify + * 'https://test.salesforce.com'. To copy data from custom domain, specify, + * for example, 'https://[domain].my.salesforce.com'. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.environmentUrl") + private Object environmentUrl; + + /** + * The username for Basic authentication of the Salesforce instance. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password for Basic authentication of the Salesforce instance. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The security token is required to remotely access Salesforce instance. + */ + @JsonProperty(value = "typeProperties.securityToken") + private SecretBase securityToken; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the URL of Salesforce instance. Default is 'https://login.salesforce.com'. To copy data from sandbox, specify 'https://test.salesforce.com'. To copy data from custom domain, specify, for example, 'https://[domain].my.salesforce.com'. Type: string (or Expression with resultType string). + * + * @return the environmentUrl value + */ + public Object environmentUrl() { + return this.environmentUrl; + } + + /** + * Set the URL of Salesforce instance. Default is 'https://login.salesforce.com'. To copy data from sandbox, specify 'https://test.salesforce.com'. To copy data from custom domain, specify, for example, 'https://[domain].my.salesforce.com'. Type: string (or Expression with resultType string). + * + * @param environmentUrl the environmentUrl value to set + * @return the SalesforceLinkedService object itself. + */ + public SalesforceLinkedService withEnvironmentUrl(Object environmentUrl) { + this.environmentUrl = environmentUrl; + return this; + } + + /** + * Get the username for Basic authentication of the Salesforce instance. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the username for Basic authentication of the Salesforce instance. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the SalesforceLinkedService object itself. + */ + public SalesforceLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password for Basic authentication of the Salesforce instance. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password for Basic authentication of the Salesforce instance. + * + * @param password the password value to set + * @return the SalesforceLinkedService object itself. + */ + public SalesforceLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the security token is required to remotely access Salesforce instance. + * + * @return the securityToken value + */ + public SecretBase securityToken() { + return this.securityToken; + } + + /** + * Set the security token is required to remotely access Salesforce instance. + * + * @param securityToken the securityToken value to set + * @return the SalesforceLinkedService object itself. + */ + public SalesforceLinkedService withSecurityToken(SecretBase securityToken) { + this.securityToken = securityToken; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SalesforceLinkedService object itself. + */ + public SalesforceLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudLinkedService.java new file mode 100644 index 000000000000..b4759235918e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudLinkedService.java @@ -0,0 +1,191 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Salesforce Marketing Cloud linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SalesforceMarketingCloud") +@JsonFlatten +public class SalesforceMarketingCloudLinkedService extends LinkedServiceInner { + /** + * The client ID associated with the Salesforce Marketing Cloud + * application. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * The client secret associated with the Salesforce Marketing Cloud + * application. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. Type: boolean (or Expression with + * resultType boolean). + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the client ID associated with the Salesforce Marketing Cloud application. Type: string (or Expression with resultType string). + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set the client ID associated with the Salesforce Marketing Cloud application. Type: string (or Expression with resultType string). + * + * @param clientId the clientId value to set + * @return the SalesforceMarketingCloudLinkedService object itself. + */ + public SalesforceMarketingCloudLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret associated with the Salesforce Marketing Cloud application. Type: string (or Expression with resultType string). + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret associated with the Salesforce Marketing Cloud application. Type: string (or Expression with resultType string). + * + * @param clientSecret the clientSecret value to set + * @return the SalesforceMarketingCloudLinkedService object itself. + */ + public SalesforceMarketingCloudLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the SalesforceMarketingCloudLinkedService object itself. + */ + public SalesforceMarketingCloudLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param useHostVerification the useHostVerification value to set + * @return the SalesforceMarketingCloudLinkedService object itself. + */ + public SalesforceMarketingCloudLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param usePeerVerification the usePeerVerification value to set + * @return the SalesforceMarketingCloudLinkedService object itself. + */ + public SalesforceMarketingCloudLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SalesforceMarketingCloudLinkedService object itself. + */ + public SalesforceMarketingCloudLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudObjectDataset.java new file mode 100644 index 000000000000..4d02bc6dc26f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Salesforce Marketing Cloud dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SalesforceMarketingCloudObject") +public class SalesforceMarketingCloudObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudSource.java new file mode 100644 index 000000000000..e03f08a2f222 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceMarketingCloudSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Salesforce Marketing Cloud source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SalesforceMarketingCloudSource") +public class SalesforceMarketingCloudSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the SalesforceMarketingCloudSource object itself. + */ + public SalesforceMarketingCloudSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceObjectDataset.java new file mode 100644 index 000000000000..887dc8beeffb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceObjectDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The Salesforce object dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SalesforceObject") +@JsonFlatten +public class SalesforceObjectDataset extends DatasetInner { + /** + * The Salesforce object API name. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.objectApiName") + private Object objectApiName; + + /** + * Get the Salesforce object API name. Type: string (or Expression with resultType string). + * + * @return the objectApiName value + */ + public Object objectApiName() { + return this.objectApiName; + } + + /** + * Set the Salesforce object API name. Type: string (or Expression with resultType string). + * + * @param objectApiName the objectApiName value to set + * @return the SalesforceObjectDataset object itself. + */ + public SalesforceObjectDataset withObjectApiName(Object objectApiName) { + this.objectApiName = objectApiName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceSink.java new file mode 100644 index 000000000000..c725395e590e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceSink.java @@ -0,0 +1,107 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Salesforce sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SalesforceSink") +public class SalesforceSink extends CopySink { + /** + * The write behavior for the operation. Default is Insert. + */ + @JsonProperty(value = "writeBehavior") + private Object writeBehavior; + + /** + * The name of the external ID field for upsert operation. Default value is + * 'Id' column. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "externalIdFieldName") + private Object externalIdFieldName; + + /** + * The flag indicating whether or not to ignore null values from input + * dataset (except key fields) during write operation. Default value is + * false. If set it to true, it means ADF will leave the data in the + * destination object unchanged when doing upsert/update operation and + * insert defined default value when doing insert operation, versus ADF + * will update the data in the destination object to NULL when doing + * upsert/update operation and insert NULL value when doing insert + * operation. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "ignoreNullValues") + private Object ignoreNullValues; + + /** + * Get the write behavior for the operation. Default is Insert. + * + * @return the writeBehavior value + */ + public Object writeBehavior() { + return this.writeBehavior; + } + + /** + * Set the write behavior for the operation. Default is Insert. + * + * @param writeBehavior the writeBehavior value to set + * @return the SalesforceSink object itself. + */ + public SalesforceSink withWriteBehavior(Object writeBehavior) { + this.writeBehavior = writeBehavior; + return this; + } + + /** + * Get the name of the external ID field for upsert operation. Default value is 'Id' column. Type: string (or Expression with resultType string). + * + * @return the externalIdFieldName value + */ + public Object externalIdFieldName() { + return this.externalIdFieldName; + } + + /** + * Set the name of the external ID field for upsert operation. Default value is 'Id' column. Type: string (or Expression with resultType string). + * + * @param externalIdFieldName the externalIdFieldName value to set + * @return the SalesforceSink object itself. + */ + public SalesforceSink withExternalIdFieldName(Object externalIdFieldName) { + this.externalIdFieldName = externalIdFieldName; + return this; + } + + /** + * Get the flag indicating whether or not to ignore null values from input dataset (except key fields) during write operation. Default value is false. If set it to true, it means ADF will leave the data in the destination object unchanged when doing upsert/update operation and insert defined default value when doing insert operation, versus ADF will update the data in the destination object to NULL when doing upsert/update operation and insert NULL value when doing insert operation. Type: boolean (or Expression with resultType boolean). + * + * @return the ignoreNullValues value + */ + public Object ignoreNullValues() { + return this.ignoreNullValues; + } + + /** + * Set the flag indicating whether or not to ignore null values from input dataset (except key fields) during write operation. Default value is false. If set it to true, it means ADF will leave the data in the destination object unchanged when doing upsert/update operation and insert defined default value when doing insert operation, versus ADF will update the data in the destination object to NULL when doing upsert/update operation and insert NULL value when doing insert operation. Type: boolean (or Expression with resultType boolean). + * + * @param ignoreNullValues the ignoreNullValues value to set + * @return the SalesforceSink object itself. + */ + public SalesforceSink withIgnoreNullValues(Object ignoreNullValues) { + this.ignoreNullValues = ignoreNullValues; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceSource.java new file mode 100644 index 000000000000..5467c65b05c5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SalesforceSource.java @@ -0,0 +1,73 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Salesforce source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SalesforceSource") +public class SalesforceSource extends CopySource { + /** + * Database query. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * The read behavior for the operation. Default is Query. + */ + @JsonProperty(value = "readBehavior") + private Object readBehavior; + + /** + * Get database query. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set database query. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the SalesforceSource object itself. + */ + public SalesforceSource withQuery(Object query) { + this.query = query; + return this; + } + + /** + * Get the read behavior for the operation. Default is Query. + * + * @return the readBehavior value + */ + public Object readBehavior() { + return this.readBehavior; + } + + /** + * Set the read behavior for the operation. Default is Query. + * + * @param readBehavior the readBehavior value to set + * @return the SalesforceSource object itself. + */ + public SalesforceSource withReadBehavior(Object readBehavior) { + this.readBehavior = readBehavior; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapBWLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapBWLinkedService.java new file mode 100644 index 000000000000..dc9278652ff3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapBWLinkedService.java @@ -0,0 +1,188 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * SAP Business Warehouse Linked Service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapBW") +@JsonFlatten +public class SapBWLinkedService extends LinkedServiceInner { + /** + * Host name of the SAP BW instance. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.server", required = true) + private Object server; + + /** + * System number of the BW system. (Usually a two-digit decimal number + * represented as a string.) Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.systemNumber", required = true) + private Object systemNumber; + + /** + * Client ID of the client on the BW system. (Usually a three-digit decimal + * number represented as a string) Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * Username to access the SAP BW server. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password to access the SAP BW server. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get host name of the SAP BW instance. Type: string (or Expression with resultType string). + * + * @return the server value + */ + public Object server() { + return this.server; + } + + /** + * Set host name of the SAP BW instance. Type: string (or Expression with resultType string). + * + * @param server the server value to set + * @return the SapBWLinkedService object itself. + */ + public SapBWLinkedService withServer(Object server) { + this.server = server; + return this; + } + + /** + * Get system number of the BW system. (Usually a two-digit decimal number represented as a string.) Type: string (or Expression with resultType string). + * + * @return the systemNumber value + */ + public Object systemNumber() { + return this.systemNumber; + } + + /** + * Set system number of the BW system. (Usually a two-digit decimal number represented as a string.) Type: string (or Expression with resultType string). + * + * @param systemNumber the systemNumber value to set + * @return the SapBWLinkedService object itself. + */ + public SapBWLinkedService withSystemNumber(Object systemNumber) { + this.systemNumber = systemNumber; + return this; + } + + /** + * Get client ID of the client on the BW system. (Usually a three-digit decimal number represented as a string) Type: string (or Expression with resultType string). + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set client ID of the client on the BW system. (Usually a three-digit decimal number represented as a string) Type: string (or Expression with resultType string). + * + * @param clientId the clientId value to set + * @return the SapBWLinkedService object itself. + */ + public SapBWLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get username to access the SAP BW server. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set username to access the SAP BW server. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the SapBWLinkedService object itself. + */ + public SapBWLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password to access the SAP BW server. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password to access the SAP BW server. + * + * @param password the password value to set + * @return the SapBWLinkedService object itself. + */ + public SapBWLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SapBWLinkedService object itself. + */ + public SapBWLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerLinkedService.java new file mode 100644 index 000000000000..6997191c4b21 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerLinkedService.java @@ -0,0 +1,134 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for SAP Cloud for Customer. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapCloudForCustomer") +@JsonFlatten +public class SapCloudForCustomerLinkedService extends LinkedServiceInner { + /** + * The URL of SAP Cloud for Customer OData API. For example, + * '[https://[tenantname].crm.ondemand.com/sap/c4c/odata/v1]'. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.url", required = true) + private Object url; + + /** + * The username for Basic authentication. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password for Basic authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Either + * encryptedCredential or username/password must be provided. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the URL of SAP Cloud for Customer OData API. For example, '[https://[tenantname].crm.ondemand.com/sap/c4c/odata/v1]'. Type: string (or Expression with resultType string). + * + * @return the url value + */ + public Object url() { + return this.url; + } + + /** + * Set the URL of SAP Cloud for Customer OData API. For example, '[https://[tenantname].crm.ondemand.com/sap/c4c/odata/v1]'. Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the SapCloudForCustomerLinkedService object itself. + */ + public SapCloudForCustomerLinkedService withUrl(Object url) { + this.url = url; + return this; + } + + /** + * Get the username for Basic authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the username for Basic authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the SapCloudForCustomerLinkedService object itself. + */ + public SapCloudForCustomerLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password for Basic authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password for Basic authentication. + * + * @param password the password value to set + * @return the SapCloudForCustomerLinkedService object itself. + */ + public SapCloudForCustomerLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Either encryptedCredential or username/password must be provided. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Either encryptedCredential or username/password must be provided. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SapCloudForCustomerLinkedService object itself. + */ + public SapCloudForCustomerLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerResourceDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerResourceDataset.java new file mode 100644 index 000000000000..fed8d4811ff0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerResourceDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The path of the SAP Cloud for Customer OData entity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapCloudForCustomerResource") +@JsonFlatten +public class SapCloudForCustomerResourceDataset extends DatasetInner { + /** + * The path of the SAP Cloud for Customer OData entity. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.path", required = true) + private Object path; + + /** + * Get the path of the SAP Cloud for Customer OData entity. Type: string (or Expression with resultType string). + * + * @return the path value + */ + public Object path() { + return this.path; + } + + /** + * Set the path of the SAP Cloud for Customer OData entity. Type: string (or Expression with resultType string). + * + * @param path the path value to set + * @return the SapCloudForCustomerResourceDataset object itself. + */ + public SapCloudForCustomerResourceDataset withPath(Object path) { + this.path = path; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerSink.java new file mode 100644 index 000000000000..afc1c2f50fb6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerSink.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity SAP Cloud for Customer sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapCloudForCustomerSink") +public class SapCloudForCustomerSink extends CopySink { + /** + * The write behavior for the operation. Default is 'Insert'. + */ + @JsonProperty(value = "writeBehavior") + private Object writeBehavior; + + /** + * Get the write behavior for the operation. Default is 'Insert'. + * + * @return the writeBehavior value + */ + public Object writeBehavior() { + return this.writeBehavior; + } + + /** + * Set the write behavior for the operation. Default is 'Insert'. + * + * @param writeBehavior the writeBehavior value to set + * @return the SapCloudForCustomerSink object itself. + */ + public SapCloudForCustomerSink withWriteBehavior(Object writeBehavior) { + this.writeBehavior = writeBehavior; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerSource.java new file mode 100644 index 000000000000..62ef8c201eb7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapCloudForCustomerSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for SAP Cloud for Customer source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapCloudForCustomerSource") +public class SapCloudForCustomerSource extends CopySource { + /** + * SAP Cloud for Customer OData query. For example, "$top=1". Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get sAP Cloud for Customer OData query. For example, "$top=1". Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set sAP Cloud for Customer OData query. For example, "$top=1". Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the SapCloudForCustomerSource object itself. + */ + public SapCloudForCustomerSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccLinkedService.java new file mode 100644 index 000000000000..535da71425ad --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccLinkedService.java @@ -0,0 +1,134 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for SAP ERP Central Component(SAP ECC). + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapEcc") +@JsonFlatten +public class SapEccLinkedService extends LinkedServiceInner { + /** + * The URL of SAP ECC OData API. For example, + * '[https://hostname:port/sap/opu/odata/sap/servicename/]'. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.url", required = true) + private String url; + + /** + * The username for Basic authentication. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.username") + private String username; + + /** + * The password for Basic authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Either + * encryptedCredential or username/password must be provided. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private String encryptedCredential; + + /** + * Get the URL of SAP ECC OData API. For example, '[https://hostname:port/sap/opu/odata/sap/servicename/]'. Type: string (or Expression with resultType string). + * + * @return the url value + */ + public String url() { + return this.url; + } + + /** + * Set the URL of SAP ECC OData API. For example, '[https://hostname:port/sap/opu/odata/sap/servicename/]'. Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the SapEccLinkedService object itself. + */ + public SapEccLinkedService withUrl(String url) { + this.url = url; + return this; + } + + /** + * Get the username for Basic authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public String username() { + return this.username; + } + + /** + * Set the username for Basic authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the SapEccLinkedService object itself. + */ + public SapEccLinkedService withUsername(String username) { + this.username = username; + return this; + } + + /** + * Get the password for Basic authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password for Basic authentication. + * + * @param password the password value to set + * @return the SapEccLinkedService object itself. + */ + public SapEccLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Either encryptedCredential or username/password must be provided. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public String encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Either encryptedCredential or username/password must be provided. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SapEccLinkedService object itself. + */ + public SapEccLinkedService withEncryptedCredential(String encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccResourceDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccResourceDataset.java new file mode 100644 index 000000000000..d087fd649925 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccResourceDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The path of the SAP ECC OData entity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapEccResource") +@JsonFlatten +public class SapEccResourceDataset extends DatasetInner { + /** + * The path of the SAP ECC OData entity. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.path", required = true) + private Object path; + + /** + * Get the path of the SAP ECC OData entity. Type: string (or Expression with resultType string). + * + * @return the path value + */ + public Object path() { + return this.path; + } + + /** + * Set the path of the SAP ECC OData entity. Type: string (or Expression with resultType string). + * + * @param path the path value to set + * @return the SapEccResourceDataset object itself. + */ + public SapEccResourceDataset withPath(Object path) { + this.path = path; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccSource.java new file mode 100644 index 000000000000..d32793cc3041 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapEccSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for SAP ECC source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapEccSource") +public class SapEccSource extends CopySource { + /** + * SAP ECC OData query. For example, "$top=1". Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get sAP ECC OData query. For example, "$top=1". Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set sAP ECC OData query. For example, "$top=1". Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the SapEccSource object itself. + */ + public SapEccSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapHanaAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapHanaAuthenticationType.java new file mode 100644 index 000000000000..c22a210d030d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapHanaAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SapHanaAuthenticationType. + */ +public final class SapHanaAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for SapHanaAuthenticationType. */ + public static final SapHanaAuthenticationType BASIC = fromString("Basic"); + + /** Static value Windows for SapHanaAuthenticationType. */ + public static final SapHanaAuthenticationType WINDOWS = fromString("Windows"); + + /** + * Creates or finds a SapHanaAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding SapHanaAuthenticationType + */ + @JsonCreator + public static SapHanaAuthenticationType fromString(String name) { + return fromString(name, SapHanaAuthenticationType.class); + } + + /** + * @return known SapHanaAuthenticationType values + */ + public static Collection values() { + return values(SapHanaAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapHanaLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapHanaLinkedService.java new file mode 100644 index 000000000000..37f9ba392ed9 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SapHanaLinkedService.java @@ -0,0 +1,159 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * SAP HANA Linked Service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SapHana") +@JsonFlatten +public class SapHanaLinkedService extends LinkedServiceInner { + /** + * Host name of the SAP HANA server. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.server", required = true) + private Object server; + + /** + * The authentication type to be used to connect to the SAP HANA server. + * Possible values include: 'Basic', 'Windows'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private SapHanaAuthenticationType authenticationType; + + /** + * Username to access the SAP HANA server. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password to access the SAP HANA server. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get host name of the SAP HANA server. Type: string (or Expression with resultType string). + * + * @return the server value + */ + public Object server() { + return this.server; + } + + /** + * Set host name of the SAP HANA server. Type: string (or Expression with resultType string). + * + * @param server the server value to set + * @return the SapHanaLinkedService object itself. + */ + public SapHanaLinkedService withServer(Object server) { + this.server = server; + return this; + } + + /** + * Get the authentication type to be used to connect to the SAP HANA server. Possible values include: 'Basic', 'Windows'. + * + * @return the authenticationType value + */ + public SapHanaAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to be used to connect to the SAP HANA server. Possible values include: 'Basic', 'Windows'. + * + * @param authenticationType the authenticationType value to set + * @return the SapHanaLinkedService object itself. + */ + public SapHanaLinkedService withAuthenticationType(SapHanaAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get username to access the SAP HANA server. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set username to access the SAP HANA server. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the SapHanaLinkedService object itself. + */ + public SapHanaLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password to access the SAP HANA server. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password to access the SAP HANA server. + * + * @param password the password value to set + * @return the SapHanaLinkedService object itself. + */ + public SapHanaLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SapHanaLinkedService object itself. + */ + public SapHanaLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ScheduleTrigger.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ScheduleTrigger.java new file mode 100644 index 000000000000..4bb3bd54dcf9 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ScheduleTrigger.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Trigger that creates pipeline runs periodically, on schedule. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ScheduleTrigger") +@JsonFlatten +public class ScheduleTrigger extends MultiplePipelineTrigger { + /** + * Recurrence schedule configuration. + */ + @JsonProperty(value = "typeProperties.recurrence", required = true) + private ScheduleTriggerRecurrence recurrence; + + /** + * Get recurrence schedule configuration. + * + * @return the recurrence value + */ + public ScheduleTriggerRecurrence recurrence() { + return this.recurrence; + } + + /** + * Set recurrence schedule configuration. + * + * @param recurrence the recurrence value to set + * @return the ScheduleTrigger object itself. + */ + public ScheduleTrigger withRecurrence(ScheduleTriggerRecurrence recurrence) { + this.recurrence = recurrence; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ScheduleTriggerRecurrence.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ScheduleTriggerRecurrence.java new file mode 100644 index 000000000000..25606de76a8e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ScheduleTriggerRecurrence.java @@ -0,0 +1,202 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import org.joda.time.DateTime; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The workflow trigger recurrence. + */ +public class ScheduleTriggerRecurrence { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The frequency. Possible values include: 'NotSpecified', 'Minute', + * 'Hour', 'Day', 'Week', 'Month', 'Year'. + */ + @JsonProperty(value = "frequency") + private RecurrenceFrequency frequency; + + /** + * The interval. + */ + @JsonProperty(value = "interval") + private Integer interval; + + /** + * The start time. + */ + @JsonProperty(value = "startTime") + private DateTime startTime; + + /** + * The end time. + */ + @JsonProperty(value = "endTime") + private DateTime endTime; + + /** + * The time zone. + */ + @JsonProperty(value = "timeZone") + private String timeZone; + + /** + * The recurrence schedule. + */ + @JsonProperty(value = "schedule") + private RecurrenceSchedule schedule; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the ScheduleTriggerRecurrence object itself. + */ + public ScheduleTriggerRecurrence withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the frequency. Possible values include: 'NotSpecified', 'Minute', 'Hour', 'Day', 'Week', 'Month', 'Year'. + * + * @return the frequency value + */ + public RecurrenceFrequency frequency() { + return this.frequency; + } + + /** + * Set the frequency. Possible values include: 'NotSpecified', 'Minute', 'Hour', 'Day', 'Week', 'Month', 'Year'. + * + * @param frequency the frequency value to set + * @return the ScheduleTriggerRecurrence object itself. + */ + public ScheduleTriggerRecurrence withFrequency(RecurrenceFrequency frequency) { + this.frequency = frequency; + return this; + } + + /** + * Get the interval. + * + * @return the interval value + */ + public Integer interval() { + return this.interval; + } + + /** + * Set the interval. + * + * @param interval the interval value to set + * @return the ScheduleTriggerRecurrence object itself. + */ + public ScheduleTriggerRecurrence withInterval(Integer interval) { + this.interval = interval; + return this; + } + + /** + * Get the start time. + * + * @return the startTime value + */ + public DateTime startTime() { + return this.startTime; + } + + /** + * Set the start time. + * + * @param startTime the startTime value to set + * @return the ScheduleTriggerRecurrence object itself. + */ + public ScheduleTriggerRecurrence withStartTime(DateTime startTime) { + this.startTime = startTime; + return this; + } + + /** + * Get the end time. + * + * @return the endTime value + */ + public DateTime endTime() { + return this.endTime; + } + + /** + * Set the end time. + * + * @param endTime the endTime value to set + * @return the ScheduleTriggerRecurrence object itself. + */ + public ScheduleTriggerRecurrence withEndTime(DateTime endTime) { + this.endTime = endTime; + return this; + } + + /** + * Get the time zone. + * + * @return the timeZone value + */ + public String timeZone() { + return this.timeZone; + } + + /** + * Set the time zone. + * + * @param timeZone the timeZone value to set + * @return the ScheduleTriggerRecurrence object itself. + */ + public ScheduleTriggerRecurrence withTimeZone(String timeZone) { + this.timeZone = timeZone; + return this; + } + + /** + * Get the recurrence schedule. + * + * @return the schedule value + */ + public RecurrenceSchedule schedule() { + return this.schedule; + } + + /** + * Set the recurrence schedule. + * + * @param schedule the schedule value to set + * @return the ScheduleTriggerRecurrence object itself. + */ + public ScheduleTriggerRecurrence withSchedule(RecurrenceSchedule schedule) { + this.schedule = schedule; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SecretBase.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SecretBase.java new file mode 100644 index 000000000000..43b5cec7e1da --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SecretBase.java @@ -0,0 +1,25 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * The base definition of a secret type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SecretBase") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "SecureString", value = SecureString.class), + @JsonSubTypes.Type(name = "AzureKeyVaultSecret", value = AzureKeyVaultSecretReference.class) +}) +public class SecretBase { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SecureString.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SecureString.java new file mode 100644 index 000000000000..79b5b88ef225 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SecureString.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * Azure Data Factory secure string definition. The string value will be masked + * with asterisks '*' during Get or List API calls. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SecureString") +public class SecureString extends SecretBase { + /** + * Value of secure string. + */ + @JsonProperty(value = "value", required = true) + private String value; + + /** + * Get value of secure string. + * + * @return the value value + */ + public String value() { + return this.value; + } + + /** + * Set value of secure string. + * + * @param value the value value to set + * @return the SecureString object itself. + */ + public SecureString withValue(String value) { + this.value = value; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntime.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntime.java new file mode 100644 index 000000000000..c3372bf214e4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntime.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.IntegrationRuntimeInner; + +/** + * Self-hosted integration runtime. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SelfHosted") +@JsonFlatten +public class SelfHostedIntegrationRuntime extends IntegrationRuntimeInner { + /** + * The linkedInfo property. + */ + @JsonProperty(value = "typeProperties.linkedInfo") + private LinkedIntegrationRuntimeProperties linkedInfo; + + /** + * Get the linkedInfo value. + * + * @return the linkedInfo value + */ + public LinkedIntegrationRuntimeProperties linkedInfo() { + return this.linkedInfo; + } + + /** + * Set the linkedInfo value. + * + * @param linkedInfo the linkedInfo value to set + * @return the SelfHostedIntegrationRuntime object itself. + */ + public SelfHostedIntegrationRuntime withLinkedInfo(LinkedIntegrationRuntimeProperties linkedInfo) { + this.linkedInfo = linkedInfo; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeNode.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeNode.java new file mode 100644 index 000000000000..d2594de3f3c3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeNode.java @@ -0,0 +1,112 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.SelfHostedIntegrationRuntimeNodeInner; +import java.util.Map; +import org.joda.time.DateTime; + +/** + * Type representing SelfHostedIntegrationRuntimeNode. + */ +public interface SelfHostedIntegrationRuntimeNode extends HasInner, HasManager { + /** + * @return the capabilities value. + */ + Map capabilities(); + + /** + * @return the concurrentJobsLimit value. + */ + Integer concurrentJobsLimit(); + + /** + * @return the expiryTime value. + */ + DateTime expiryTime(); + + /** + * @return the hostServiceUri value. + */ + String hostServiceUri(); + + /** + * @return the isActiveDispatcher value. + */ + Boolean isActiveDispatcher(); + + /** + * @return the lastConnectTime value. + */ + DateTime lastConnectTime(); + + /** + * @return the lastEndUpdateTime value. + */ + DateTime lastEndUpdateTime(); + + /** + * @return the lastStartTime value. + */ + DateTime lastStartTime(); + + /** + * @return the lastStartUpdateTime value. + */ + DateTime lastStartUpdateTime(); + + /** + * @return the lastStopTime value. + */ + DateTime lastStopTime(); + + /** + * @return the lastUpdateResult value. + */ + IntegrationRuntimeUpdateResult lastUpdateResult(); + + /** + * @return the machineName value. + */ + String machineName(); + + /** + * @return the maxConcurrentJobs value. + */ + Integer maxConcurrentJobs(); + + /** + * @return the nodeName value. + */ + String nodeName(); + + /** + * @return the registerTime value. + */ + DateTime registerTime(); + + /** + * @return the status value. + */ + SelfHostedIntegrationRuntimeNodeStatus status(); + + /** + * @return the version value. + */ + String version(); + + /** + * @return the versionStatus value. + */ + String versionStatus(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeNodeStatus.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeNodeStatus.java new file mode 100644 index 000000000000..7125300b2cc5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeNodeStatus.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SelfHostedIntegrationRuntimeNodeStatus. + */ +public final class SelfHostedIntegrationRuntimeNodeStatus extends ExpandableStringEnum { + /** Static value NeedRegistration for SelfHostedIntegrationRuntimeNodeStatus. */ + public static final SelfHostedIntegrationRuntimeNodeStatus NEED_REGISTRATION = fromString("NeedRegistration"); + + /** Static value Online for SelfHostedIntegrationRuntimeNodeStatus. */ + public static final SelfHostedIntegrationRuntimeNodeStatus ONLINE = fromString("Online"); + + /** Static value Limited for SelfHostedIntegrationRuntimeNodeStatus. */ + public static final SelfHostedIntegrationRuntimeNodeStatus LIMITED = fromString("Limited"); + + /** Static value Offline for SelfHostedIntegrationRuntimeNodeStatus. */ + public static final SelfHostedIntegrationRuntimeNodeStatus OFFLINE = fromString("Offline"); + + /** Static value Upgrading for SelfHostedIntegrationRuntimeNodeStatus. */ + public static final SelfHostedIntegrationRuntimeNodeStatus UPGRADING = fromString("Upgrading"); + + /** Static value Initializing for SelfHostedIntegrationRuntimeNodeStatus. */ + public static final SelfHostedIntegrationRuntimeNodeStatus INITIALIZING = fromString("Initializing"); + + /** Static value InitializeFailed for SelfHostedIntegrationRuntimeNodeStatus. */ + public static final SelfHostedIntegrationRuntimeNodeStatus INITIALIZE_FAILED = fromString("InitializeFailed"); + + /** + * Creates or finds a SelfHostedIntegrationRuntimeNodeStatus from its string representation. + * @param name a name to look for + * @return the corresponding SelfHostedIntegrationRuntimeNodeStatus + */ + @JsonCreator + public static SelfHostedIntegrationRuntimeNodeStatus fromString(String name) { + return fromString(name, SelfHostedIntegrationRuntimeNodeStatus.class); + } + + /** + * @return known SelfHostedIntegrationRuntimeNodeStatus values + */ + public static Collection values() { + return values(SelfHostedIntegrationRuntimeNodeStatus.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeStatus.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeStatus.java new file mode 100644 index 000000000000..6b3e120a41f1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SelfHostedIntegrationRuntimeStatus.java @@ -0,0 +1,252 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import org.joda.time.DateTime; +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.SelfHostedIntegrationRuntimeNodeInner; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Self-hosted integration runtime status. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SelfHosted") +@JsonFlatten +public class SelfHostedIntegrationRuntimeStatus extends IntegrationRuntimeStatus { + /** + * The time at which the integration runtime was created, in ISO8601 + * format. + */ + @JsonProperty(value = "typeProperties.createTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime createTime; + + /** + * The task queue id of the integration runtime. + */ + @JsonProperty(value = "typeProperties.taskQueueId", access = JsonProperty.Access.WRITE_ONLY) + private String taskQueueId; + + /** + * It is used to set the encryption mode for node-node communication + * channel (when more than 2 self-hosted integration runtime nodes exist). + * Possible values include: 'NotSet', 'SslEncrypted', 'NotEncrypted'. + */ + @JsonProperty(value = "typeProperties.internalChannelEncryption", access = JsonProperty.Access.WRITE_ONLY) + private IntegrationRuntimeInternalChannelEncryptionMode internalChannelEncryption; + + /** + * Version of the integration runtime. + */ + @JsonProperty(value = "typeProperties.version", access = JsonProperty.Access.WRITE_ONLY) + private String version; + + /** + * The list of nodes for this integration runtime. + */ + @JsonProperty(value = "typeProperties.nodes") + private List nodes; + + /** + * The date at which the integration runtime will be scheduled to update, + * in ISO8601 format. + */ + @JsonProperty(value = "typeProperties.scheduledUpdateDate", access = JsonProperty.Access.WRITE_ONLY) + private DateTime scheduledUpdateDate; + + /** + * The time in the date scheduled by service to update the integration + * runtime, e.g., PT03H is 3 hours. + */ + @JsonProperty(value = "typeProperties.updateDelayOffset", access = JsonProperty.Access.WRITE_ONLY) + private String updateDelayOffset; + + /** + * The local time zone offset in hours. + */ + @JsonProperty(value = "typeProperties.localTimeZoneOffset", access = JsonProperty.Access.WRITE_ONLY) + private String localTimeZoneOffset; + + /** + * Object with additional information about integration runtime + * capabilities. + */ + @JsonProperty(value = "typeProperties.capabilities", access = JsonProperty.Access.WRITE_ONLY) + private Map capabilities; + + /** + * The URLs for the services used in integration runtime backend service. + */ + @JsonProperty(value = "typeProperties.serviceUrls", access = JsonProperty.Access.WRITE_ONLY) + private List serviceUrls; + + /** + * Whether Self-hosted integration runtime auto update has been turned on. + * Possible values include: 'On', 'Off'. + */ + @JsonProperty(value = "typeProperties.autoUpdate", access = JsonProperty.Access.WRITE_ONLY) + private IntegrationRuntimeAutoUpdate autoUpdate; + + /** + * Status of the integration runtime version. + */ + @JsonProperty(value = "typeProperties.versionStatus", access = JsonProperty.Access.WRITE_ONLY) + private String versionStatus; + + /** + * The list of linked integration runtimes that are created to share with + * this integration runtime. + */ + @JsonProperty(value = "typeProperties.links") + private List links; + + /** + * Get the time at which the integration runtime was created, in ISO8601 format. + * + * @return the createTime value + */ + public DateTime createTime() { + return this.createTime; + } + + /** + * Get the task queue id of the integration runtime. + * + * @return the taskQueueId value + */ + public String taskQueueId() { + return this.taskQueueId; + } + + /** + * Get it is used to set the encryption mode for node-node communication channel (when more than 2 self-hosted integration runtime nodes exist). Possible values include: 'NotSet', 'SslEncrypted', 'NotEncrypted'. + * + * @return the internalChannelEncryption value + */ + public IntegrationRuntimeInternalChannelEncryptionMode internalChannelEncryption() { + return this.internalChannelEncryption; + } + + /** + * Get version of the integration runtime. + * + * @return the version value + */ + public String version() { + return this.version; + } + + /** + * Get the list of nodes for this integration runtime. + * + * @return the nodes value + */ + public List nodes() { + return this.nodes; + } + + /** + * Set the list of nodes for this integration runtime. + * + * @param nodes the nodes value to set + * @return the SelfHostedIntegrationRuntimeStatus object itself. + */ + public SelfHostedIntegrationRuntimeStatus withNodes(List nodes) { + this.nodes = nodes; + return this; + } + + /** + * Get the date at which the integration runtime will be scheduled to update, in ISO8601 format. + * + * @return the scheduledUpdateDate value + */ + public DateTime scheduledUpdateDate() { + return this.scheduledUpdateDate; + } + + /** + * Get the time in the date scheduled by service to update the integration runtime, e.g., PT03H is 3 hours. + * + * @return the updateDelayOffset value + */ + public String updateDelayOffset() { + return this.updateDelayOffset; + } + + /** + * Get the local time zone offset in hours. + * + * @return the localTimeZoneOffset value + */ + public String localTimeZoneOffset() { + return this.localTimeZoneOffset; + } + + /** + * Get object with additional information about integration runtime capabilities. + * + * @return the capabilities value + */ + public Map capabilities() { + return this.capabilities; + } + + /** + * Get the URLs for the services used in integration runtime backend service. + * + * @return the serviceUrls value + */ + public List serviceUrls() { + return this.serviceUrls; + } + + /** + * Get whether Self-hosted integration runtime auto update has been turned on. Possible values include: 'On', 'Off'. + * + * @return the autoUpdate value + */ + public IntegrationRuntimeAutoUpdate autoUpdate() { + return this.autoUpdate; + } + + /** + * Get status of the integration runtime version. + * + * @return the versionStatus value + */ + public String versionStatus() { + return this.versionStatus; + } + + /** + * Get the list of linked integration runtimes that are created to share with this integration runtime. + * + * @return the links value + */ + public List links() { + return this.links; + } + + /** + * Set the list of linked integration runtimes that are created to share with this integration runtime. + * + * @param links the links value to set + * @return the SelfHostedIntegrationRuntimeStatus object itself. + */ + public SelfHostedIntegrationRuntimeStatus withLinks(List links) { + this.links = links; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowAuthenticationType.java new file mode 100644 index 000000000000..378a8c6fdcfb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for ServiceNowAuthenticationType. + */ +public final class ServiceNowAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for ServiceNowAuthenticationType. */ + public static final ServiceNowAuthenticationType BASIC = fromString("Basic"); + + /** Static value OAuth2 for ServiceNowAuthenticationType. */ + public static final ServiceNowAuthenticationType OAUTH2 = fromString("OAuth2"); + + /** + * Creates or finds a ServiceNowAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding ServiceNowAuthenticationType + */ + @JsonCreator + public static ServiceNowAuthenticationType fromString(String name) { + return fromString(name, ServiceNowAuthenticationType.class); + } + + /** + * @return known ServiceNowAuthenticationType values + */ + public static Collection values() { + return values(ServiceNowAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowLinkedService.java new file mode 100644 index 000000000000..d3d8a44c3221 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowLinkedService.java @@ -0,0 +1,294 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * ServiceNow server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ServiceNow") +@JsonFlatten +public class ServiceNowLinkedService extends LinkedServiceInner { + /** + * The endpoint of the ServiceNow server. (i.e. + * <instance>.service-now.com). + */ + @JsonProperty(value = "typeProperties.endpoint", required = true) + private Object endpoint; + + /** + * The authentication type to use. Possible values include: 'Basic', + * 'OAuth2'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private ServiceNowAuthenticationType authenticationType; + + /** + * The user name used to connect to the ServiceNow server for Basic and + * OAuth2 authentication. + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password corresponding to the user name for Basic and OAuth2 + * authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The client id for OAuth2 authentication. + */ + @JsonProperty(value = "typeProperties.clientId") + private Object clientId; + + /** + * The client secret for OAuth2 authentication. + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the ServiceNow server. (i.e. <instance>.service-now.com). + * + * @return the endpoint value + */ + public Object endpoint() { + return this.endpoint; + } + + /** + * Set the endpoint of the ServiceNow server. (i.e. <instance>.service-now.com). + * + * @param endpoint the endpoint value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withEndpoint(Object endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Get the authentication type to use. Possible values include: 'Basic', 'OAuth2'. + * + * @return the authenticationType value + */ + public ServiceNowAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to use. Possible values include: 'Basic', 'OAuth2'. + * + * @param authenticationType the authenticationType value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withAuthenticationType(ServiceNowAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the user name used to connect to the ServiceNow server for Basic and OAuth2 authentication. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name used to connect to the ServiceNow server for Basic and OAuth2 authentication. + * + * @param username the username value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name for Basic and OAuth2 authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name for Basic and OAuth2 authentication. + * + * @param password the password value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the client id for OAuth2 authentication. + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set the client id for OAuth2 authentication. + * + * @param clientId the clientId value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret for OAuth2 authentication. + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret for OAuth2 authentication. + * + * @param clientSecret the clientSecret value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the ServiceNowLinkedService object itself. + */ + public ServiceNowLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowObjectDataset.java new file mode 100644 index 000000000000..3fd0a5bfaf77 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * ServiceNow server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ServiceNowObject") +public class ServiceNowObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowSource.java new file mode 100644 index 000000000000..f3353e1377ae --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ServiceNowSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity ServiceNow server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ServiceNowSource") +public class ServiceNowSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the ServiceNowSource object itself. + */ + public ServiceNowSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SftpAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SftpAuthenticationType.java new file mode 100644 index 000000000000..c8a45939c298 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SftpAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SftpAuthenticationType. + */ +public final class SftpAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for SftpAuthenticationType. */ + public static final SftpAuthenticationType BASIC = fromString("Basic"); + + /** Static value SshPublicKey for SftpAuthenticationType. */ + public static final SftpAuthenticationType SSH_PUBLIC_KEY = fromString("SshPublicKey"); + + /** + * Creates or finds a SftpAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding SftpAuthenticationType + */ + @JsonCreator + public static SftpAuthenticationType fromString(String name) { + return fromString(name, SftpAuthenticationType.class); + } + + /** + * @return known SftpAuthenticationType values + */ + public static Collection values() { + return values(SftpAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SftpServerLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SftpServerLinkedService.java new file mode 100644 index 000000000000..f544bbd89ce0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SftpServerLinkedService.java @@ -0,0 +1,328 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * A linked service for an SSH File Transfer Protocol (SFTP) server. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Sftp") +@JsonFlatten +public class SftpServerLinkedService extends LinkedServiceInner { + /** + * The SFTP server host name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port number that the SFTP server uses to listen for client + * connections. Default value is 22. Type: integer (or Expression with + * resultType integer), minimum: 0. + */ + @JsonProperty(value = "typeProperties.port") + private Object port; + + /** + * The authentication type to be used to connect to the FTP server. + * Possible values include: 'Basic', 'SshPublicKey'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private SftpAuthenticationType authenticationType; + + /** + * The username used to log on to the SFTP server. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * Password to logon the SFTP server for Basic authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * The SSH private key file path for SshPublicKey authentication. Only + * valid for on-premises copy. For on-premises copy with SshPublicKey + * authentication, either PrivateKeyPath or PrivateKeyContent should be + * specified. SSH private key should be OpenSSH format. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.privateKeyPath") + private Object privateKeyPath; + + /** + * Base64 encoded SSH private key content for SshPublicKey authentication. + * For on-premises copy with SshPublicKey authentication, either + * PrivateKeyPath or PrivateKeyContent should be specified. SSH private key + * should be OpenSSH format. + */ + @JsonProperty(value = "typeProperties.privateKeyContent") + private SecretBase privateKeyContent; + + /** + * The password to decrypt the SSH private key if the SSH private key is + * encrypted. + */ + @JsonProperty(value = "typeProperties.passPhrase") + private SecretBase passPhrase; + + /** + * If true, skip the SSH host key validation. Default value is false. Type: + * boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "typeProperties.skipHostKeyValidation") + private Object skipHostKeyValidation; + + /** + * The host key finger-print of the SFTP server. When SkipHostKeyValidation + * is false, HostKeyFingerprint should be specified. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.hostKeyFingerprint") + private Object hostKeyFingerprint; + + /** + * Get the SFTP server host name. Type: string (or Expression with resultType string). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the SFTP server host name. Type: string (or Expression with resultType string). + * + * @param host the host value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port number that the SFTP server uses to listen for client connections. Default value is 22. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port number that the SFTP server uses to listen for client connections. Default value is 22. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param port the port value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the authentication type to be used to connect to the FTP server. Possible values include: 'Basic', 'SshPublicKey'. + * + * @return the authenticationType value + */ + public SftpAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication type to be used to connect to the FTP server. Possible values include: 'Basic', 'SshPublicKey'. + * + * @param authenticationType the authenticationType value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withAuthenticationType(SftpAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the username used to log on to the SFTP server. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set the username used to log on to the SFTP server. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get password to logon the SFTP server for Basic authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password to logon the SFTP server for Basic authentication. + * + * @param password the password value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + + /** + * Get the SSH private key file path for SshPublicKey authentication. Only valid for on-premises copy. For on-premises copy with SshPublicKey authentication, either PrivateKeyPath or PrivateKeyContent should be specified. SSH private key should be OpenSSH format. Type: string (or Expression with resultType string). + * + * @return the privateKeyPath value + */ + public Object privateKeyPath() { + return this.privateKeyPath; + } + + /** + * Set the SSH private key file path for SshPublicKey authentication. Only valid for on-premises copy. For on-premises copy with SshPublicKey authentication, either PrivateKeyPath or PrivateKeyContent should be specified. SSH private key should be OpenSSH format. Type: string (or Expression with resultType string). + * + * @param privateKeyPath the privateKeyPath value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withPrivateKeyPath(Object privateKeyPath) { + this.privateKeyPath = privateKeyPath; + return this; + } + + /** + * Get base64 encoded SSH private key content for SshPublicKey authentication. For on-premises copy with SshPublicKey authentication, either PrivateKeyPath or PrivateKeyContent should be specified. SSH private key should be OpenSSH format. + * + * @return the privateKeyContent value + */ + public SecretBase privateKeyContent() { + return this.privateKeyContent; + } + + /** + * Set base64 encoded SSH private key content for SshPublicKey authentication. For on-premises copy with SshPublicKey authentication, either PrivateKeyPath or PrivateKeyContent should be specified. SSH private key should be OpenSSH format. + * + * @param privateKeyContent the privateKeyContent value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withPrivateKeyContent(SecretBase privateKeyContent) { + this.privateKeyContent = privateKeyContent; + return this; + } + + /** + * Get the password to decrypt the SSH private key if the SSH private key is encrypted. + * + * @return the passPhrase value + */ + public SecretBase passPhrase() { + return this.passPhrase; + } + + /** + * Set the password to decrypt the SSH private key if the SSH private key is encrypted. + * + * @param passPhrase the passPhrase value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withPassPhrase(SecretBase passPhrase) { + this.passPhrase = passPhrase; + return this; + } + + /** + * Get if true, skip the SSH host key validation. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @return the skipHostKeyValidation value + */ + public Object skipHostKeyValidation() { + return this.skipHostKeyValidation; + } + + /** + * Set if true, skip the SSH host key validation. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @param skipHostKeyValidation the skipHostKeyValidation value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withSkipHostKeyValidation(Object skipHostKeyValidation) { + this.skipHostKeyValidation = skipHostKeyValidation; + return this; + } + + /** + * Get the host key finger-print of the SFTP server. When SkipHostKeyValidation is false, HostKeyFingerprint should be specified. Type: string (or Expression with resultType string). + * + * @return the hostKeyFingerprint value + */ + public Object hostKeyFingerprint() { + return this.hostKeyFingerprint; + } + + /** + * Set the host key finger-print of the SFTP server. When SkipHostKeyValidation is false, HostKeyFingerprint should be specified. Type: string (or Expression with resultType string). + * + * @param hostKeyFingerprint the hostKeyFingerprint value to set + * @return the SftpServerLinkedService object itself. + */ + public SftpServerLinkedService withHostKeyFingerprint(Object hostKeyFingerprint) { + this.hostKeyFingerprint = hostKeyFingerprint; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifyLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifyLinkedService.java new file mode 100644 index 000000000000..d69682c5b875 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifyLinkedService.java @@ -0,0 +1,187 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Shopify Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Shopify") +@JsonFlatten +public class ShopifyLinkedService extends LinkedServiceInner { + /** + * The endpoint of the Shopify server. (i.e. mystore.myshopify.com). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The API access token that can be used to access Shopify’s data. The + * token won't expire if it is offline mode. + */ + @JsonProperty(value = "typeProperties.accessToken") + private SecretBase accessToken; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the Shopify server. (i.e. mystore.myshopify.com). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the endpoint of the Shopify server. (i.e. mystore.myshopify.com). + * + * @param host the host value to set + * @return the ShopifyLinkedService object itself. + */ + public ShopifyLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the API access token that can be used to access Shopify’s data. The token won't expire if it is offline mode. + * + * @return the accessToken value + */ + public SecretBase accessToken() { + return this.accessToken; + } + + /** + * Set the API access token that can be used to access Shopify’s data. The token won't expire if it is offline mode. + * + * @param accessToken the accessToken value to set + * @return the ShopifyLinkedService object itself. + */ + public ShopifyLinkedService withAccessToken(SecretBase accessToken) { + this.accessToken = accessToken; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the ShopifyLinkedService object itself. + */ + public ShopifyLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the ShopifyLinkedService object itself. + */ + public ShopifyLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the ShopifyLinkedService object itself. + */ + public ShopifyLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the ShopifyLinkedService object itself. + */ + public ShopifyLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifyObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifyObjectDataset.java new file mode 100644 index 000000000000..207a9e480386 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifyObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Shopify Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ShopifyObject") +public class ShopifyObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifySource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifySource.java new file mode 100644 index 000000000000..be4f887b9547 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ShopifySource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Shopify Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ShopifySource") +public class ShopifySource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the ShopifySource object itself. + */ + public ShopifySource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkAuthenticationType.java new file mode 100644 index 000000000000..00f6b8bae7a4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkAuthenticationType.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SparkAuthenticationType. + */ +public final class SparkAuthenticationType extends ExpandableStringEnum { + /** Static value Anonymous for SparkAuthenticationType. */ + public static final SparkAuthenticationType ANONYMOUS = fromString("Anonymous"); + + /** Static value Username for SparkAuthenticationType. */ + public static final SparkAuthenticationType USERNAME = fromString("Username"); + + /** Static value UsernameAndPassword for SparkAuthenticationType. */ + public static final SparkAuthenticationType USERNAME_AND_PASSWORD = fromString("UsernameAndPassword"); + + /** Static value WindowsAzureHDInsightService for SparkAuthenticationType. */ + public static final SparkAuthenticationType WINDOWS_AZURE_HDINSIGHT_SERVICE = fromString("WindowsAzureHDInsightService"); + + /** + * Creates or finds a SparkAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding SparkAuthenticationType + */ + @JsonCreator + public static SparkAuthenticationType fromString(String name) { + return fromString(name, SparkAuthenticationType.class); + } + + /** + * @return known SparkAuthenticationType values + */ + public static Collection values() { + return values(SparkAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkLinkedService.java new file mode 100644 index 000000000000..69fd7b5b3090 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkLinkedService.java @@ -0,0 +1,404 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Spark Server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Spark") +@JsonFlatten +public class SparkLinkedService extends LinkedServiceInner { + /** + * IP address or host name of the Spark server. + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The TCP port that the Spark server uses to listen for client + * connections. + */ + @JsonProperty(value = "typeProperties.port", required = true) + private Object port; + + /** + * The type of Spark server. Possible values include: 'SharkServer', + * 'SharkServer2', 'SparkThriftServer'. + */ + @JsonProperty(value = "typeProperties.serverType") + private SparkServerType serverType; + + /** + * The transport protocol to use in the Thrift layer. Possible values + * include: 'Binary', 'SASL', 'HTTP '. + */ + @JsonProperty(value = "typeProperties.thriftTransportProtocol") + private SparkThriftTransportProtocol thriftTransportProtocol; + + /** + * The authentication method used to access the Spark server. Possible + * values include: 'Anonymous', 'Username', 'UsernameAndPassword', + * 'WindowsAzureHDInsightService'. + */ + @JsonProperty(value = "typeProperties.authenticationType", required = true) + private SparkAuthenticationType authenticationType; + + /** + * The user name that you use to access Spark Server. + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * The password corresponding to the user name that you provided in the + * Username field. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The partial URL corresponding to the Spark server. + */ + @JsonProperty(value = "typeProperties.httpPath") + private Object httpPath; + + /** + * Specifies whether the connections to the server are encrypted using SSL. + * The default value is false. + */ + @JsonProperty(value = "typeProperties.enableSsl") + private Object enableSsl; + + /** + * The full path of the .pem file containing trusted CA certificates for + * verifying the server when connecting over SSL. This property can only be + * set when using SSL on self-hosted IR. The default value is the + * cacerts.pem file installed with the IR. + */ + @JsonProperty(value = "typeProperties.trustedCertPath") + private Object trustedCertPath; + + /** + * Specifies whether to use a CA certificate from the system trust store or + * from a specified PEM file. The default value is false. + */ + @JsonProperty(value = "typeProperties.useSystemTrustStore") + private Object useSystemTrustStore; + + /** + * Specifies whether to require a CA-issued SSL certificate name to match + * the host name of the server when connecting over SSL. The default value + * is false. + */ + @JsonProperty(value = "typeProperties.allowHostNameCNMismatch") + private Object allowHostNameCNMismatch; + + /** + * Specifies whether to allow self-signed certificates from the server. The + * default value is false. + */ + @JsonProperty(value = "typeProperties.allowSelfSignedServerCert") + private Object allowSelfSignedServerCert; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get iP address or host name of the Spark server. + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set iP address or host name of the Spark server. + * + * @param host the host value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the TCP port that the Spark server uses to listen for client connections. + * + * @return the port value + */ + public Object port() { + return this.port; + } + + /** + * Set the TCP port that the Spark server uses to listen for client connections. + * + * @param port the port value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withPort(Object port) { + this.port = port; + return this; + } + + /** + * Get the type of Spark server. Possible values include: 'SharkServer', 'SharkServer2', 'SparkThriftServer'. + * + * @return the serverType value + */ + public SparkServerType serverType() { + return this.serverType; + } + + /** + * Set the type of Spark server. Possible values include: 'SharkServer', 'SharkServer2', 'SparkThriftServer'. + * + * @param serverType the serverType value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withServerType(SparkServerType serverType) { + this.serverType = serverType; + return this; + } + + /** + * Get the transport protocol to use in the Thrift layer. Possible values include: 'Binary', 'SASL', 'HTTP '. + * + * @return the thriftTransportProtocol value + */ + public SparkThriftTransportProtocol thriftTransportProtocol() { + return this.thriftTransportProtocol; + } + + /** + * Set the transport protocol to use in the Thrift layer. Possible values include: 'Binary', 'SASL', 'HTTP '. + * + * @param thriftTransportProtocol the thriftTransportProtocol value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withThriftTransportProtocol(SparkThriftTransportProtocol thriftTransportProtocol) { + this.thriftTransportProtocol = thriftTransportProtocol; + return this; + } + + /** + * Get the authentication method used to access the Spark server. Possible values include: 'Anonymous', 'Username', 'UsernameAndPassword', 'WindowsAzureHDInsightService'. + * + * @return the authenticationType value + */ + public SparkAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set the authentication method used to access the Spark server. Possible values include: 'Anonymous', 'Username', 'UsernameAndPassword', 'WindowsAzureHDInsightService'. + * + * @param authenticationType the authenticationType value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withAuthenticationType(SparkAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get the user name that you use to access Spark Server. + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set the user name that you use to access Spark Server. + * + * @param username the username value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password corresponding to the user name that you provided in the Username field. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password corresponding to the user name that you provided in the Username field. + * + * @param password the password value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the partial URL corresponding to the Spark server. + * + * @return the httpPath value + */ + public Object httpPath() { + return this.httpPath; + } + + /** + * Set the partial URL corresponding to the Spark server. + * + * @param httpPath the httpPath value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withHttpPath(Object httpPath) { + this.httpPath = httpPath; + return this; + } + + /** + * Get specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @return the enableSsl value + */ + public Object enableSsl() { + return this.enableSsl; + } + + /** + * Set specifies whether the connections to the server are encrypted using SSL. The default value is false. + * + * @param enableSsl the enableSsl value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withEnableSsl(Object enableSsl) { + this.enableSsl = enableSsl; + return this; + } + + /** + * Get the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @return the trustedCertPath value + */ + public Object trustedCertPath() { + return this.trustedCertPath; + } + + /** + * Set the full path of the .pem file containing trusted CA certificates for verifying the server when connecting over SSL. This property can only be set when using SSL on self-hosted IR. The default value is the cacerts.pem file installed with the IR. + * + * @param trustedCertPath the trustedCertPath value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withTrustedCertPath(Object trustedCertPath) { + this.trustedCertPath = trustedCertPath; + return this; + } + + /** + * Get specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @return the useSystemTrustStore value + */ + public Object useSystemTrustStore() { + return this.useSystemTrustStore; + } + + /** + * Set specifies whether to use a CA certificate from the system trust store or from a specified PEM file. The default value is false. + * + * @param useSystemTrustStore the useSystemTrustStore value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withUseSystemTrustStore(Object useSystemTrustStore) { + this.useSystemTrustStore = useSystemTrustStore; + return this; + } + + /** + * Get specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @return the allowHostNameCNMismatch value + */ + public Object allowHostNameCNMismatch() { + return this.allowHostNameCNMismatch; + } + + /** + * Set specifies whether to require a CA-issued SSL certificate name to match the host name of the server when connecting over SSL. The default value is false. + * + * @param allowHostNameCNMismatch the allowHostNameCNMismatch value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withAllowHostNameCNMismatch(Object allowHostNameCNMismatch) { + this.allowHostNameCNMismatch = allowHostNameCNMismatch; + return this; + } + + /** + * Get specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @return the allowSelfSignedServerCert value + */ + public Object allowSelfSignedServerCert() { + return this.allowSelfSignedServerCert; + } + + /** + * Set specifies whether to allow self-signed certificates from the server. The default value is false. + * + * @param allowSelfSignedServerCert the allowSelfSignedServerCert value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withAllowSelfSignedServerCert(Object allowSelfSignedServerCert) { + this.allowSelfSignedServerCert = allowSelfSignedServerCert; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SparkLinkedService object itself. + */ + public SparkLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkObjectDataset.java new file mode 100644 index 000000000000..9fa51eb01d33 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Spark Server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SparkObject") +public class SparkObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkServerType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkServerType.java new file mode 100644 index 000000000000..89fa94095825 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkServerType.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SparkServerType. + */ +public final class SparkServerType extends ExpandableStringEnum { + /** Static value SharkServer for SparkServerType. */ + public static final SparkServerType SHARK_SERVER = fromString("SharkServer"); + + /** Static value SharkServer2 for SparkServerType. */ + public static final SparkServerType SHARK_SERVER2 = fromString("SharkServer2"); + + /** Static value SparkThriftServer for SparkServerType. */ + public static final SparkServerType SPARK_THRIFT_SERVER = fromString("SparkThriftServer"); + + /** + * Creates or finds a SparkServerType from its string representation. + * @param name a name to look for + * @return the corresponding SparkServerType + */ + @JsonCreator + public static SparkServerType fromString(String name) { + return fromString(name, SparkServerType.class); + } + + /** + * @return known SparkServerType values + */ + public static Collection values() { + return values(SparkServerType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkSource.java new file mode 100644 index 000000000000..2b6aec144dbe --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Spark Server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SparkSource") +public class SparkSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the SparkSource object itself. + */ + public SparkSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkThriftTransportProtocol.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkThriftTransportProtocol.java new file mode 100644 index 000000000000..39a98704c92b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SparkThriftTransportProtocol.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SparkThriftTransportProtocol. + */ +public final class SparkThriftTransportProtocol extends ExpandableStringEnum { + /** Static value Binary for SparkThriftTransportProtocol. */ + public static final SparkThriftTransportProtocol BINARY = fromString("Binary"); + + /** Static value SASL for SparkThriftTransportProtocol. */ + public static final SparkThriftTransportProtocol SASL = fromString("SASL"); + + /** Static value HTTP for SparkThriftTransportProtocol. */ + public static final SparkThriftTransportProtocol HTTP_ = fromString("HTTP "); + + /** + * Creates or finds a SparkThriftTransportProtocol from its string representation. + * @param name a name to look for + * @return the corresponding SparkThriftTransportProtocol + */ + @JsonCreator + public static SparkThriftTransportProtocol fromString(String name) { + return fromString(name, SparkThriftTransportProtocol.class); + } + + /** + * @return known SparkThriftTransportProtocol values + */ + public static Collection values() { + return values(SparkThriftTransportProtocol.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlDWSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlDWSink.java new file mode 100644 index 000000000000..64f339e108c9 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlDWSink.java @@ -0,0 +1,101 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity SQL Data Warehouse sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SqlDWSink") +public class SqlDWSink extends CopySink { + /** + * SQL pre-copy script. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "preCopyScript") + private Object preCopyScript; + + /** + * Indicates to use PolyBase to copy data into SQL Data Warehouse when + * applicable. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "allowPolyBase") + private Object allowPolyBase; + + /** + * Specifies PolyBase-related settings when allowPolyBase is true. + */ + @JsonProperty(value = "polyBaseSettings") + private PolybaseSettings polyBaseSettings; + + /** + * Get sQL pre-copy script. Type: string (or Expression with resultType string). + * + * @return the preCopyScript value + */ + public Object preCopyScript() { + return this.preCopyScript; + } + + /** + * Set sQL pre-copy script. Type: string (or Expression with resultType string). + * + * @param preCopyScript the preCopyScript value to set + * @return the SqlDWSink object itself. + */ + public SqlDWSink withPreCopyScript(Object preCopyScript) { + this.preCopyScript = preCopyScript; + return this; + } + + /** + * Get indicates to use PolyBase to copy data into SQL Data Warehouse when applicable. Type: boolean (or Expression with resultType boolean). + * + * @return the allowPolyBase value + */ + public Object allowPolyBase() { + return this.allowPolyBase; + } + + /** + * Set indicates to use PolyBase to copy data into SQL Data Warehouse when applicable. Type: boolean (or Expression with resultType boolean). + * + * @param allowPolyBase the allowPolyBase value to set + * @return the SqlDWSink object itself. + */ + public SqlDWSink withAllowPolyBase(Object allowPolyBase) { + this.allowPolyBase = allowPolyBase; + return this; + } + + /** + * Get specifies PolyBase-related settings when allowPolyBase is true. + * + * @return the polyBaseSettings value + */ + public PolybaseSettings polyBaseSettings() { + return this.polyBaseSettings; + } + + /** + * Set specifies PolyBase-related settings when allowPolyBase is true. + * + * @param polyBaseSettings the polyBaseSettings value to set + * @return the SqlDWSink object itself. + */ + public SqlDWSink withPolyBaseSettings(PolybaseSettings polyBaseSettings) { + this.polyBaseSettings = polyBaseSettings; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlDWSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlDWSource.java new file mode 100644 index 000000000000..5a094543436b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlDWSource.java @@ -0,0 +1,104 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity SQL Data Warehouse source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SqlDWSource") +public class SqlDWSource extends CopySource { + /** + * SQL Data Warehouse reader query. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "sqlReaderQuery") + private Object sqlReaderQuery; + + /** + * Name of the stored procedure for a SQL Data Warehouse source. This + * cannot be used at the same time as SqlReaderQuery. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "sqlReaderStoredProcedureName") + private Object sqlReaderStoredProcedureName; + + /** + * Value and type setting for stored procedure parameters. Example: + * "{Parameter1: {value: "1", type: "int"}}". Type: object (or Expression + * with resultType object), itemType: StoredProcedureParameter. + */ + @JsonProperty(value = "storedProcedureParameters") + private Object storedProcedureParameters; + + /** + * Get sQL Data Warehouse reader query. Type: string (or Expression with resultType string). + * + * @return the sqlReaderQuery value + */ + public Object sqlReaderQuery() { + return this.sqlReaderQuery; + } + + /** + * Set sQL Data Warehouse reader query. Type: string (or Expression with resultType string). + * + * @param sqlReaderQuery the sqlReaderQuery value to set + * @return the SqlDWSource object itself. + */ + public SqlDWSource withSqlReaderQuery(Object sqlReaderQuery) { + this.sqlReaderQuery = sqlReaderQuery; + return this; + } + + /** + * Get name of the stored procedure for a SQL Data Warehouse source. This cannot be used at the same time as SqlReaderQuery. Type: string (or Expression with resultType string). + * + * @return the sqlReaderStoredProcedureName value + */ + public Object sqlReaderStoredProcedureName() { + return this.sqlReaderStoredProcedureName; + } + + /** + * Set name of the stored procedure for a SQL Data Warehouse source. This cannot be used at the same time as SqlReaderQuery. Type: string (or Expression with resultType string). + * + * @param sqlReaderStoredProcedureName the sqlReaderStoredProcedureName value to set + * @return the SqlDWSource object itself. + */ + public SqlDWSource withSqlReaderStoredProcedureName(Object sqlReaderStoredProcedureName) { + this.sqlReaderStoredProcedureName = sqlReaderStoredProcedureName; + return this; + } + + /** + * Get value and type setting for stored procedure parameters. Example: "{Parameter1: {value: "1", type: "int"}}". Type: object (or Expression with resultType object), itemType: StoredProcedureParameter. + * + * @return the storedProcedureParameters value + */ + public Object storedProcedureParameters() { + return this.storedProcedureParameters; + } + + /** + * Set value and type setting for stored procedure parameters. Example: "{Parameter1: {value: "1", type: "int"}}". Type: object (or Expression with resultType object), itemType: StoredProcedureParameter. + * + * @param storedProcedureParameters the storedProcedureParameters value to set + * @return the SqlDWSource object itself. + */ + public SqlDWSource withStoredProcedureParameters(Object storedProcedureParameters) { + this.storedProcedureParameters = storedProcedureParameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerLinkedService.java new file mode 100644 index 000000000000..d0cbdfa400f5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerLinkedService.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * SQL Server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SqlServer") +@JsonFlatten +public class SqlServerLinkedService extends LinkedServiceInner { + /** + * The connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString", required = true) + private Object connectionString; + + /** + * The on-premises Windows authentication user name. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.userName") + private Object userName; + + /** + * The on-premises Windows authentication password. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set the connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the SqlServerLinkedService object itself. + */ + public SqlServerLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the on-premises Windows authentication user name. Type: string (or Expression with resultType string). + * + * @return the userName value + */ + public Object userName() { + return this.userName; + } + + /** + * Set the on-premises Windows authentication user name. Type: string (or Expression with resultType string). + * + * @param userName the userName value to set + * @return the SqlServerLinkedService object itself. + */ + public SqlServerLinkedService withUserName(Object userName) { + this.userName = userName; + return this; + } + + /** + * Get the on-premises Windows authentication password. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the on-premises Windows authentication password. + * + * @param password the password value to set + * @return the SqlServerLinkedService object itself. + */ + public SqlServerLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SqlServerLinkedService object itself. + */ + public SqlServerLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerStoredProcedureActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerStoredProcedureActivity.java new file mode 100644 index 000000000000..269fb8c17f04 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerStoredProcedureActivity.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * SQL stored procedure activity type. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SqlServerStoredProcedure") +@JsonFlatten +public class SqlServerStoredProcedureActivity extends ExecutionActivity { + /** + * Stored procedure name. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.storedProcedureName", required = true) + private Object storedProcedureName; + + /** + * Value and type setting for stored procedure parameters. Example: + * "{Parameter1: {value: "1", type: "int"}}". + */ + @JsonProperty(value = "typeProperties.storedProcedureParameters") + private Map storedProcedureParameters; + + /** + * Get stored procedure name. Type: string (or Expression with resultType string). + * + * @return the storedProcedureName value + */ + public Object storedProcedureName() { + return this.storedProcedureName; + } + + /** + * Set stored procedure name. Type: string (or Expression with resultType string). + * + * @param storedProcedureName the storedProcedureName value to set + * @return the SqlServerStoredProcedureActivity object itself. + */ + public SqlServerStoredProcedureActivity withStoredProcedureName(Object storedProcedureName) { + this.storedProcedureName = storedProcedureName; + return this; + } + + /** + * Get value and type setting for stored procedure parameters. Example: "{Parameter1: {value: "1", type: "int"}}". + * + * @return the storedProcedureParameters value + */ + public Map storedProcedureParameters() { + return this.storedProcedureParameters; + } + + /** + * Set value and type setting for stored procedure parameters. Example: "{Parameter1: {value: "1", type: "int"}}". + * + * @param storedProcedureParameters the storedProcedureParameters value to set + * @return the SqlServerStoredProcedureActivity object itself. + */ + public SqlServerStoredProcedureActivity withStoredProcedureParameters(Map storedProcedureParameters) { + this.storedProcedureParameters = storedProcedureParameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerTableDataset.java new file mode 100644 index 000000000000..ef95194f0daa --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlServerTableDataset.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The on-premises SQL Server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SqlServerTable") +@JsonFlatten +public class SqlServerTableDataset extends DatasetInner { + /** + * The table name of the SQL Server dataset. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.tableName", required = true) + private Object tableName; + + /** + * Get the table name of the SQL Server dataset. Type: string (or Expression with resultType string). + * + * @return the tableName value + */ + public Object tableName() { + return this.tableName; + } + + /** + * Set the table name of the SQL Server dataset. Type: string (or Expression with resultType string). + * + * @param tableName the tableName value to set + * @return the SqlServerTableDataset object itself. + */ + public SqlServerTableDataset withTableName(Object tableName) { + this.tableName = tableName; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlSink.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlSink.java new file mode 100644 index 000000000000..e6889b5251b2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlSink.java @@ -0,0 +1,129 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity SQL sink. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SqlSink") +public class SqlSink extends CopySink { + /** + * SQL writer stored procedure name. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "sqlWriterStoredProcedureName") + private Object sqlWriterStoredProcedureName; + + /** + * SQL writer table type. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "sqlWriterTableType") + private Object sqlWriterTableType; + + /** + * SQL pre-copy script. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "preCopyScript") + private Object preCopyScript; + + /** + * SQL stored procedure parameters. + */ + @JsonProperty(value = "storedProcedureParameters") + private Map storedProcedureParameters; + + /** + * Get sQL writer stored procedure name. Type: string (or Expression with resultType string). + * + * @return the sqlWriterStoredProcedureName value + */ + public Object sqlWriterStoredProcedureName() { + return this.sqlWriterStoredProcedureName; + } + + /** + * Set sQL writer stored procedure name. Type: string (or Expression with resultType string). + * + * @param sqlWriterStoredProcedureName the sqlWriterStoredProcedureName value to set + * @return the SqlSink object itself. + */ + public SqlSink withSqlWriterStoredProcedureName(Object sqlWriterStoredProcedureName) { + this.sqlWriterStoredProcedureName = sqlWriterStoredProcedureName; + return this; + } + + /** + * Get sQL writer table type. Type: string (or Expression with resultType string). + * + * @return the sqlWriterTableType value + */ + public Object sqlWriterTableType() { + return this.sqlWriterTableType; + } + + /** + * Set sQL writer table type. Type: string (or Expression with resultType string). + * + * @param sqlWriterTableType the sqlWriterTableType value to set + * @return the SqlSink object itself. + */ + public SqlSink withSqlWriterTableType(Object sqlWriterTableType) { + this.sqlWriterTableType = sqlWriterTableType; + return this; + } + + /** + * Get sQL pre-copy script. Type: string (or Expression with resultType string). + * + * @return the preCopyScript value + */ + public Object preCopyScript() { + return this.preCopyScript; + } + + /** + * Set sQL pre-copy script. Type: string (or Expression with resultType string). + * + * @param preCopyScript the preCopyScript value to set + * @return the SqlSink object itself. + */ + public SqlSink withPreCopyScript(Object preCopyScript) { + this.preCopyScript = preCopyScript; + return this; + } + + /** + * Get sQL stored procedure parameters. + * + * @return the storedProcedureParameters value + */ + public Map storedProcedureParameters() { + return this.storedProcedureParameters; + } + + /** + * Set sQL stored procedure parameters. + * + * @param storedProcedureParameters the storedProcedureParameters value to set + * @return the SqlSink object itself. + */ + public SqlSink withStoredProcedureParameters(Map storedProcedureParameters) { + this.storedProcedureParameters = storedProcedureParameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlSource.java new file mode 100644 index 000000000000..12f0e1ac8dd7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SqlSource.java @@ -0,0 +1,103 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity SQL source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SqlSource") +public class SqlSource extends CopySource { + /** + * SQL reader query. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "sqlReaderQuery") + private Object sqlReaderQuery; + + /** + * Name of the stored procedure for a SQL Database source. This cannot be + * used at the same time as SqlReaderQuery. Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "sqlReaderStoredProcedureName") + private Object sqlReaderStoredProcedureName; + + /** + * Value and type setting for stored procedure parameters. Example: + * "{Parameter1: {value: "1", type: "int"}}". + */ + @JsonProperty(value = "storedProcedureParameters") + private Map storedProcedureParameters; + + /** + * Get sQL reader query. Type: string (or Expression with resultType string). + * + * @return the sqlReaderQuery value + */ + public Object sqlReaderQuery() { + return this.sqlReaderQuery; + } + + /** + * Set sQL reader query. Type: string (or Expression with resultType string). + * + * @param sqlReaderQuery the sqlReaderQuery value to set + * @return the SqlSource object itself. + */ + public SqlSource withSqlReaderQuery(Object sqlReaderQuery) { + this.sqlReaderQuery = sqlReaderQuery; + return this; + } + + /** + * Get name of the stored procedure for a SQL Database source. This cannot be used at the same time as SqlReaderQuery. Type: string (or Expression with resultType string). + * + * @return the sqlReaderStoredProcedureName value + */ + public Object sqlReaderStoredProcedureName() { + return this.sqlReaderStoredProcedureName; + } + + /** + * Set name of the stored procedure for a SQL Database source. This cannot be used at the same time as SqlReaderQuery. Type: string (or Expression with resultType string). + * + * @param sqlReaderStoredProcedureName the sqlReaderStoredProcedureName value to set + * @return the SqlSource object itself. + */ + public SqlSource withSqlReaderStoredProcedureName(Object sqlReaderStoredProcedureName) { + this.sqlReaderStoredProcedureName = sqlReaderStoredProcedureName; + return this; + } + + /** + * Get value and type setting for stored procedure parameters. Example: "{Parameter1: {value: "1", type: "int"}}". + * + * @return the storedProcedureParameters value + */ + public Map storedProcedureParameters() { + return this.storedProcedureParameters; + } + + /** + * Set value and type setting for stored procedure parameters. Example: "{Parameter1: {value: "1", type: "int"}}". + * + * @param storedProcedureParameters the storedProcedureParameters value to set + * @return the SqlSource object itself. + */ + public SqlSource withStoredProcedureParameters(Map storedProcedureParameters) { + this.storedProcedureParameters = storedProcedureParameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareLinkedService.java new file mode 100644 index 000000000000..64a0bb7ea94f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareLinkedService.java @@ -0,0 +1,239 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Square Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Square") +@JsonFlatten +public class SquareLinkedService extends LinkedServiceInner { + /** + * The URL of the Square instance. (i.e. mystore.mysquare.com). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The client ID associated with your Square application. + */ + @JsonProperty(value = "typeProperties.clientId", required = true) + private Object clientId; + + /** + * The client secret associated with your Square application. + */ + @JsonProperty(value = "typeProperties.clientSecret") + private SecretBase clientSecret; + + /** + * The redirect URL assigned in the Square application dashboard. (i.e. + * http://localhost:2500). + */ + @JsonProperty(value = "typeProperties.redirectUri", required = true) + private Object redirectUri; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the URL of the Square instance. (i.e. mystore.mysquare.com). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the URL of the Square instance. (i.e. mystore.mysquare.com). + * + * @param host the host value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the client ID associated with your Square application. + * + * @return the clientId value + */ + public Object clientId() { + return this.clientId; + } + + /** + * Set the client ID associated with your Square application. + * + * @param clientId the clientId value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withClientId(Object clientId) { + this.clientId = clientId; + return this; + } + + /** + * Get the client secret associated with your Square application. + * + * @return the clientSecret value + */ + public SecretBase clientSecret() { + return this.clientSecret; + } + + /** + * Set the client secret associated with your Square application. + * + * @param clientSecret the clientSecret value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withClientSecret(SecretBase clientSecret) { + this.clientSecret = clientSecret; + return this; + } + + /** + * Get the redirect URL assigned in the Square application dashboard. (i.e. http://localhost:2500). + * + * @return the redirectUri value + */ + public Object redirectUri() { + return this.redirectUri; + } + + /** + * Set the redirect URL assigned in the Square application dashboard. (i.e. http://localhost:2500). + * + * @param redirectUri the redirectUri value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withRedirectUri(Object redirectUri) { + this.redirectUri = redirectUri; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SquareLinkedService object itself. + */ + public SquareLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareObjectDataset.java new file mode 100644 index 000000000000..428cfb77ce10 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Square Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SquareObject") +public class SquareObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareSource.java new file mode 100644 index 000000000000..ff0ab36da834 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SquareSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Square Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("SquareSource") +public class SquareSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the SquareSource object itself. + */ + public SquareSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SsisPackageLocationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SsisPackageLocationType.java new file mode 100644 index 000000000000..f5ab5cb09ec6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SsisPackageLocationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SsisPackageLocationType. + */ +public final class SsisPackageLocationType extends ExpandableStringEnum { + /** Static value SSISDB for SsisPackageLocationType. */ + public static final SsisPackageLocationType SSISDB = fromString("SSISDB"); + + /** Static value File for SsisPackageLocationType. */ + public static final SsisPackageLocationType FILE = fromString("File"); + + /** + * Creates or finds a SsisPackageLocationType from its string representation. + * @param name a name to look for + * @return the corresponding SsisPackageLocationType + */ + @JsonCreator + public static SsisPackageLocationType fromString(String name) { + return fromString(name, SsisPackageLocationType.class); + } + + /** + * @return known SsisPackageLocationType values + */ + public static Collection values() { + return values(SsisPackageLocationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/StagingSettings.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/StagingSettings.java new file mode 100644 index 000000000000..698c78fb811e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/StagingSettings.java @@ -0,0 +1,125 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Staging settings. + */ +public class StagingSettings { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Staging linked service reference. + */ + @JsonProperty(value = "linkedServiceName", required = true) + private LinkedServiceReference linkedServiceName; + + /** + * The path to storage for storing the interim data. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "path") + private Object path; + + /** + * Specifies whether to use compression when copying data via an interim + * staging. Default value is false. Type: boolean (or Expression with + * resultType boolean). + */ + @JsonProperty(value = "enableCompression") + private Object enableCompression; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the StagingSettings object itself. + */ + public StagingSettings withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get staging linked service reference. + * + * @return the linkedServiceName value + */ + public LinkedServiceReference linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set staging linked service reference. + * + * @param linkedServiceName the linkedServiceName value to set + * @return the StagingSettings object itself. + */ + public StagingSettings withLinkedServiceName(LinkedServiceReference linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + + /** + * Get the path to storage for storing the interim data. Type: string (or Expression with resultType string). + * + * @return the path value + */ + public Object path() { + return this.path; + } + + /** + * Set the path to storage for storing the interim data. Type: string (or Expression with resultType string). + * + * @param path the path value to set + * @return the StagingSettings object itself. + */ + public StagingSettings withPath(Object path) { + this.path = path; + return this; + } + + /** + * Get specifies whether to use compression when copying data via an interim staging. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @return the enableCompression value + */ + public Object enableCompression() { + return this.enableCompression; + } + + /** + * Set specifies whether to use compression when copying data via an interim staging. Default value is false. Type: boolean (or Expression with resultType boolean). + * + * @param enableCompression the enableCompression value to set + * @return the StagingSettings object itself. + */ + public StagingSettings withEnableCompression(Object enableCompression) { + this.enableCompression = enableCompression; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/StoredProcedureParameter.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/StoredProcedureParameter.java new file mode 100644 index 000000000000..dc8b6248e928 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/StoredProcedureParameter.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * SQL stored procedure parameter. + */ +public class StoredProcedureParameter { + /** + * Stored procedure parameter value. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "value", required = true) + private Object value; + + /** + * Stored procedure parameter type. + */ + @JsonProperty(value = "type") + private Object type; + + /** + * Get stored procedure parameter value. Type: string (or Expression with resultType string). + * + * @return the value value + */ + public Object value() { + return this.value; + } + + /** + * Set stored procedure parameter value. Type: string (or Expression with resultType string). + * + * @param value the value value to set + * @return the StoredProcedureParameter object itself. + */ + public StoredProcedureParameter withValue(Object value) { + this.value = value; + return this; + } + + /** + * Get stored procedure parameter type. + * + * @return the type value + */ + public Object type() { + return this.type; + } + + /** + * Set stored procedure parameter type. + * + * @param type the type value to set + * @return the StoredProcedureParameter object itself. + */ + public StoredProcedureParameter withType(Object type) { + this.type = type; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SybaseAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SybaseAuthenticationType.java new file mode 100644 index 000000000000..e7c6e987bb6d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SybaseAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for SybaseAuthenticationType. + */ +public final class SybaseAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for SybaseAuthenticationType. */ + public static final SybaseAuthenticationType BASIC = fromString("Basic"); + + /** Static value Windows for SybaseAuthenticationType. */ + public static final SybaseAuthenticationType WINDOWS = fromString("Windows"); + + /** + * Creates or finds a SybaseAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding SybaseAuthenticationType + */ + @JsonCreator + public static SybaseAuthenticationType fromString(String name) { + return fromString(name, SybaseAuthenticationType.class); + } + + /** + * @return known SybaseAuthenticationType values + */ + public static Collection values() { + return values(SybaseAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SybaseLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SybaseLinkedService.java new file mode 100644 index 000000000000..cac33961e799 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/SybaseLinkedService.java @@ -0,0 +1,213 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for Sybase data source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Sybase") +@JsonFlatten +public class SybaseLinkedService extends LinkedServiceInner { + /** + * Server name for connection. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.server", required = true) + private Object server; + + /** + * Database name for connection. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.database", required = true) + private Object database; + + /** + * Schema name for connection. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.schema") + private Object schema; + + /** + * AuthenticationType to be used for connection. Possible values include: + * 'Basic', 'Windows'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private SybaseAuthenticationType authenticationType; + + /** + * Username for authentication. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * Password for authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get server name for connection. Type: string (or Expression with resultType string). + * + * @return the server value + */ + public Object server() { + return this.server; + } + + /** + * Set server name for connection. Type: string (or Expression with resultType string). + * + * @param server the server value to set + * @return the SybaseLinkedService object itself. + */ + public SybaseLinkedService withServer(Object server) { + this.server = server; + return this; + } + + /** + * Get database name for connection. Type: string (or Expression with resultType string). + * + * @return the database value + */ + public Object database() { + return this.database; + } + + /** + * Set database name for connection. Type: string (or Expression with resultType string). + * + * @param database the database value to set + * @return the SybaseLinkedService object itself. + */ + public SybaseLinkedService withDatabase(Object database) { + this.database = database; + return this; + } + + /** + * Get schema name for connection. Type: string (or Expression with resultType string). + * + * @return the schema value + */ + public Object schema() { + return this.schema; + } + + /** + * Set schema name for connection. Type: string (or Expression with resultType string). + * + * @param schema the schema value to set + * @return the SybaseLinkedService object itself. + */ + public SybaseLinkedService withSchema(Object schema) { + this.schema = schema; + return this; + } + + /** + * Get authenticationType to be used for connection. Possible values include: 'Basic', 'Windows'. + * + * @return the authenticationType value + */ + public SybaseAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set authenticationType to be used for connection. Possible values include: 'Basic', 'Windows'. + * + * @param authenticationType the authenticationType value to set + * @return the SybaseLinkedService object itself. + */ + public SybaseLinkedService withAuthenticationType(SybaseAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get username for authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set username for authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the SybaseLinkedService object itself. + */ + public SybaseLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get password for authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for authentication. + * + * @param password the password value to set + * @return the SybaseLinkedService object itself. + */ + public SybaseLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the SybaseLinkedService object itself. + */ + public SybaseLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TeradataAuthenticationType.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TeradataAuthenticationType.java new file mode 100644 index 000000000000..5aaab3afdc42 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TeradataAuthenticationType.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for TeradataAuthenticationType. + */ +public final class TeradataAuthenticationType extends ExpandableStringEnum { + /** Static value Basic for TeradataAuthenticationType. */ + public static final TeradataAuthenticationType BASIC = fromString("Basic"); + + /** Static value Windows for TeradataAuthenticationType. */ + public static final TeradataAuthenticationType WINDOWS = fromString("Windows"); + + /** + * Creates or finds a TeradataAuthenticationType from its string representation. + * @param name a name to look for + * @return the corresponding TeradataAuthenticationType + */ + @JsonCreator + public static TeradataAuthenticationType fromString(String name) { + return fromString(name, TeradataAuthenticationType.class); + } + + /** + * @return known TeradataAuthenticationType values + */ + public static Collection values() { + return values(TeradataAuthenticationType.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TeradataLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TeradataLinkedService.java new file mode 100644 index 000000000000..c77086d1ddf6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TeradataLinkedService.java @@ -0,0 +1,159 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Linked service for Teradata data source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Teradata") +@JsonFlatten +public class TeradataLinkedService extends LinkedServiceInner { + /** + * Server name for connection. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.server", required = true) + private Object server; + + /** + * AuthenticationType to be used for connection. Possible values include: + * 'Basic', 'Windows'. + */ + @JsonProperty(value = "typeProperties.authenticationType") + private TeradataAuthenticationType authenticationType; + + /** + * Username for authentication. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "typeProperties.username") + private Object username; + + /** + * Password for authentication. + */ + @JsonProperty(value = "typeProperties.password") + private SecretBase password; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get server name for connection. Type: string (or Expression with resultType string). + * + * @return the server value + */ + public Object server() { + return this.server; + } + + /** + * Set server name for connection. Type: string (or Expression with resultType string). + * + * @param server the server value to set + * @return the TeradataLinkedService object itself. + */ + public TeradataLinkedService withServer(Object server) { + this.server = server; + return this; + } + + /** + * Get authenticationType to be used for connection. Possible values include: 'Basic', 'Windows'. + * + * @return the authenticationType value + */ + public TeradataAuthenticationType authenticationType() { + return this.authenticationType; + } + + /** + * Set authenticationType to be used for connection. Possible values include: 'Basic', 'Windows'. + * + * @param authenticationType the authenticationType value to set + * @return the TeradataLinkedService object itself. + */ + public TeradataLinkedService withAuthenticationType(TeradataAuthenticationType authenticationType) { + this.authenticationType = authenticationType; + return this; + } + + /** + * Get username for authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set username for authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the TeradataLinkedService object itself. + */ + public TeradataLinkedService withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get password for authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for authentication. + * + * @param password the password value to set + * @return the TeradataLinkedService object itself. + */ + public TeradataLinkedService withPassword(SecretBase password) { + this.password = password; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the TeradataLinkedService object itself. + */ + public TeradataLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TextFormat.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TextFormat.java new file mode 100644 index 000000000000..44aa6eef2a9e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TextFormat.java @@ -0,0 +1,270 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * The data stored in text format. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("TextFormat") +public class TextFormat extends DatasetStorageFormat { + /** + * The column delimiter. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "columnDelimiter") + private Object columnDelimiter; + + /** + * The row delimiter. Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "rowDelimiter") + private Object rowDelimiter; + + /** + * The escape character. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "escapeChar") + private Object escapeChar; + + /** + * The quote character. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "quoteChar") + private Object quoteChar; + + /** + * The null value string. Type: string (or Expression with resultType + * string). + */ + @JsonProperty(value = "nullValue") + private Object nullValue; + + /** + * The code page name of the preferred encoding. If miss, the default value + * is ΓÇ£utf-8ΓÇ¥, unless BOM denotes another Unicode encoding. Refer to + * the ΓÇ£NameΓÇ¥ column of the table in the following link to set + * supported values: + * https://msdn.microsoft.com/library/system.text.encoding.aspx. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "encodingName") + private Object encodingName; + + /** + * Treat empty column values in the text file as null. The default value is + * true. Type: boolean (or Expression with resultType boolean). + */ + @JsonProperty(value = "treatEmptyAsNull") + private Object treatEmptyAsNull; + + /** + * The number of lines/rows to be skipped when parsing text files. The + * default value is 0. Type: integer (or Expression with resultType + * integer). + */ + @JsonProperty(value = "skipLineCount") + private Object skipLineCount; + + /** + * When used as input, treat the first row of data as headers. When used as + * output,write the headers into the output as the first row of data. The + * default value is false. Type: boolean (or Expression with resultType + * boolean). + */ + @JsonProperty(value = "firstRowAsHeader") + private Object firstRowAsHeader; + + /** + * Get the column delimiter. Type: string (or Expression with resultType string). + * + * @return the columnDelimiter value + */ + public Object columnDelimiter() { + return this.columnDelimiter; + } + + /** + * Set the column delimiter. Type: string (or Expression with resultType string). + * + * @param columnDelimiter the columnDelimiter value to set + * @return the TextFormat object itself. + */ + public TextFormat withColumnDelimiter(Object columnDelimiter) { + this.columnDelimiter = columnDelimiter; + return this; + } + + /** + * Get the row delimiter. Type: string (or Expression with resultType string). + * + * @return the rowDelimiter value + */ + public Object rowDelimiter() { + return this.rowDelimiter; + } + + /** + * Set the row delimiter. Type: string (or Expression with resultType string). + * + * @param rowDelimiter the rowDelimiter value to set + * @return the TextFormat object itself. + */ + public TextFormat withRowDelimiter(Object rowDelimiter) { + this.rowDelimiter = rowDelimiter; + return this; + } + + /** + * Get the escape character. Type: string (or Expression with resultType string). + * + * @return the escapeChar value + */ + public Object escapeChar() { + return this.escapeChar; + } + + /** + * Set the escape character. Type: string (or Expression with resultType string). + * + * @param escapeChar the escapeChar value to set + * @return the TextFormat object itself. + */ + public TextFormat withEscapeChar(Object escapeChar) { + this.escapeChar = escapeChar; + return this; + } + + /** + * Get the quote character. Type: string (or Expression with resultType string). + * + * @return the quoteChar value + */ + public Object quoteChar() { + return this.quoteChar; + } + + /** + * Set the quote character. Type: string (or Expression with resultType string). + * + * @param quoteChar the quoteChar value to set + * @return the TextFormat object itself. + */ + public TextFormat withQuoteChar(Object quoteChar) { + this.quoteChar = quoteChar; + return this; + } + + /** + * Get the null value string. Type: string (or Expression with resultType string). + * + * @return the nullValue value + */ + public Object nullValue() { + return this.nullValue; + } + + /** + * Set the null value string. Type: string (or Expression with resultType string). + * + * @param nullValue the nullValue value to set + * @return the TextFormat object itself. + */ + public TextFormat withNullValue(Object nullValue) { + this.nullValue = nullValue; + return this; + } + + /** + * Get the code page name of the preferred encoding. If miss, the default value is ΓÇ£utf-8ΓÇ¥, unless BOM denotes another Unicode encoding. Refer to the ΓÇ£NameΓÇ¥ column of the table in the following link to set supported values: https://msdn.microsoft.com/library/system.text.encoding.aspx. Type: string (or Expression with resultType string). + * + * @return the encodingName value + */ + public Object encodingName() { + return this.encodingName; + } + + /** + * Set the code page name of the preferred encoding. If miss, the default value is ΓÇ£utf-8ΓÇ¥, unless BOM denotes another Unicode encoding. Refer to the ΓÇ£NameΓÇ¥ column of the table in the following link to set supported values: https://msdn.microsoft.com/library/system.text.encoding.aspx. Type: string (or Expression with resultType string). + * + * @param encodingName the encodingName value to set + * @return the TextFormat object itself. + */ + public TextFormat withEncodingName(Object encodingName) { + this.encodingName = encodingName; + return this; + } + + /** + * Get treat empty column values in the text file as null. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @return the treatEmptyAsNull value + */ + public Object treatEmptyAsNull() { + return this.treatEmptyAsNull; + } + + /** + * Set treat empty column values in the text file as null. The default value is true. Type: boolean (or Expression with resultType boolean). + * + * @param treatEmptyAsNull the treatEmptyAsNull value to set + * @return the TextFormat object itself. + */ + public TextFormat withTreatEmptyAsNull(Object treatEmptyAsNull) { + this.treatEmptyAsNull = treatEmptyAsNull; + return this; + } + + /** + * Get the number of lines/rows to be skipped when parsing text files. The default value is 0. Type: integer (or Expression with resultType integer). + * + * @return the skipLineCount value + */ + public Object skipLineCount() { + return this.skipLineCount; + } + + /** + * Set the number of lines/rows to be skipped when parsing text files. The default value is 0. Type: integer (or Expression with resultType integer). + * + * @param skipLineCount the skipLineCount value to set + * @return the TextFormat object itself. + */ + public TextFormat withSkipLineCount(Object skipLineCount) { + this.skipLineCount = skipLineCount; + return this; + } + + /** + * Get when used as input, treat the first row of data as headers. When used as output,write the headers into the output as the first row of data. The default value is false. Type: boolean (or Expression with resultType boolean). + * + * @return the firstRowAsHeader value + */ + public Object firstRowAsHeader() { + return this.firstRowAsHeader; + } + + /** + * Set when used as input, treat the first row of data as headers. When used as output,write the headers into the output as the first row of data. The default value is false. Type: boolean (or Expression with resultType boolean). + * + * @param firstRowAsHeader the firstRowAsHeader value to set + * @return the TextFormat object itself. + */ + public TextFormat withFirstRowAsHeader(Object firstRowAsHeader) { + this.firstRowAsHeader = firstRowAsHeader; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerPipelineReference.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerPipelineReference.java new file mode 100644 index 000000000000..cecc916d4e18 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerPipelineReference.java @@ -0,0 +1,70 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Pipeline that needs to be triggered with the given parameters. + */ +public class TriggerPipelineReference { + /** + * Pipeline reference. + */ + @JsonProperty(value = "pipelineReference") + private PipelineReference pipelineReference; + + /** + * Pipeline parameters. + */ + @JsonProperty(value = "parameters") + private Map parameters; + + /** + * Get pipeline reference. + * + * @return the pipelineReference value + */ + public PipelineReference pipelineReference() { + return this.pipelineReference; + } + + /** + * Set pipeline reference. + * + * @param pipelineReference the pipelineReference value to set + * @return the TriggerPipelineReference object itself. + */ + public TriggerPipelineReference withPipelineReference(PipelineReference pipelineReference) { + this.pipelineReference = pipelineReference; + return this; + } + + /** + * Get pipeline parameters. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set pipeline parameters. + * + * @param parameters the parameters value to set + * @return the TriggerPipelineReference object itself. + */ + public TriggerPipelineReference withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerResource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerResource.java new file mode 100644 index 000000000000..0e03716a8940 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerResource.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.TriggerResourceInner; +import com.microsoft.azure.arm.model.Indexable; +import com.microsoft.azure.arm.model.Refreshable; +import com.microsoft.azure.arm.model.Updatable; +import com.microsoft.azure.arm.model.Appliable; +import com.microsoft.azure.arm.model.Creatable; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.TriggerInner; +import java.util.Map; + +/** + * Type representing TriggerResource. + */ +public interface TriggerResource extends HasInner, Indexable, Refreshable, Updatable, HasManager { + /** + * @return the etag value. + */ + String etag(); + + /** + * @return the id value. + */ + String id(); + + /** + * @return the name value. + */ + String name(); + + /** + * @return the properties value. + */ + TriggerInner properties(); + + /** + * @return the type value. + */ + String type(); + + /** + * The entirety of the TriggerResource definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithFactory, DefinitionStages.WithIfMatch, DefinitionStages.WithProperties, DefinitionStages.WithCreate { + } + + /** + * Grouping of TriggerResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of a TriggerResource definition. + */ + interface Blank extends WithFactory { + } + + /** + * The stage of the triggerresource definition allowing to specify Factory. + */ + interface WithFactory { + /** + * Specifies resourceGroupName, factoryName. + * @param resourceGroupName The resource group name + * @param factoryName The factory name + * @return the next definition stage + */ + WithIfMatch withExistingFactory(String resourceGroupName, String factoryName); + } + + /** + * The stage of the triggerresource definition allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the trigger entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next definition stage + */ + WithProperties withIfMatch(String ifMatch); + } + + /** + * The stage of the triggerresource definition allowing to specify Properties. + */ + interface WithProperties { + /** + * Specifies properties. + * @param properties Properties of the trigger + * @return the next definition stage + */ + WithCreate withProperties(TriggerInner properties); + } + + /** + * The stage of the definition which contains all the minimum required inputs for + * the resource to be created (via {@link WithCreate#create()}), but also allows + * for any other optional settings to be specified. + */ + interface WithCreate extends Creatable { + } + } + /** + * The template for a TriggerResource update operation, containing all the settings that can be modified. + */ + interface Update extends Appliable, UpdateStages.WithIfMatch, UpdateStages.WithProperties { + } + + /** + * Grouping of TriggerResource update stages. + */ + interface UpdateStages { + /** + * The stage of the triggerresource update allowing to specify IfMatch. + */ + interface WithIfMatch { + /** + * Specifies ifMatch. + * @param ifMatch ETag of the trigger entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update + * @return the next update stage + */ + Update withIfMatch(String ifMatch); + } + + /** + * The stage of the triggerresource update allowing to specify Properties. + */ + interface WithProperties { + /** + * Specifies properties. + * @param properties Properties of the trigger + * @return the next update stage + */ + Update withProperties(TriggerInner properties); + } + + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRun.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRun.java new file mode 100644 index 000000000000..7409d92e72dd --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRun.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.TriggerRunInner; +import com.microsoft.azure.arm.resources.models.HasManager; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DataFactoryManager; +import java.util.Map; +import org.joda.time.DateTime; + +/** + * Type representing TriggerRun. + */ +public interface TriggerRun extends HasInner, HasManager { + /** + * @return the additionalProperties value. + */ + Map additionalProperties(); + + /** + * @return the message value. + */ + String message(); + + /** + * @return the properties value. + */ + Map properties(); + + /** + * @return the status value. + */ + TriggerRunStatus status(); + + /** + * @return the triggeredPipelines value. + */ + Map triggeredPipelines(); + + /** + * @return the triggerName value. + */ + String triggerName(); + + /** + * @return the triggerRunId value. + */ + String triggerRunId(); + + /** + * @return the triggerRunTimestamp value. + */ + DateTime triggerRunTimestamp(); + + /** + * @return the triggerType value. + */ + String triggerType(); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRunStatus.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRunStatus.java new file mode 100644 index 000000000000..b5f67e1a7d24 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRunStatus.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for TriggerRunStatus. + */ +public final class TriggerRunStatus extends ExpandableStringEnum { + /** Static value Succeeded for TriggerRunStatus. */ + public static final TriggerRunStatus SUCCEEDED = fromString("Succeeded"); + + /** Static value Failed for TriggerRunStatus. */ + public static final TriggerRunStatus FAILED = fromString("Failed"); + + /** Static value Inprogress for TriggerRunStatus. */ + public static final TriggerRunStatus INPROGRESS = fromString("Inprogress"); + + /** + * Creates or finds a TriggerRunStatus from its string representation. + * @param name a name to look for + * @return the corresponding TriggerRunStatus + */ + @JsonCreator + public static TriggerRunStatus fromString(String name) { + return fromString(name, TriggerRunStatus.class); + } + + /** + * @return known TriggerRunStatus values + */ + public static Collection values() { + return values(TriggerRunStatus.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRuntimeState.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRuntimeState.java new file mode 100644 index 000000000000..5272fb76cfd9 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TriggerRuntimeState.java @@ -0,0 +1,44 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for TriggerRuntimeState. + */ +public final class TriggerRuntimeState extends ExpandableStringEnum { + /** Static value Started for TriggerRuntimeState. */ + public static final TriggerRuntimeState STARTED = fromString("Started"); + + /** Static value Stopped for TriggerRuntimeState. */ + public static final TriggerRuntimeState STOPPED = fromString("Stopped"); + + /** Static value Disabled for TriggerRuntimeState. */ + public static final TriggerRuntimeState DISABLED = fromString("Disabled"); + + /** + * Creates or finds a TriggerRuntimeState from its string representation. + * @param name a name to look for + * @return the corresponding TriggerRuntimeState + */ + @JsonCreator + public static TriggerRuntimeState fromString(String name) { + return fromString(name, TriggerRuntimeState.class); + } + + /** + * @return known TriggerRuntimeState values + */ + public static Collection values() { + return values(TriggerRuntimeState.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Triggers.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Triggers.java new file mode 100644 index 000000000000..078e53db5a70 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/Triggers.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.microsoft.azure.arm.collection.SupportsCreating; +import rx.Completable; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.TriggersInner; +import com.microsoft.azure.arm.model.HasInner; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerRun; + +/** + * Type representing Triggers. + */ +public interface Triggers extends SupportsCreating, HasInner { + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable startAsync(String resourceGroupName, String factoryName, String triggerName); + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable stopAsync(String resourceGroupName, String factoryName, String triggerName); + + /** + * Gets a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable getAsync(String resourceGroupName, String factoryName, String triggerName); + + /** + * Lists triggers. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listByFactoryAsync(final String resourceGroupName, final String factoryName); + + /** + * Deletes a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Completable deleteAsync(String resourceGroupName, String factoryName, String triggerName); + + /** + * List trigger runs. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param startTime Start time for trigger runs. + * @param endTime End time for trigger runs. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + Observable listRunsAsync(final String resourceGroupName, final String factoryName, final String triggerName, final DateTime startTime, final DateTime endTime); + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TumblingWindowFrequency.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TumblingWindowFrequency.java new file mode 100644 index 000000000000..d7b5ed327d00 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TumblingWindowFrequency.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for TumblingWindowFrequency. + */ +public final class TumblingWindowFrequency extends ExpandableStringEnum { + /** Static value Minute for TumblingWindowFrequency. */ + public static final TumblingWindowFrequency MINUTE = fromString("Minute"); + + /** Static value Hour for TumblingWindowFrequency. */ + public static final TumblingWindowFrequency HOUR = fromString("Hour"); + + /** + * Creates or finds a TumblingWindowFrequency from its string representation. + * @param name a name to look for + * @return the corresponding TumblingWindowFrequency + */ + @JsonCreator + public static TumblingWindowFrequency fromString(String name) { + return fromString(name, TumblingWindowFrequency.class); + } + + /** + * @return known TumblingWindowFrequency values + */ + public static Collection values() { + return values(TumblingWindowFrequency.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TumblingWindowTrigger.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TumblingWindowTrigger.java new file mode 100644 index 000000000000..76dbba6add11 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/TumblingWindowTrigger.java @@ -0,0 +1,245 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import org.joda.time.DateTime; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.TriggerInner; + +/** + * Trigger that schedules pipeline runs for all fixed time interval windows + * from a start time without gaps and also supports backfill scenarios (when + * start time is in the past). + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("TumblingWindowTrigger") +@JsonFlatten +public class TumblingWindowTrigger extends TriggerInner { + /** + * Pipeline for which runs are created when an event is fired for trigger + * window that is ready. + */ + @JsonProperty(value = "pipeline", required = true) + private TriggerPipelineReference pipeline; + + /** + * The frequency of the time windows. Possible values include: 'Minute', + * 'Hour'. + */ + @JsonProperty(value = "typeProperties.frequency", required = true) + private TumblingWindowFrequency frequency; + + /** + * The interval of the time windows. The minimum interval allowed is 15 + * Minutes. + */ + @JsonProperty(value = "typeProperties.interval", required = true) + private int interval; + + /** + * The start time for the time period for the trigger during which events + * are fired for windows that are ready. Only UTC time is currently + * supported. + */ + @JsonProperty(value = "typeProperties.startTime", required = true) + private DateTime startTime; + + /** + * The end time for the time period for the trigger during which events are + * fired for windows that are ready. Only UTC time is currently supported. + */ + @JsonProperty(value = "typeProperties.endTime") + private DateTime endTime; + + /** + * Specifies how long the trigger waits past due time before triggering new + * run. It doesn't alter window start and end time. The default is 0. Type: + * string (or Expression with resultType string), pattern: + * ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "typeProperties.delay") + private Object delay; + + /** + * The max number of parallel time windows (ready for execution) for which + * a new run is triggered. + */ + @JsonProperty(value = "typeProperties.maxConcurrency", required = true) + private int maxConcurrency; + + /** + * Retry policy that will be applied for failed pipeline runs. + */ + @JsonProperty(value = "typeProperties.retryPolicy") + private RetryPolicy retryPolicy; + + /** + * Get pipeline for which runs are created when an event is fired for trigger window that is ready. + * + * @return the pipeline value + */ + public TriggerPipelineReference pipeline() { + return this.pipeline; + } + + /** + * Set pipeline for which runs are created when an event is fired for trigger window that is ready. + * + * @param pipeline the pipeline value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withPipeline(TriggerPipelineReference pipeline) { + this.pipeline = pipeline; + return this; + } + + /** + * Get the frequency of the time windows. Possible values include: 'Minute', 'Hour'. + * + * @return the frequency value + */ + public TumblingWindowFrequency frequency() { + return this.frequency; + } + + /** + * Set the frequency of the time windows. Possible values include: 'Minute', 'Hour'. + * + * @param frequency the frequency value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withFrequency(TumblingWindowFrequency frequency) { + this.frequency = frequency; + return this; + } + + /** + * Get the interval of the time windows. The minimum interval allowed is 15 Minutes. + * + * @return the interval value + */ + public int interval() { + return this.interval; + } + + /** + * Set the interval of the time windows. The minimum interval allowed is 15 Minutes. + * + * @param interval the interval value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withInterval(int interval) { + this.interval = interval; + return this; + } + + /** + * Get the start time for the time period for the trigger during which events are fired for windows that are ready. Only UTC time is currently supported. + * + * @return the startTime value + */ + public DateTime startTime() { + return this.startTime; + } + + /** + * Set the start time for the time period for the trigger during which events are fired for windows that are ready. Only UTC time is currently supported. + * + * @param startTime the startTime value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withStartTime(DateTime startTime) { + this.startTime = startTime; + return this; + } + + /** + * Get the end time for the time period for the trigger during which events are fired for windows that are ready. Only UTC time is currently supported. + * + * @return the endTime value + */ + public DateTime endTime() { + return this.endTime; + } + + /** + * Set the end time for the time period for the trigger during which events are fired for windows that are ready. Only UTC time is currently supported. + * + * @param endTime the endTime value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withEndTime(DateTime endTime) { + this.endTime = endTime; + return this; + } + + /** + * Get specifies how long the trigger waits past due time before triggering new run. It doesn't alter window start and end time. The default is 0. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the delay value + */ + public Object delay() { + return this.delay; + } + + /** + * Set specifies how long the trigger waits past due time before triggering new run. It doesn't alter window start and end time. The default is 0. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param delay the delay value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withDelay(Object delay) { + this.delay = delay; + return this; + } + + /** + * Get the max number of parallel time windows (ready for execution) for which a new run is triggered. + * + * @return the maxConcurrency value + */ + public int maxConcurrency() { + return this.maxConcurrency; + } + + /** + * Set the max number of parallel time windows (ready for execution) for which a new run is triggered. + * + * @param maxConcurrency the maxConcurrency value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withMaxConcurrency(int maxConcurrency) { + this.maxConcurrency = maxConcurrency; + return this; + } + + /** + * Get retry policy that will be applied for failed pipeline runs. + * + * @return the retryPolicy value + */ + public RetryPolicy retryPolicy() { + return this.retryPolicy; + } + + /** + * Set retry policy that will be applied for failed pipeline runs. + * + * @param retryPolicy the retryPolicy value to set + * @return the TumblingWindowTrigger object itself. + */ + public TumblingWindowTrigger withRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UntilActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UntilActivity.java new file mode 100644 index 000000000000..79d44a386b82 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UntilActivity.java @@ -0,0 +1,109 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * This activity executes inner activities until the specified boolean + * expression results to true or timeout is reached, whichever is earlier. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Until") +@JsonFlatten +public class UntilActivity extends ControlActivity { + /** + * An expression that would evaluate to Boolean. The loop will continue + * until this expression evaluates to true. + */ + @JsonProperty(value = "typeProperties.expression", required = true) + private Expression expression; + + /** + * Specifies the timeout for the activity to run. If there is no value + * specified, it takes the value of TimeSpan.FromDays(7) which is 1 week as + * default. Type: string (or Expression with resultType string), pattern: + * ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). Type: string (or + * Expression with resultType string), pattern: + * ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + */ + @JsonProperty(value = "typeProperties.timeout") + private Object timeout; + + /** + * List of activities to execute. + */ + @JsonProperty(value = "typeProperties.activities", required = true) + private List activities; + + /** + * Get an expression that would evaluate to Boolean. The loop will continue until this expression evaluates to true. + * + * @return the expression value + */ + public Expression expression() { + return this.expression; + } + + /** + * Set an expression that would evaluate to Boolean. The loop will continue until this expression evaluates to true. + * + * @param expression the expression value to set + * @return the UntilActivity object itself. + */ + public UntilActivity withExpression(Expression expression) { + this.expression = expression; + return this; + } + + /** + * Get specifies the timeout for the activity to run. If there is no value specified, it takes the value of TimeSpan.FromDays(7) which is 1 week as default. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @return the timeout value + */ + public Object timeout() { + return this.timeout; + } + + /** + * Set specifies the timeout for the activity to run. If there is no value specified, it takes the value of TimeSpan.FromDays(7) which is 1 week as default. Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). Type: string (or Expression with resultType string), pattern: ((\d+)\.)?(\d\d):(60|([0-5][0-9])):(60|([0-5][0-9])). + * + * @param timeout the timeout value to set + * @return the UntilActivity object itself. + */ + public UntilActivity withTimeout(Object timeout) { + this.timeout = timeout; + return this; + } + + /** + * Get list of activities to execute. + * + * @return the activities value + */ + public List activities() { + return this.activities; + } + + /** + * Set list of activities to execute. + * + * @param activities the activities value to set + * @return the UntilActivity object itself. + */ + public UntilActivity withActivities(List activities) { + this.activities = activities; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UpdateIntegrationRuntimeNodeRequest.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UpdateIntegrationRuntimeNodeRequest.java new file mode 100644 index 000000000000..d9f7ab6bfde6 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UpdateIntegrationRuntimeNodeRequest.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Update integration runtime node request. + */ +public class UpdateIntegrationRuntimeNodeRequest { + /** + * The number of concurrent jobs permitted to run on the integration + * runtime node. Values between 1 and maxConcurrentJobs(inclusive) are + * allowed. + */ + @JsonProperty(value = "concurrentJobsLimit") + private Integer concurrentJobsLimit; + + /** + * Get the number of concurrent jobs permitted to run on the integration runtime node. Values between 1 and maxConcurrentJobs(inclusive) are allowed. + * + * @return the concurrentJobsLimit value + */ + public Integer concurrentJobsLimit() { + return this.concurrentJobsLimit; + } + + /** + * Set the number of concurrent jobs permitted to run on the integration runtime node. Values between 1 and maxConcurrentJobs(inclusive) are allowed. + * + * @param concurrentJobsLimit the concurrentJobsLimit value to set + * @return the UpdateIntegrationRuntimeNodeRequest object itself. + */ + public UpdateIntegrationRuntimeNodeRequest withConcurrentJobsLimit(Integer concurrentJobsLimit) { + this.concurrentJobsLimit = concurrentJobsLimit; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UpdateIntegrationRuntimeRequest.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UpdateIntegrationRuntimeRequest.java new file mode 100644 index 000000000000..0691afb9508a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/UpdateIntegrationRuntimeRequest.java @@ -0,0 +1,72 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Update integration runtime request. + */ +public class UpdateIntegrationRuntimeRequest { + /** + * Enables or disables the auto-update feature of the self-hosted + * integration runtime. See https://go.microsoft.com/fwlink/?linkid=854189. + * Possible values include: 'On', 'Off'. + */ + @JsonProperty(value = "autoUpdate") + private IntegrationRuntimeAutoUpdate autoUpdate; + + /** + * The time offset (in hours) in the day, e.g., PT03H is 3 hours. The + * integration runtime auto update will happen on that time. + */ + @JsonProperty(value = "updateDelayOffset") + private String updateDelayOffset; + + /** + * Get enables or disables the auto-update feature of the self-hosted integration runtime. See https://go.microsoft.com/fwlink/?linkid=854189. Possible values include: 'On', 'Off'. + * + * @return the autoUpdate value + */ + public IntegrationRuntimeAutoUpdate autoUpdate() { + return this.autoUpdate; + } + + /** + * Set enables or disables the auto-update feature of the self-hosted integration runtime. See https://go.microsoft.com/fwlink/?linkid=854189. Possible values include: 'On', 'Off'. + * + * @param autoUpdate the autoUpdate value to set + * @return the UpdateIntegrationRuntimeRequest object itself. + */ + public UpdateIntegrationRuntimeRequest withAutoUpdate(IntegrationRuntimeAutoUpdate autoUpdate) { + this.autoUpdate = autoUpdate; + return this; + } + + /** + * Get the time offset (in hours) in the day, e.g., PT03H is 3 hours. The integration runtime auto update will happen on that time. + * + * @return the updateDelayOffset value + */ + public String updateDelayOffset() { + return this.updateDelayOffset; + } + + /** + * Set the time offset (in hours) in the day, e.g., PT03H is 3 hours. The integration runtime auto update will happen on that time. + * + * @param updateDelayOffset the updateDelayOffset value to set + * @return the UpdateIntegrationRuntimeRequest object itself. + */ + public UpdateIntegrationRuntimeRequest withUpdateDelayOffset(String updateDelayOffset) { + this.updateDelayOffset = updateDelayOffset; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaLinkedService.java new file mode 100644 index 000000000000..450b3f4e16e7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaLinkedService.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Vertica linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Vertica") +@JsonFlatten +public class VerticaLinkedService extends LinkedServiceInner { + /** + * An ODBC connection string. Type: string, SecureString or + * AzureKeyVaultSecretReference. + */ + @JsonProperty(value = "typeProperties.connectionString") + private Object connectionString; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @return the connectionString value + */ + public Object connectionString() { + return this.connectionString; + } + + /** + * Set an ODBC connection string. Type: string, SecureString or AzureKeyVaultSecretReference. + * + * @param connectionString the connectionString value to set + * @return the VerticaLinkedService object itself. + */ + public VerticaLinkedService withConnectionString(Object connectionString) { + this.connectionString = connectionString; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the VerticaLinkedService object itself. + */ + public VerticaLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaSource.java new file mode 100644 index 000000000000..208d4aba9738 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Vertica source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("VerticaSource") +public class VerticaSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the VerticaSource object itself. + */ + public VerticaSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaTableDataset.java new file mode 100644 index 000000000000..56190d27c55c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/VerticaTableDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Vertica dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("VerticaTable") +public class VerticaTableDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WaitActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WaitActivity.java new file mode 100644 index 000000000000..71414841fe1f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WaitActivity.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * This activity suspends pipeline execution for the specified interval. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Wait") +@JsonFlatten +public class WaitActivity extends ControlActivity { + /** + * Duration in seconds. + */ + @JsonProperty(value = "typeProperties.waitTimeInSeconds", required = true) + private int waitTimeInSeconds; + + /** + * Get duration in seconds. + * + * @return the waitTimeInSeconds value + */ + public int waitTimeInSeconds() { + return this.waitTimeInSeconds; + } + + /** + * Set duration in seconds. + * + * @param waitTimeInSeconds the waitTimeInSeconds value to set + * @return the WaitActivity object itself. + */ + public WaitActivity withWaitTimeInSeconds(int waitTimeInSeconds) { + this.waitTimeInSeconds = waitTimeInSeconds; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivity.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivity.java new file mode 100644 index 000000000000..cda8b863bcee --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivity.java @@ -0,0 +1,213 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Web activity. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("WebActivity") +@JsonFlatten +public class WebActivity extends ExecutionActivity { + /** + * Rest API method for target endpoint. Possible values include: 'GET', + * 'POST', 'PUT', 'DELETE'. + */ + @JsonProperty(value = "typeProperties.method", required = true) + private WebActivityMethod method; + + /** + * Web activity target endpoint and path. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "typeProperties.url", required = true) + private Object url; + + /** + * Represents the headers that will be sent to the request. For example, to + * set the language and type on a request: "headers" : { "Accept-Language": + * "en-us", "Content-Type": "application/json" }. Type: string (or + * Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.headers") + private Object headers; + + /** + * Represents the payload that will be sent to the endpoint. Required for + * POST/PUT method, not allowed for GET method Type: string (or Expression + * with resultType string). + */ + @JsonProperty(value = "typeProperties.body") + private Object body; + + /** + * Authentication method used for calling the endpoint. + */ + @JsonProperty(value = "typeProperties.authentication") + private WebActivityAuthentication authentication; + + /** + * List of datasets passed to web endpoint. + */ + @JsonProperty(value = "typeProperties.datasets") + private List datasets; + + /** + * List of linked services passed to web endpoint. + */ + @JsonProperty(value = "typeProperties.linkedServices") + private List linkedServices; + + /** + * Get rest API method for target endpoint. Possible values include: 'GET', 'POST', 'PUT', 'DELETE'. + * + * @return the method value + */ + public WebActivityMethod method() { + return this.method; + } + + /** + * Set rest API method for target endpoint. Possible values include: 'GET', 'POST', 'PUT', 'DELETE'. + * + * @param method the method value to set + * @return the WebActivity object itself. + */ + public WebActivity withMethod(WebActivityMethod method) { + this.method = method; + return this; + } + + /** + * Get web activity target endpoint and path. Type: string (or Expression with resultType string). + * + * @return the url value + */ + public Object url() { + return this.url; + } + + /** + * Set web activity target endpoint and path. Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the WebActivity object itself. + */ + public WebActivity withUrl(Object url) { + this.url = url; + return this; + } + + /** + * Get represents the headers that will be sent to the request. For example, to set the language and type on a request: "headers" : { "Accept-Language": "en-us", "Content-Type": "application/json" }. Type: string (or Expression with resultType string). + * + * @return the headers value + */ + public Object headers() { + return this.headers; + } + + /** + * Set represents the headers that will be sent to the request. For example, to set the language and type on a request: "headers" : { "Accept-Language": "en-us", "Content-Type": "application/json" }. Type: string (or Expression with resultType string). + * + * @param headers the headers value to set + * @return the WebActivity object itself. + */ + public WebActivity withHeaders(Object headers) { + this.headers = headers; + return this; + } + + /** + * Get represents the payload that will be sent to the endpoint. Required for POST/PUT method, not allowed for GET method Type: string (or Expression with resultType string). + * + * @return the body value + */ + public Object body() { + return this.body; + } + + /** + * Set represents the payload that will be sent to the endpoint. Required for POST/PUT method, not allowed for GET method Type: string (or Expression with resultType string). + * + * @param body the body value to set + * @return the WebActivity object itself. + */ + public WebActivity withBody(Object body) { + this.body = body; + return this; + } + + /** + * Get authentication method used for calling the endpoint. + * + * @return the authentication value + */ + public WebActivityAuthentication authentication() { + return this.authentication; + } + + /** + * Set authentication method used for calling the endpoint. + * + * @param authentication the authentication value to set + * @return the WebActivity object itself. + */ + public WebActivity withAuthentication(WebActivityAuthentication authentication) { + this.authentication = authentication; + return this; + } + + /** + * Get list of datasets passed to web endpoint. + * + * @return the datasets value + */ + public List datasets() { + return this.datasets; + } + + /** + * Set list of datasets passed to web endpoint. + * + * @param datasets the datasets value to set + * @return the WebActivity object itself. + */ + public WebActivity withDatasets(List datasets) { + this.datasets = datasets; + return this; + } + + /** + * Get list of linked services passed to web endpoint. + * + * @return the linkedServices value + */ + public List linkedServices() { + return this.linkedServices; + } + + /** + * Set list of linked services passed to web endpoint. + * + * @param linkedServices the linkedServices value to set + * @return the WebActivity object itself. + */ + public WebActivity withLinkedServices(List linkedServices) { + this.linkedServices = linkedServices; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivityAuthentication.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivityAuthentication.java new file mode 100644 index 000000000000..5db75fa3dad4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivityAuthentication.java @@ -0,0 +1,148 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Web activity authentication properties. + */ +public class WebActivityAuthentication { + /** + * Web activity authentication (Basic/ClientCertificate/MSI). + */ + @JsonProperty(value = "type", required = true) + private String type; + + /** + * Base64-encoded contents of a PFX file. + */ + @JsonProperty(value = "pfx") + private SecureString pfx; + + /** + * Web activity authentication user name for basic authentication. + */ + @JsonProperty(value = "username") + private String username; + + /** + * Password for the PFX file or basic authentication. + */ + @JsonProperty(value = "password") + private SecureString password; + + /** + * Resource for which Azure Auth token will be requested when using MSI + * Authentication. + */ + @JsonProperty(value = "resource") + private String resource; + + /** + * Get web activity authentication (Basic/ClientCertificate/MSI). + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Set web activity authentication (Basic/ClientCertificate/MSI). + * + * @param type the type value to set + * @return the WebActivityAuthentication object itself. + */ + public WebActivityAuthentication withType(String type) { + this.type = type; + return this; + } + + /** + * Get base64-encoded contents of a PFX file. + * + * @return the pfx value + */ + public SecureString pfx() { + return this.pfx; + } + + /** + * Set base64-encoded contents of a PFX file. + * + * @param pfx the pfx value to set + * @return the WebActivityAuthentication object itself. + */ + public WebActivityAuthentication withPfx(SecureString pfx) { + this.pfx = pfx; + return this; + } + + /** + * Get web activity authentication user name for basic authentication. + * + * @return the username value + */ + public String username() { + return this.username; + } + + /** + * Set web activity authentication user name for basic authentication. + * + * @param username the username value to set + * @return the WebActivityAuthentication object itself. + */ + public WebActivityAuthentication withUsername(String username) { + this.username = username; + return this; + } + + /** + * Get password for the PFX file or basic authentication. + * + * @return the password value + */ + public SecureString password() { + return this.password; + } + + /** + * Set password for the PFX file or basic authentication. + * + * @param password the password value to set + * @return the WebActivityAuthentication object itself. + */ + public WebActivityAuthentication withPassword(SecureString password) { + this.password = password; + return this; + } + + /** + * Get resource for which Azure Auth token will be requested when using MSI Authentication. + * + * @return the resource value + */ + public String resource() { + return this.resource; + } + + /** + * Set resource for which Azure Auth token will be requested when using MSI Authentication. + * + * @param resource the resource value to set + * @return the WebActivityAuthentication object itself. + */ + public WebActivityAuthentication withResource(String resource) { + this.resource = resource; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivityMethod.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivityMethod.java new file mode 100644 index 000000000000..1c4eda28af00 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebActivityMethod.java @@ -0,0 +1,47 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.microsoft.rest.ExpandableStringEnum; + +/** + * Defines values for WebActivityMethod. + */ +public final class WebActivityMethod extends ExpandableStringEnum { + /** Static value GET for WebActivityMethod. */ + public static final WebActivityMethod GET = fromString("GET"); + + /** Static value POST for WebActivityMethod. */ + public static final WebActivityMethod POST = fromString("POST"); + + /** Static value PUT for WebActivityMethod. */ + public static final WebActivityMethod PUT = fromString("PUT"); + + /** Static value DELETE for WebActivityMethod. */ + public static final WebActivityMethod DELETE = fromString("DELETE"); + + /** + * Creates or finds a WebActivityMethod from its string representation. + * @param name a name to look for + * @return the corresponding WebActivityMethod + */ + @JsonCreator + public static WebActivityMethod fromString(String name) { + return fromString(name, WebActivityMethod.class); + } + + /** + * @return known WebActivityMethod values + */ + public static Collection values() { + return values(WebActivityMethod.class); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebAnonymousAuthentication.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebAnonymousAuthentication.java new file mode 100644 index 000000000000..89c66b458f40 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebAnonymousAuthentication.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A WebLinkedService that uses anonymous authentication to communicate with an + * HTTP endpoint. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "authenticationType") +@JsonTypeName("Anonymous") +public class WebAnonymousAuthentication extends WebLinkedServiceTypeProperties { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebBasicAuthentication.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebBasicAuthentication.java new file mode 100644 index 000000000000..f7f26c4016a2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebBasicAuthentication.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A WebLinkedService that uses basic authentication to communicate with an + * HTTP endpoint. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "authenticationType") +@JsonTypeName("Basic") +public class WebBasicAuthentication extends WebLinkedServiceTypeProperties { + /** + * User name for Basic authentication. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "username", required = true) + private Object username; + + /** + * The password for Basic authentication. + */ + @JsonProperty(value = "password", required = true) + private SecretBase password; + + /** + * Get user name for Basic authentication. Type: string (or Expression with resultType string). + * + * @return the username value + */ + public Object username() { + return this.username; + } + + /** + * Set user name for Basic authentication. Type: string (or Expression with resultType string). + * + * @param username the username value to set + * @return the WebBasicAuthentication object itself. + */ + public WebBasicAuthentication withUsername(Object username) { + this.username = username; + return this; + } + + /** + * Get the password for Basic authentication. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set the password for Basic authentication. + * + * @param password the password value to set + * @return the WebBasicAuthentication object itself. + */ + public WebBasicAuthentication withPassword(SecretBase password) { + this.password = password; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebClientCertificateAuthentication.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebClientCertificateAuthentication.java new file mode 100644 index 000000000000..38b844aa81eb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebClientCertificateAuthentication.java @@ -0,0 +1,76 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A WebLinkedService that uses client certificate based authentication to + * communicate with an HTTP endpoint. This scheme follows mutual + * authentication; the server must also provide valid credentials to the + * client. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "authenticationType") +@JsonTypeName("ClientCertificate") +public class WebClientCertificateAuthentication extends WebLinkedServiceTypeProperties { + /** + * Base64-encoded contents of a PFX file. + */ + @JsonProperty(value = "pfx", required = true) + private SecretBase pfx; + + /** + * Password for the PFX file. + */ + @JsonProperty(value = "password", required = true) + private SecretBase password; + + /** + * Get base64-encoded contents of a PFX file. + * + * @return the pfx value + */ + public SecretBase pfx() { + return this.pfx; + } + + /** + * Set base64-encoded contents of a PFX file. + * + * @param pfx the pfx value to set + * @return the WebClientCertificateAuthentication object itself. + */ + public WebClientCertificateAuthentication withPfx(SecretBase pfx) { + this.pfx = pfx; + return this; + } + + /** + * Get password for the PFX file. + * + * @return the password value + */ + public SecretBase password() { + return this.password; + } + + /** + * Set password for the PFX file. + * + * @param password the password value to set + * @return the WebClientCertificateAuthentication object itself. + */ + public WebClientCertificateAuthentication withPassword(SecretBase password) { + this.password = password; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebLinkedService.java new file mode 100644 index 000000000000..b591b0bb213c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebLinkedService.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Web linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Web") +public class WebLinkedService extends LinkedServiceInner { + /** + * Web linked service properties. + */ + @JsonProperty(value = "typeProperties", required = true) + private WebLinkedServiceTypeProperties typeProperties; + + /** + * Get web linked service properties. + * + * @return the typeProperties value + */ + public WebLinkedServiceTypeProperties typeProperties() { + return this.typeProperties; + } + + /** + * Set web linked service properties. + * + * @param typeProperties the typeProperties value to set + * @return the WebLinkedService object itself. + */ + public WebLinkedService withTypeProperties(WebLinkedServiceTypeProperties typeProperties) { + this.typeProperties = typeProperties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebLinkedServiceTypeProperties.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebLinkedServiceTypeProperties.java new file mode 100644 index 000000000000..a51246a04d31 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebLinkedServiceTypeProperties.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Base definition of WebLinkedServiceTypeProperties, this typeProperties is + * polymorphic based on authenticationType, so not flattened in SDK models. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "authenticationType") +@JsonTypeName("WebLinkedServiceTypeProperties") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "ClientCertificate", value = WebClientCertificateAuthentication.class), + @JsonSubTypes.Type(name = "Basic", value = WebBasicAuthentication.class), + @JsonSubTypes.Type(name = "Anonymous", value = WebAnonymousAuthentication.class) +}) +public class WebLinkedServiceTypeProperties { + /** + * The URL of the web service endpoint, e.g. http://www.microsoft.com . + * Type: string (or Expression with resultType string). + */ + @JsonProperty(value = "url", required = true) + private Object url; + + /** + * Get the URL of the web service endpoint, e.g. http://www.microsoft.com . Type: string (or Expression with resultType string). + * + * @return the url value + */ + public Object url() { + return this.url; + } + + /** + * Set the URL of the web service endpoint, e.g. http://www.microsoft.com . Type: string (or Expression with resultType string). + * + * @param url the url value to set + * @return the WebLinkedServiceTypeProperties object itself. + */ + public WebLinkedServiceTypeProperties withUrl(Object url) { + this.url = url; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebSource.java new file mode 100644 index 000000000000..1ef127f35502 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebSource.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity source for web page table. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("WebSource") +public class WebSource extends CopySource { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebTableDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebTableDataset.java new file mode 100644 index 000000000000..ea7523d60f22 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/WebTableDataset.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * The dataset points to a HTML table in the web page. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("WebTable") +@JsonFlatten +public class WebTableDataset extends DatasetInner { + /** + * The zero-based index of the table in the web page. Type: integer (or + * Expression with resultType integer), minimum: 0. + */ + @JsonProperty(value = "typeProperties.index", required = true) + private Object index; + + /** + * The relative URL to the web page from the linked service URL. Type: + * string (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.path") + private Object path; + + /** + * Get the zero-based index of the table in the web page. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @return the index value + */ + public Object index() { + return this.index; + } + + /** + * Set the zero-based index of the table in the web page. Type: integer (or Expression with resultType integer), minimum: 0. + * + * @param index the index value to set + * @return the WebTableDataset object itself. + */ + public WebTableDataset withIndex(Object index) { + this.index = index; + return this; + } + + /** + * Get the relative URL to the web page from the linked service URL. Type: string (or Expression with resultType string). + * + * @return the path value + */ + public Object path() { + return this.path; + } + + /** + * Set the relative URL to the web page from the linked service URL. Type: string (or Expression with resultType string). + * + * @param path the path value to set + * @return the WebTableDataset object itself. + */ + public WebTableDataset withPath(Object path) { + this.path = path; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroLinkedService.java new file mode 100644 index 000000000000..c193d4b8ffc8 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroLinkedService.java @@ -0,0 +1,217 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Xero Service linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Xero") +@JsonFlatten +public class XeroLinkedService extends LinkedServiceInner { + /** + * The endpoint of the Xero server. (i.e. api.xero.com). + */ + @JsonProperty(value = "typeProperties.host", required = true) + private Object host; + + /** + * The consumer key associated with the Xero application. + */ + @JsonProperty(value = "typeProperties.consumerKey") + private SecretBase consumerKey; + + /** + * The private key from the .pem file that was generated for your Xero + * private application. You must include all the text from the .pem file, + * including the Unix line endings( + * ). + */ + @JsonProperty(value = "typeProperties.privateKey") + private SecretBase privateKey; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the Xero server. (i.e. api.xero.com). + * + * @return the host value + */ + public Object host() { + return this.host; + } + + /** + * Set the endpoint of the Xero server. (i.e. api.xero.com). + * + * @param host the host value to set + * @return the XeroLinkedService object itself. + */ + public XeroLinkedService withHost(Object host) { + this.host = host; + return this; + } + + /** + * Get the consumer key associated with the Xero application. + * + * @return the consumerKey value + */ + public SecretBase consumerKey() { + return this.consumerKey; + } + + /** + * Set the consumer key associated with the Xero application. + * + * @param consumerKey the consumerKey value to set + * @return the XeroLinkedService object itself. + */ + public XeroLinkedService withConsumerKey(SecretBase consumerKey) { + this.consumerKey = consumerKey; + return this; + } + + /** + * Get the private key from the .pem file that was generated for your Xero private application. You must include all the text from the .pem file, including the Unix line endings( + ). + * + * @return the privateKey value + */ + public SecretBase privateKey() { + return this.privateKey; + } + + /** + * Set the private key from the .pem file that was generated for your Xero private application. You must include all the text from the .pem file, including the Unix line endings( + ). + * + * @param privateKey the privateKey value to set + * @return the XeroLinkedService object itself. + */ + public XeroLinkedService withPrivateKey(SecretBase privateKey) { + this.privateKey = privateKey; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the XeroLinkedService object itself. + */ + public XeroLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the XeroLinkedService object itself. + */ + public XeroLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the XeroLinkedService object itself. + */ + public XeroLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the XeroLinkedService object itself. + */ + public XeroLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroObjectDataset.java new file mode 100644 index 000000000000..ac40ed1561de --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Xero Service dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("XeroObject") +public class XeroObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroSource.java new file mode 100644 index 000000000000..ac46e892c85e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/XeroSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Xero Service source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("XeroSource") +public class XeroSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the XeroSource object itself. + */ + public XeroSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoLinkedService.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoLinkedService.java new file mode 100644 index 000000000000..c56f59e4661d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoLinkedService.java @@ -0,0 +1,186 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.LinkedServiceInner; + +/** + * Zoho server linked service. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Zoho") +@JsonFlatten +public class ZohoLinkedService extends LinkedServiceInner { + /** + * The endpoint of the Zoho server. (i.e. crm.zoho.com/crm/private). + */ + @JsonProperty(value = "typeProperties.endpoint", required = true) + private Object endpoint; + + /** + * The access token for Zoho authentication. + */ + @JsonProperty(value = "typeProperties.accessToken") + private SecretBase accessToken; + + /** + * Specifies whether the data source endpoints are encrypted using HTTPS. + * The default value is true. + */ + @JsonProperty(value = "typeProperties.useEncryptedEndpoints") + private Object useEncryptedEndpoints; + + /** + * Specifies whether to require the host name in the server's certificate + * to match the host name of the server when connecting over SSL. The + * default value is true. + */ + @JsonProperty(value = "typeProperties.useHostVerification") + private Object useHostVerification; + + /** + * Specifies whether to verify the identity of the server when connecting + * over SSL. The default value is true. + */ + @JsonProperty(value = "typeProperties.usePeerVerification") + private Object usePeerVerification; + + /** + * The encrypted credential used for authentication. Credentials are + * encrypted using the integration runtime credential manager. Type: string + * (or Expression with resultType string). + */ + @JsonProperty(value = "typeProperties.encryptedCredential") + private Object encryptedCredential; + + /** + * Get the endpoint of the Zoho server. (i.e. crm.zoho.com/crm/private). + * + * @return the endpoint value + */ + public Object endpoint() { + return this.endpoint; + } + + /** + * Set the endpoint of the Zoho server. (i.e. crm.zoho.com/crm/private). + * + * @param endpoint the endpoint value to set + * @return the ZohoLinkedService object itself. + */ + public ZohoLinkedService withEndpoint(Object endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Get the access token for Zoho authentication. + * + * @return the accessToken value + */ + public SecretBase accessToken() { + return this.accessToken; + } + + /** + * Set the access token for Zoho authentication. + * + * @param accessToken the accessToken value to set + * @return the ZohoLinkedService object itself. + */ + public ZohoLinkedService withAccessToken(SecretBase accessToken) { + this.accessToken = accessToken; + return this; + } + + /** + * Get specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @return the useEncryptedEndpoints value + */ + public Object useEncryptedEndpoints() { + return this.useEncryptedEndpoints; + } + + /** + * Set specifies whether the data source endpoints are encrypted using HTTPS. The default value is true. + * + * @param useEncryptedEndpoints the useEncryptedEndpoints value to set + * @return the ZohoLinkedService object itself. + */ + public ZohoLinkedService withUseEncryptedEndpoints(Object useEncryptedEndpoints) { + this.useEncryptedEndpoints = useEncryptedEndpoints; + return this; + } + + /** + * Get specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @return the useHostVerification value + */ + public Object useHostVerification() { + return this.useHostVerification; + } + + /** + * Set specifies whether to require the host name in the server's certificate to match the host name of the server when connecting over SSL. The default value is true. + * + * @param useHostVerification the useHostVerification value to set + * @return the ZohoLinkedService object itself. + */ + public ZohoLinkedService withUseHostVerification(Object useHostVerification) { + this.useHostVerification = useHostVerification; + return this; + } + + /** + * Get specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @return the usePeerVerification value + */ + public Object usePeerVerification() { + return this.usePeerVerification; + } + + /** + * Set specifies whether to verify the identity of the server when connecting over SSL. The default value is true. + * + * @param usePeerVerification the usePeerVerification value to set + * @return the ZohoLinkedService object itself. + */ + public ZohoLinkedService withUsePeerVerification(Object usePeerVerification) { + this.usePeerVerification = usePeerVerification; + return this; + } + + /** + * Get the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @return the encryptedCredential value + */ + public Object encryptedCredential() { + return this.encryptedCredential; + } + + /** + * Set the encrypted credential used for authentication. Credentials are encrypted using the integration runtime credential manager. Type: string (or Expression with resultType string). + * + * @param encryptedCredential the encryptedCredential value to set + * @return the ZohoLinkedService object itself. + */ + public ZohoLinkedService withEncryptedCredential(Object encryptedCredential) { + this.encryptedCredential = encryptedCredential; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoObjectDataset.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoObjectDataset.java new file mode 100644 index 000000000000..94f1e807baf0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoObjectDataset.java @@ -0,0 +1,21 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation.DatasetInner; + +/** + * Zoho server dataset. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ZohoObject") +public class ZohoObjectDataset extends DatasetInner { +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoSource.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoSource.java new file mode 100644 index 000000000000..b26c120304c0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/ZohoSource.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +/** + * A copy activity Zoho server source. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("ZohoSource") +public class ZohoSource extends CopySource { + /** + * A query to retrieve data from source. Type: string (or Expression with + * resultType string). + */ + @JsonProperty(value = "query") + private Object query; + + /** + * Get a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @return the query value + */ + public Object query() { + return this.query; + } + + /** + * Set a query to retrieve data from source. Type: string (or Expression with resultType string). + * + * @param query the query value to set + * @return the ZohoSource object itself. + */ + public ZohoSource withQuery(Object query) { + this.query = query; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunImpl.java new file mode 100644 index 000000000000..65b28a795b43 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunImpl.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ActivityRun; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import rx.Observable; +import org.joda.time.DateTime; +import java.util.Map; + +class ActivityRunImpl extends WrapperImpl implements ActivityRun { + private final DataFactoryManager manager; + + ActivityRunImpl(ActivityRunInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + + + @Override + public String activityName() { + return this.inner().activityName(); + } + + @Override + public DateTime activityRunEnd() { + return this.inner().activityRunEnd(); + } + + @Override + public String activityRunId() { + return this.inner().activityRunId(); + } + + @Override + public DateTime activityRunStart() { + return this.inner().activityRunStart(); + } + + @Override + public String activityType() { + return this.inner().activityType(); + } + + @Override + public Map additionalProperties() { + return this.inner().additionalProperties(); + } + + @Override + public Integer durationInMs() { + return this.inner().durationInMs(); + } + + @Override + public Object error() { + return this.inner().error(); + } + + @Override + public Object input() { + return this.inner().input(); + } + + @Override + public String linkedServiceName() { + return this.inner().linkedServiceName(); + } + + @Override + public Object output() { + return this.inner().output(); + } + + @Override + public String pipelineName() { + return this.inner().pipelineName(); + } + + @Override + public String pipelineRunId() { + return this.inner().pipelineRunId(); + } + + @Override + public String status() { + return this.inner().status(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunInner.java new file mode 100644 index 000000000000..6c634d2dca13 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunInner.java @@ -0,0 +1,240 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import org.joda.time.DateTime; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Information about an activity run in a pipeline. + */ +public class ActivityRunInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The name of the pipeline. + */ + @JsonProperty(value = "pipelineName", access = JsonProperty.Access.WRITE_ONLY) + private String pipelineName; + + /** + * The id of the pipeline run. + */ + @JsonProperty(value = "pipelineRunId", access = JsonProperty.Access.WRITE_ONLY) + private String pipelineRunId; + + /** + * The name of the activity. + */ + @JsonProperty(value = "activityName", access = JsonProperty.Access.WRITE_ONLY) + private String activityName; + + /** + * The type of the activity. + */ + @JsonProperty(value = "activityType", access = JsonProperty.Access.WRITE_ONLY) + private String activityType; + + /** + * The id of the activity run. + */ + @JsonProperty(value = "activityRunId", access = JsonProperty.Access.WRITE_ONLY) + private String activityRunId; + + /** + * The name of the compute linked service. + */ + @JsonProperty(value = "linkedServiceName", access = JsonProperty.Access.WRITE_ONLY) + private String linkedServiceName; + + /** + * The status of the activity run. + */ + @JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY) + private String status; + + /** + * The start time of the activity run in 'ISO 8601' format. + */ + @JsonProperty(value = "activityRunStart", access = JsonProperty.Access.WRITE_ONLY) + private DateTime activityRunStart; + + /** + * The end time of the activity run in 'ISO 8601' format. + */ + @JsonProperty(value = "activityRunEnd", access = JsonProperty.Access.WRITE_ONLY) + private DateTime activityRunEnd; + + /** + * The duration of the activity run. + */ + @JsonProperty(value = "durationInMs", access = JsonProperty.Access.WRITE_ONLY) + private Integer durationInMs; + + /** + * The input for the activity. + */ + @JsonProperty(value = "input", access = JsonProperty.Access.WRITE_ONLY) + private Object input; + + /** + * The output for the activity. + */ + @JsonProperty(value = "output", access = JsonProperty.Access.WRITE_ONLY) + private Object output; + + /** + * The error if any from the activity run. + */ + @JsonProperty(value = "error", access = JsonProperty.Access.WRITE_ONLY) + private Object error; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the ActivityRunInner object itself. + */ + public ActivityRunInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the name of the pipeline. + * + * @return the pipelineName value + */ + public String pipelineName() { + return this.pipelineName; + } + + /** + * Get the id of the pipeline run. + * + * @return the pipelineRunId value + */ + public String pipelineRunId() { + return this.pipelineRunId; + } + + /** + * Get the name of the activity. + * + * @return the activityName value + */ + public String activityName() { + return this.activityName; + } + + /** + * Get the type of the activity. + * + * @return the activityType value + */ + public String activityType() { + return this.activityType; + } + + /** + * Get the id of the activity run. + * + * @return the activityRunId value + */ + public String activityRunId() { + return this.activityRunId; + } + + /** + * Get the name of the compute linked service. + * + * @return the linkedServiceName value + */ + public String linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Get the status of the activity run. + * + * @return the status value + */ + public String status() { + return this.status; + } + + /** + * Get the start time of the activity run in 'ISO 8601' format. + * + * @return the activityRunStart value + */ + public DateTime activityRunStart() { + return this.activityRunStart; + } + + /** + * Get the end time of the activity run in 'ISO 8601' format. + * + * @return the activityRunEnd value + */ + public DateTime activityRunEnd() { + return this.activityRunEnd; + } + + /** + * Get the duration of the activity run. + * + * @return the durationInMs value + */ + public Integer durationInMs() { + return this.durationInMs; + } + + /** + * Get the input for the activity. + * + * @return the input value + */ + public Object input() { + return this.input; + } + + /** + * Get the output for the activity. + * + * @return the output value + */ + public Object output() { + return this.output; + } + + /** + * Get the error if any from the activity run. + * + * @return the error value + */ + public Object error() { + return this.error; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunsImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunsImpl.java new file mode 100644 index 000000000000..17e1f761fa37 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunsImpl.java @@ -0,0 +1,53 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ActivityRuns; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ActivityRun; + +class ActivityRunsImpl extends WrapperImpl implements ActivityRuns { + private final DataFactoryManager manager; + + ActivityRunsImpl(DataFactoryManager manager) { + super(manager.inner().activityRuns()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + private ActivityRunImpl wrapModel(ActivityRunInner inner) { + return new ActivityRunImpl(inner, manager()); + } + + @Override + public Observable listByPipelineRunAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime) { + ActivityRunsInner client = this.inner(); + return client.listByPipelineRunAsync(resourceGroupName, factoryName, runId, startTime, endTime) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public ActivityRun call(ActivityRunInner inner) { + return wrapModel(inner); + } + }); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunsInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunsInner.java new file mode 100644 index 000000000000..3f0c465ab577 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/ActivityRunsInner.java @@ -0,0 +1,486 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import org.joda.time.DateTime; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.Path; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in ActivityRuns. + */ +public class ActivityRunsInner { + /** The Retrofit service to perform REST calls. */ + private ActivityRunsService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of ActivityRunsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public ActivityRunsInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(ActivityRunsService.class); + this.client = client; + } + + /** + * The interface defining all the services for ActivityRuns to be + * used by Retrofit to perform actually REST calls. + */ + interface ActivityRunsService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.ActivityRuns listByPipelineRun" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}/activityruns") + Observable> listByPipelineRun(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("runId") String runId, @Query("api-version") String apiVersion, @Query("startTime") DateTime startTime, @Query("endTime") DateTime endTime, @Query("status") String status, @Query("activityName") String activityName, @Query("linkedServiceName") String linkedServiceName, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.ActivityRuns listByPipelineRunNext" }) + @GET + Observable> listByPipelineRunNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ActivityRunInner> object if successful. + */ + public PagedList listByPipelineRun(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime) { + ServiceResponse> response = listByPipelineRunSinglePageAsync(resourceGroupName, factoryName, runId, startTime, endTime).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByPipelineRunNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByPipelineRunAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByPipelineRunSinglePageAsync(resourceGroupName, factoryName, runId, startTime, endTime), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByPipelineRunNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ActivityRunInner> object + */ + public Observable> listByPipelineRunAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime) { + return listByPipelineRunWithServiceResponseAsync(resourceGroupName, factoryName, runId, startTime, endTime) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ActivityRunInner> object + */ + public Observable>> listByPipelineRunWithServiceResponseAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime) { + return listByPipelineRunSinglePageAsync(resourceGroupName, factoryName, runId, startTime, endTime) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByPipelineRunNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ActivityRunInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByPipelineRunSinglePageAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (runId == null) { + throw new IllegalArgumentException("Parameter runId is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (startTime == null) { + throw new IllegalArgumentException("Parameter startTime is required and cannot be null."); + } + if (endTime == null) { + throw new IllegalArgumentException("Parameter endTime is required and cannot be null."); + } + final String status = null; + final String activityName = null; + final String linkedServiceName = null; + return service.listByPipelineRun(this.client.subscriptionId(), resourceGroupName, factoryName, runId, this.client.apiVersion(), startTime, endTime, status, activityName, linkedServiceName, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByPipelineRunDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @param status The status of the pipeline run. + * @param activityName The name of the activity. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ActivityRunInner> object if successful. + */ + public PagedList listByPipelineRun(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime, final String status, final String activityName, final String linkedServiceName) { + ServiceResponse> response = listByPipelineRunSinglePageAsync(resourceGroupName, factoryName, runId, startTime, endTime, status, activityName, linkedServiceName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByPipelineRunNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @param status The status of the pipeline run. + * @param activityName The name of the activity. + * @param linkedServiceName The linked service name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByPipelineRunAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime, final String status, final String activityName, final String linkedServiceName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByPipelineRunSinglePageAsync(resourceGroupName, factoryName, runId, startTime, endTime, status, activityName, linkedServiceName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByPipelineRunNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @param status The status of the pipeline run. + * @param activityName The name of the activity. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ActivityRunInner> object + */ + public Observable> listByPipelineRunAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime, final String status, final String activityName, final String linkedServiceName) { + return listByPipelineRunWithServiceResponseAsync(resourceGroupName, factoryName, runId, startTime, endTime, status, activityName, linkedServiceName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * List activity runs based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param startTime The start time of activity runs in ISO8601 format. + * @param endTime The end time of activity runs in ISO8601 format. + * @param status The status of the pipeline run. + * @param activityName The name of the activity. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ActivityRunInner> object + */ + public Observable>> listByPipelineRunWithServiceResponseAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime, final String status, final String activityName, final String linkedServiceName) { + return listByPipelineRunSinglePageAsync(resourceGroupName, factoryName, runId, startTime, endTime, status, activityName, linkedServiceName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByPipelineRunNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * List activity runs based on input filter conditions. + * + ServiceResponse> * @param resourceGroupName The resource group name. + ServiceResponse> * @param factoryName The factory name. + ServiceResponse> * @param runId The pipeline run identifier. + ServiceResponse> * @param startTime The start time of activity runs in ISO8601 format. + ServiceResponse> * @param endTime The end time of activity runs in ISO8601 format. + ServiceResponse> * @param status The status of the pipeline run. + ServiceResponse> * @param activityName The name of the activity. + ServiceResponse> * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ActivityRunInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByPipelineRunSinglePageAsync(final String resourceGroupName, final String factoryName, final String runId, final DateTime startTime, final DateTime endTime, final String status, final String activityName, final String linkedServiceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (runId == null) { + throw new IllegalArgumentException("Parameter runId is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (startTime == null) { + throw new IllegalArgumentException("Parameter startTime is required and cannot be null."); + } + if (endTime == null) { + throw new IllegalArgumentException("Parameter endTime is required and cannot be null."); + } + return service.listByPipelineRun(this.client.subscriptionId(), resourceGroupName, factoryName, runId, this.client.apiVersion(), startTime, endTime, status, activityName, linkedServiceName, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByPipelineRunDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByPipelineRunDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * List activity runs based on input filter conditions. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<ActivityRunInner> object if successful. + */ + public PagedList listByPipelineRunNext(final String nextPageLink) { + ServiceResponse> response = listByPipelineRunNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByPipelineRunNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * List activity runs based on input filter conditions. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByPipelineRunNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByPipelineRunNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByPipelineRunNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * List activity runs based on input filter conditions. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ActivityRunInner> object + */ + public Observable> listByPipelineRunNextAsync(final String nextPageLink) { + return listByPipelineRunNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * List activity runs based on input filter conditions. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<ActivityRunInner> object + */ + public Observable>> listByPipelineRunNextWithServiceResponseAsync(final String nextPageLink) { + return listByPipelineRunNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByPipelineRunNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * List activity runs based on input filter conditions. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<ActivityRunInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByPipelineRunNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByPipelineRunNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByPipelineRunNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByPipelineRunNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/CreateRunResponseImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/CreateRunResponseImpl.java new file mode 100644 index 000000000000..e3aa7d8196ee --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/CreateRunResponseImpl.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.CreateRunResponse; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; + +class CreateRunResponseImpl extends WrapperImpl implements CreateRunResponse { + private final DataFactoryManager manager; + CreateRunResponseImpl(CreateRunResponseInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public String runId() { + return this.inner().runId(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/CreateRunResponseInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/CreateRunResponseInner.java new file mode 100644 index 000000000000..b8bbb0845ae2 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/CreateRunResponseInner.java @@ -0,0 +1,43 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Response body with a run identifier. + */ +public class CreateRunResponseInner { + /** + * Identifier of a run. + */ + @JsonProperty(value = "runId", required = true) + private String runId; + + /** + * Get identifier of a run. + * + * @return the runId value + */ + public String runId() { + return this.runId; + } + + /** + * Set identifier of a run. + * + * @param runId the runId value to set + * @return the CreateRunResponseInner object itself. + */ + public CreateRunResponseInner withRunId(String runId) { + this.runId = runId; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DataFactoryManagementClientImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DataFactoryManagementClientImpl.java new file mode 100644 index 000000000000..54a4966ae97a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DataFactoryManagementClientImpl.java @@ -0,0 +1,322 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.AzureClient; +import com.microsoft.azure.AzureServiceClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; +import com.microsoft.rest.RestClient; + +/** + * Initializes a new instance of the DataFactoryManagementClientImpl class. + */ +public class DataFactoryManagementClientImpl extends AzureServiceClient { + /** the {@link AzureClient} used for long running operations. */ + private AzureClient azureClient; + + /** + * Gets the {@link AzureClient} used for long running operations. + * @return the azure client; + */ + public AzureClient getAzureClient() { + return this.azureClient; + } + + /** The subscription identifier. */ + private String subscriptionId; + + /** + * Gets The subscription identifier. + * + * @return the subscriptionId value. + */ + public String subscriptionId() { + return this.subscriptionId; + } + + /** + * Sets The subscription identifier. + * + * @param subscriptionId the subscriptionId value. + * @return the service client itself + */ + public DataFactoryManagementClientImpl withSubscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /** The API version. */ + private String apiVersion; + + /** + * Gets The API version. + * + * @return the apiVersion value. + */ + public String apiVersion() { + return this.apiVersion; + } + + /** The preferred language for the response. */ + private String acceptLanguage; + + /** + * Gets The preferred language for the response. + * + * @return the acceptLanguage value. + */ + public String acceptLanguage() { + return this.acceptLanguage; + } + + /** + * Sets The preferred language for the response. + * + * @param acceptLanguage the acceptLanguage value. + * @return the service client itself + */ + public DataFactoryManagementClientImpl withAcceptLanguage(String acceptLanguage) { + this.acceptLanguage = acceptLanguage; + return this; + } + + /** The retry timeout in seconds for Long Running Operations. Default value is 30. */ + private int longRunningOperationRetryTimeout; + + /** + * Gets The retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @return the longRunningOperationRetryTimeout value. + */ + public int longRunningOperationRetryTimeout() { + return this.longRunningOperationRetryTimeout; + } + + /** + * Sets The retry timeout in seconds for Long Running Operations. Default value is 30. + * + * @param longRunningOperationRetryTimeout the longRunningOperationRetryTimeout value. + * @return the service client itself + */ + public DataFactoryManagementClientImpl withLongRunningOperationRetryTimeout(int longRunningOperationRetryTimeout) { + this.longRunningOperationRetryTimeout = longRunningOperationRetryTimeout; + return this; + } + + /** Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. */ + private boolean generateClientRequestId; + + /** + * Gets Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @return the generateClientRequestId value. + */ + public boolean generateClientRequestId() { + return this.generateClientRequestId; + } + + /** + * Sets Whether a unique x-ms-client-request-id should be generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true. + * + * @param generateClientRequestId the generateClientRequestId value. + * @return the service client itself + */ + public DataFactoryManagementClientImpl withGenerateClientRequestId(boolean generateClientRequestId) { + this.generateClientRequestId = generateClientRequestId; + return this; + } + + /** + * The OperationsInner object to access its operations. + */ + private OperationsInner operations; + + /** + * Gets the OperationsInner object to access its operations. + * @return the OperationsInner object. + */ + public OperationsInner operations() { + return this.operations; + } + + /** + * The FactoriesInner object to access its operations. + */ + private FactoriesInner factories; + + /** + * Gets the FactoriesInner object to access its operations. + * @return the FactoriesInner object. + */ + public FactoriesInner factories() { + return this.factories; + } + + /** + * The IntegrationRuntimesInner object to access its operations. + */ + private IntegrationRuntimesInner integrationRuntimes; + + /** + * Gets the IntegrationRuntimesInner object to access its operations. + * @return the IntegrationRuntimesInner object. + */ + public IntegrationRuntimesInner integrationRuntimes() { + return this.integrationRuntimes; + } + + /** + * The IntegrationRuntimeNodesInner object to access its operations. + */ + private IntegrationRuntimeNodesInner integrationRuntimeNodes; + + /** + * Gets the IntegrationRuntimeNodesInner object to access its operations. + * @return the IntegrationRuntimeNodesInner object. + */ + public IntegrationRuntimeNodesInner integrationRuntimeNodes() { + return this.integrationRuntimeNodes; + } + + /** + * The LinkedServicesInner object to access its operations. + */ + private LinkedServicesInner linkedServices; + + /** + * Gets the LinkedServicesInner object to access its operations. + * @return the LinkedServicesInner object. + */ + public LinkedServicesInner linkedServices() { + return this.linkedServices; + } + + /** + * The DatasetsInner object to access its operations. + */ + private DatasetsInner datasets; + + /** + * Gets the DatasetsInner object to access its operations. + * @return the DatasetsInner object. + */ + public DatasetsInner datasets() { + return this.datasets; + } + + /** + * The PipelinesInner object to access its operations. + */ + private PipelinesInner pipelines; + + /** + * Gets the PipelinesInner object to access its operations. + * @return the PipelinesInner object. + */ + public PipelinesInner pipelines() { + return this.pipelines; + } + + /** + * The PipelineRunsInner object to access its operations. + */ + private PipelineRunsInner pipelineRuns; + + /** + * Gets the PipelineRunsInner object to access its operations. + * @return the PipelineRunsInner object. + */ + public PipelineRunsInner pipelineRuns() { + return this.pipelineRuns; + } + + /** + * The ActivityRunsInner object to access its operations. + */ + private ActivityRunsInner activityRuns; + + /** + * Gets the ActivityRunsInner object to access its operations. + * @return the ActivityRunsInner object. + */ + public ActivityRunsInner activityRuns() { + return this.activityRuns; + } + + /** + * The TriggersInner object to access its operations. + */ + private TriggersInner triggers; + + /** + * Gets the TriggersInner object to access its operations. + * @return the TriggersInner object. + */ + public TriggersInner triggers() { + return this.triggers; + } + + /** + * Initializes an instance of DataFactoryManagementClient client. + * + * @param credentials the management credentials for Azure + */ + public DataFactoryManagementClientImpl(ServiceClientCredentials credentials) { + this("https://management.azure.com", credentials); + } + + /** + * Initializes an instance of DataFactoryManagementClient client. + * + * @param baseUrl the base URL of the host + * @param credentials the management credentials for Azure + */ + public DataFactoryManagementClientImpl(String baseUrl, ServiceClientCredentials credentials) { + super(baseUrl, credentials); + initialize(); + } + + /** + * Initializes an instance of DataFactoryManagementClient client. + * + * @param restClient the REST client to connect to Azure. + */ + public DataFactoryManagementClientImpl(RestClient restClient) { + super(restClient); + initialize(); + } + + protected void initialize() { + this.apiVersion = "2017-09-01-preview"; + this.acceptLanguage = "en-US"; + this.longRunningOperationRetryTimeout = 30; + this.generateClientRequestId = true; + this.operations = new OperationsInner(restClient().retrofit(), this); + this.factories = new FactoriesInner(restClient().retrofit(), this); + this.integrationRuntimes = new IntegrationRuntimesInner(restClient().retrofit(), this); + this.integrationRuntimeNodes = new IntegrationRuntimeNodesInner(restClient().retrofit(), this); + this.linkedServices = new LinkedServicesInner(restClient().retrofit(), this); + this.datasets = new DatasetsInner(restClient().retrofit(), this); + this.pipelines = new PipelinesInner(restClient().retrofit(), this); + this.pipelineRuns = new PipelineRunsInner(restClient().retrofit(), this); + this.activityRuns = new ActivityRunsInner(restClient().retrofit(), this); + this.triggers = new TriggersInner(restClient().retrofit(), this); + this.azureClient = new AzureClient(this); + } + + /** + * Gets the User-Agent header for the client. + * + * @return the user agent string. + */ + @Override + public String userAgent() { + return String.format("%s (%s, %s, auto-generated)", super.userAgent(), "DataFactoryManagementClient", "2017-09-01-preview"); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DataFactoryManager.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DataFactoryManager.java new file mode 100644 index 000000000000..5d331fd766f7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DataFactoryManager.java @@ -0,0 +1,207 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.AzureEnvironment; +import com.microsoft.azure.AzureResponseBuilder; +import com.microsoft.azure.credentials.AzureTokenCredentials; +import com.microsoft.azure.management.apigeneration.Beta; +import com.microsoft.azure.management.apigeneration.Beta.SinceVersion; +import com.microsoft.azure.arm.resources.AzureConfigurable; +import com.microsoft.azure.serializer.AzureJacksonAdapter; +import com.microsoft.rest.RestClient; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Operations; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodes; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServices; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Datasets; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRuns; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ActivityRuns; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers; +import com.microsoft.azure.arm.resources.implementation.AzureConfigurableCoreImpl; +import com.microsoft.azure.arm.resources.implementation.ManagerCore; + +/** + * Entry point to Azure DataFactory resource management. + */ +public final class DataFactoryManager extends ManagerCore { + private Operations operations; + private Factories factories; + private IntegrationRuntimes integrationRuntimes; + private IntegrationRuntimeNodes integrationRuntimeNodes; + private LinkedServices linkedServices; + private Datasets datasets; + private Pipelines pipelines; + private PipelineRuns pipelineRuns; + private ActivityRuns activityRuns; + private Triggers triggers; + /** + * Get a Configurable instance that can be used to create DataFactoryManager with optional configuration. + * + * @return the instance allowing configurations + */ + public static Configurable configure() { + return new DataFactoryManager.ConfigurableImpl(); + } + /** + * Creates an instance of DataFactoryManager that exposes DataFactory resource management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the DataFactoryManager + */ + public static DataFactoryManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return new DataFactoryManager(new RestClient.Builder() + .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) + .withCredentials(credentials) + .withSerializerAdapter(new AzureJacksonAdapter()) + .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) + .build(), subscriptionId); + } + /** + * Creates an instance of DataFactoryManager that exposes DataFactory resource management API entry points. + * + * @param restClient the RestClient to be used for API calls. + * @param subscriptionId the subscription UUID + * @return the DataFactoryManager + */ + public static DataFactoryManager authenticate(RestClient restClient, String subscriptionId) { + return new DataFactoryManager(restClient, subscriptionId); + } + /** + * The interface allowing configurations to be set. + */ + public interface Configurable extends AzureConfigurable { + /** + * Creates an instance of DataFactoryManager that exposes DataFactory management API entry points. + * + * @param credentials the credentials to use + * @param subscriptionId the subscription UUID + * @return the interface exposing DataFactory management API entry points that work across subscriptions + */ + DataFactoryManager authenticate(AzureTokenCredentials credentials, String subscriptionId); + } + + /** + * @return Entry point to manage Operations. + */ + public Operations operations() { + if (this.operations == null) { + this.operations = new OperationsImpl(this); + } + return this.operations; + } + + /** + * @return Entry point to manage Factories. + */ + public Factories factories() { + if (this.factories == null) { + this.factories = new FactoriesImpl(this); + } + return this.factories; + } + + /** + * @return Entry point to manage IntegrationRuntimes. + */ + public IntegrationRuntimes integrationRuntimes() { + if (this.integrationRuntimes == null) { + this.integrationRuntimes = new IntegrationRuntimesImpl(this); + } + return this.integrationRuntimes; + } + + /** + * @return Entry point to manage IntegrationRuntimeNodes. + */ + public IntegrationRuntimeNodes integrationRuntimeNodes() { + if (this.integrationRuntimeNodes == null) { + this.integrationRuntimeNodes = new IntegrationRuntimeNodesImpl(this); + } + return this.integrationRuntimeNodes; + } + + /** + * @return Entry point to manage LinkedServices. + */ + public LinkedServices linkedServices() { + if (this.linkedServices == null) { + this.linkedServices = new LinkedServicesImpl(this); + } + return this.linkedServices; + } + + /** + * @return Entry point to manage Datasets. + */ + public Datasets datasets() { + if (this.datasets == null) { + this.datasets = new DatasetsImpl(this); + } + return this.datasets; + } + + /** + * @return Entry point to manage Pipelines. + */ + public Pipelines pipelines() { + if (this.pipelines == null) { + this.pipelines = new PipelinesImpl(this); + } + return this.pipelines; + } + + /** + * @return Entry point to manage PipelineRuns. + */ + public PipelineRuns pipelineRuns() { + if (this.pipelineRuns == null) { + this.pipelineRuns = new PipelineRunsImpl(this); + } + return this.pipelineRuns; + } + + /** + * @return Entry point to manage ActivityRuns. + */ + public ActivityRuns activityRuns() { + if (this.activityRuns == null) { + this.activityRuns = new ActivityRunsImpl(this); + } + return this.activityRuns; + } + + /** + * @return Entry point to manage Triggers. + */ + public Triggers triggers() { + if (this.triggers == null) { + this.triggers = new TriggersImpl(this); + } + return this.triggers; + } + + /** + * The implementation for Configurable interface. + */ + private static final class ConfigurableImpl extends AzureConfigurableCoreImpl implements Configurable { + public DataFactoryManager authenticate(AzureTokenCredentials credentials, String subscriptionId) { + return DataFactoryManager.authenticate(buildRestClient(credentials), subscriptionId); + } + } + private DataFactoryManager(RestClient restClient, String subscriptionId) { + super( + restClient, + subscriptionId, + new DataFactoryManagementClientImpl(restClient).withSubscriptionId(subscriptionId)); + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetInner.java new file mode 100644 index 000000000000..ddf3f8e6bee5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetInner.java @@ -0,0 +1,239 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServiceReference; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ParameterSpecification; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * The Azure Data Factory nested object which identifies data within different + * data stores, such as tables, files, folders, and documents. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Dataset") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "ResponsysObject", value = ResponsysObjectDataset.class), + @JsonSubTypes.Type(name = "SalesforceMarketingCloudObject", value = SalesforceMarketingCloudObjectDataset.class), + @JsonSubTypes.Type(name = "VerticaTable", value = VerticaTableDataset.class), + @JsonSubTypes.Type(name = "NetezzaTable", value = NetezzaTableDataset.class), + @JsonSubTypes.Type(name = "ZohoObject", value = ZohoObjectDataset.class), + @JsonSubTypes.Type(name = "XeroObject", value = XeroObjectDataset.class), + @JsonSubTypes.Type(name = "SquareObject", value = SquareObjectDataset.class), + @JsonSubTypes.Type(name = "SparkObject", value = SparkObjectDataset.class), + @JsonSubTypes.Type(name = "ShopifyObject", value = ShopifyObjectDataset.class), + @JsonSubTypes.Type(name = "ServiceNowObject", value = ServiceNowObjectDataset.class), + @JsonSubTypes.Type(name = "QuickBooksObject", value = QuickBooksObjectDataset.class), + @JsonSubTypes.Type(name = "PrestoObject", value = PrestoObjectDataset.class), + @JsonSubTypes.Type(name = "PhoenixObject", value = PhoenixObjectDataset.class), + @JsonSubTypes.Type(name = "PaypalObject", value = PaypalObjectDataset.class), + @JsonSubTypes.Type(name = "MarketoObject", value = MarketoObjectDataset.class), + @JsonSubTypes.Type(name = "MariaDBTable", value = MariaDBTableDataset.class), + @JsonSubTypes.Type(name = "MagentoObject", value = MagentoObjectDataset.class), + @JsonSubTypes.Type(name = "JiraObject", value = JiraObjectDataset.class), + @JsonSubTypes.Type(name = "ImpalaObject", value = ImpalaObjectDataset.class), + @JsonSubTypes.Type(name = "HubspotObject", value = HubspotObjectDataset.class), + @JsonSubTypes.Type(name = "HiveObject", value = HiveObjectDataset.class), + @JsonSubTypes.Type(name = "HBaseObject", value = HBaseObjectDataset.class), + @JsonSubTypes.Type(name = "GreenplumTable", value = GreenplumTableDataset.class), + @JsonSubTypes.Type(name = "GoogleBigQueryObject", value = GoogleBigQueryObjectDataset.class), + @JsonSubTypes.Type(name = "EloquaObject", value = EloquaObjectDataset.class), + @JsonSubTypes.Type(name = "DrillTable", value = DrillTableDataset.class), + @JsonSubTypes.Type(name = "CouchbaseTable", value = CouchbaseTableDataset.class), + @JsonSubTypes.Type(name = "ConcurObject", value = ConcurObjectDataset.class), + @JsonSubTypes.Type(name = "AzurePostgreSqlTable", value = AzurePostgreSqlTableDataset.class), + @JsonSubTypes.Type(name = "AmazonMWSObject", value = AmazonMWSObjectDataset.class), + @JsonSubTypes.Type(name = "HttpFile", value = HttpDataset.class), + @JsonSubTypes.Type(name = "AzureSearchIndex", value = AzureSearchIndexDataset.class), + @JsonSubTypes.Type(name = "WebTable", value = WebTableDataset.class), + @JsonSubTypes.Type(name = "SqlServerTable", value = SqlServerTableDataset.class), + @JsonSubTypes.Type(name = "SapEccResource", value = SapEccResourceDataset.class), + @JsonSubTypes.Type(name = "SapCloudForCustomerResource", value = SapCloudForCustomerResourceDataset.class), + @JsonSubTypes.Type(name = "SalesforceObject", value = SalesforceObjectDataset.class), + @JsonSubTypes.Type(name = "RelationalTable", value = RelationalTableDataset.class), + @JsonSubTypes.Type(name = "AzureMySqlTable", value = AzureMySqlTableDataset.class), + @JsonSubTypes.Type(name = "OracleTable", value = OracleTableDataset.class), + @JsonSubTypes.Type(name = "ODataResource", value = ODataResourceDataset.class), + @JsonSubTypes.Type(name = "MongoDbCollection", value = MongoDbCollectionDataset.class), + @JsonSubTypes.Type(name = "FileShare", value = FileShareDataset.class), + @JsonSubTypes.Type(name = "AzureDataLakeStoreFile", value = AzureDataLakeStoreDataset.class), + @JsonSubTypes.Type(name = "DynamicsEntity", value = DynamicsEntityDataset.class), + @JsonSubTypes.Type(name = "DocumentDbCollection", value = DocumentDbCollectionDataset.class), + @JsonSubTypes.Type(name = "CustomDataset", value = CustomDataset.class), + @JsonSubTypes.Type(name = "CassandraTable", value = CassandraTableDataset.class), + @JsonSubTypes.Type(name = "AzureSqlDWTable", value = AzureSqlDWTableDataset.class), + @JsonSubTypes.Type(name = "AzureSqlTable", value = AzureSqlTableDataset.class), + @JsonSubTypes.Type(name = "AzureTable", value = AzureTableDataset.class), + @JsonSubTypes.Type(name = "AzureBlob", value = AzureBlobDataset.class), + @JsonSubTypes.Type(name = "AmazonS3Object", value = AmazonS3Dataset.class) +}) +public class DatasetInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Dataset description. + */ + @JsonProperty(value = "description") + private String description; + + /** + * Columns that define the structure of the dataset. Type: array (or + * Expression with resultType array), itemType: DatasetDataElement. + */ + @JsonProperty(value = "structure") + private Object structure; + + /** + * Linked service reference. + */ + @JsonProperty(value = "linkedServiceName", required = true) + private LinkedServiceReference linkedServiceName; + + /** + * Parameters for dataset. + */ + @JsonProperty(value = "parameters") + private Map parameters; + + /** + * List of tags that can be used for describing the Dataset. + */ + @JsonProperty(value = "annotations") + private List annotations; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the DatasetInner object itself. + */ + public DatasetInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get dataset description. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Set dataset description. + * + * @param description the description value to set + * @return the DatasetInner object itself. + */ + public DatasetInner withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get columns that define the structure of the dataset. Type: array (or Expression with resultType array), itemType: DatasetDataElement. + * + * @return the structure value + */ + public Object structure() { + return this.structure; + } + + /** + * Set columns that define the structure of the dataset. Type: array (or Expression with resultType array), itemType: DatasetDataElement. + * + * @param structure the structure value to set + * @return the DatasetInner object itself. + */ + public DatasetInner withStructure(Object structure) { + this.structure = structure; + return this; + } + + /** + * Get linked service reference. + * + * @return the linkedServiceName value + */ + public LinkedServiceReference linkedServiceName() { + return this.linkedServiceName; + } + + /** + * Set linked service reference. + * + * @param linkedServiceName the linkedServiceName value to set + * @return the DatasetInner object itself. + */ + public DatasetInner withLinkedServiceName(LinkedServiceReference linkedServiceName) { + this.linkedServiceName = linkedServiceName; + return this; + } + + /** + * Get parameters for dataset. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set parameters for dataset. + * + * @param parameters the parameters value to set + * @return the DatasetInner object itself. + */ + public DatasetInner withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + + /** + * Get list of tags that can be used for describing the Dataset. + * + * @return the annotations value + */ + public List annotations() { + return this.annotations; + } + + /** + * Set list of tags that can be used for describing the Dataset. + * + * @param annotations the annotations value to set + * @return the DatasetInner object itself. + */ + public DatasetInner withAnnotations(List annotations) { + this.annotations = annotations; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetResourceImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetResourceImpl.java new file mode 100644 index 000000000000..2bc41bae7c35 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetResourceImpl.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.DatasetResource; +import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl; +import rx.Observable; +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServiceReference; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ParameterSpecification; +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.; +import rx.functions.Func1; + +class DatasetResourceImpl extends CreatableUpdatableImpl implements DatasetResource, DatasetResource.Definition, DatasetResource.Update { + private final DataFactoryManager manager; + private String resourceGroupName; + private String factoryName; + private String datasetName; + private String cifMatch; + private DatasetInner cproperties; + private String uifMatch; + private DatasetInner uproperties; + + DatasetResourceImpl(String name, DataFactoryManager manager) { + super(name, new DatasetResourceInner()); + this.manager = manager; + // Set resource name + this.datasetName = name; + // + this.cproperties = new DatasetInner(); + this.uproperties = new DatasetInner(); + } + + DatasetResourceImpl(DatasetResourceInner inner, DataFactoryManager manager) { + super(inner.name(), inner); + this.manager = manager; + // Set resource name + this.datasetName = inner.name(); + // set resource ancestor and positional variables + this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups"); + this.factoryName = IdParsingUtils.getValueFromIdByName(inner.id(), "factories"); + this.datasetName = IdParsingUtils.getValueFromIdByName(inner.id(), "datasets"); + // + this.cproperties = new DatasetInner(); + this.uproperties = new DatasetInner(); + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Observable createResourceAsync() { + DatasetsInner client = this.manager().inner().datasets(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.datasetName, this.cproperties, this.cifMatch) + .map(new Func1() { + @Override + public DatasetResourceInner call(DatasetResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + DatasetsInner client = this.manager().inner().datasets(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.datasetName, this.uproperties, this.uifMatch) + .map(new Func1() { + @Override + public DatasetResourceInner call(DatasetResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + DatasetsInner client = this.manager().inner().datasets(); + return client.getAsync(this.resourceGroupName, this.factoryName, this.datasetName); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + private void resetCreateUpdateParameters() { + this.cproperties = new DatasetInner(); + this.uproperties = new DatasetInner(); + } + + @Override + public String etag() { + return this.inner().etag(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public DatasetInner properties() { + return this.inner().properties(); + } + + @Override + public String type() { + return this.inner().type(); + } + + @Override + public DatasetResourceImpl withExistingFactory(String resourceGroupName, String factoryName) { + this.resourceGroupName = resourceGroupName; + this.factoryName = factoryName; + return this; + } + + @Override + public DatasetResourceImpl withIfMatch(String ifMatch) { + if (isInCreateMode()) { + this.cifMatch = ifMatch; + } else { + this.uifMatch = ifMatch; + } + return this; + } + + @Override + public DatasetResourceImpl withProperties(DatasetInner properties) { + if (isInCreateMode()) { + this.cproperties = properties; + } else { + this.uproperties = properties; + } + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetResourceInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetResourceInner.java new file mode 100644 index 000000000000..402ba6b8f90a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetResourceInner.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.SubResource; + +/** + * Dataset resource type. + */ +public class DatasetResourceInner extends SubResource { + /** + * Dataset properties. + */ + @JsonProperty(value = "properties", required = true) + private DatasetInner properties; + + /** + * The resource name. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The resource type. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * Etag identifies change in the resource. + */ + @JsonProperty(value = "etag", access = JsonProperty.Access.WRITE_ONLY) + private String etag; + + /** + * Get dataset properties. + * + * @return the properties value + */ + public DatasetInner properties() { + return this.properties; + } + + /** + * Set dataset properties. + * + * @param properties the properties value to set + * @return the DatasetResourceInner object itself. + */ + public DatasetResourceInner withProperties(DatasetInner properties) { + this.properties = properties; + return this; + } + + /** + * Get the resource name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the resource type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get etag identifies change in the resource. + * + * @return the etag value + */ + public String etag() { + return this.etag; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetsImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetsImpl.java new file mode 100644 index 000000000000..51621a9d2ffb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetsImpl.java @@ -0,0 +1,81 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Datasets; +import rx.Completable; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.DatasetResource; + +class DatasetsImpl extends WrapperImpl implements Datasets { + private final DataFactoryManager manager; + + DatasetsImpl(DataFactoryManager manager) { + super(manager.inner().datasets()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public DatasetResourceImpl define(String name) { + return wrapModel(name); + } + + private DatasetResourceImpl wrapModel(DatasetResourceInner inner) { + return new DatasetResourceImpl(inner, manager()); + } + + private DatasetResourceImpl wrapModel(String name) { + return new DatasetResourceImpl(name, this.manager()); + } + + @Override + public Observable listByFactoryAsync(final String resourceGroupName, final String factoryName) { + DatasetsInner client = this.inner(); + return client.listByFactoryAsync(resourceGroupName, factoryName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public DatasetResource call(DatasetResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Observable getAsync(String resourceGroupName, String factoryName, String datasetName) { + DatasetsInner client = this.inner(); + return client.getAsync(resourceGroupName, factoryName, datasetName) + .map(new Func1() { + @Override + public DatasetResource call(DatasetResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Completable deleteAsync(String resourceGroupName, String factoryName, String datasetName) { + DatasetsInner client = this.inner(); + return client.deleteAsync(resourceGroupName, factoryName, datasetName).toCompletable(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetsInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetsInner.java new file mode 100644 index 000000000000..1340ec8db3c3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/DatasetsInner.java @@ -0,0 +1,710 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in Datasets. + */ +public class DatasetsInner { + /** The Retrofit service to perform REST calls. */ + private DatasetsService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of DatasetsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public DatasetsInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(DatasetsService.class); + this.client = client; + } + + /** + * The interface defining all the services for Datasets to be + * used by Retrofit to perform actually REST calls. + */ + interface DatasetsService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Datasets listByFactory" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets") + Observable> listByFactory(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Datasets createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("datasetName") String datasetName, @Query("api-version") String apiVersion, @Header("If-Match") String ifMatch, @Header("accept-language") String acceptLanguage, @Body DatasetResourceInner dataset, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Datasets get" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}") + Observable> get(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("datasetName") String datasetName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Datasets delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/datasets/{datasetName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("datasetName") String datasetName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Datasets listByFactoryNext" }) + @GET + Observable> listByFactoryNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Lists datasets. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<DatasetResourceInner> object if successful. + */ + public PagedList listByFactory(final String resourceGroupName, final String factoryName) { + ServiceResponse> response = listByFactorySinglePageAsync(resourceGroupName, factoryName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists datasets. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryAsync(final String resourceGroupName, final String factoryName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactorySinglePageAsync(resourceGroupName, factoryName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists datasets. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<DatasetResourceInner> object + */ + public Observable> listByFactoryAsync(final String resourceGroupName, final String factoryName) { + return listByFactoryWithServiceResponseAsync(resourceGroupName, factoryName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists datasets. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<DatasetResourceInner> object + */ + public Observable>> listByFactoryWithServiceResponseAsync(final String resourceGroupName, final String factoryName) { + return listByFactorySinglePageAsync(resourceGroupName, factoryName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists datasets. + * + ServiceResponse> * @param resourceGroupName The resource group name. + ServiceResponse> * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<DatasetResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactorySinglePageAsync(final String resourceGroupName, final String factoryName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listByFactory(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the DatasetResourceInner object if successful. + */ + public DatasetResourceInner createOrUpdate(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, datasetName, properties).toBlocking().single().body(); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, datasetName, properties), serviceCallback); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the DatasetResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, datasetName, properties).map(new Func1, DatasetResourceInner>() { + @Override + public DatasetResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the DatasetResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (datasetName == null) { + throw new IllegalArgumentException("Parameter datasetName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + final String ifMatch = null; + DatasetResourceInner dataset = new DatasetResourceInner(); + dataset.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, datasetName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), dataset, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @param ifMatch ETag of the dataset entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the DatasetResourceInner object if successful. + */ + public DatasetResourceInner createOrUpdate(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, datasetName, properties, ifMatch).toBlocking().single().body(); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @param ifMatch ETag of the dataset entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties, String ifMatch, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, datasetName, properties, ifMatch), serviceCallback); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @param ifMatch ETag of the dataset entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the DatasetResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, datasetName, properties, ifMatch).map(new Func1, DatasetResourceInner>() { + @Override + public DatasetResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param properties Dataset properties. + * @param ifMatch ETag of the dataset entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the DatasetResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String datasetName, DatasetInner properties, String ifMatch) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (datasetName == null) { + throw new IllegalArgumentException("Parameter datasetName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + DatasetResourceInner dataset = new DatasetResourceInner(); + dataset.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, datasetName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), dataset, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse createOrUpdateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the DatasetResourceInner object if successful. + */ + public DatasetResourceInner get(String resourceGroupName, String factoryName, String datasetName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, datasetName).toBlocking().single().body(); + } + + /** + * Gets a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAsync(String resourceGroupName, String factoryName, String datasetName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, factoryName, datasetName), serviceCallback); + } + + /** + * Gets a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the DatasetResourceInner object + */ + public Observable getAsync(String resourceGroupName, String factoryName, String datasetName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, datasetName).map(new Func1, DatasetResourceInner>() { + @Override + public DatasetResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the DatasetResourceInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String factoryName, String datasetName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (datasetName == null) { + throw new IllegalArgumentException("Parameter datasetName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(this.client.subscriptionId(), resourceGroupName, factoryName, datasetName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Deletes a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String factoryName, String datasetName) { + deleteWithServiceResponseAsync(resourceGroupName, factoryName, datasetName).toBlocking().single().body(); + } + + /** + * Deletes a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String factoryName, String datasetName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, factoryName, datasetName), serviceCallback); + } + + /** + * Deletes a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String factoryName, String datasetName) { + return deleteWithServiceResponseAsync(resourceGroupName, factoryName, datasetName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a dataset. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param datasetName The dataset name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String factoryName, String datasetName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (datasetName == null) { + throw new IllegalArgumentException("Parameter datasetName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.delete(this.client.subscriptionId(), resourceGroupName, factoryName, datasetName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists datasets. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<DatasetResourceInner> object if successful. + */ + public PagedList listByFactoryNext(final String nextPageLink) { + ServiceResponse> response = listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists datasets. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactoryNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists datasets. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<DatasetResourceInner> object + */ + public Observable> listByFactoryNextAsync(final String nextPageLink) { + return listByFactoryNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists datasets. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<DatasetResourceInner> object + */ + public Observable>> listByFactoryNextWithServiceResponseAsync(final String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists datasets. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<DatasetResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactoryNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByFactoryNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoriesImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoriesImpl.java new file mode 100644 index 000000000000..8f52d6e57320 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoriesImpl.java @@ -0,0 +1,157 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * def + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.resources.collection.implementation.GroupableResourcesCoreImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factory; +import rx.Observable; +import rx.Completable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import com.microsoft.azure.arm.resources.ResourceUtilsCore; +import com.microsoft.azure.arm.utils.RXMapper; +import rx.functions.Func1; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryRepoUpdate; + +class FactoriesImpl extends GroupableResourcesCoreImpl implements Factories { + protected FactoriesImpl(DataFactoryManager manager) { + super(manager.inner().factories(), manager); + } + + @Override + protected Observable getInnerAsync(String resourceGroupName, String name) { + FactoriesInner client = this.inner(); + return client.getByResourceGroupAsync(resourceGroupName, name); + } + + @Override + protected Completable deleteInnerAsync(String resourceGroupName, String name) { + FactoriesInner client = this.inner(); + return client.deleteAsync(resourceGroupName, name).toCompletable(); + } + + @Override + public Observable deleteByIdsAsync(Collection ids) { + if (ids == null || ids.isEmpty()) { + return Observable.empty(); + } + Collection> observables = new ArrayList<>(); + for (String id : ids) { + final String resourceGroupName = ResourceUtilsCore.groupFromResourceId(id); + final String name = ResourceUtilsCore.nameFromResourceId(id); + Observable o = RXMapper.map(this.inner().deleteAsync(resourceGroupName, name), id); + observables.add(o); + } + return Observable.mergeDelayError(observables); + } + + @Override + public Observable deleteByIdsAsync(String...ids) { + return this.deleteByIdsAsync(new ArrayList(Arrays.asList(ids))); + } + + @Override + public void deleteByIds(Collection ids) { + if (ids != null && !ids.isEmpty()) { + this.deleteByIdsAsync(ids).toBlocking().last(); + } + } + + @Override + public void deleteByIds(String...ids) { + this.deleteByIds(new ArrayList(Arrays.asList(ids))); + } + + @Override + public PagedList listByResourceGroup(String resourceGroupName) { + FactoriesInner client = this.inner(); + return this.wrapList(client.listByResourceGroup(resourceGroupName)); + } + + @Override + public Observable listByResourceGroupAsync(String resourceGroupName) { + FactoriesInner client = this.inner(); + return client.listByResourceGroupAsync(resourceGroupName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public Factory call(FactoryInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public PagedList list() { + FactoriesInner client = this.inner(); + return this.wrapList(client.list()); + } + + @Override + public Observable listAsync() { + FactoriesInner client = this.inner(); + return client.listAsync() + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public Factory call(FactoryInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public FactoryImpl define(String name) { + return wrapModel(name); + } + + @Override + public Completable cancelPipelineRunAsync(String resourceGroupName, String factoryName, String runId) { + FactoriesInner client = this.inner(); + return client.cancelPipelineRunAsync(resourceGroupName, factoryName, runId).toCompletable(); + } + + @Override + protected FactoryImpl wrapModel(FactoryInner inner) { + return new FactoryImpl(inner.name(), inner, manager()); + } + + @Override + protected FactoryImpl wrapModel(String name) { + return new FactoryImpl(name, new FactoryInner(), this.manager()); + } + + @Override + public Observable configureFactoryRepoAsync(String locationId, FactoryRepoUpdate factoryRepoUpdate) { + FactoriesInner client = this.inner(); + return client.configureFactoryRepoAsync(locationId, factoryRepoUpdate) + .map(new Func1() { + @Override + public Factory call(FactoryInner inner) { + return new FactoryImpl(inner.name(), inner, manager()); + } + }); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoriesInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoriesInner.java new file mode 100644 index 000000000000..727b28f7aca1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoriesInner.java @@ -0,0 +1,1096 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.collection.InnerSupportsGet; +import com.microsoft.azure.arm.collection.InnerSupportsDelete; +import com.microsoft.azure.arm.collection.InnerSupportsListing; +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryRepoUpdate; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryUpdateParameters; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in Factories. + */ +public class FactoriesInner implements InnerSupportsGet, InnerSupportsDelete, InnerSupportsListing { + /** The Retrofit service to perform REST calls. */ + private FactoriesService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of FactoriesInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public FactoriesInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(FactoriesService.class); + this.client = client; + } + + /** + * The interface defining all the services for Factories to be + * used by Retrofit to perform actually REST calls. + */ + interface FactoriesService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories list" }) + @GET("subscriptions/{subscriptionId}/providers/Microsoft.DataFactory/factories") + Observable> list(@Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories configureFactoryRepo" }) + @POST("subscriptions/{subscriptionId}/providers/Microsoft.DataFactory/locations/{locationId}/configureFactoryRepo") + Observable> configureFactoryRepo(@Path("subscriptionId") String subscriptionId, @Path("locationId") String locationId, @Query("api-version") String apiVersion, @Body FactoryRepoUpdate factoryRepoUpdate, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories listByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories") + Observable> listByResourceGroup(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Body FactoryInner factory, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories update" }) + @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}") + Observable> update(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Body FactoryUpdateParameters factoryUpdateParameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories getByResourceGroup" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}") + Observable> getByResourceGroup(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories cancelPipelineRun" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/cancelpipelinerun/{runId}") + Observable> cancelPipelineRun(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("runId") String runId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories listNext" }) + @GET + Observable> listNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factories listByResourceGroupNext" }) + @GET + Observable> listByResourceGroupNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Lists factories under the specified subscription. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<FactoryInner> object if successful. + */ + public PagedList list() { + ServiceResponse> response = listSinglePageAsync().toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists factories under the specified subscription. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listAsync(final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listSinglePageAsync(), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists factories under the specified subscription. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable> listAsync() { + return listWithServiceResponseAsync() + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists factories under the specified subscription. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable>> listWithServiceResponseAsync() { + return listSinglePageAsync() + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists factories under the specified subscription. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<FactoryInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listSinglePageAsync() { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.list(this.client.subscriptionId(), this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Updates a factory's repo information. + * + * @param locationId The location identifier. + * @param factoryRepoUpdate Update factory repo request definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the FactoryInner object if successful. + */ + public FactoryInner configureFactoryRepo(String locationId, FactoryRepoUpdate factoryRepoUpdate) { + return configureFactoryRepoWithServiceResponseAsync(locationId, factoryRepoUpdate).toBlocking().single().body(); + } + + /** + * Updates a factory's repo information. + * + * @param locationId The location identifier. + * @param factoryRepoUpdate Update factory repo request definition. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture configureFactoryRepoAsync(String locationId, FactoryRepoUpdate factoryRepoUpdate, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(configureFactoryRepoWithServiceResponseAsync(locationId, factoryRepoUpdate), serviceCallback); + } + + /** + * Updates a factory's repo information. + * + * @param locationId The location identifier. + * @param factoryRepoUpdate Update factory repo request definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable configureFactoryRepoAsync(String locationId, FactoryRepoUpdate factoryRepoUpdate) { + return configureFactoryRepoWithServiceResponseAsync(locationId, factoryRepoUpdate).map(new Func1, FactoryInner>() { + @Override + public FactoryInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates a factory's repo information. + * + * @param locationId The location identifier. + * @param factoryRepoUpdate Update factory repo request definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable> configureFactoryRepoWithServiceResponseAsync(String locationId, FactoryRepoUpdate factoryRepoUpdate) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (locationId == null) { + throw new IllegalArgumentException("Parameter locationId is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (factoryRepoUpdate == null) { + throw new IllegalArgumentException("Parameter factoryRepoUpdate is required and cannot be null."); + } + Validator.validate(factoryRepoUpdate); + return service.configureFactoryRepo(this.client.subscriptionId(), locationId, this.client.apiVersion(), factoryRepoUpdate, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = configureFactoryRepoDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse configureFactoryRepoDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists factories. + * + * @param resourceGroupName The resource group name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<FactoryInner> object if successful. + */ + public PagedList listByResourceGroup(final String resourceGroupName) { + ServiceResponse> response = listByResourceGroupSinglePageAsync(resourceGroupName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists factories. + * + * @param resourceGroupName The resource group name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupAsync(final String resourceGroupName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupSinglePageAsync(resourceGroupName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists factories. + * + * @param resourceGroupName The resource group name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable> listByResourceGroupAsync(final String resourceGroupName) { + return listByResourceGroupWithServiceResponseAsync(resourceGroupName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists factories. + * + * @param resourceGroupName The resource group name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable>> listByResourceGroupWithServiceResponseAsync(final String resourceGroupName) { + return listByResourceGroupSinglePageAsync(resourceGroupName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists factories. + * + ServiceResponse> * @param resourceGroupName The resource group name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<FactoryInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupSinglePageAsync(final String resourceGroupName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listByResourceGroup(this.client.subscriptionId(), resourceGroupName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Creates or updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factory Factory resource definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the FactoryInner object if successful. + */ + public FactoryInner createOrUpdate(String resourceGroupName, String factoryName, FactoryInner factory) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, factory).toBlocking().single().body(); + } + + /** + * Creates or updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factory Factory resource definition. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, FactoryInner factory, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, factory), serviceCallback); + } + + /** + * Creates or updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factory Factory resource definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, FactoryInner factory) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, factory).map(new Func1, FactoryInner>() { + @Override + public FactoryInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factory Factory resource definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, FactoryInner factory) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (factory == null) { + throw new IllegalArgumentException("Parameter factory is required and cannot be null."); + } + Validator.validate(factory); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), factory, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse createOrUpdateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factoryUpdateParameters The parameters for updating a factory. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the FactoryInner object if successful. + */ + public FactoryInner update(String resourceGroupName, String factoryName, FactoryUpdateParameters factoryUpdateParameters) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, factoryUpdateParameters).toBlocking().single().body(); + } + + /** + * Updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factoryUpdateParameters The parameters for updating a factory. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateAsync(String resourceGroupName, String factoryName, FactoryUpdateParameters factoryUpdateParameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateWithServiceResponseAsync(resourceGroupName, factoryName, factoryUpdateParameters), serviceCallback); + } + + /** + * Updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factoryUpdateParameters The parameters for updating a factory. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable updateAsync(String resourceGroupName, String factoryName, FactoryUpdateParameters factoryUpdateParameters) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, factoryUpdateParameters).map(new Func1, FactoryInner>() { + @Override + public FactoryInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param factoryUpdateParameters The parameters for updating a factory. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable> updateWithServiceResponseAsync(String resourceGroupName, String factoryName, FactoryUpdateParameters factoryUpdateParameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (factoryUpdateParameters == null) { + throw new IllegalArgumentException("Parameter factoryUpdateParameters is required and cannot be null."); + } + Validator.validate(factoryUpdateParameters); + return service.update(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), factoryUpdateParameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse updateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the FactoryInner object if successful. + */ + public FactoryInner getByResourceGroup(String resourceGroupName, String factoryName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, factoryName).toBlocking().single().body(); + } + + /** + * Gets a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getByResourceGroupAsync(String resourceGroupName, String factoryName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getByResourceGroupWithServiceResponseAsync(resourceGroupName, factoryName), serviceCallback); + } + + /** + * Gets a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable getByResourceGroupAsync(String resourceGroupName, String factoryName) { + return getByResourceGroupWithServiceResponseAsync(resourceGroupName, factoryName).map(new Func1, FactoryInner>() { + @Override + public FactoryInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the FactoryInner object + */ + public Observable> getByResourceGroupWithServiceResponseAsync(String resourceGroupName, String factoryName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.getByResourceGroup(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getByResourceGroupDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getByResourceGroupDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Deletes a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String factoryName) { + deleteWithServiceResponseAsync(resourceGroupName, factoryName).toBlocking().single().body(); + } + + /** + * Deletes a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String factoryName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, factoryName), serviceCallback); + } + + /** + * Deletes a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String factoryName) { + return deleteWithServiceResponseAsync(resourceGroupName, factoryName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a factory. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String factoryName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.delete(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Cancel a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void cancelPipelineRun(String resourceGroupName, String factoryName, String runId) { + cancelPipelineRunWithServiceResponseAsync(resourceGroupName, factoryName, runId).toBlocking().single().body(); + } + + /** + * Cancel a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture cancelPipelineRunAsync(String resourceGroupName, String factoryName, String runId, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(cancelPipelineRunWithServiceResponseAsync(resourceGroupName, factoryName, runId), serviceCallback); + } + + /** + * Cancel a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable cancelPipelineRunAsync(String resourceGroupName, String factoryName, String runId) { + return cancelPipelineRunWithServiceResponseAsync(resourceGroupName, factoryName, runId).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Cancel a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> cancelPipelineRunWithServiceResponseAsync(String resourceGroupName, String factoryName, String runId) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (runId == null) { + throw new IllegalArgumentException("Parameter runId is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.cancelPipelineRun(this.client.subscriptionId(), resourceGroupName, factoryName, runId, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = cancelPipelineRunDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse cancelPipelineRunDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists factories under the specified subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<FactoryInner> object if successful. + */ + public PagedList listNext(final String nextPageLink) { + ServiceResponse> response = listNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists factories under the specified subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists factories under the specified subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable> listNextAsync(final String nextPageLink) { + return listNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists factories under the specified subscription. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable>> listNextWithServiceResponseAsync(final String nextPageLink) { + return listNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists factories under the specified subscription. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<FactoryInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists factories. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<FactoryInner> object if successful. + */ + public PagedList listByResourceGroupNext(final String nextPageLink) { + ServiceResponse> response = listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists factories. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByResourceGroupNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByResourceGroupNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists factories. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable> listByResourceGroupNextAsync(final String nextPageLink) { + return listByResourceGroupNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists factories. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<FactoryInner> object + */ + public Observable>> listByResourceGroupNextWithServiceResponseAsync(final String nextPageLink) { + return listByResourceGroupNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByResourceGroupNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists factories. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<FactoryInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByResourceGroupNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByResourceGroupNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByResourceGroupNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByResourceGroupNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoryImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoryImpl.java new file mode 100644 index 000000000000..cea072ecf271 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoryImpl.java @@ -0,0 +1,123 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.resources.models.implementation.GroupableResourceCoreImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Factory; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryUpdateParameters; +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryIdentity; +import org.joda.time.DateTime; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryVSTSConfiguration; +import rx.functions.Func1; + +class FactoryImpl extends GroupableResourceCoreImpl implements Factory, Factory.Definition, Factory.Update { + private FactoryUpdateParameters updateParameter; + FactoryImpl(String name, FactoryInner inner, DataFactoryManager manager) { + super(name, inner, manager); + this.updateParameter = new FactoryUpdateParameters(); + } + + @Override + public Observable createResourceAsync() { + FactoriesInner client = this.manager().inner().factories(); + return client.createOrUpdateAsync(this.resourceGroupName(), this.name(), this.inner()) + .map(new Func1() { + @Override + public FactoryInner call(FactoryInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + FactoriesInner client = this.manager().inner().factories(); + return client.updateAsync(this.resourceGroupName(), this.name(), this.updateParameter) + .map(new Func1() { + @Override + public FactoryInner call(FactoryInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + FactoriesInner client = this.manager().inner().factories(); + return client.getByResourceGroupAsync(this.resourceGroupName(), this.name()); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + private void resetCreateUpdateParameters() { + this.updateParameter = new FactoryUpdateParameters(); + } + + @Override + public Map additionalProperties() { + return this.inner().additionalProperties(); + } + + @Override + public DateTime createTime() { + return this.inner().createTime(); + } + + @Override + public FactoryIdentity identity() { + return this.inner().identity(); + } + + @Override + public String provisioningState() { + return this.inner().provisioningState(); + } + + @Override + public String version() { + return this.inner().version(); + } + + @Override + public FactoryVSTSConfiguration vstsConfiguration() { + return this.inner().vstsConfiguration(); + } + + @Override + public FactoryImpl withAdditionalProperties(Map additionalProperties) { + this.inner().withAdditionalProperties(additionalProperties); + return this; + } + + @Override + public FactoryImpl withVstsConfiguration(FactoryVSTSConfiguration vstsConfiguration) { + this.inner().withVstsConfiguration(vstsConfiguration); + return this; + } + + @Override + public FactoryImpl withIdentity(FactoryIdentity identity) { + if (isInCreateMode()) { + this.inner().withIdentity(identity); + } else { + this.updateParameter.withIdentity(identity); + } + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoryInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoryInner.java new file mode 100644 index 000000000000..2dbf4265e561 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/FactoryInner.java @@ -0,0 +1,149 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryIdentity; +import org.joda.time.DateTime; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.FactoryVSTSConfiguration; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.rest.SkipParentValidation; +import com.microsoft.azure.Resource; + +/** + * Factory resource type. + */ +@JsonFlatten +@SkipParentValidation +public class FactoryInner extends Resource { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Managed service identity of the factory. + */ + @JsonProperty(value = "identity") + private FactoryIdentity identity; + + /** + * Factory provisioning state, example Succeeded. + */ + @JsonProperty(value = "properties.provisioningState", access = JsonProperty.Access.WRITE_ONLY) + private String provisioningState; + + /** + * Time the factory was created in ISO8601 format. + */ + @JsonProperty(value = "properties.createTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime createTime; + + /** + * Version of the factory. + */ + @JsonProperty(value = "properties.version", access = JsonProperty.Access.WRITE_ONLY) + private String version; + + /** + * VSTS repo information of the factory. + */ + @JsonProperty(value = "properties.vstsConfiguration") + private FactoryVSTSConfiguration vstsConfiguration; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the FactoryInner object itself. + */ + public FactoryInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get managed service identity of the factory. + * + * @return the identity value + */ + public FactoryIdentity identity() { + return this.identity; + } + + /** + * Set managed service identity of the factory. + * + * @param identity the identity value to set + * @return the FactoryInner object itself. + */ + public FactoryInner withIdentity(FactoryIdentity identity) { + this.identity = identity; + return this; + } + + /** + * Get factory provisioning state, example Succeeded. + * + * @return the provisioningState value + */ + public String provisioningState() { + return this.provisioningState; + } + + /** + * Get time the factory was created in ISO8601 format. + * + * @return the createTime value + */ + public DateTime createTime() { + return this.createTime; + } + + /** + * Get version of the factory. + * + * @return the version value + */ + public String version() { + return this.version; + } + + /** + * Get vSTS repo information of the factory. + * + * @return the vstsConfiguration value + */ + public FactoryVSTSConfiguration vstsConfiguration() { + return this.vstsConfiguration; + } + + /** + * Set vSTS repo information of the factory. + * + * @param vstsConfiguration the vstsConfiguration value to set + * @return the FactoryInner object itself. + */ + public FactoryInner withVstsConfiguration(FactoryVSTSConfiguration vstsConfiguration) { + this.vstsConfiguration = vstsConfiguration; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IdParsingUtils.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IdParsingUtils.java new file mode 100644 index 000000000000..c976373fb576 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IdParsingUtils.java @@ -0,0 +1,57 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; +import java.util.Arrays; +import java.util.Iterator; + +class IdParsingUtils { + public static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterable iterable = Arrays.asList(id.split("/")); + Iterator itr = iterable.iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && part.trim() != "") { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + public static String getValueFromIdByPosition(String id, int pos) { + if (id == null) { + return null; + } + Iterable iterable = Arrays.asList(id.split("/")); + Iterator itr = iterable.iterator(); + int index = 0; + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && part.trim() != "") { + if (index == pos) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + index++; + } + return null; + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeAuthKeysImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeAuthKeysImpl.java new file mode 100644 index 000000000000..412d4c2f31de --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeAuthKeysImpl.java @@ -0,0 +1,36 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeAuthKeys; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; + +class IntegrationRuntimeAuthKeysImpl extends WrapperImpl implements IntegrationRuntimeAuthKeys { + private final DataFactoryManager manager; + IntegrationRuntimeAuthKeysImpl(IntegrationRuntimeAuthKeysInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public String authKey1() { + return this.inner().authKey1(); + } + + @Override + public String authKey2() { + return this.inner().authKey2(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeAuthKeysInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeAuthKeysInner.java new file mode 100644 index 000000000000..866d0378a259 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeAuthKeysInner.java @@ -0,0 +1,69 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The integration runtime authentication keys. + */ +public class IntegrationRuntimeAuthKeysInner { + /** + * The primary integration runtime authentication key. + */ + @JsonProperty(value = "authKey1") + private String authKey1; + + /** + * The secondary integration runtime authentication key. + */ + @JsonProperty(value = "authKey2") + private String authKey2; + + /** + * Get the primary integration runtime authentication key. + * + * @return the authKey1 value + */ + public String authKey1() { + return this.authKey1; + } + + /** + * Set the primary integration runtime authentication key. + * + * @param authKey1 the authKey1 value to set + * @return the IntegrationRuntimeAuthKeysInner object itself. + */ + public IntegrationRuntimeAuthKeysInner withAuthKey1(String authKey1) { + this.authKey1 = authKey1; + return this; + } + + /** + * Get the secondary integration runtime authentication key. + * + * @return the authKey2 value + */ + public String authKey2() { + return this.authKey2; + } + + /** + * Set the secondary integration runtime authentication key. + * + * @param authKey2 the authKey2 value to set + * @return the IntegrationRuntimeAuthKeysInner object itself. + */ + public IntegrationRuntimeAuthKeysInner withAuthKey2(String authKey2) { + this.authKey2 = authKey2; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeConnectionInfoImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeConnectionInfoImpl.java new file mode 100644 index 000000000000..4ee76a336dc3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeConnectionInfoImpl.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeConnectionInfo; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.Map; + +class IntegrationRuntimeConnectionInfoImpl extends WrapperImpl implements IntegrationRuntimeConnectionInfo { + private final DataFactoryManager manager; + IntegrationRuntimeConnectionInfoImpl(IntegrationRuntimeConnectionInfoInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Map additionalProperties() { + return this.inner().additionalProperties(); + } + + @Override + public String hostServiceUri() { + return this.inner().hostServiceUri(); + } + + @Override + public String identityCertThumbprint() { + return this.inner().identityCertThumbprint(); + } + + @Override + public Boolean isIdentityCertExprired() { + return this.inner().isIdentityCertExprired(); + } + + @Override + public String publicKey() { + return this.inner().publicKey(); + } + + @Override + public String serviceToken() { + return this.inner().serviceToken(); + } + + @Override + public String version() { + return this.inner().version(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeConnectionInfoInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeConnectionInfoInner.java new file mode 100644 index 000000000000..3417401938be --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeConnectionInfoInner.java @@ -0,0 +1,138 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Connection information for encrypting the on-premises data source + * credentials. + */ +public class IntegrationRuntimeConnectionInfoInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The token generated in service. Callers use this token to authenticate + * to integration runtime. + */ + @JsonProperty(value = "serviceToken", access = JsonProperty.Access.WRITE_ONLY) + private String serviceToken; + + /** + * The integration runtime SSL certificate thumbprint. Click-Once + * application uses it to do server validation. + */ + @JsonProperty(value = "identityCertThumbprint", access = JsonProperty.Access.WRITE_ONLY) + private String identityCertThumbprint; + + /** + * The on-premises integration runtime host URL. + */ + @JsonProperty(value = "hostServiceUri", access = JsonProperty.Access.WRITE_ONLY) + private String hostServiceUri; + + /** + * The integration runtime version. + */ + @JsonProperty(value = "version", access = JsonProperty.Access.WRITE_ONLY) + private String version; + + /** + * The public key for encrypting a credential when transferring the + * credential to the integration runtime. + */ + @JsonProperty(value = "publicKey", access = JsonProperty.Access.WRITE_ONLY) + private String publicKey; + + /** + * Whether the identity certificate is expired. + */ + @JsonProperty(value = "isIdentityCertExprired", access = JsonProperty.Access.WRITE_ONLY) + private Boolean isIdentityCertExprired; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeConnectionInfoInner object itself. + */ + public IntegrationRuntimeConnectionInfoInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the token generated in service. Callers use this token to authenticate to integration runtime. + * + * @return the serviceToken value + */ + public String serviceToken() { + return this.serviceToken; + } + + /** + * Get the integration runtime SSL certificate thumbprint. Click-Once application uses it to do server validation. + * + * @return the identityCertThumbprint value + */ + public String identityCertThumbprint() { + return this.identityCertThumbprint; + } + + /** + * Get the on-premises integration runtime host URL. + * + * @return the hostServiceUri value + */ + public String hostServiceUri() { + return this.hostServiceUri; + } + + /** + * Get the integration runtime version. + * + * @return the version value + */ + public String version() { + return this.version; + } + + /** + * Get the public key for encrypting a credential when transferring the credential to the integration runtime. + * + * @return the publicKey value + */ + public String publicKey() { + return this.publicKey; + } + + /** + * Get whether the identity certificate is expired. + * + * @return the isIdentityCertExprired value + */ + public Boolean isIdentityCertExprired() { + return this.isIdentityCertExprired; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeInner.java new file mode 100644 index 000000000000..ede23e441b2d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeInner.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Azure Data Factory nested object which serves as a compute resource for + * activities. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("IntegrationRuntime") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "SelfHosted", value = SelfHostedIntegrationRuntime.class), + @JsonSubTypes.Type(name = "Managed", value = ManagedIntegrationRuntime.class) +}) +public class IntegrationRuntimeInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Integration runtime description. + */ + @JsonProperty(value = "description") + private String description; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the IntegrationRuntimeInner object itself. + */ + public IntegrationRuntimeInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get integration runtime description. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Set integration runtime description. + * + * @param description the description value to set + * @return the IntegrationRuntimeInner object itself. + */ + public IntegrationRuntimeInner withDescription(String description) { + this.description = description; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeMonitoringDataImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeMonitoringDataImpl.java new file mode 100644 index 000000000000..4f17d3f53e2f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeMonitoringDataImpl.java @@ -0,0 +1,38 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeMonitoringData; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodeMonitoringData; + +class IntegrationRuntimeMonitoringDataImpl extends WrapperImpl implements IntegrationRuntimeMonitoringData { + private final DataFactoryManager manager; + IntegrationRuntimeMonitoringDataImpl(IntegrationRuntimeMonitoringDataInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public List nodes() { + return this.inner().nodes(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeMonitoringDataInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeMonitoringDataInner.java new file mode 100644 index 000000000000..6863072a5326 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeMonitoringDataInner.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodeMonitoringData; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Get monitoring data response. + */ +public class IntegrationRuntimeMonitoringDataInner { + /** + * Integration runtime name. + */ + @JsonProperty(value = "name") + private String name; + + /** + * Integration runtime node monitoring data. + */ + @JsonProperty(value = "nodes") + private List nodes; + + /** + * Get integration runtime name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set integration runtime name. + * + * @param name the name value to set + * @return the IntegrationRuntimeMonitoringDataInner object itself. + */ + public IntegrationRuntimeMonitoringDataInner withName(String name) { + this.name = name; + return this; + } + + /** + * Get integration runtime node monitoring data. + * + * @return the nodes value + */ + public List nodes() { + return this.nodes; + } + + /** + * Set integration runtime node monitoring data. + * + * @param nodes the nodes value to set + * @return the IntegrationRuntimeMonitoringDataInner object itself. + */ + public IntegrationRuntimeMonitoringDataInner withNodes(List nodes) { + this.nodes = nodes; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodeIpAddressImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodeIpAddressImpl.java new file mode 100644 index 000000000000..da2f23bece3d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodeIpAddressImpl.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodeIpAddress; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; + +class IntegrationRuntimeNodeIpAddressImpl extends WrapperImpl implements IntegrationRuntimeNodeIpAddress { + private final DataFactoryManager manager; + IntegrationRuntimeNodeIpAddressImpl(IntegrationRuntimeNodeIpAddressInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public String ipAddress() { + return this.inner().ipAddress(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodeIpAddressInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodeIpAddressInner.java new file mode 100644 index 000000000000..de2e8de6ad77 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodeIpAddressInner.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The IP address of self-hosted integration runtime node. + */ +public class IntegrationRuntimeNodeIpAddressInner { + /** + * The IP address of self-hosted integration runtime node. + */ + @JsonProperty(value = "ipAddress", access = JsonProperty.Access.WRITE_ONLY) + private String ipAddress; + + /** + * Get the IP address of self-hosted integration runtime node. + * + * @return the ipAddress value + */ + public String ipAddress() { + return this.ipAddress; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodesImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodesImpl.java new file mode 100644 index 000000000000..b52bd644c1cb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodesImpl.java @@ -0,0 +1,55 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * abc + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodes; +import rx.functions.Func1; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.SelfHostedIntegrationRuntimeNode; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodeIpAddress; + +class IntegrationRuntimeNodesImpl extends WrapperImpl implements IntegrationRuntimeNodes { + private final DataFactoryManager manager; + + IntegrationRuntimeNodesImpl(DataFactoryManager manager) { + super(manager.inner().integrationRuntimeNodes()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Observable updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + IntegrationRuntimeNodesInner client = this.inner(); + return client.updateAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName) + .map(new Func1() { + @Override + public SelfHostedIntegrationRuntimeNode call(SelfHostedIntegrationRuntimeNodeInner inner) { + return new SelfHostedIntegrationRuntimeNodeImpl(inner, manager()); + } + }); + } + + @Override + public Observable getIpAddressAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + IntegrationRuntimeNodesInner client = this.inner(); + return client.getIpAddressAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName) + .map(new Func1() { + @Override + public IntegrationRuntimeNodeIpAddress call(IntegrationRuntimeNodeIpAddressInner inner) { + return new IntegrationRuntimeNodeIpAddressImpl(inner, manager()); + } + }); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodesInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodesInner.java new file mode 100644 index 000000000000..fd8358de228f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeNodesInner.java @@ -0,0 +1,474 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.UpdateIntegrationRuntimeNodeRequest; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import java.io.IOException; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.Query; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in IntegrationRuntimeNodes. + */ +public class IntegrationRuntimeNodesInner { + /** The Retrofit service to perform REST calls. */ + private IntegrationRuntimeNodesService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of IntegrationRuntimeNodesInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public IntegrationRuntimeNodesInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(IntegrationRuntimeNodesService.class); + this.client = client; + } + + /** + * The interface defining all the services for IntegrationRuntimeNodes to be + * used by Retrofit to perform actually REST calls. + */ + interface IntegrationRuntimeNodesService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodes delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/nodes/{nodeName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Path("nodeName") String nodeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodes update" }) + @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/nodes/{nodeName}") + Observable> update(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Path("nodeName") String nodeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body UpdateIntegrationRuntimeNodeRequest updateIntegrationRuntimeNodeRequest, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeNodes getIpAddress" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/nodes/{nodeName}/ipAddress") + Observable> getIpAddress(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Path("nodeName") String nodeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Deletes a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + deleteWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName).toBlocking().single().body(); + } + + /** + * Deletes a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName), serviceCallback); + } + + /** + * Deletes a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + return deleteWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (nodeName == null) { + throw new IllegalArgumentException("Parameter nodeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.delete(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, nodeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the SelfHostedIntegrationRuntimeNodeInner object if successful. + */ + public SelfHostedIntegrationRuntimeNodeInner update(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName).toBlocking().single().body(); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName), serviceCallback); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the SelfHostedIntegrationRuntimeNodeInner object + */ + public Observable updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName).map(new Func1, SelfHostedIntegrationRuntimeNodeInner>() { + @Override + public SelfHostedIntegrationRuntimeNodeInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the SelfHostedIntegrationRuntimeNodeInner object + */ + public Observable> updateWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (nodeName == null) { + throw new IllegalArgumentException("Parameter nodeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final Integer concurrentJobsLimit = null; + UpdateIntegrationRuntimeNodeRequest updateIntegrationRuntimeNodeRequest = new UpdateIntegrationRuntimeNodeRequest(); + updateIntegrationRuntimeNodeRequest.withConcurrentJobsLimit(null); + return service.update(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, nodeName, this.client.apiVersion(), this.client.acceptLanguage(), updateIntegrationRuntimeNodeRequest, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @param concurrentJobsLimit The number of concurrent jobs permitted to run on the integration runtime node. Values between 1 and maxConcurrentJobs(inclusive) are allowed. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the SelfHostedIntegrationRuntimeNodeInner object if successful. + */ + public SelfHostedIntegrationRuntimeNodeInner update(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName, Integer concurrentJobsLimit) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName, concurrentJobsLimit).toBlocking().single().body(); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @param concurrentJobsLimit The number of concurrent jobs permitted to run on the integration runtime node. Values between 1 and maxConcurrentJobs(inclusive) are allowed. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName, Integer concurrentJobsLimit, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName, concurrentJobsLimit), serviceCallback); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @param concurrentJobsLimit The number of concurrent jobs permitted to run on the integration runtime node. Values between 1 and maxConcurrentJobs(inclusive) are allowed. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the SelfHostedIntegrationRuntimeNodeInner object + */ + public Observable updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName, Integer concurrentJobsLimit) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName, concurrentJobsLimit).map(new Func1, SelfHostedIntegrationRuntimeNodeInner>() { + @Override + public SelfHostedIntegrationRuntimeNodeInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates a self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @param concurrentJobsLimit The number of concurrent jobs permitted to run on the integration runtime node. Values between 1 and maxConcurrentJobs(inclusive) are allowed. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the SelfHostedIntegrationRuntimeNodeInner object + */ + public Observable> updateWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName, Integer concurrentJobsLimit) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (nodeName == null) { + throw new IllegalArgumentException("Parameter nodeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + UpdateIntegrationRuntimeNodeRequest updateIntegrationRuntimeNodeRequest = new UpdateIntegrationRuntimeNodeRequest(); + updateIntegrationRuntimeNodeRequest.withConcurrentJobsLimit(concurrentJobsLimit); + return service.update(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, nodeName, this.client.apiVersion(), this.client.acceptLanguage(), updateIntegrationRuntimeNodeRequest, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse updateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Get the IP address of self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeNodeIpAddressInner object if successful. + */ + public IntegrationRuntimeNodeIpAddressInner getIpAddress(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + return getIpAddressWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName).toBlocking().single().body(); + } + + /** + * Get the IP address of self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getIpAddressAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getIpAddressWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName), serviceCallback); + } + + /** + * Get the IP address of self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeNodeIpAddressInner object + */ + public Observable getIpAddressAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + return getIpAddressWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, nodeName).map(new Func1, IntegrationRuntimeNodeIpAddressInner>() { + @Override + public IntegrationRuntimeNodeIpAddressInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Get the IP address of self-hosted integration runtime node. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param nodeName The integration runtime node name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeNodeIpAddressInner object + */ + public Observable> getIpAddressWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, String nodeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (nodeName == null) { + throw new IllegalArgumentException("Parameter nodeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.getIpAddress(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, nodeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getIpAddressDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getIpAddressDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeResourceImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeResourceImpl.java new file mode 100644 index 000000000000..887a8aeaac2a --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeResourceImpl.java @@ -0,0 +1,158 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeResource; +import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.UpdateIntegrationRuntimeRequest; +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeAutoUpdate; +import rx.functions.Func1; + +class IntegrationRuntimeResourceImpl extends CreatableUpdatableImpl implements IntegrationRuntimeResource, IntegrationRuntimeResource.Definition, IntegrationRuntimeResource.Update { + private final DataFactoryManager manager; + private String resourceGroupName; + private String factoryName; + private String integrationRuntimeName; + private String cifMatch; + private IntegrationRuntimeInner cproperties; + private UpdateIntegrationRuntimeRequest updateParameter; + + IntegrationRuntimeResourceImpl(String name, DataFactoryManager manager) { + super(name, new IntegrationRuntimeResourceInner()); + this.manager = manager; + // Set resource name + this.integrationRuntimeName = name; + // + this.cproperties = new IntegrationRuntimeInner(); + this.updateParameter = new UpdateIntegrationRuntimeRequest(); + } + + IntegrationRuntimeResourceImpl(IntegrationRuntimeResourceInner inner, DataFactoryManager manager) { + super(inner.name(), inner); + this.manager = manager; + // Set resource name + this.integrationRuntimeName = inner.name(); + // set resource ancestor and positional variables + this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups"); + this.factoryName = IdParsingUtils.getValueFromIdByName(inner.id(), "factories"); + this.integrationRuntimeName = IdParsingUtils.getValueFromIdByName(inner.id(), "integrationRuntimes"); + // + this.cproperties = new IntegrationRuntimeInner(); + this.updateParameter = new UpdateIntegrationRuntimeRequest(); + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Observable createResourceAsync() { + IntegrationRuntimesInner client = this.manager().inner().integrationRuntimes(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.integrationRuntimeName, this.cproperties, this.cifMatch) + .map(new Func1() { + @Override + public IntegrationRuntimeResourceInner call(IntegrationRuntimeResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + IntegrationRuntimesInner client = this.manager().inner().integrationRuntimes(); + return client.updateAsync(this.resourceGroupName, this.factoryName, this.integrationRuntimeName, this.updateParameter) + .map(new Func1() { + @Override + public IntegrationRuntimeResourceInner call(IntegrationRuntimeResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + IntegrationRuntimesInner client = this.manager().inner().integrationRuntimes(); + return client.getAsync(this.resourceGroupName, this.factoryName, this.integrationRuntimeName); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + private void resetCreateUpdateParameters() { + this.cproperties = new IntegrationRuntimeInner(); + this.updateParameter = new UpdateIntegrationRuntimeRequest(); + } + + @Override + public String etag() { + return this.inner().etag(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public IntegrationRuntimeInner properties() { + return this.inner().properties(); + } + + @Override + public String type() { + return this.inner().type(); + } + + @Override + public IntegrationRuntimeResourceImpl withExistingFactory(String resourceGroupName, String factoryName) { + this.resourceGroupName = resourceGroupName; + this.factoryName = factoryName; + return this; + } + + @Override + public IntegrationRuntimeResourceImpl withIfMatch(String ifMatch) { + this.cifMatch = ifMatch; + return this; + } + + @Override + public IntegrationRuntimeResourceImpl withProperties(IntegrationRuntimeInner properties) { + this.cproperties = properties; + return this; + } + + @Override + public IntegrationRuntimeResourceImpl withAutoUpdate(IntegrationRuntimeAutoUpdate autoUpdate) { + this.updateParameter.withAutoUpdate(autoUpdate); + return this; + } + + @Override + public IntegrationRuntimeResourceImpl withUpdateDelayOffset(String updateDelayOffset) { + this.updateParameter.withUpdateDelayOffset(updateDelayOffset); + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeResourceInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeResourceInner.java new file mode 100644 index 000000000000..f9cc2909bcd0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeResourceInner.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.SubResource; + +/** + * Integration runtime resource type. + */ +public class IntegrationRuntimeResourceInner extends SubResource { + /** + * Integration runtime properties. + */ + @JsonProperty(value = "properties", required = true) + private IntegrationRuntimeInner properties; + + /** + * The resource name. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The resource type. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * Etag identifies change in the resource. + */ + @JsonProperty(value = "etag", access = JsonProperty.Access.WRITE_ONLY) + private String etag; + + /** + * Get integration runtime properties. + * + * @return the properties value + */ + public IntegrationRuntimeInner properties() { + return this.properties; + } + + /** + * Set integration runtime properties. + * + * @param properties the properties value to set + * @return the IntegrationRuntimeResourceInner object itself. + */ + public IntegrationRuntimeResourceInner withProperties(IntegrationRuntimeInner properties) { + this.properties = properties; + return this; + } + + /** + * Get the resource name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the resource type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get etag identifies change in the resource. + * + * @return the etag value + */ + public String etag() { + return this.etag; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeStatusResponseImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeStatusResponseImpl.java new file mode 100644 index 000000000000..6568bea32034 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeStatusResponseImpl.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeStatusResponse; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeStatus; + +class IntegrationRuntimeStatusResponseImpl extends WrapperImpl implements IntegrationRuntimeStatusResponse { + private final DataFactoryManager manager; + IntegrationRuntimeStatusResponseImpl(IntegrationRuntimeStatusResponseInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public IntegrationRuntimeStatus properties() { + return this.inner().properties(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeStatusResponseInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeStatusResponseInner.java new file mode 100644 index 000000000000..496c2aba8595 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimeStatusResponseInner.java @@ -0,0 +1,59 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeStatus; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Integration runtime status response. + */ +public class IntegrationRuntimeStatusResponseInner { + /** + * The integration runtime name. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * Integration runtime properties. + */ + @JsonProperty(value = "properties", required = true) + private IntegrationRuntimeStatus properties; + + /** + * Get the integration runtime name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get integration runtime properties. + * + * @return the properties value + */ + public IntegrationRuntimeStatus properties() { + return this.properties; + } + + /** + * Set integration runtime properties. + * + * @param properties the properties value to set + * @return the IntegrationRuntimeStatusResponseInner object itself. + */ + public IntegrationRuntimeStatusResponseInner withProperties(IntegrationRuntimeStatus properties) { + this.properties = properties; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimesImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimesImpl.java new file mode 100644 index 000000000000..ca3b1d6869bd --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimesImpl.java @@ -0,0 +1,182 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes; +import rx.Completable; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeStatusResponse; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeConnectionInfo; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeAuthKeys; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeMonitoringData; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeRemoveNodeRequest; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeResource; + +class IntegrationRuntimesImpl extends WrapperImpl implements IntegrationRuntimes { + private final DataFactoryManager manager; + + IntegrationRuntimesImpl(DataFactoryManager manager) { + super(manager.inner().integrationRuntimes()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public IntegrationRuntimeResourceImpl define(String name) { + return wrapModel(name); + } + + private IntegrationRuntimeResourceImpl wrapModel(IntegrationRuntimeResourceInner inner) { + return new IntegrationRuntimeResourceImpl(inner, manager()); + } + + private IntegrationRuntimeResourceImpl wrapModel(String name) { + return new IntegrationRuntimeResourceImpl(name, this.manager()); + } + + @Override + public Observable getStatusAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.getStatusAsync(resourceGroupName, factoryName, integrationRuntimeName) + .map(new Func1() { + @Override + public IntegrationRuntimeStatusResponse call(IntegrationRuntimeStatusResponseInner inner) { + return new IntegrationRuntimeStatusResponseImpl(inner, manager()); + } + }); + } + + @Override + public Observable getConnectionInfoAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.getConnectionInfoAsync(resourceGroupName, factoryName, integrationRuntimeName) + .map(new Func1() { + @Override + public IntegrationRuntimeConnectionInfo call(IntegrationRuntimeConnectionInfoInner inner) { + return new IntegrationRuntimeConnectionInfoImpl(inner, manager()); + } + }); + } + + @Override + public Observable regenerateAuthKeyAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.regenerateAuthKeyAsync(resourceGroupName, factoryName, integrationRuntimeName) + .map(new Func1() { + @Override + public IntegrationRuntimeAuthKeys call(IntegrationRuntimeAuthKeysInner inner) { + return new IntegrationRuntimeAuthKeysImpl(inner, manager()); + } + }); + } + + @Override + public Observable listAuthKeysAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.listAuthKeysAsync(resourceGroupName, factoryName, integrationRuntimeName) + .map(new Func1() { + @Override + public IntegrationRuntimeAuthKeys call(IntegrationRuntimeAuthKeysInner inner) { + return new IntegrationRuntimeAuthKeysImpl(inner, manager()); + } + }); + } + + @Override + public Observable startAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.startAsync(resourceGroupName, factoryName, integrationRuntimeName) + .map(new Func1() { + @Override + public IntegrationRuntimeStatusResponse call(IntegrationRuntimeStatusResponseInner inner) { + return new IntegrationRuntimeStatusResponseImpl(inner, manager()); + } + }); + } + + @Override + public Completable stopAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.stopAsync(resourceGroupName, factoryName, integrationRuntimeName).toCompletable(); + } + + @Override + public Completable removeNodeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeRemoveNodeRequest removeNodeParameters) { + IntegrationRuntimesInner client = this.inner(); + return client.removeNodeAsync(resourceGroupName, factoryName, integrationRuntimeName, removeNodeParameters).toCompletable(); + } + + @Override + public Completable syncCredentialsAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.syncCredentialsAsync(resourceGroupName, factoryName, integrationRuntimeName).toCompletable(); + } + + @Override + public Observable getMonitoringDataAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.getMonitoringDataAsync(resourceGroupName, factoryName, integrationRuntimeName) + .map(new Func1() { + @Override + public IntegrationRuntimeMonitoringData call(IntegrationRuntimeMonitoringDataInner inner) { + return new IntegrationRuntimeMonitoringDataImpl(inner, manager()); + } + }); + } + + @Override + public Completable upgradeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.upgradeAsync(resourceGroupName, factoryName, integrationRuntimeName).toCompletable(); + } + + @Override + public Observable listByFactoryAsync(final String resourceGroupName, final String factoryName) { + IntegrationRuntimesInner client = this.inner(); + return client.listByFactoryAsync(resourceGroupName, factoryName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public IntegrationRuntimeResource call(IntegrationRuntimeResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Observable getAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.getAsync(resourceGroupName, factoryName, integrationRuntimeName) + .map(new Func1() { + @Override + public IntegrationRuntimeResource call(IntegrationRuntimeResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Completable deleteAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + IntegrationRuntimesInner client = this.inner(); + return client.deleteAsync(resourceGroupName, factoryName, integrationRuntimeName).toCompletable(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimesInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimesInner.java new file mode 100644 index 000000000000..59a421b48b84 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/IntegrationRuntimesInner.java @@ -0,0 +1,2052 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeAuthKeyName; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeRegenerateKeyParameters; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeRemoveNodeRequest; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.UpdateIntegrationRuntimeRequest; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.PATCH; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in IntegrationRuntimes. + */ +public class IntegrationRuntimesInner { + /** The Retrofit service to perform REST calls. */ + private IntegrationRuntimesService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of IntegrationRuntimesInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public IntegrationRuntimesInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(IntegrationRuntimesService.class); + this.client = client; + } + + /** + * The interface defining all the services for IntegrationRuntimes to be + * used by Retrofit to perform actually REST calls. + */ + interface IntegrationRuntimesService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes listByFactory" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes") + Observable> listByFactory(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("If-Match") String ifMatch, @Header("accept-language") String acceptLanguage, @Body IntegrationRuntimeResourceInner integrationRuntime, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes get" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}") + Observable> get(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes update" }) + @PATCH("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}") + Observable> update(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Body UpdateIntegrationRuntimeRequest updateIntegrationRuntimeRequest, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes getStatus" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/getStatus") + Observable> getStatus(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes getConnectionInfo" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/getConnectionInfo") + Observable> getConnectionInfo(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes regenerateAuthKey" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/regenerateAuthKey") + Observable> regenerateAuthKey(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Body IntegrationRuntimeRegenerateKeyParameters regenerateKeyParameters, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes listAuthKeys" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/listAuthKeys") + Observable> listAuthKeys(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes start" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/start") + Observable> start(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes beginStart" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/start") + Observable> beginStart(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes stop" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/stop") + Observable> stop(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes beginStop" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/stop") + Observable> beginStop(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes removeNode" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/removeNode") + Observable> removeNode(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Body IntegrationRuntimeRemoveNodeRequest removeNodeParameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes syncCredentials" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/syncCredentials") + Observable> syncCredentials(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes getMonitoringData" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/monitoringData") + Observable> getMonitoringData(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes upgrade" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/integrationRuntimes/{integrationRuntimeName}/upgrade") + Observable> upgrade(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("integrationRuntimeName") String integrationRuntimeName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimes listByFactoryNext" }) + @GET + Observable> listByFactoryNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Lists integration runtimes. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<IntegrationRuntimeResourceInner> object if successful. + */ + public PagedList listByFactory(final String resourceGroupName, final String factoryName) { + ServiceResponse> response = listByFactorySinglePageAsync(resourceGroupName, factoryName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists integration runtimes. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryAsync(final String resourceGroupName, final String factoryName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactorySinglePageAsync(resourceGroupName, factoryName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists integration runtimes. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<IntegrationRuntimeResourceInner> object + */ + public Observable> listByFactoryAsync(final String resourceGroupName, final String factoryName) { + return listByFactoryWithServiceResponseAsync(resourceGroupName, factoryName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists integration runtimes. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<IntegrationRuntimeResourceInner> object + */ + public Observable>> listByFactoryWithServiceResponseAsync(final String resourceGroupName, final String factoryName) { + return listByFactorySinglePageAsync(resourceGroupName, factoryName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists integration runtimes. + * + ServiceResponse> * @param resourceGroupName The resource group name. + ServiceResponse> * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<IntegrationRuntimeResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactorySinglePageAsync(final String resourceGroupName, final String factoryName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listByFactory(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeResourceInner object if successful. + */ + public IntegrationRuntimeResourceInner createOrUpdate(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, properties).toBlocking().single().body(); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, properties), serviceCallback); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, properties).map(new Func1, IntegrationRuntimeResourceInner>() { + @Override + public IntegrationRuntimeResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + final String ifMatch = null; + IntegrationRuntimeResourceInner integrationRuntime = new IntegrationRuntimeResourceInner(); + integrationRuntime.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), integrationRuntime, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @param ifMatch ETag of the integration runtime entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeResourceInner object if successful. + */ + public IntegrationRuntimeResourceInner createOrUpdate(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, properties, ifMatch).toBlocking().single().body(); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @param ifMatch ETag of the integration runtime entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties, String ifMatch, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, properties, ifMatch), serviceCallback); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @param ifMatch ETag of the integration runtime entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, properties, ifMatch).map(new Func1, IntegrationRuntimeResourceInner>() { + @Override + public IntegrationRuntimeResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param properties Integration runtime properties. + * @param ifMatch ETag of the integration runtime entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeInner properties, String ifMatch) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + IntegrationRuntimeResourceInner integrationRuntime = new IntegrationRuntimeResourceInner(); + integrationRuntime.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), integrationRuntime, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse createOrUpdateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeResourceInner object if successful. + */ + public IntegrationRuntimeResourceInner get(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Gets an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Gets an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeResourceInner object + */ + public Observable getAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeResourceInner>() { + @Override + public IntegrationRuntimeResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeResourceInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param updateIntegrationRuntimeRequest The parameters for updating an integration runtime. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeStatusResponseInner object if successful. + */ + public IntegrationRuntimeStatusResponseInner update(String resourceGroupName, String factoryName, String integrationRuntimeName, UpdateIntegrationRuntimeRequest updateIntegrationRuntimeRequest) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, updateIntegrationRuntimeRequest).toBlocking().single().body(); + } + + /** + * Updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param updateIntegrationRuntimeRequest The parameters for updating an integration runtime. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, UpdateIntegrationRuntimeRequest updateIntegrationRuntimeRequest, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, updateIntegrationRuntimeRequest), serviceCallback); + } + + /** + * Updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param updateIntegrationRuntimeRequest The parameters for updating an integration runtime. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeStatusResponseInner object + */ + public Observable updateAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, UpdateIntegrationRuntimeRequest updateIntegrationRuntimeRequest) { + return updateWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, updateIntegrationRuntimeRequest).map(new Func1, IntegrationRuntimeStatusResponseInner>() { + @Override + public IntegrationRuntimeStatusResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Updates an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param updateIntegrationRuntimeRequest The parameters for updating an integration runtime. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeStatusResponseInner object + */ + public Observable> updateWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, UpdateIntegrationRuntimeRequest updateIntegrationRuntimeRequest) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (updateIntegrationRuntimeRequest == null) { + throw new IllegalArgumentException("Parameter updateIntegrationRuntimeRequest is required and cannot be null."); + } + Validator.validate(updateIntegrationRuntimeRequest); + return service.update(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), updateIntegrationRuntimeRequest, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = updateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse updateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Deletes an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String factoryName, String integrationRuntimeName) { + deleteWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Deletes an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Deletes an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return deleteWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.delete(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets detailed status information for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeStatusResponseInner object if successful. + */ + public IntegrationRuntimeStatusResponseInner getStatus(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getStatusWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Gets detailed status information for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getStatusAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getStatusWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Gets detailed status information for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeStatusResponseInner object + */ + public Observable getStatusAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getStatusWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeStatusResponseInner>() { + @Override + public IntegrationRuntimeStatusResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets detailed status information for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeStatusResponseInner object + */ + public Observable> getStatusWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.getStatus(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getStatusDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getStatusDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets the on-premises integration runtime connection information for encrypting the on-premises data source credentials. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeConnectionInfoInner object if successful. + */ + public IntegrationRuntimeConnectionInfoInner getConnectionInfo(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getConnectionInfoWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Gets the on-premises integration runtime connection information for encrypting the on-premises data source credentials. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getConnectionInfoAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getConnectionInfoWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Gets the on-premises integration runtime connection information for encrypting the on-premises data source credentials. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeConnectionInfoInner object + */ + public Observable getConnectionInfoAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getConnectionInfoWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeConnectionInfoInner>() { + @Override + public IntegrationRuntimeConnectionInfoInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets the on-premises integration runtime connection information for encrypting the on-premises data source credentials. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeConnectionInfoInner object + */ + public Observable> getConnectionInfoWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.getConnectionInfo(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getConnectionInfoDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getConnectionInfoDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeAuthKeysInner object if successful. + */ + public IntegrationRuntimeAuthKeysInner regenerateAuthKey(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return regenerateAuthKeyWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture regenerateAuthKeyAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(regenerateAuthKeyWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeAuthKeysInner object + */ + public Observable regenerateAuthKeyAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return regenerateAuthKeyWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeAuthKeysInner>() { + @Override + public IntegrationRuntimeAuthKeysInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeAuthKeysInner object + */ + public Observable> regenerateAuthKeyWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final IntegrationRuntimeAuthKeyName keyName = null; + IntegrationRuntimeRegenerateKeyParameters regenerateKeyParameters = new IntegrationRuntimeRegenerateKeyParameters(); + regenerateKeyParameters.withKeyName(null); + return service.regenerateAuthKey(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), regenerateKeyParameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = regenerateAuthKeyDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param keyName The name of the authentication key to regenerate. Possible values include: 'authKey1', 'authKey2' + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeAuthKeysInner object if successful. + */ + public IntegrationRuntimeAuthKeysInner regenerateAuthKey(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeAuthKeyName keyName) { + return regenerateAuthKeyWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, keyName).toBlocking().single().body(); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param keyName The name of the authentication key to regenerate. Possible values include: 'authKey1', 'authKey2' + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture regenerateAuthKeyAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeAuthKeyName keyName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(regenerateAuthKeyWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, keyName), serviceCallback); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param keyName The name of the authentication key to regenerate. Possible values include: 'authKey1', 'authKey2' + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeAuthKeysInner object + */ + public Observable regenerateAuthKeyAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeAuthKeyName keyName) { + return regenerateAuthKeyWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, keyName).map(new Func1, IntegrationRuntimeAuthKeysInner>() { + @Override + public IntegrationRuntimeAuthKeysInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Regenerates the authentication key for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param keyName The name of the authentication key to regenerate. Possible values include: 'authKey1', 'authKey2' + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeAuthKeysInner object + */ + public Observable> regenerateAuthKeyWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeAuthKeyName keyName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + IntegrationRuntimeRegenerateKeyParameters regenerateKeyParameters = new IntegrationRuntimeRegenerateKeyParameters(); + regenerateKeyParameters.withKeyName(keyName); + return service.regenerateAuthKey(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), regenerateKeyParameters, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = regenerateAuthKeyDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse regenerateAuthKeyDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Retrieves the authentication keys for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeAuthKeysInner object if successful. + */ + public IntegrationRuntimeAuthKeysInner listAuthKeys(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return listAuthKeysWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Retrieves the authentication keys for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture listAuthKeysAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(listAuthKeysWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Retrieves the authentication keys for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeAuthKeysInner object + */ + public Observable listAuthKeysAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return listAuthKeysWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeAuthKeysInner>() { + @Override + public IntegrationRuntimeAuthKeysInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Retrieves the authentication keys for an integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeAuthKeysInner object + */ + public Observable> listAuthKeysWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listAuthKeys(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = listAuthKeysDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse listAuthKeysDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeStatusResponseInner object if successful. + */ + public IntegrationRuntimeStatusResponseInner start(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return startWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().last().body(); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture startAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(startWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable startAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return startWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeStatusResponseInner>() { + @Override + public IntegrationRuntimeStatusResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> startWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Observable> observable = service.start(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeStatusResponseInner object if successful. + */ + public IntegrationRuntimeStatusResponseInner beginStart(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return beginStartWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginStartAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginStartWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeStatusResponseInner object + */ + public Observable beginStartAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return beginStartWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeStatusResponseInner>() { + @Override + public IntegrationRuntimeStatusResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Starts a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeStatusResponseInner object + */ + public Observable> beginStartWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.beginStart(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginStartDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginStartDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(202, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void stop(String resourceGroupName, String factoryName, String integrationRuntimeName) { + stopWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().last().body(); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture stopAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(stopWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable stopAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return stopWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> stopWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Observable> observable = service.stop(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginStop(String resourceGroupName, String factoryName, String integrationRuntimeName) { + beginStopWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginStopAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginStopWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginStopAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return beginStopWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Stops a ManagedReserved type integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginStopWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.beginStop(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginStopDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginStopDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(202, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Remove a node from integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param removeNodeParameters The name of the node to be removed from an integration runtime. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void removeNode(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeRemoveNodeRequest removeNodeParameters) { + removeNodeWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, removeNodeParameters).toBlocking().single().body(); + } + + /** + * Remove a node from integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param removeNodeParameters The name of the node to be removed from an integration runtime. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture removeNodeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeRemoveNodeRequest removeNodeParameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(removeNodeWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, removeNodeParameters), serviceCallback); + } + + /** + * Remove a node from integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param removeNodeParameters The name of the node to be removed from an integration runtime. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable removeNodeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeRemoveNodeRequest removeNodeParameters) { + return removeNodeWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName, removeNodeParameters).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Remove a node from integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param removeNodeParameters The name of the node to be removed from an integration runtime. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> removeNodeWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, IntegrationRuntimeRemoveNodeRequest removeNodeParameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (removeNodeParameters == null) { + throw new IllegalArgumentException("Parameter removeNodeParameters is required and cannot be null."); + } + Validator.validate(removeNodeParameters); + return service.removeNode(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), removeNodeParameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = removeNodeDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse removeNodeDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Force the integration runtime to synchronize credentials across integration runtime nodes, and this will override the credentials across all worker nodes with those available on the dispatcher node. If you already have the latest credential backup file, you should manually import it (preferred) on any self-hosted integration runtime node than using this API directly. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void syncCredentials(String resourceGroupName, String factoryName, String integrationRuntimeName) { + syncCredentialsWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Force the integration runtime to synchronize credentials across integration runtime nodes, and this will override the credentials across all worker nodes with those available on the dispatcher node. If you already have the latest credential backup file, you should manually import it (preferred) on any self-hosted integration runtime node than using this API directly. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture syncCredentialsAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(syncCredentialsWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Force the integration runtime to synchronize credentials across integration runtime nodes, and this will override the credentials across all worker nodes with those available on the dispatcher node. If you already have the latest credential backup file, you should manually import it (preferred) on any self-hosted integration runtime node than using this API directly. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable syncCredentialsAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return syncCredentialsWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Force the integration runtime to synchronize credentials across integration runtime nodes, and this will override the credentials across all worker nodes with those available on the dispatcher node. If you already have the latest credential backup file, you should manually import it (preferred) on any self-hosted integration runtime node than using this API directly. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> syncCredentialsWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.syncCredentials(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = syncCredentialsDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse syncCredentialsDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Get the integration runtime monitoring data, which includes the monitor data for all the nodes under this integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the IntegrationRuntimeMonitoringDataInner object if successful. + */ + public IntegrationRuntimeMonitoringDataInner getMonitoringData(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getMonitoringDataWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Get the integration runtime monitoring data, which includes the monitor data for all the nodes under this integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getMonitoringDataAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getMonitoringDataWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Get the integration runtime monitoring data, which includes the monitor data for all the nodes under this integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeMonitoringDataInner object + */ + public Observable getMonitoringDataAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return getMonitoringDataWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, IntegrationRuntimeMonitoringDataInner>() { + @Override + public IntegrationRuntimeMonitoringDataInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Get the integration runtime monitoring data, which includes the monitor data for all the nodes under this integration runtime. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the IntegrationRuntimeMonitoringDataInner object + */ + public Observable> getMonitoringDataWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.getMonitoringData(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getMonitoringDataDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getMonitoringDataDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Upgrade self-hosted integration runtime to latest version if availability. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void upgrade(String resourceGroupName, String factoryName, String integrationRuntimeName) { + upgradeWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).toBlocking().single().body(); + } + + /** + * Upgrade self-hosted integration runtime to latest version if availability. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture upgradeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(upgradeWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName), serviceCallback); + } + + /** + * Upgrade self-hosted integration runtime to latest version if availability. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable upgradeAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + return upgradeWithServiceResponseAsync(resourceGroupName, factoryName, integrationRuntimeName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Upgrade self-hosted integration runtime to latest version if availability. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param integrationRuntimeName The integration runtime name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> upgradeWithServiceResponseAsync(String resourceGroupName, String factoryName, String integrationRuntimeName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (integrationRuntimeName == null) { + throw new IllegalArgumentException("Parameter integrationRuntimeName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.upgrade(this.client.subscriptionId(), resourceGroupName, factoryName, integrationRuntimeName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = upgradeDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse upgradeDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists integration runtimes. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<IntegrationRuntimeResourceInner> object if successful. + */ + public PagedList listByFactoryNext(final String nextPageLink) { + ServiceResponse> response = listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists integration runtimes. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactoryNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists integration runtimes. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<IntegrationRuntimeResourceInner> object + */ + public Observable> listByFactoryNextAsync(final String nextPageLink) { + return listByFactoryNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists integration runtimes. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<IntegrationRuntimeResourceInner> object + */ + public Observable>> listByFactoryNextWithServiceResponseAsync(final String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists integration runtimes. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<IntegrationRuntimeResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactoryNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByFactoryNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceInner.java new file mode 100644 index 000000000000..9a2067f8c46e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceInner.java @@ -0,0 +1,230 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeReference; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ParameterSpecification; +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * The Azure Data Factory nested object which contains the information and + * credential which can be used to connect with related store or compute + * resource. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("LinkedService") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "Responsys", value = ResponsysLinkedService.class), + @JsonSubTypes.Type(name = "AzureDatabricks", value = AzureDatabricksLinkedService.class), + @JsonSubTypes.Type(name = "AzureDataLakeAnalytics", value = AzureDataLakeAnalyticsLinkedService.class), + @JsonSubTypes.Type(name = "HDInsightOnDemand", value = HDInsightOnDemandLinkedService.class), + @JsonSubTypes.Type(name = "SalesforceMarketingCloud", value = SalesforceMarketingCloudLinkedService.class), + @JsonSubTypes.Type(name = "Netezza", value = NetezzaLinkedService.class), + @JsonSubTypes.Type(name = "Vertica", value = VerticaLinkedService.class), + @JsonSubTypes.Type(name = "Zoho", value = ZohoLinkedService.class), + @JsonSubTypes.Type(name = "Xero", value = XeroLinkedService.class), + @JsonSubTypes.Type(name = "Square", value = SquareLinkedService.class), + @JsonSubTypes.Type(name = "Spark", value = SparkLinkedService.class), + @JsonSubTypes.Type(name = "Shopify", value = ShopifyLinkedService.class), + @JsonSubTypes.Type(name = "ServiceNow", value = ServiceNowLinkedService.class), + @JsonSubTypes.Type(name = "QuickBooks", value = QuickBooksLinkedService.class), + @JsonSubTypes.Type(name = "Presto", value = PrestoLinkedService.class), + @JsonSubTypes.Type(name = "Phoenix", value = PhoenixLinkedService.class), + @JsonSubTypes.Type(name = "Paypal", value = PaypalLinkedService.class), + @JsonSubTypes.Type(name = "Marketo", value = MarketoLinkedService.class), + @JsonSubTypes.Type(name = "MariaDB", value = MariaDBLinkedService.class), + @JsonSubTypes.Type(name = "Magento", value = MagentoLinkedService.class), + @JsonSubTypes.Type(name = "Jira", value = JiraLinkedService.class), + @JsonSubTypes.Type(name = "Impala", value = ImpalaLinkedService.class), + @JsonSubTypes.Type(name = "Hubspot", value = HubspotLinkedService.class), + @JsonSubTypes.Type(name = "Hive", value = HiveLinkedService.class), + @JsonSubTypes.Type(name = "HBase", value = HBaseLinkedService.class), + @JsonSubTypes.Type(name = "Greenplum", value = GreenplumLinkedService.class), + @JsonSubTypes.Type(name = "GoogleBigQuery", value = GoogleBigQueryLinkedService.class), + @JsonSubTypes.Type(name = "Eloqua", value = EloquaLinkedService.class), + @JsonSubTypes.Type(name = "Drill", value = DrillLinkedService.class), + @JsonSubTypes.Type(name = "Couchbase", value = CouchbaseLinkedService.class), + @JsonSubTypes.Type(name = "Concur", value = ConcurLinkedService.class), + @JsonSubTypes.Type(name = "AzurePostgreSql", value = AzurePostgreSqlLinkedService.class), + @JsonSubTypes.Type(name = "AmazonMWS", value = AmazonMWSLinkedService.class), + @JsonSubTypes.Type(name = "SapHana", value = SapHanaLinkedService.class), + @JsonSubTypes.Type(name = "SapBW", value = SapBWLinkedService.class), + @JsonSubTypes.Type(name = "Sftp", value = SftpServerLinkedService.class), + @JsonSubTypes.Type(name = "FtpServer", value = FtpServerLinkedService.class), + @JsonSubTypes.Type(name = "HttpServer", value = HttpLinkedService.class), + @JsonSubTypes.Type(name = "AzureSearch", value = AzureSearchLinkedService.class), + @JsonSubTypes.Type(name = "CustomDataSource", value = CustomDataSourceLinkedService.class), + @JsonSubTypes.Type(name = "AmazonRedshift", value = AmazonRedshiftLinkedService.class), + @JsonSubTypes.Type(name = "AmazonS3", value = AmazonS3LinkedService.class), + @JsonSubTypes.Type(name = "SapEcc", value = SapEccLinkedService.class), + @JsonSubTypes.Type(name = "SapCloudForCustomer", value = SapCloudForCustomerLinkedService.class), + @JsonSubTypes.Type(name = "Salesforce", value = SalesforceLinkedService.class), + @JsonSubTypes.Type(name = "AzureDataLakeStore", value = AzureDataLakeStoreLinkedService.class), + @JsonSubTypes.Type(name = "MongoDb", value = MongoDbLinkedService.class), + @JsonSubTypes.Type(name = "Cassandra", value = CassandraLinkedService.class), + @JsonSubTypes.Type(name = "Web", value = WebLinkedService.class), + @JsonSubTypes.Type(name = "OData", value = ODataLinkedService.class), + @JsonSubTypes.Type(name = "Hdfs", value = HdfsLinkedService.class), + @JsonSubTypes.Type(name = "Odbc", value = OdbcLinkedService.class), + @JsonSubTypes.Type(name = "AzureML", value = AzureMLLinkedService.class), + @JsonSubTypes.Type(name = "Teradata", value = TeradataLinkedService.class), + @JsonSubTypes.Type(name = "Db2", value = Db2LinkedService.class), + @JsonSubTypes.Type(name = "Sybase", value = SybaseLinkedService.class), + @JsonSubTypes.Type(name = "PostgreSql", value = PostgreSqlLinkedService.class), + @JsonSubTypes.Type(name = "MySql", value = MySqlLinkedService.class), + @JsonSubTypes.Type(name = "AzureMySql", value = AzureMySqlLinkedService.class), + @JsonSubTypes.Type(name = "Oracle", value = OracleLinkedService.class), + @JsonSubTypes.Type(name = "FileServer", value = FileServerLinkedService.class), + @JsonSubTypes.Type(name = "HDInsight", value = HDInsightLinkedService.class), + @JsonSubTypes.Type(name = "Dynamics", value = DynamicsLinkedService.class), + @JsonSubTypes.Type(name = "CosmosDb", value = CosmosDbLinkedService.class), + @JsonSubTypes.Type(name = "AzureKeyVault", value = AzureKeyVaultLinkedService.class), + @JsonSubTypes.Type(name = "AzureBatch", value = AzureBatchLinkedService.class), + @JsonSubTypes.Type(name = "AzureSqlDatabase", value = AzureSqlDatabaseLinkedService.class), + @JsonSubTypes.Type(name = "SqlServer", value = SqlServerLinkedService.class), + @JsonSubTypes.Type(name = "AzureSqlDW", value = AzureSqlDWLinkedService.class), + @JsonSubTypes.Type(name = "AzureStorage", value = AzureStorageLinkedService.class) +}) +public class LinkedServiceInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The integration runtime reference. + */ + @JsonProperty(value = "connectVia") + private IntegrationRuntimeReference connectVia; + + /** + * Linked service description. + */ + @JsonProperty(value = "description") + private String description; + + /** + * Parameters for linked service. + */ + @JsonProperty(value = "parameters") + private Map parameters; + + /** + * List of tags that can be used for describing the Dataset. + */ + @JsonProperty(value = "annotations") + private List annotations; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the LinkedServiceInner object itself. + */ + public LinkedServiceInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the integration runtime reference. + * + * @return the connectVia value + */ + public IntegrationRuntimeReference connectVia() { + return this.connectVia; + } + + /** + * Set the integration runtime reference. + * + * @param connectVia the connectVia value to set + * @return the LinkedServiceInner object itself. + */ + public LinkedServiceInner withConnectVia(IntegrationRuntimeReference connectVia) { + this.connectVia = connectVia; + return this; + } + + /** + * Get linked service description. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Set linked service description. + * + * @param description the description value to set + * @return the LinkedServiceInner object itself. + */ + public LinkedServiceInner withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get parameters for linked service. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set parameters for linked service. + * + * @param parameters the parameters value to set + * @return the LinkedServiceInner object itself. + */ + public LinkedServiceInner withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + + /** + * Get list of tags that can be used for describing the Dataset. + * + * @return the annotations value + */ + public List annotations() { + return this.annotations; + } + + /** + * Set list of tags that can be used for describing the Dataset. + * + * @param annotations the annotations value to set + * @return the LinkedServiceInner object itself. + */ + public LinkedServiceInner withAnnotations(List annotations) { + this.annotations = annotations; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceResourceImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceResourceImpl.java new file mode 100644 index 000000000000..600de6d891ac --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceResourceImpl.java @@ -0,0 +1,156 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServiceResource; +import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl; +import rx.Observable; +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeReference; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ParameterSpecification; +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.; +import rx.functions.Func1; + +class LinkedServiceResourceImpl extends CreatableUpdatableImpl implements LinkedServiceResource, LinkedServiceResource.Definition, LinkedServiceResource.Update { + private final DataFactoryManager manager; + private String resourceGroupName; + private String factoryName; + private String linkedServiceName; + private String cifMatch; + private LinkedServiceInner cproperties; + private String uifMatch; + private LinkedServiceInner uproperties; + + LinkedServiceResourceImpl(String name, DataFactoryManager manager) { + super(name, new LinkedServiceResourceInner()); + this.manager = manager; + // Set resource name + this.linkedServiceName = name; + // + this.cproperties = new LinkedServiceInner(); + this.uproperties = new LinkedServiceInner(); + } + + LinkedServiceResourceImpl(LinkedServiceResourceInner inner, DataFactoryManager manager) { + super(inner.name(), inner); + this.manager = manager; + // Set resource name + this.linkedServiceName = inner.name(); + // set resource ancestor and positional variables + this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups"); + this.factoryName = IdParsingUtils.getValueFromIdByName(inner.id(), "factories"); + this.linkedServiceName = IdParsingUtils.getValueFromIdByName(inner.id(), "linkedservices"); + // + this.cproperties = new LinkedServiceInner(); + this.uproperties = new LinkedServiceInner(); + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Observable createResourceAsync() { + LinkedServicesInner client = this.manager().inner().linkedServices(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.linkedServiceName, this.cproperties, this.cifMatch) + .map(new Func1() { + @Override + public LinkedServiceResourceInner call(LinkedServiceResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + LinkedServicesInner client = this.manager().inner().linkedServices(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.linkedServiceName, this.uproperties, this.uifMatch) + .map(new Func1() { + @Override + public LinkedServiceResourceInner call(LinkedServiceResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + LinkedServicesInner client = this.manager().inner().linkedServices(); + return client.getAsync(this.resourceGroupName, this.factoryName, this.linkedServiceName); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + private void resetCreateUpdateParameters() { + this.cproperties = new LinkedServiceInner(); + this.uproperties = new LinkedServiceInner(); + } + + @Override + public String etag() { + return this.inner().etag(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public LinkedServiceInner properties() { + return this.inner().properties(); + } + + @Override + public String type() { + return this.inner().type(); + } + + @Override + public LinkedServiceResourceImpl withExistingFactory(String resourceGroupName, String factoryName) { + this.resourceGroupName = resourceGroupName; + this.factoryName = factoryName; + return this; + } + + @Override + public LinkedServiceResourceImpl withIfMatch(String ifMatch) { + if (isInCreateMode()) { + this.cifMatch = ifMatch; + } else { + this.uifMatch = ifMatch; + } + return this; + } + + @Override + public LinkedServiceResourceImpl withProperties(LinkedServiceInner properties) { + if (isInCreateMode()) { + this.cproperties = properties; + } else { + this.uproperties = properties; + } + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceResourceInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceResourceInner.java new file mode 100644 index 000000000000..9dbf66a7a10c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServiceResourceInner.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.SubResource; + +/** + * Linked service resource type. + */ +public class LinkedServiceResourceInner extends SubResource { + /** + * Properties of linked service. + */ + @JsonProperty(value = "properties", required = true) + private LinkedServiceInner properties; + + /** + * The resource name. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The resource type. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * Etag identifies change in the resource. + */ + @JsonProperty(value = "etag", access = JsonProperty.Access.WRITE_ONLY) + private String etag; + + /** + * Get properties of linked service. + * + * @return the properties value + */ + public LinkedServiceInner properties() { + return this.properties; + } + + /** + * Set properties of linked service. + * + * @param properties the properties value to set + * @return the LinkedServiceResourceInner object itself. + */ + public LinkedServiceResourceInner withProperties(LinkedServiceInner properties) { + this.properties = properties; + return this; + } + + /** + * Get the resource name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the resource type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get etag identifies change in the resource. + * + * @return the etag value + */ + public String etag() { + return this.etag; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServicesImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServicesImpl.java new file mode 100644 index 000000000000..1a3886184ad1 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServicesImpl.java @@ -0,0 +1,81 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServices; +import rx.Completable; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServiceResource; + +class LinkedServicesImpl extends WrapperImpl implements LinkedServices { + private final DataFactoryManager manager; + + LinkedServicesImpl(DataFactoryManager manager) { + super(manager.inner().linkedServices()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public LinkedServiceResourceImpl define(String name) { + return wrapModel(name); + } + + private LinkedServiceResourceImpl wrapModel(LinkedServiceResourceInner inner) { + return new LinkedServiceResourceImpl(inner, manager()); + } + + private LinkedServiceResourceImpl wrapModel(String name) { + return new LinkedServiceResourceImpl(name, this.manager()); + } + + @Override + public Observable listByFactoryAsync(final String resourceGroupName, final String factoryName) { + LinkedServicesInner client = this.inner(); + return client.listByFactoryAsync(resourceGroupName, factoryName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public LinkedServiceResource call(LinkedServiceResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Observable getAsync(String resourceGroupName, String factoryName, String linkedServiceName) { + LinkedServicesInner client = this.inner(); + return client.getAsync(resourceGroupName, factoryName, linkedServiceName) + .map(new Func1() { + @Override + public LinkedServiceResource call(LinkedServiceResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Completable deleteAsync(String resourceGroupName, String factoryName, String linkedServiceName) { + LinkedServicesInner client = this.inner(); + return client.deleteAsync(resourceGroupName, factoryName, linkedServiceName).toCompletable(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServicesInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServicesInner.java new file mode 100644 index 000000000000..cbf3385bd408 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/LinkedServicesInner.java @@ -0,0 +1,710 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in LinkedServices. + */ +public class LinkedServicesInner { + /** The Retrofit service to perform REST calls. */ + private LinkedServicesService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of LinkedServicesInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public LinkedServicesInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(LinkedServicesService.class); + this.client = client; + } + + /** + * The interface defining all the services for LinkedServices to be + * used by Retrofit to perform actually REST calls. + */ + interface LinkedServicesService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServices listByFactory" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/linkedservices") + Observable> listByFactory(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServices createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/linkedservices/{linkedServiceName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("linkedServiceName") String linkedServiceName, @Query("api-version") String apiVersion, @Header("If-Match") String ifMatch, @Header("accept-language") String acceptLanguage, @Body LinkedServiceResourceInner linkedService, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServices get" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/linkedservices/{linkedServiceName}") + Observable> get(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("linkedServiceName") String linkedServiceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServices delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/linkedservices/{linkedServiceName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("linkedServiceName") String linkedServiceName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.LinkedServices listByFactoryNext" }) + @GET + Observable> listByFactoryNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Lists linked services. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<LinkedServiceResourceInner> object if successful. + */ + public PagedList listByFactory(final String resourceGroupName, final String factoryName) { + ServiceResponse> response = listByFactorySinglePageAsync(resourceGroupName, factoryName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists linked services. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryAsync(final String resourceGroupName, final String factoryName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactorySinglePageAsync(resourceGroupName, factoryName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists linked services. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<LinkedServiceResourceInner> object + */ + public Observable> listByFactoryAsync(final String resourceGroupName, final String factoryName) { + return listByFactoryWithServiceResponseAsync(resourceGroupName, factoryName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists linked services. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<LinkedServiceResourceInner> object + */ + public Observable>> listByFactoryWithServiceResponseAsync(final String resourceGroupName, final String factoryName) { + return listByFactorySinglePageAsync(resourceGroupName, factoryName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists linked services. + * + ServiceResponse> * @param resourceGroupName The resource group name. + ServiceResponse> * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<LinkedServiceResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactorySinglePageAsync(final String resourceGroupName, final String factoryName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listByFactory(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the LinkedServiceResourceInner object if successful. + */ + public LinkedServiceResourceInner createOrUpdate(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName, properties).toBlocking().single().body(); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName, properties), serviceCallback); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the LinkedServiceResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName, properties).map(new Func1, LinkedServiceResourceInner>() { + @Override + public LinkedServiceResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the LinkedServiceResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (linkedServiceName == null) { + throw new IllegalArgumentException("Parameter linkedServiceName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + final String ifMatch = null; + LinkedServiceResourceInner linkedService = new LinkedServiceResourceInner(); + linkedService.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, linkedServiceName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), linkedService, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @param ifMatch ETag of the linkedService entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the LinkedServiceResourceInner object if successful. + */ + public LinkedServiceResourceInner createOrUpdate(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName, properties, ifMatch).toBlocking().single().body(); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @param ifMatch ETag of the linkedService entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties, String ifMatch, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName, properties, ifMatch), serviceCallback); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @param ifMatch ETag of the linkedService entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the LinkedServiceResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName, properties, ifMatch).map(new Func1, LinkedServiceResourceInner>() { + @Override + public LinkedServiceResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param properties Properties of linked service. + * @param ifMatch ETag of the linkedService entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the LinkedServiceResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String linkedServiceName, LinkedServiceInner properties, String ifMatch) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (linkedServiceName == null) { + throw new IllegalArgumentException("Parameter linkedServiceName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + LinkedServiceResourceInner linkedService = new LinkedServiceResourceInner(); + linkedService.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, linkedServiceName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), linkedService, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse createOrUpdateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the LinkedServiceResourceInner object if successful. + */ + public LinkedServiceResourceInner get(String resourceGroupName, String factoryName, String linkedServiceName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName).toBlocking().single().body(); + } + + /** + * Gets a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAsync(String resourceGroupName, String factoryName, String linkedServiceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName), serviceCallback); + } + + /** + * Gets a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the LinkedServiceResourceInner object + */ + public Observable getAsync(String resourceGroupName, String factoryName, String linkedServiceName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName).map(new Func1, LinkedServiceResourceInner>() { + @Override + public LinkedServiceResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the LinkedServiceResourceInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String factoryName, String linkedServiceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (linkedServiceName == null) { + throw new IllegalArgumentException("Parameter linkedServiceName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(this.client.subscriptionId(), resourceGroupName, factoryName, linkedServiceName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Deletes a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String factoryName, String linkedServiceName) { + deleteWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName).toBlocking().single().body(); + } + + /** + * Deletes a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String factoryName, String linkedServiceName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName), serviceCallback); + } + + /** + * Deletes a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String factoryName, String linkedServiceName) { + return deleteWithServiceResponseAsync(resourceGroupName, factoryName, linkedServiceName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a linked service. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param linkedServiceName The linked service name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String factoryName, String linkedServiceName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (linkedServiceName == null) { + throw new IllegalArgumentException("Parameter linkedServiceName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.delete(this.client.subscriptionId(), resourceGroupName, factoryName, linkedServiceName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists linked services. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<LinkedServiceResourceInner> object if successful. + */ + public PagedList listByFactoryNext(final String nextPageLink) { + ServiceResponse> response = listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists linked services. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactoryNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists linked services. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<LinkedServiceResourceInner> object + */ + public Observable> listByFactoryNextAsync(final String nextPageLink) { + return listByFactoryNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists linked services. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<LinkedServiceResourceInner> object + */ + public Observable>> listByFactoryNextWithServiceResponseAsync(final String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists linked services. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<LinkedServiceResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactoryNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByFactoryNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationInner.java new file mode 100644 index 000000000000..339cc10e23e5 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationInner.java @@ -0,0 +1,125 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.OperationDisplay; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.OperationServiceSpecification; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; + +/** + * Azure Data Factory API operation definition. + */ +@JsonFlatten +public class OperationInner { + /** + * Operation name: {provider}/{resource}/{operation}. + */ + @JsonProperty(value = "name") + private String name; + + /** + * The intended executor of the operation. + */ + @JsonProperty(value = "origin") + private String origin; + + /** + * Metadata associated with the operation. + */ + @JsonProperty(value = "display") + private OperationDisplay display; + + /** + * Details about a service operation. + */ + @JsonProperty(value = "properties.serviceSpecification") + private OperationServiceSpecification serviceSpecification; + + /** + * Get operation name: {provider}/{resource}/{operation}. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Set operation name: {provider}/{resource}/{operation}. + * + * @param name the name value to set + * @return the OperationInner object itself. + */ + public OperationInner withName(String name) { + this.name = name; + return this; + } + + /** + * Get the intended executor of the operation. + * + * @return the origin value + */ + public String origin() { + return this.origin; + } + + /** + * Set the intended executor of the operation. + * + * @param origin the origin value to set + * @return the OperationInner object itself. + */ + public OperationInner withOrigin(String origin) { + this.origin = origin; + return this; + } + + /** + * Get metadata associated with the operation. + * + * @return the display value + */ + public OperationDisplay display() { + return this.display; + } + + /** + * Set metadata associated with the operation. + * + * @param display the display value to set + * @return the OperationInner object itself. + */ + public OperationInner withDisplay(OperationDisplay display) { + this.display = display; + return this; + } + + /** + * Get details about a service operation. + * + * @return the serviceSpecification value + */ + public OperationServiceSpecification serviceSpecification() { + return this.serviceSpecification; + } + + /** + * Set details about a service operation. + * + * @param serviceSpecification the serviceSpecification value to set + * @return the OperationInner object itself. + */ + public OperationInner withServiceSpecification(OperationServiceSpecification serviceSpecification) { + this.serviceSpecification = serviceSpecification; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationListResponseImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationListResponseImpl.java new file mode 100644 index 000000000000..e0e2d93086e3 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationListResponseImpl.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.OperationListResponse; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.List; + +class OperationListResponseImpl extends WrapperImpl implements OperationListResponse { + private final DataFactoryManager manager; + OperationListResponseImpl(OperationListResponseInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public String nextLink() { + return this.inner().nextLink(); + } + + @Override + public List value() { + return this.inner().value(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationListResponseInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationListResponseInner.java new file mode 100644 index 000000000000..fbcd28ee9fd0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationListResponseInner.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A list of operations that can be performed by the Data Factory service. + */ +public class OperationListResponseInner { + /** + * List of Data Factory operations supported by the Data Factory resource + * provider. + */ + @JsonProperty(value = "value") + private List value; + + /** + * The link to the next page of results, if any remaining results exist. + */ + @JsonProperty(value = "nextLink") + private String nextLink; + + /** + * Get list of Data Factory operations supported by the Data Factory resource provider. + * + * @return the value value + */ + public List value() { + return this.value; + } + + /** + * Set list of Data Factory operations supported by the Data Factory resource provider. + * + * @param value the value value to set + * @return the OperationListResponseInner object itself. + */ + public OperationListResponseInner withValue(List value) { + this.value = value; + return this; + } + + /** + * Get the link to the next page of results, if any remaining results exist. + * + * @return the nextLink value + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Set the link to the next page of results, if any remaining results exist. + * + * @param nextLink the nextLink value to set + * @return the OperationListResponseInner object itself. + */ + public OperationListResponseInner withNextLink(String nextLink) { + this.nextLink = nextLink; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationsImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationsImpl.java new file mode 100644 index 000000000000..2f6588b4695e --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationsImpl.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * abc + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Operations; +import rx.functions.Func1; +import rx.Observable; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.OperationListResponse; + +class OperationsImpl extends WrapperImpl implements Operations { + private final DataFactoryManager manager; + + OperationsImpl(DataFactoryManager manager) { + super(manager.inner().operations()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Observable listAsync() { + OperationsInner client = this.inner(); + return client.listAsync() + .map(new Func1() { + @Override + public OperationListResponse call(OperationListResponseInner inner) { + return new OperationListResponseImpl(inner, manager()); + } + }); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationsInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationsInner.java new file mode 100644 index 000000000000..04e6c86aa5bb --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/OperationsInner.java @@ -0,0 +1,128 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import java.io.IOException; +import okhttp3.ResponseBody; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.Query; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in Operations. + */ +public class OperationsInner { + /** The Retrofit service to perform REST calls. */ + private OperationsService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of OperationsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public OperationsInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(OperationsService.class); + this.client = client; + } + + /** + * The interface defining all the services for Operations to be + * used by Retrofit to perform actually REST calls. + */ + interface OperationsService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Operations list" }) + @GET("providers/Microsoft.DataFactory/operations") + Observable> list(@Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Lists the available Azure Data Factory API operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the OperationListResponseInner object if successful. + */ + public OperationListResponseInner list() { + return listWithServiceResponseAsync().toBlocking().single().body(); + } + + /** + * Lists the available Azure Data Factory API operations. + * + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture listAsync(final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(listWithServiceResponseAsync(), serviceCallback); + } + + /** + * Lists the available Azure Data Factory API operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OperationListResponseInner object + */ + public Observable listAsync() { + return listWithServiceResponseAsync().map(new Func1, OperationListResponseInner>() { + @Override + public OperationListResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Lists the available Azure Data Factory API operations. + * + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the OperationListResponseInner object + */ + public Observable> listWithServiceResponseAsync() { + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.list(this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = listDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse listDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PageImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PageImpl.java new file mode 100644 index 000000000000..f83cf370573d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PageImpl.java @@ -0,0 +1,75 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.Page; +import java.util.List; + +/** + * An instance of this class defines a page of Azure resources and a link to + * get the next page of resources, if any. + * + * @param type of Azure resource + */ +public class PageImpl implements Page { + /** + * The link to the next page. + */ + @JsonProperty("nextLink") + private String nextPageLink; + + /** + * The list of items. + */ + @JsonProperty("value") + private List items; + + /** + * Gets the link to the next page. + * + * @return the link to the next page. + */ + @Override + public String nextPageLink() { + return this.nextPageLink; + } + + /** + * Gets the list of items. + * + * @return the list of items in {@link List}. + */ + @Override + public List items() { + return items; + } + + /** + * Sets the link to the next page. + * + * @param nextPageLink the link to the next page. + * @return this Page object itself. + */ + public PageImpl setNextPageLink(String nextPageLink) { + this.nextPageLink = nextPageLink; + return this; + } + + /** + * Sets the list of items. + * + * @param items the list of items in {@link List}. + * @return this Page object itself. + */ + public PageImpl setItems(List items) { + this.items = items; + return this; + } +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineResourceImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineResourceImpl.java new file mode 100644 index 000000000000..ab4c9ba113bf --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineResourceImpl.java @@ -0,0 +1,181 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineResource; +import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl; +import rx.Observable; +import java.util.Map; +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Activity; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ParameterSpecification; + +class PipelineResourceImpl extends CreatableUpdatableImpl implements PipelineResource, PipelineResource.Definition, PipelineResource.Update { + private final DataFactoryManager manager; + private String resourceGroupName; + private String factoryName; + private String pipelineName; + private String cifMatch; + private String uifMatch; + + PipelineResourceImpl(String name, DataFactoryManager manager) { + super(name, new PipelineResourceInner()); + this.manager = manager; + // Set resource name + this.pipelineName = name; + // + } + + PipelineResourceImpl(PipelineResourceInner inner, DataFactoryManager manager) { + super(inner.name(), inner); + this.manager = manager; + // Set resource name + this.pipelineName = inner.name(); + // set resource ancestor and positional variables + this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups"); + this.factoryName = IdParsingUtils.getValueFromIdByName(inner.id(), "factories"); + this.pipelineName = IdParsingUtils.getValueFromIdByName(inner.id(), "pipelines"); + // + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Observable createResourceAsync() { + PipelinesInner client = this.manager().inner().pipelines(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.pipelineName, this.inner(), this.cifMatch) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + PipelinesInner client = this.manager().inner().pipelines(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.pipelineName, this.inner(), this.uifMatch) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + PipelinesInner client = this.manager().inner().pipelines(); + return client.getAsync(this.resourceGroupName, this.factoryName, this.pipelineName); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + + @Override + public List activities() { + return this.inner().activities(); + } + + @Override + public Map additionalProperties() { + return this.inner().additionalProperties(); + } + + @Override + public List annotations() { + return this.inner().annotations(); + } + + @Override + public Integer concurrency() { + return this.inner().concurrency(); + } + + @Override + public String description() { + return this.inner().description(); + } + + @Override + public String etag() { + return this.inner().etag(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public Map parameters() { + return this.inner().parameters(); + } + + @Override + public String type() { + return this.inner().type(); + } + + @Override + public PipelineResourceImpl withExistingFactory(String resourceGroupName, String factoryName) { + this.resourceGroupName = resourceGroupName; + this.factoryName = factoryName; + return this; + } + + @Override + public PipelineResourceImpl withIfMatch(String ifMatch) { + if (isInCreateMode()) { + this.cifMatch = ifMatch; + } else { + this.uifMatch = ifMatch; + } + return this; + } + + @Override + public PipelineResourceImpl withActivities(List activities) { + this.inner().withActivities(activities); + return this; + } + + @Override + public PipelineResourceImpl withAdditionalProperties(Map additionalProperties) { + this.inner().withAdditionalProperties(additionalProperties); + return this; + } + + @Override + public PipelineResourceImpl withAnnotations(List annotations) { + this.inner().withAnnotations(annotations); + return this; + } + + @Override + public PipelineResourceImpl withConcurrency(Integer concurrency) { + this.inner().withConcurrency(concurrency); + return this; + } + + @Override + public PipelineResourceImpl withDescription(String description) { + this.inner().withDescription(description); + return this; + } + + @Override + public PipelineResourceImpl withParameters(Map parameters) { + this.inner().withParameters(parameters); + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineResourceInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineResourceInner.java new file mode 100644 index 000000000000..7544aa11a270 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineResourceInner.java @@ -0,0 +1,225 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import java.util.List; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Activity; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ParameterSpecification; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.rest.serializer.JsonFlatten; +import com.microsoft.azure.SubResource; + +/** + * Pipeline resource type. + */ +@JsonFlatten +public class PipelineResourceInner extends SubResource { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * The description of the pipeline. + */ + @JsonProperty(value = "properties.description") + private String description; + + /** + * List of activities in pipeline. + */ + @JsonProperty(value = "properties.activities") + private List activities; + + /** + * List of parameters for pipeline. + */ + @JsonProperty(value = "properties.parameters") + private Map parameters; + + /** + * The max number of concurrent runs for the pipeline. + */ + @JsonProperty(value = "properties.concurrency") + private Integer concurrency; + + /** + * List of tags that can be used for describing the Pipeline. + */ + @JsonProperty(value = "properties.annotations") + private List annotations; + + /** + * The resource name. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The resource type. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * Etag identifies change in the resource. + */ + @JsonProperty(value = "etag", access = JsonProperty.Access.WRITE_ONLY) + private String etag; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the PipelineResourceInner object itself. + */ + public PipelineResourceInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get the description of the pipeline. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Set the description of the pipeline. + * + * @param description the description value to set + * @return the PipelineResourceInner object itself. + */ + public PipelineResourceInner withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get list of activities in pipeline. + * + * @return the activities value + */ + public List activities() { + return this.activities; + } + + /** + * Set list of activities in pipeline. + * + * @param activities the activities value to set + * @return the PipelineResourceInner object itself. + */ + public PipelineResourceInner withActivities(List activities) { + this.activities = activities; + return this; + } + + /** + * Get list of parameters for pipeline. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Set list of parameters for pipeline. + * + * @param parameters the parameters value to set + * @return the PipelineResourceInner object itself. + */ + public PipelineResourceInner withParameters(Map parameters) { + this.parameters = parameters; + return this; + } + + /** + * Get the max number of concurrent runs for the pipeline. + * + * @return the concurrency value + */ + public Integer concurrency() { + return this.concurrency; + } + + /** + * Set the max number of concurrent runs for the pipeline. + * + * @param concurrency the concurrency value to set + * @return the PipelineResourceInner object itself. + */ + public PipelineResourceInner withConcurrency(Integer concurrency) { + this.concurrency = concurrency; + return this; + } + + /** + * Get list of tags that can be used for describing the Pipeline. + * + * @return the annotations value + */ + public List annotations() { + return this.annotations; + } + + /** + * Set list of tags that can be used for describing the Pipeline. + * + * @param annotations the annotations value to set + * @return the PipelineResourceInner object itself. + */ + public PipelineResourceInner withAnnotations(List annotations) { + this.annotations = annotations; + return this; + } + + /** + * Get the resource name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the resource type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get etag identifies change in the resource. + * + * @return the etag value + */ + public String etag() { + return this.etag; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunImpl.java new file mode 100644 index 000000000000..47837812d327 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunImpl.java @@ -0,0 +1,91 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRun; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import rx.Observable; +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRunInvokedBy; +import org.joda.time.DateTime; + +class PipelineRunImpl extends WrapperImpl implements PipelineRun { + private final DataFactoryManager manager; + private String resourceGroupName; + private String factoryName; + private String runId; + + PipelineRunImpl(PipelineRunInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + + + @Override + public Map additionalProperties() { + return this.inner().additionalProperties(); + } + + @Override + public Integer durationInMs() { + return this.inner().durationInMs(); + } + + @Override + public PipelineRunInvokedBy invokedBy() { + return this.inner().invokedBy(); + } + + @Override + public DateTime lastUpdated() { + return this.inner().lastUpdated(); + } + + @Override + public String message() { + return this.inner().message(); + } + + @Override + public Map parameters() { + return this.inner().parameters(); + } + + @Override + public String pipelineName() { + return this.inner().pipelineName(); + } + + @Override + public DateTime runEnd() { + return this.inner().runEnd(); + } + + @Override + public String runId() { + return this.inner().runId(); + } + + @Override + public DateTime runStart() { + return this.inner().runStart(); + } + + @Override + public String status() { + return this.inner().status(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunInner.java new file mode 100644 index 000000000000..98a1f78bf36f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunInner.java @@ -0,0 +1,197 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRunInvokedBy; +import org.joda.time.DateTime; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Information about a pipeline run. + */ +public class PipelineRunInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Identifier of a run. + */ + @JsonProperty(value = "runId", access = JsonProperty.Access.WRITE_ONLY) + private String runId; + + /** + * The pipeline name. + */ + @JsonProperty(value = "pipelineName", access = JsonProperty.Access.WRITE_ONLY) + private String pipelineName; + + /** + * The full or partial list of parameter name, value pair used in the + * pipeline run. + */ + @JsonProperty(value = "parameters", access = JsonProperty.Access.WRITE_ONLY) + private Map parameters; + + /** + * Entity that started the pipeline run. + */ + @JsonProperty(value = "invokedBy", access = JsonProperty.Access.WRITE_ONLY) + private PipelineRunInvokedBy invokedBy; + + /** + * The last updated timestamp for the pipeline run event in ISO8601 format. + */ + @JsonProperty(value = "lastUpdated", access = JsonProperty.Access.WRITE_ONLY) + private DateTime lastUpdated; + + /** + * The start time of a pipeline run in ISO8601 format. + */ + @JsonProperty(value = "runStart", access = JsonProperty.Access.WRITE_ONLY) + private DateTime runStart; + + /** + * The end time of a pipeline run in ISO8601 format. + */ + @JsonProperty(value = "runEnd", access = JsonProperty.Access.WRITE_ONLY) + private DateTime runEnd; + + /** + * The duration of a pipeline run. + */ + @JsonProperty(value = "durationInMs", access = JsonProperty.Access.WRITE_ONLY) + private Integer durationInMs; + + /** + * The status of a pipeline run. + */ + @JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY) + private String status; + + /** + * The message from a pipeline run. + */ + @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) + private String message; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the PipelineRunInner object itself. + */ + public PipelineRunInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get identifier of a run. + * + * @return the runId value + */ + public String runId() { + return this.runId; + } + + /** + * Get the pipeline name. + * + * @return the pipelineName value + */ + public String pipelineName() { + return this.pipelineName; + } + + /** + * Get the full or partial list of parameter name, value pair used in the pipeline run. + * + * @return the parameters value + */ + public Map parameters() { + return this.parameters; + } + + /** + * Get entity that started the pipeline run. + * + * @return the invokedBy value + */ + public PipelineRunInvokedBy invokedBy() { + return this.invokedBy; + } + + /** + * Get the last updated timestamp for the pipeline run event in ISO8601 format. + * + * @return the lastUpdated value + */ + public DateTime lastUpdated() { + return this.lastUpdated; + } + + /** + * Get the start time of a pipeline run in ISO8601 format. + * + * @return the runStart value + */ + public DateTime runStart() { + return this.runStart; + } + + /** + * Get the end time of a pipeline run in ISO8601 format. + * + * @return the runEnd value + */ + public DateTime runEnd() { + return this.runEnd; + } + + /** + * Get the duration of a pipeline run. + * + * @return the durationInMs value + */ + public Integer durationInMs() { + return this.durationInMs; + } + + /** + * Get the status of a pipeline run. + * + * @return the status value + */ + public String status() { + return this.status; + } + + /** + * Get the message from a pipeline run. + * + * @return the message value + */ + public String message() { + return this.message; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunQueryResponseImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunQueryResponseImpl.java new file mode 100644 index 000000000000..6a5f19a04932 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunQueryResponseImpl.java @@ -0,0 +1,37 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRunQueryResponse; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.List; + +class PipelineRunQueryResponseImpl extends WrapperImpl implements PipelineRunQueryResponse { + private final DataFactoryManager manager; + PipelineRunQueryResponseImpl(PipelineRunQueryResponseInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public String continuationToken() { + return this.inner().continuationToken(); + } + + @Override + public List value() { + return this.inner().value(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunQueryResponseInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunQueryResponseInner.java new file mode 100644 index 000000000000..1cf860a9887c --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunQueryResponseInner.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * A list pipeline runs. + */ +public class PipelineRunQueryResponseInner { + /** + * List of pipeline runs. + */ + @JsonProperty(value = "value", required = true) + private List value; + + /** + * The continuation token for getting the next page of results, if any + * remaining results exist, null otherwise. + */ + @JsonProperty(value = "continuationToken") + private String continuationToken; + + /** + * Get list of pipeline runs. + * + * @return the value value + */ + public List value() { + return this.value; + } + + /** + * Set list of pipeline runs. + * + * @param value the value value to set + * @return the PipelineRunQueryResponseInner object itself. + */ + public PipelineRunQueryResponseInner withValue(List value) { + this.value = value; + return this; + } + + /** + * Get the continuation token for getting the next page of results, if any remaining results exist, null otherwise. + * + * @return the continuationToken value + */ + public String continuationToken() { + return this.continuationToken; + } + + /** + * Set the continuation token for getting the next page of results, if any remaining results exist, null otherwise. + * + * @param continuationToken the continuationToken value to set + * @return the PipelineRunQueryResponseInner object itself. + */ + public PipelineRunQueryResponseInner withContinuationToken(String continuationToken) { + this.continuationToken = continuationToken; + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunsImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunsImpl.java new file mode 100644 index 000000000000..80b508b440bd --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunsImpl.java @@ -0,0 +1,60 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRuns; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRun; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRunQueryResponse; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRunFilterParameters; + +class PipelineRunsImpl extends WrapperImpl implements PipelineRuns { + private final DataFactoryManager manager; + + PipelineRunsImpl(DataFactoryManager manager) { + super(manager.inner().pipelineRuns()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + private PipelineRunImpl wrapModel(PipelineRunInner inner) { + return new PipelineRunImpl(inner, manager()); + } + + @Override + public Observable getAsync(String resourceGroupName, String factoryName, String runId) { + PipelineRunsInner client = this.inner(); + return client.getAsync(resourceGroupName, factoryName, runId) + .map(new Func1() { + @Override + public PipelineRun call(PipelineRunInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Observable queryByFactoryAsync(String resourceGroupName, String factoryName, PipelineRunFilterParameters filterParameters) { + PipelineRunsInner client = this.inner(); + return client.queryByFactoryAsync(resourceGroupName, factoryName, filterParameters) + .map(new Func1() { + @Override + public PipelineRunQueryResponse call(PipelineRunQueryResponseInner inner) { + return new PipelineRunQueryResponseImpl(inner, manager()); + } + }); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunsInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunsInner.java new file mode 100644 index 000000000000..f87502113cd7 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelineRunsInner.java @@ -0,0 +1,255 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRunFilterParameters; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.Query; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in PipelineRuns. + */ +public class PipelineRunsInner { + /** The Retrofit service to perform REST calls. */ + private PipelineRunsService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of PipelineRunsInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public PipelineRunsInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(PipelineRunsService.class); + this.client = client; + } + + /** + * The interface defining all the services for PipelineRuns to be + * used by Retrofit to perform actually REST calls. + */ + interface PipelineRunsService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRuns queryByFactory" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns") + Observable> queryByFactory(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Body PipelineRunFilterParameters filterParameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineRuns get" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelineruns/{runId}") + Observable> get(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("runId") String runId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Query pipeline runs in the factory based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param filterParameters Parameters to filter the pipeline run. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PipelineRunQueryResponseInner object if successful. + */ + public PipelineRunQueryResponseInner queryByFactory(String resourceGroupName, String factoryName, PipelineRunFilterParameters filterParameters) { + return queryByFactoryWithServiceResponseAsync(resourceGroupName, factoryName, filterParameters).toBlocking().single().body(); + } + + /** + * Query pipeline runs in the factory based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param filterParameters Parameters to filter the pipeline run. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture queryByFactoryAsync(String resourceGroupName, String factoryName, PipelineRunFilterParameters filterParameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(queryByFactoryWithServiceResponseAsync(resourceGroupName, factoryName, filterParameters), serviceCallback); + } + + /** + * Query pipeline runs in the factory based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param filterParameters Parameters to filter the pipeline run. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineRunQueryResponseInner object + */ + public Observable queryByFactoryAsync(String resourceGroupName, String factoryName, PipelineRunFilterParameters filterParameters) { + return queryByFactoryWithServiceResponseAsync(resourceGroupName, factoryName, filterParameters).map(new Func1, PipelineRunQueryResponseInner>() { + @Override + public PipelineRunQueryResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Query pipeline runs in the factory based on input filter conditions. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param filterParameters Parameters to filter the pipeline run. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineRunQueryResponseInner object + */ + public Observable> queryByFactoryWithServiceResponseAsync(String resourceGroupName, String factoryName, PipelineRunFilterParameters filterParameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (filterParameters == null) { + throw new IllegalArgumentException("Parameter filterParameters is required and cannot be null."); + } + Validator.validate(filterParameters); + return service.queryByFactory(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), filterParameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = queryByFactoryDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse queryByFactoryDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Get a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PipelineRunInner object if successful. + */ + public PipelineRunInner get(String resourceGroupName, String factoryName, String runId) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, runId).toBlocking().single().body(); + } + + /** + * Get a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAsync(String resourceGroupName, String factoryName, String runId, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, factoryName, runId), serviceCallback); + } + + /** + * Get a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineRunInner object + */ + public Observable getAsync(String resourceGroupName, String factoryName, String runId) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, runId).map(new Func1, PipelineRunInner>() { + @Override + public PipelineRunInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Get a pipeline run by its run ID. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param runId The pipeline run identifier. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineRunInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String factoryName, String runId) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (runId == null) { + throw new IllegalArgumentException("Parameter runId is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(this.client.subscriptionId(), resourceGroupName, factoryName, runId, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelinesImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelinesImpl.java new file mode 100644 index 000000000000..674ec6589be4 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelinesImpl.java @@ -0,0 +1,94 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines; +import rx.Completable; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.CreateRunResponse; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.PipelineResource; + +class PipelinesImpl extends WrapperImpl implements Pipelines { + private final DataFactoryManager manager; + + PipelinesImpl(DataFactoryManager manager) { + super(manager.inner().pipelines()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public PipelineResourceImpl define(String name) { + return wrapModel(name); + } + + private PipelineResourceImpl wrapModel(PipelineResourceInner inner) { + return new PipelineResourceImpl(inner, manager()); + } + + private PipelineResourceImpl wrapModel(String name) { + return new PipelineResourceImpl(name, this.manager()); + } + + @Override + public Observable createRunAsync(String resourceGroupName, String factoryName, String pipelineName) { + PipelinesInner client = this.inner(); + return client.createRunAsync(resourceGroupName, factoryName, pipelineName) + .map(new Func1() { + @Override + public CreateRunResponse call(CreateRunResponseInner inner) { + return new CreateRunResponseImpl(inner, manager()); + } + }); + } + + @Override + public Observable listByFactoryAsync(final String resourceGroupName, final String factoryName) { + PipelinesInner client = this.inner(); + return client.listByFactoryAsync(resourceGroupName, factoryName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public PipelineResource call(PipelineResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Observable getAsync(String resourceGroupName, String factoryName, String pipelineName) { + PipelinesInner client = this.inner(); + return client.getAsync(resourceGroupName, factoryName, pipelineName) + .map(new Func1() { + @Override + public PipelineResource call(PipelineResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Completable deleteAsync(String resourceGroupName, String factoryName, String pipelineName) { + PipelinesInner client = this.inner(); + return client.deleteAsync(resourceGroupName, factoryName, pipelineName).toCompletable(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelinesInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelinesInner.java new file mode 100644 index 000000000000..9aece8a59932 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/PipelinesInner.java @@ -0,0 +1,897 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import okhttp3.ResponseBody; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in Pipelines. + */ +public class PipelinesInner { + /** The Retrofit service to perform REST calls. */ + private PipelinesService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of PipelinesInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public PipelinesInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(PipelinesService.class); + this.client = client; + } + + /** + * The interface defining all the services for Pipelines to be + * used by Retrofit to perform actually REST calls. + */ + interface PipelinesService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines listByFactory" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines") + Observable> listByFactory(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("pipelineName") String pipelineName, @Query("api-version") String apiVersion, @Header("If-Match") String ifMatch, @Body PipelineResourceInner pipeline, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines get" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}") + Observable> get(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("pipelineName") String pipelineName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("pipelineName") String pipelineName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines createRun" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/pipelines/{pipelineName}/createRun") + Observable> createRun(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("pipelineName") String pipelineName, @Query("api-version") String apiVersion, @Body Map parameters, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Pipelines listByFactoryNext" }) + @GET + Observable> listByFactoryNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Lists pipelines. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<PipelineResourceInner> object if successful. + */ + public PagedList listByFactory(final String resourceGroupName, final String factoryName) { + ServiceResponse> response = listByFactorySinglePageAsync(resourceGroupName, factoryName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists pipelines. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryAsync(final String resourceGroupName, final String factoryName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactorySinglePageAsync(resourceGroupName, factoryName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists pipelines. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<PipelineResourceInner> object + */ + public Observable> listByFactoryAsync(final String resourceGroupName, final String factoryName) { + return listByFactoryWithServiceResponseAsync(resourceGroupName, factoryName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists pipelines. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<PipelineResourceInner> object + */ + public Observable>> listByFactoryWithServiceResponseAsync(final String resourceGroupName, final String factoryName) { + return listByFactorySinglePageAsync(resourceGroupName, factoryName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists pipelines. + * + ServiceResponse> * @param resourceGroupName The resource group name. + ServiceResponse> * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<PipelineResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactorySinglePageAsync(final String resourceGroupName, final String factoryName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listByFactory(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PipelineResourceInner object if successful. + */ + public PipelineResourceInner createOrUpdate(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, pipeline).toBlocking().single().body(); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, pipeline), serviceCallback); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, pipeline).map(new Func1, PipelineResourceInner>() { + @Override + public PipelineResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (pipelineName == null) { + throw new IllegalArgumentException("Parameter pipelineName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (pipeline == null) { + throw new IllegalArgumentException("Parameter pipeline is required and cannot be null."); + } + Validator.validate(pipeline); + final String ifMatch = null; + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, pipelineName, this.client.apiVersion(), ifMatch, pipeline, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @param ifMatch ETag of the pipeline entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PipelineResourceInner object if successful. + */ + public PipelineResourceInner createOrUpdate(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, pipeline, ifMatch).toBlocking().single().body(); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @param ifMatch ETag of the pipeline entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline, String ifMatch, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, pipeline, ifMatch), serviceCallback); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @param ifMatch ETag of the pipeline entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, pipeline, ifMatch).map(new Func1, PipelineResourceInner>() { + @Override + public PipelineResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param pipeline Pipeline resource definition. + * @param ifMatch ETag of the pipeline entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String pipelineName, PipelineResourceInner pipeline, String ifMatch) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (pipelineName == null) { + throw new IllegalArgumentException("Parameter pipelineName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (pipeline == null) { + throw new IllegalArgumentException("Parameter pipeline is required and cannot be null."); + } + Validator.validate(pipeline); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, pipelineName, this.client.apiVersion(), ifMatch, pipeline, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse createOrUpdateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PipelineResourceInner object if successful. + */ + public PipelineResourceInner get(String resourceGroupName, String factoryName, String pipelineName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName).toBlocking().single().body(); + } + + /** + * Gets a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAsync(String resourceGroupName, String factoryName, String pipelineName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName), serviceCallback); + } + + /** + * Gets a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineResourceInner object + */ + public Observable getAsync(String resourceGroupName, String factoryName, String pipelineName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName).map(new Func1, PipelineResourceInner>() { + @Override + public PipelineResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PipelineResourceInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String factoryName, String pipelineName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (pipelineName == null) { + throw new IllegalArgumentException("Parameter pipelineName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(this.client.subscriptionId(), resourceGroupName, factoryName, pipelineName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Deletes a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String factoryName, String pipelineName) { + deleteWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName).toBlocking().single().body(); + } + + /** + * Deletes a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String factoryName, String pipelineName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName), serviceCallback); + } + + /** + * Deletes a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String factoryName, String pipelineName) { + return deleteWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String factoryName, String pipelineName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (pipelineName == null) { + throw new IllegalArgumentException("Parameter pipelineName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.delete(this.client.subscriptionId(), resourceGroupName, factoryName, pipelineName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the CreateRunResponseInner object if successful. + */ + public CreateRunResponseInner createRun(String resourceGroupName, String factoryName, String pipelineName) { + return createRunWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName).toBlocking().single().body(); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createRunAsync(String resourceGroupName, String factoryName, String pipelineName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createRunWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName), serviceCallback); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CreateRunResponseInner object + */ + public Observable createRunAsync(String resourceGroupName, String factoryName, String pipelineName) { + return createRunWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName).map(new Func1, CreateRunResponseInner>() { + @Override + public CreateRunResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CreateRunResponseInner object + */ + public Observable> createRunWithServiceResponseAsync(String resourceGroupName, String factoryName, String pipelineName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (pipelineName == null) { + throw new IllegalArgumentException("Parameter pipelineName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + final Map parameters = null; + return service.createRun(this.client.subscriptionId(), resourceGroupName, factoryName, pipelineName, this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createRunDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param parameters Parameters of the pipeline run. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the CreateRunResponseInner object if successful. + */ + public CreateRunResponseInner createRun(String resourceGroupName, String factoryName, String pipelineName, Map parameters) { + return createRunWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, parameters).toBlocking().single().body(); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param parameters Parameters of the pipeline run. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createRunAsync(String resourceGroupName, String factoryName, String pipelineName, Map parameters, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createRunWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, parameters), serviceCallback); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param parameters Parameters of the pipeline run. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CreateRunResponseInner object + */ + public Observable createRunAsync(String resourceGroupName, String factoryName, String pipelineName, Map parameters) { + return createRunWithServiceResponseAsync(resourceGroupName, factoryName, pipelineName, parameters).map(new Func1, CreateRunResponseInner>() { + @Override + public CreateRunResponseInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates a run of a pipeline. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param pipelineName The pipeline name. + * @param parameters Parameters of the pipeline run. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the CreateRunResponseInner object + */ + public Observable> createRunWithServiceResponseAsync(String resourceGroupName, String factoryName, String pipelineName, Map parameters) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (pipelineName == null) { + throw new IllegalArgumentException("Parameter pipelineName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Validator.validate(parameters); + return service.createRun(this.client.subscriptionId(), resourceGroupName, factoryName, pipelineName, this.client.apiVersion(), parameters, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createRunDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse createRunDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(202, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists pipelines. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<PipelineResourceInner> object if successful. + */ + public PagedList listByFactoryNext(final String nextPageLink) { + ServiceResponse> response = listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists pipelines. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactoryNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists pipelines. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<PipelineResourceInner> object + */ + public Observable> listByFactoryNextAsync(final String nextPageLink) { + return listByFactoryNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists pipelines. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<PipelineResourceInner> object + */ + public Observable>> listByFactoryNextWithServiceResponseAsync(final String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists pipelines. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<PipelineResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactoryNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByFactoryNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/SelfHostedIntegrationRuntimeNodeImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/SelfHostedIntegrationRuntimeNodeImpl.java new file mode 100644 index 000000000000..c16a32f90267 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/SelfHostedIntegrationRuntimeNodeImpl.java @@ -0,0 +1,120 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.SelfHostedIntegrationRuntimeNode; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import java.util.Map; +import org.joda.time.DateTime; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeUpdateResult; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.SelfHostedIntegrationRuntimeNodeStatus; + +class SelfHostedIntegrationRuntimeNodeImpl extends WrapperImpl implements SelfHostedIntegrationRuntimeNode { + private final DataFactoryManager manager; + SelfHostedIntegrationRuntimeNodeImpl(SelfHostedIntegrationRuntimeNodeInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Map capabilities() { + return this.inner().capabilities(); + } + + @Override + public Integer concurrentJobsLimit() { + return this.inner().concurrentJobsLimit(); + } + + @Override + public DateTime expiryTime() { + return this.inner().expiryTime(); + } + + @Override + public String hostServiceUri() { + return this.inner().hostServiceUri(); + } + + @Override + public Boolean isActiveDispatcher() { + return this.inner().isActiveDispatcher(); + } + + @Override + public DateTime lastConnectTime() { + return this.inner().lastConnectTime(); + } + + @Override + public DateTime lastEndUpdateTime() { + return this.inner().lastEndUpdateTime(); + } + + @Override + public DateTime lastStartTime() { + return this.inner().lastStartTime(); + } + + @Override + public DateTime lastStartUpdateTime() { + return this.inner().lastStartUpdateTime(); + } + + @Override + public DateTime lastStopTime() { + return this.inner().lastStopTime(); + } + + @Override + public IntegrationRuntimeUpdateResult lastUpdateResult() { + return this.inner().lastUpdateResult(); + } + + @Override + public String machineName() { + return this.inner().machineName(); + } + + @Override + public Integer maxConcurrentJobs() { + return this.inner().maxConcurrentJobs(); + } + + @Override + public String nodeName() { + return this.inner().nodeName(); + } + + @Override + public DateTime registerTime() { + return this.inner().registerTime(); + } + + @Override + public SelfHostedIntegrationRuntimeNodeStatus status() { + return this.inner().status(); + } + + @Override + public String version() { + return this.inner().version(); + } + + @Override + public String versionStatus() { + return this.inner().versionStatus(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/SelfHostedIntegrationRuntimeNodeInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/SelfHostedIntegrationRuntimeNodeInner.java new file mode 100644 index 000000000000..510b5aad1bca --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/SelfHostedIntegrationRuntimeNodeInner.java @@ -0,0 +1,297 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.SelfHostedIntegrationRuntimeNodeStatus; +import java.util.Map; +import org.joda.time.DateTime; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.IntegrationRuntimeUpdateResult; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Properties of Self-hosted integration runtime node. + */ +public class SelfHostedIntegrationRuntimeNodeInner { + /** + * Name of the integration runtime node. + */ + @JsonProperty(value = "nodeName", access = JsonProperty.Access.WRITE_ONLY) + private String nodeName; + + /** + * Machine name of the integration runtime node. + */ + @JsonProperty(value = "machineName", access = JsonProperty.Access.WRITE_ONLY) + private String machineName; + + /** + * URI for the host machine of the integration runtime. + */ + @JsonProperty(value = "hostServiceUri", access = JsonProperty.Access.WRITE_ONLY) + private String hostServiceUri; + + /** + * Status of the integration runtime node. Possible values include: + * 'NeedRegistration', 'Online', 'Limited', 'Offline', 'Upgrading', + * 'Initializing', 'InitializeFailed'. + */ + @JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY) + private SelfHostedIntegrationRuntimeNodeStatus status; + + /** + * The integration runtime capabilities dictionary. + */ + @JsonProperty(value = "capabilities", access = JsonProperty.Access.WRITE_ONLY) + private Map capabilities; + + /** + * Status of the integration runtime node version. + */ + @JsonProperty(value = "versionStatus", access = JsonProperty.Access.WRITE_ONLY) + private String versionStatus; + + /** + * Version of the integration runtime node. + */ + @JsonProperty(value = "version", access = JsonProperty.Access.WRITE_ONLY) + private String version; + + /** + * The time at which the integration runtime node was registered in ISO8601 + * format. + */ + @JsonProperty(value = "registerTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime registerTime; + + /** + * The most recent time at which the integration runtime was connected in + * ISO8601 format. + */ + @JsonProperty(value = "lastConnectTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime lastConnectTime; + + /** + * The time at which the integration runtime will expire in ISO8601 format. + */ + @JsonProperty(value = "expiryTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime expiryTime; + + /** + * The time the node last started up. + */ + @JsonProperty(value = "lastStartTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime lastStartTime; + + /** + * The integration runtime node last stop time. + */ + @JsonProperty(value = "lastStopTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime lastStopTime; + + /** + * The result of the last integration runtime node update. Possible values + * include: 'Succeed', 'Fail'. + */ + @JsonProperty(value = "lastUpdateResult", access = JsonProperty.Access.WRITE_ONLY) + private IntegrationRuntimeUpdateResult lastUpdateResult; + + /** + * The last time for the integration runtime node update start. + */ + @JsonProperty(value = "lastStartUpdateTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime lastStartUpdateTime; + + /** + * The last time for the integration runtime node update end. + */ + @JsonProperty(value = "lastEndUpdateTime", access = JsonProperty.Access.WRITE_ONLY) + private DateTime lastEndUpdateTime; + + /** + * Indicates whether this node is the active dispatcher for integration + * runtime requests. + */ + @JsonProperty(value = "isActiveDispatcher", access = JsonProperty.Access.WRITE_ONLY) + private Boolean isActiveDispatcher; + + /** + * Maximum concurrent jobs on the integration runtime node. + */ + @JsonProperty(value = "concurrentJobsLimit", access = JsonProperty.Access.WRITE_ONLY) + private Integer concurrentJobsLimit; + + /** + * The maximum concurrent jobs in this integration runtime. + */ + @JsonProperty(value = "maxConcurrentJobs", access = JsonProperty.Access.WRITE_ONLY) + private Integer maxConcurrentJobs; + + /** + * Get name of the integration runtime node. + * + * @return the nodeName value + */ + public String nodeName() { + return this.nodeName; + } + + /** + * Get machine name of the integration runtime node. + * + * @return the machineName value + */ + public String machineName() { + return this.machineName; + } + + /** + * Get uRI for the host machine of the integration runtime. + * + * @return the hostServiceUri value + */ + public String hostServiceUri() { + return this.hostServiceUri; + } + + /** + * Get status of the integration runtime node. Possible values include: 'NeedRegistration', 'Online', 'Limited', 'Offline', 'Upgrading', 'Initializing', 'InitializeFailed'. + * + * @return the status value + */ + public SelfHostedIntegrationRuntimeNodeStatus status() { + return this.status; + } + + /** + * Get the integration runtime capabilities dictionary. + * + * @return the capabilities value + */ + public Map capabilities() { + return this.capabilities; + } + + /** + * Get status of the integration runtime node version. + * + * @return the versionStatus value + */ + public String versionStatus() { + return this.versionStatus; + } + + /** + * Get version of the integration runtime node. + * + * @return the version value + */ + public String version() { + return this.version; + } + + /** + * Get the time at which the integration runtime node was registered in ISO8601 format. + * + * @return the registerTime value + */ + public DateTime registerTime() { + return this.registerTime; + } + + /** + * Get the most recent time at which the integration runtime was connected in ISO8601 format. + * + * @return the lastConnectTime value + */ + public DateTime lastConnectTime() { + return this.lastConnectTime; + } + + /** + * Get the time at which the integration runtime will expire in ISO8601 format. + * + * @return the expiryTime value + */ + public DateTime expiryTime() { + return this.expiryTime; + } + + /** + * Get the time the node last started up. + * + * @return the lastStartTime value + */ + public DateTime lastStartTime() { + return this.lastStartTime; + } + + /** + * Get the integration runtime node last stop time. + * + * @return the lastStopTime value + */ + public DateTime lastStopTime() { + return this.lastStopTime; + } + + /** + * Get the result of the last integration runtime node update. Possible values include: 'Succeed', 'Fail'. + * + * @return the lastUpdateResult value + */ + public IntegrationRuntimeUpdateResult lastUpdateResult() { + return this.lastUpdateResult; + } + + /** + * Get the last time for the integration runtime node update start. + * + * @return the lastStartUpdateTime value + */ + public DateTime lastStartUpdateTime() { + return this.lastStartUpdateTime; + } + + /** + * Get the last time for the integration runtime node update end. + * + * @return the lastEndUpdateTime value + */ + public DateTime lastEndUpdateTime() { + return this.lastEndUpdateTime; + } + + /** + * Get indicates whether this node is the active dispatcher for integration runtime requests. + * + * @return the isActiveDispatcher value + */ + public Boolean isActiveDispatcher() { + return this.isActiveDispatcher; + } + + /** + * Get maximum concurrent jobs on the integration runtime node. + * + * @return the concurrentJobsLimit value + */ + public Integer concurrentJobsLimit() { + return this.concurrentJobsLimit; + } + + /** + * Get the maximum concurrent jobs in this integration runtime. + * + * @return the maxConcurrentJobs value + */ + public Integer maxConcurrentJobs() { + return this.maxConcurrentJobs; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerInner.java new file mode 100644 index 000000000000..6d34afcf225b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerInner.java @@ -0,0 +1,98 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerRuntimeState; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.annotation.JsonSubTypes; + +/** + * Azure data factory nested object which contains information about creating + * pipeline run. + */ +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type") +@JsonTypeName("Trigger") +@JsonSubTypes({ + @JsonSubTypes.Type(name = "TumblingWindowTrigger", value = TumblingWindowTrigger.class), + @JsonSubTypes.Type(name = "MultiplePipelineTrigger", value = MultiplePipelineTrigger.class) +}) +public class TriggerInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Trigger description. + */ + @JsonProperty(value = "description") + private String description; + + /** + * Indicates if trigger is running or not. Updated when Start/Stop APIs are + * called on the Trigger. Possible values include: 'Started', 'Stopped', + * 'Disabled'. + */ + @JsonProperty(value = "runtimeState", access = JsonProperty.Access.WRITE_ONLY) + private TriggerRuntimeState runtimeState; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the TriggerInner object itself. + */ + public TriggerInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get trigger description. + * + * @return the description value + */ + public String description() { + return this.description; + } + + /** + * Set trigger description. + * + * @param description the description value to set + * @return the TriggerInner object itself. + */ + public TriggerInner withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get indicates if trigger is running or not. Updated when Start/Stop APIs are called on the Trigger. Possible values include: 'Started', 'Stopped', 'Disabled'. + * + * @return the runtimeState value + */ + public TriggerRuntimeState runtimeState() { + return this.runtimeState; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerResourceImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerResourceImpl.java new file mode 100644 index 000000000000..5ebe6abe9f94 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerResourceImpl.java @@ -0,0 +1,154 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerResource; +import com.microsoft.azure.arm.model.implementation.CreatableUpdatableImpl; +import rx.Observable; +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerRuntimeState; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.; +import rx.functions.Func1; + +class TriggerResourceImpl extends CreatableUpdatableImpl implements TriggerResource, TriggerResource.Definition, TriggerResource.Update { + private final DataFactoryManager manager; + private String resourceGroupName; + private String factoryName; + private String triggerName; + private String cifMatch; + private TriggerInner cproperties; + private String uifMatch; + private TriggerInner uproperties; + + TriggerResourceImpl(String name, DataFactoryManager manager) { + super(name, new TriggerResourceInner()); + this.manager = manager; + // Set resource name + this.triggerName = name; + // + this.cproperties = new TriggerInner(); + this.uproperties = new TriggerInner(); + } + + TriggerResourceImpl(TriggerResourceInner inner, DataFactoryManager manager) { + super(inner.name(), inner); + this.manager = manager; + // Set resource name + this.triggerName = inner.name(); + // set resource ancestor and positional variables + this.resourceGroupName = IdParsingUtils.getValueFromIdByName(inner.id(), "resourceGroups"); + this.factoryName = IdParsingUtils.getValueFromIdByName(inner.id(), "factories"); + this.triggerName = IdParsingUtils.getValueFromIdByName(inner.id(), "triggers"); + // + this.cproperties = new TriggerInner(); + this.uproperties = new TriggerInner(); + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public Observable createResourceAsync() { + TriggersInner client = this.manager().inner().triggers(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.triggerName, this.cproperties, this.cifMatch) + .map(new Func1() { + @Override + public TriggerResourceInner call(TriggerResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + public Observable updateResourceAsync() { + TriggersInner client = this.manager().inner().triggers(); + return client.createOrUpdateAsync(this.resourceGroupName, this.factoryName, this.triggerName, this.uproperties, this.uifMatch) + .map(new Func1() { + @Override + public TriggerResourceInner call(TriggerResourceInner resource) { + resetCreateUpdateParameters(); + return resource; + } + }) + .map(innerToFluentMap(this)); + } + + @Override + protected Observable getInnerAsync() { + TriggersInner client = this.manager().inner().triggers(); + return client.getAsync(this.resourceGroupName, this.factoryName, this.triggerName); + } + + @Override + public boolean isInCreateMode() { + return this.inner().id() == null; + } + + private void resetCreateUpdateParameters() { + this.cproperties = new TriggerInner(); + this.uproperties = new TriggerInner(); + } + + @Override + public String etag() { + return this.inner().etag(); + } + + @Override + public String id() { + return this.inner().id(); + } + + @Override + public String name() { + return this.inner().name(); + } + + @Override + public TriggerInner properties() { + return this.inner().properties(); + } + + @Override + public String type() { + return this.inner().type(); + } + + @Override + public TriggerResourceImpl withExistingFactory(String resourceGroupName, String factoryName) { + this.resourceGroupName = resourceGroupName; + this.factoryName = factoryName; + return this; + } + + @Override + public TriggerResourceImpl withIfMatch(String ifMatch) { + if (isInCreateMode()) { + this.cifMatch = ifMatch; + } else { + this.uifMatch = ifMatch; + } + return this; + } + + @Override + public TriggerResourceImpl withProperties(TriggerInner properties) { + if (isInCreateMode()) { + this.cproperties = properties; + } else { + this.uproperties = properties; + } + return this; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerResourceInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerResourceInner.java new file mode 100644 index 000000000000..566a4eacc51f --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerResourceInner.java @@ -0,0 +1,89 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.microsoft.azure.SubResource; + +/** + * Trigger resource type. + */ +public class TriggerResourceInner extends SubResource { + /** + * Properties of the trigger. + */ + @JsonProperty(value = "properties", required = true) + private TriggerInner properties; + + /** + * The resource name. + */ + @JsonProperty(value = "name", access = JsonProperty.Access.WRITE_ONLY) + private String name; + + /** + * The resource type. + */ + @JsonProperty(value = "type", access = JsonProperty.Access.WRITE_ONLY) + private String type; + + /** + * Etag identifies change in the resource. + */ + @JsonProperty(value = "etag", access = JsonProperty.Access.WRITE_ONLY) + private String etag; + + /** + * Get properties of the trigger. + * + * @return the properties value + */ + public TriggerInner properties() { + return this.properties; + } + + /** + * Set properties of the trigger. + * + * @param properties the properties value to set + * @return the TriggerResourceInner object itself. + */ + public TriggerResourceInner withProperties(TriggerInner properties) { + this.properties = properties; + return this; + } + + /** + * Get the resource name. + * + * @return the name value + */ + public String name() { + return this.name; + } + + /** + * Get the resource type. + * + * @return the type value + */ + public String type() { + return this.type; + } + + /** + * Get etag identifies change in the resource. + * + * @return the etag value + */ + public String etag() { + return this.etag; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerRunImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerRunImpl.java new file mode 100644 index 000000000000..14b40dc2b742 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerRunImpl.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerRun; +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import rx.Observable; +import java.util.Map; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerRunStatus; +import org.joda.time.DateTime; + +class TriggerRunImpl extends WrapperImpl implements TriggerRun { + private final DataFactoryManager manager; + + TriggerRunImpl(TriggerRunInner inner, DataFactoryManager manager) { + super(inner); + this.manager = manager; + } + + @Override + public DataFactoryManager manager() { + return this.manager; + } + + + + @Override + public Map additionalProperties() { + return this.inner().additionalProperties(); + } + + @Override + public String message() { + return this.inner().message(); + } + + @Override + public Map properties() { + return this.inner().properties(); + } + + @Override + public TriggerRunStatus status() { + return this.inner().status(); + } + + @Override + public Map triggeredPipelines() { + return this.inner().triggeredPipelines(); + } + + @Override + public String triggerName() { + return this.inner().triggerName(); + } + + @Override + public String triggerRunId() { + return this.inner().triggerRunId(); + } + + @Override + public DateTime triggerRunTimestamp() { + return this.inner().triggerRunTimestamp(); + } + + @Override + public String triggerType() { + return this.inner().triggerType(); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerRunInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerRunInner.java new file mode 100644 index 000000000000..da524f923709 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggerRunInner.java @@ -0,0 +1,168 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import java.util.Map; +import org.joda.time.DateTime; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerRunStatus; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Trigger runs. + */ +public class TriggerRunInner { + /** + * Unmatched properties from the message are deserialized this collection. + */ + @JsonProperty(value = "") + private Map additionalProperties; + + /** + * Trigger run id. + */ + @JsonProperty(value = "triggerRunId", access = JsonProperty.Access.WRITE_ONLY) + private String triggerRunId; + + /** + * Trigger name. + */ + @JsonProperty(value = "triggerName", access = JsonProperty.Access.WRITE_ONLY) + private String triggerName; + + /** + * Trigger type. + */ + @JsonProperty(value = "triggerType", access = JsonProperty.Access.WRITE_ONLY) + private String triggerType; + + /** + * Trigger run start time. + */ + @JsonProperty(value = "triggerRunTimestamp", access = JsonProperty.Access.WRITE_ONLY) + private DateTime triggerRunTimestamp; + + /** + * Trigger run status. Possible values include: 'Succeeded', 'Failed', + * 'Inprogress'. + */ + @JsonProperty(value = "status", access = JsonProperty.Access.WRITE_ONLY) + private TriggerRunStatus status; + + /** + * Trigger error message. + */ + @JsonProperty(value = "message", access = JsonProperty.Access.WRITE_ONLY) + private String message; + + /** + * List of property name and value related to trigger run. Name, value pair + * depends on type of trigger. + */ + @JsonProperty(value = "properties", access = JsonProperty.Access.WRITE_ONLY) + private Map properties; + + /** + * List of pipeline name and run Id triggered by the trigger run. + */ + @JsonProperty(value = "triggeredPipelines", access = JsonProperty.Access.WRITE_ONLY) + private Map triggeredPipelines; + + /** + * Get unmatched properties from the message are deserialized this collection. + * + * @return the additionalProperties value + */ + public Map additionalProperties() { + return this.additionalProperties; + } + + /** + * Set unmatched properties from the message are deserialized this collection. + * + * @param additionalProperties the additionalProperties value to set + * @return the TriggerRunInner object itself. + */ + public TriggerRunInner withAdditionalProperties(Map additionalProperties) { + this.additionalProperties = additionalProperties; + return this; + } + + /** + * Get trigger run id. + * + * @return the triggerRunId value + */ + public String triggerRunId() { + return this.triggerRunId; + } + + /** + * Get trigger name. + * + * @return the triggerName value + */ + public String triggerName() { + return this.triggerName; + } + + /** + * Get trigger type. + * + * @return the triggerType value + */ + public String triggerType() { + return this.triggerType; + } + + /** + * Get trigger run start time. + * + * @return the triggerRunTimestamp value + */ + public DateTime triggerRunTimestamp() { + return this.triggerRunTimestamp; + } + + /** + * Get trigger run status. Possible values include: 'Succeeded', 'Failed', 'Inprogress'. + * + * @return the status value + */ + public TriggerRunStatus status() { + return this.status; + } + + /** + * Get trigger error message. + * + * @return the message value + */ + public String message() { + return this.message; + } + + /** + * Get list of property name and value related to trigger run. Name, value pair depends on type of trigger. + * + * @return the properties value + */ + public Map properties() { + return this.properties; + } + + /** + * Get list of pipeline name and run Id triggered by the trigger run. + * + * @return the triggeredPipelines value + */ + public Map triggeredPipelines() { + return this.triggeredPipelines; + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggersImpl.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggersImpl.java new file mode 100644 index 000000000000..2155cf6ce20b --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggersImpl.java @@ -0,0 +1,116 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + * + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import com.microsoft.azure.arm.model.implementation.WrapperImpl; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers; +import rx.Completable; +import rx.Observable; +import rx.functions.Func1; +import com.microsoft.azure.Page; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerResource; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.TriggerRun; + +class TriggersImpl extends WrapperImpl implements Triggers { + private final DataFactoryManager manager; + + TriggersImpl(DataFactoryManager manager) { + super(manager.inner().triggers()); + this.manager = manager; + } + + public DataFactoryManager manager() { + return this.manager; + } + + @Override + public TriggerResourceImpl define(String name) { + return wrapModel(name); + } + + private TriggerResourceImpl wrapModel(TriggerResourceInner inner) { + return new TriggerResourceImpl(inner, manager()); + } + + private TriggerResourceImpl wrapModel(String name) { + return new TriggerResourceImpl(name, this.manager()); + } + + @Override + public Completable startAsync(String resourceGroupName, String factoryName, String triggerName) { + TriggersInner client = this.inner(); + return client.startAsync(resourceGroupName, factoryName, triggerName).toCompletable(); + } + + @Override + public Completable stopAsync(String resourceGroupName, String factoryName, String triggerName) { + TriggersInner client = this.inner(); + return client.stopAsync(resourceGroupName, factoryName, triggerName).toCompletable(); + } + + @Override + public Observable listByFactoryAsync(final String resourceGroupName, final String factoryName) { + TriggersInner client = this.inner(); + return client.listByFactoryAsync(resourceGroupName, factoryName) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public TriggerResource call(TriggerResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Observable getAsync(String resourceGroupName, String factoryName, String triggerName) { + TriggersInner client = this.inner(); + return client.getAsync(resourceGroupName, factoryName, triggerName) + .map(new Func1() { + @Override + public TriggerResource call(TriggerResourceInner inner) { + return wrapModel(inner); + } + }); + } + + @Override + public Completable deleteAsync(String resourceGroupName, String factoryName, String triggerName) { + TriggersInner client = this.inner(); + return client.deleteAsync(resourceGroupName, factoryName, triggerName).toCompletable(); + } + + private TriggerRunImpl wrapTriggerRunModel(TriggerRunInner inner) { + return new TriggerRunImpl(inner, manager()); + } + + @Override + public Observable listRunsAsync(final String resourceGroupName, final String factoryName, final String triggerName, final DateTime startTime, final DateTime endTime) { + TriggersInner client = this.inner(); + return client.listRunsAsync(resourceGroupName, factoryName, triggerName, startTime, endTime) + .flatMapIterable(new Func1, Iterable>() { + @Override + public Iterable call(Page page) { + return page.items(); + } + }) + .map(new Func1() { + @Override + public TriggerRun call(TriggerRunInner inner) { + return wrapTriggerRunModel(inner); + } + }); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggersInner.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggersInner.java new file mode 100644 index 000000000000..72c3df87879d --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/TriggersInner.java @@ -0,0 +1,1328 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + * + * Code generated by Microsoft (R) AutoRest Code Generator. + */ + +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; + +import retrofit2.Retrofit; +import com.google.common.reflect.TypeToken; +import com.microsoft.azure.AzureServiceFuture; +import com.microsoft.azure.ListOperationCallback; +import com.microsoft.azure.management.datafactory.v2017_09_01_preview.ErrorResponseException; +import com.microsoft.azure.Page; +import com.microsoft.azure.PagedList; +import com.microsoft.rest.ServiceCallback; +import com.microsoft.rest.ServiceFuture; +import com.microsoft.rest.ServiceResponse; +import com.microsoft.rest.Validator; +import java.io.IOException; +import java.util.List; +import okhttp3.ResponseBody; +import org.joda.time.DateTime; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.Header; +import retrofit2.http.Headers; +import retrofit2.http.HTTP; +import retrofit2.http.Path; +import retrofit2.http.POST; +import retrofit2.http.PUT; +import retrofit2.http.Query; +import retrofit2.http.Url; +import retrofit2.Response; +import rx.functions.Func1; +import rx.Observable; + +/** + * An instance of this class provides access to all the operations defined + * in Triggers. + */ +public class TriggersInner { + /** The Retrofit service to perform REST calls. */ + private TriggersService service; + /** The service client containing this operation class. */ + private DataFactoryManagementClientImpl client; + + /** + * Initializes an instance of TriggersInner. + * + * @param retrofit the Retrofit instance built from a Retrofit Builder. + * @param client the instance of the service client containing this operation class. + */ + public TriggersInner(Retrofit retrofit, DataFactoryManagementClientImpl client) { + this.service = retrofit.create(TriggersService.class); + this.client = client; + } + + /** + * The interface defining all the services for Triggers to be + * used by Retrofit to perform actually REST calls. + */ + interface TriggersService { + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers listByFactory" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers") + Observable> listByFactory(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers createOrUpdate" }) + @PUT("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}") + Observable> createOrUpdate(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Header("If-Match") String ifMatch, @Header("accept-language") String acceptLanguage, @Body TriggerResourceInner trigger, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers get" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}") + Observable> get(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers delete" }) + @HTTP(path = "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}", method = "DELETE", hasBody = true) + Observable> delete(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers start" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}/start") + Observable> start(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers beginStart" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}/start") + Observable> beginStart(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers stop" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}/stop") + Observable> stop(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers beginStop" }) + @POST("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}/stop") + Observable> beginStop(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers listRuns" }) + @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory/factories/{factoryName}/triggers/{triggerName}/triggerruns") + Observable> listRuns(@Path("subscriptionId") String subscriptionId, @Path("resourceGroupName") String resourceGroupName, @Path("factoryName") String factoryName, @Path("triggerName") String triggerName, @Query("api-version") String apiVersion, @Query("startTime") DateTime startTime, @Query("endTime") DateTime endTime, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers listByFactoryNext" }) + @GET + Observable> listByFactoryNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.datafactory.v2017_09_01_preview.Triggers listRunsNext" }) + @GET + Observable> listRunsNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent); + + } + + /** + * Lists triggers. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<TriggerResourceInner> object if successful. + */ + public PagedList listByFactory(final String resourceGroupName, final String factoryName) { + ServiceResponse> response = listByFactorySinglePageAsync(resourceGroupName, factoryName).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists triggers. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryAsync(final String resourceGroupName, final String factoryName, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactorySinglePageAsync(resourceGroupName, factoryName), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists triggers. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerResourceInner> object + */ + public Observable> listByFactoryAsync(final String resourceGroupName, final String factoryName) { + return listByFactoryWithServiceResponseAsync(resourceGroupName, factoryName) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists triggers. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerResourceInner> object + */ + public Observable>> listByFactoryWithServiceResponseAsync(final String resourceGroupName, final String factoryName) { + return listByFactorySinglePageAsync(resourceGroupName, factoryName) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists triggers. + * + ServiceResponse> * @param resourceGroupName The resource group name. + ServiceResponse> * @param factoryName The factory name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<TriggerResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactorySinglePageAsync(final String resourceGroupName, final String factoryName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.listByFactory(this.client.subscriptionId(), resourceGroupName, factoryName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the TriggerResourceInner object if successful. + */ + public TriggerResourceInner createOrUpdate(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, triggerName, properties).toBlocking().single().body(); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, triggerName, properties), serviceCallback); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the TriggerResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, triggerName, properties).map(new Func1, TriggerResourceInner>() { + @Override + public TriggerResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the TriggerResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + final String ifMatch = null; + TriggerResourceInner trigger = new TriggerResourceInner(); + trigger.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), trigger, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @param ifMatch ETag of the trigger entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the TriggerResourceInner object if successful. + */ + public TriggerResourceInner createOrUpdate(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, triggerName, properties, ifMatch).toBlocking().single().body(); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @param ifMatch ETag of the trigger entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture createOrUpdateAsync(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties, String ifMatch, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, triggerName, properties, ifMatch), serviceCallback); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @param ifMatch ETag of the trigger entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the TriggerResourceInner object + */ + public Observable createOrUpdateAsync(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties, String ifMatch) { + return createOrUpdateWithServiceResponseAsync(resourceGroupName, factoryName, triggerName, properties, ifMatch).map(new Func1, TriggerResourceInner>() { + @Override + public TriggerResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Creates or updates a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param properties Properties of the trigger. + * @param ifMatch ETag of the trigger entity. Should only be specified for update, for which it should match existing entity or can be * for unconditional update. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the TriggerResourceInner object + */ + public Observable> createOrUpdateWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName, TriggerInner properties, String ifMatch) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (properties == null) { + throw new IllegalArgumentException("Parameter properties is required and cannot be null."); + } + Validator.validate(properties); + TriggerResourceInner trigger = new TriggerResourceInner(); + trigger.withProperties(properties); + return service.createOrUpdate(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), ifMatch, this.client.acceptLanguage(), trigger, this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = createOrUpdateDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse createOrUpdateDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Gets a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the TriggerResourceInner object if successful. + */ + public TriggerResourceInner get(String resourceGroupName, String factoryName, String triggerName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).toBlocking().single().body(); + } + + /** + * Gets a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture getAsync(String resourceGroupName, String factoryName, String triggerName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, factoryName, triggerName), serviceCallback); + } + + /** + * Gets a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the TriggerResourceInner object + */ + public Observable getAsync(String resourceGroupName, String factoryName, String triggerName) { + return getWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).map(new Func1, TriggerResourceInner>() { + @Override + public TriggerResourceInner call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Gets a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the TriggerResourceInner object + */ + public Observable> getWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.get(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = getDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse getDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Deletes a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void delete(String resourceGroupName, String factoryName, String triggerName) { + deleteWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).toBlocking().single().body(); + } + + /** + * Deletes a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture deleteAsync(String resourceGroupName, String factoryName, String triggerName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(deleteWithServiceResponseAsync(resourceGroupName, factoryName, triggerName), serviceCallback); + } + + /** + * Deletes a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable deleteAsync(String resourceGroupName, String factoryName, String triggerName) { + return deleteWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Deletes a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> deleteWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.delete(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = deleteDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse deleteDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .register(204, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void start(String resourceGroupName, String factoryName, String triggerName) { + startWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).toBlocking().last().body(); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture startAsync(String resourceGroupName, String factoryName, String triggerName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(startWithServiceResponseAsync(resourceGroupName, factoryName, triggerName), serviceCallback); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable startAsync(String resourceGroupName, String factoryName, String triggerName) { + return startWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> startWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Observable> observable = service.start(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginStart(String resourceGroupName, String factoryName, String triggerName) { + beginStartWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).toBlocking().single().body(); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginStartAsync(String resourceGroupName, String factoryName, String triggerName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginStartWithServiceResponseAsync(resourceGroupName, factoryName, triggerName), serviceCallback); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginStartAsync(String resourceGroupName, String factoryName, String triggerName) { + return beginStartWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Starts a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginStartWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.beginStart(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginStartDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginStartDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void stop(String resourceGroupName, String factoryName, String triggerName) { + stopWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).toBlocking().last().body(); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture stopAsync(String resourceGroupName, String factoryName, String triggerName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(stopWithServiceResponseAsync(resourceGroupName, factoryName, triggerName), serviceCallback); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable stopAsync(String resourceGroupName, String factoryName, String triggerName) { + return stopWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable for the request + */ + public Observable> stopWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + Observable> observable = service.stop(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()); + return client.getAzureClient().getPostOrDeleteResultAsync(observable, new TypeToken() { }.getType()); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + */ + public void beginStop(String resourceGroupName, String factoryName, String triggerName) { + beginStopWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).toBlocking().single().body(); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture beginStopAsync(String resourceGroupName, String factoryName, String triggerName, final ServiceCallback serviceCallback) { + return ServiceFuture.fromResponse(beginStopWithServiceResponseAsync(resourceGroupName, factoryName, triggerName), serviceCallback); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable beginStopAsync(String resourceGroupName, String factoryName, String triggerName) { + return beginStopWithServiceResponseAsync(resourceGroupName, factoryName, triggerName).map(new Func1, Void>() { + @Override + public Void call(ServiceResponse response) { + return response.body(); + } + }); + } + + /** + * Stops a trigger. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceResponse} object if successful. + */ + public Observable> beginStopWithServiceResponseAsync(String resourceGroupName, String factoryName, String triggerName) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + return service.beginStop(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>() { + @Override + public Observable> call(Response response) { + try { + ServiceResponse clientResponse = beginStopDelegate(response); + return Observable.just(clientResponse); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse beginStopDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * List trigger runs. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param startTime Start time for trigger runs. + * @param endTime End time for trigger runs. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<TriggerRunInner> object if successful. + */ + public PagedList listRuns(final String resourceGroupName, final String factoryName, final String triggerName, final DateTime startTime, final DateTime endTime) { + ServiceResponse> response = listRunsSinglePageAsync(resourceGroupName, factoryName, triggerName, startTime, endTime).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listRunsNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * List trigger runs. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param startTime Start time for trigger runs. + * @param endTime End time for trigger runs. + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listRunsAsync(final String resourceGroupName, final String factoryName, final String triggerName, final DateTime startTime, final DateTime endTime, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listRunsSinglePageAsync(resourceGroupName, factoryName, triggerName, startTime, endTime), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listRunsNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * List trigger runs. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param startTime Start time for trigger runs. + * @param endTime End time for trigger runs. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerRunInner> object + */ + public Observable> listRunsAsync(final String resourceGroupName, final String factoryName, final String triggerName, final DateTime startTime, final DateTime endTime) { + return listRunsWithServiceResponseAsync(resourceGroupName, factoryName, triggerName, startTime, endTime) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * List trigger runs. + * + * @param resourceGroupName The resource group name. + * @param factoryName The factory name. + * @param triggerName The trigger name. + * @param startTime Start time for trigger runs. + * @param endTime End time for trigger runs. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerRunInner> object + */ + public Observable>> listRunsWithServiceResponseAsync(final String resourceGroupName, final String factoryName, final String triggerName, final DateTime startTime, final DateTime endTime) { + return listRunsSinglePageAsync(resourceGroupName, factoryName, triggerName, startTime, endTime) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listRunsNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * List trigger runs. + * + ServiceResponse> * @param resourceGroupName The resource group name. + ServiceResponse> * @param factoryName The factory name. + ServiceResponse> * @param triggerName The trigger name. + ServiceResponse> * @param startTime Start time for trigger runs. + ServiceResponse> * @param endTime End time for trigger runs. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<TriggerRunInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listRunsSinglePageAsync(final String resourceGroupName, final String factoryName, final String triggerName, final DateTime startTime, final DateTime endTime) { + if (this.client.subscriptionId() == null) { + throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null."); + } + if (resourceGroupName == null) { + throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."); + } + if (factoryName == null) { + throw new IllegalArgumentException("Parameter factoryName is required and cannot be null."); + } + if (triggerName == null) { + throw new IllegalArgumentException("Parameter triggerName is required and cannot be null."); + } + if (this.client.apiVersion() == null) { + throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."); + } + if (startTime == null) { + throw new IllegalArgumentException("Parameter startTime is required and cannot be null."); + } + if (endTime == null) { + throw new IllegalArgumentException("Parameter endTime is required and cannot be null."); + } + return service.listRuns(this.client.subscriptionId(), resourceGroupName, factoryName, triggerName, this.client.apiVersion(), startTime, endTime, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listRunsDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listRunsDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * Lists triggers. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<TriggerResourceInner> object if successful. + */ + public PagedList listByFactoryNext(final String nextPageLink) { + ServiceResponse> response = listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * Lists triggers. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listByFactoryNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listByFactoryNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * Lists triggers. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerResourceInner> object + */ + public Observable> listByFactoryNextAsync(final String nextPageLink) { + return listByFactoryNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * Lists triggers. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerResourceInner> object + */ + public Observable>> listByFactoryNextWithServiceResponseAsync(final String nextPageLink) { + return listByFactoryNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listByFactoryNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * Lists triggers. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<TriggerResourceInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listByFactoryNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listByFactoryNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listByFactoryNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listByFactoryNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + + /** + * List trigger runs. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @throws ErrorResponseException thrown if the request is rejected by server + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent + * @return the PagedList<TriggerRunInner> object if successful. + */ + public PagedList listRunsNext(final String nextPageLink) { + ServiceResponse> response = listRunsNextSinglePageAsync(nextPageLink).toBlocking().single(); + return new PagedList(response.body()) { + @Override + public Page nextPage(String nextPageLink) { + return listRunsNextSinglePageAsync(nextPageLink).toBlocking().single().body(); + } + }; + } + + /** + * List trigger runs. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @param serviceFuture the ServiceFuture object tracking the Retrofit calls + * @param serviceCallback the async ServiceCallback to handle successful and failed responses. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the {@link ServiceFuture} object + */ + public ServiceFuture> listRunsNextAsync(final String nextPageLink, final ServiceFuture> serviceFuture, final ListOperationCallback serviceCallback) { + return AzureServiceFuture.fromPageResponse( + listRunsNextSinglePageAsync(nextPageLink), + new Func1>>>() { + @Override + public Observable>> call(String nextPageLink) { + return listRunsNextSinglePageAsync(nextPageLink); + } + }, + serviceCallback); + } + + /** + * List trigger runs. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerRunInner> object + */ + public Observable> listRunsNextAsync(final String nextPageLink) { + return listRunsNextWithServiceResponseAsync(nextPageLink) + .map(new Func1>, Page>() { + @Override + public Page call(ServiceResponse> response) { + return response.body(); + } + }); + } + + /** + * List trigger runs. + * + * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the observable to the PagedList<TriggerRunInner> object + */ + public Observable>> listRunsNextWithServiceResponseAsync(final String nextPageLink) { + return listRunsNextSinglePageAsync(nextPageLink) + .concatMap(new Func1>, Observable>>>() { + @Override + public Observable>> call(ServiceResponse> page) { + String nextPageLink = page.body().nextPageLink(); + if (nextPageLink == null) { + return Observable.just(page); + } + return Observable.just(page).concatWith(listRunsNextWithServiceResponseAsync(nextPageLink)); + } + }); + } + + /** + * List trigger runs. + * + ServiceResponse> * @param nextPageLink The NextLink from the previous successful call to List operation. + * @throws IllegalArgumentException thrown if parameters fail the validation + * @return the PagedList<TriggerRunInner> object wrapped in {@link ServiceResponse} if successful. + */ + public Observable>> listRunsNextSinglePageAsync(final String nextPageLink) { + if (nextPageLink == null) { + throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."); + } + String nextUrl = String.format("%s", nextPageLink); + return service.listRunsNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent()) + .flatMap(new Func1, Observable>>>() { + @Override + public Observable>> call(Response response) { + try { + ServiceResponse> result = listRunsNextDelegate(response); + return Observable.just(new ServiceResponse>(result.body(), result.response())); + } catch (Throwable t) { + return Observable.error(t); + } + } + }); + } + + private ServiceResponse> listRunsNextDelegate(Response response) throws ErrorResponseException, IOException, IllegalArgumentException { + return this.client.restClient().responseBuilderFactory()., ErrorResponseException>newInstance(this.client.serializerAdapter()) + .register(200, new TypeToken>() { }.getType()) + .registerError(ErrorResponseException.class) + .build(response); + } + +} diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/package-info.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/package-info.java new file mode 100644 index 000000000000..a7aff0b57ea0 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/implementation/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the implementation classes for DataFactoryManagementClient. + * The Azure Data Factory V2 management API provides a RESTful set of web services that interact with Azure Data Factory V2 services. + */ +package com.microsoft.azure.management.datafactory.v2017_09_01_preview.implementation; diff --git a/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/package-info.java b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/package-info.java new file mode 100644 index 000000000000..f293c744db75 --- /dev/null +++ b/datafactory/resource-manager/v2017_09_01_preview/src/main/java/com/microsoft/azure/management/datafactory/v2017_09_01_preview/package-info.java @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for +// license information. +// +// Code generated by Microsoft (R) AutoRest Code Generator. + +/** + * This package contains the classes for DataFactoryManagementClient. + * The Azure Data Factory V2 management API provides a RESTful set of web services that interact with Azure Data Factory V2 services. + */ +package com.microsoft.azure.management.datafactory.v2017_09_01_preview; diff --git a/eng/.docsettings.yml b/eng/.docsettings.yml index 3ae4c9aa409d..4fb91b2a5c7e 100644 --- a/eng/.docsettings.yml +++ b/eng/.docsettings.yml @@ -75,6 +75,9 @@ known_content_issues: - ['sdk/cosmos/changelog/README.md', '#3113'] - ['sdk/cosmos/microsoft-azure-cosmos-benchmark/README.md', '#3113'] - ['sdk/cosmos/README.md', '#3113'] + - ['sdk/storage/azure-storage-blob/swagger/README.md', '#3113'] + - ['sdk/storage/azure-storage-queue/swagger/README.md', '#3113'] + - ['sdk/storage/azure-storage-file/swagger/README.md', '#3113'] package_indexing_exclusion_list: - azure-loganalytics-sample - azure-applicationinsights-query-sample diff --git a/eng/code-quality-reports/pom.xml b/eng/code-quality-reports/pom.xml index d3f7756700b8..6d78b0930566 100755 --- a/eng/code-quality-reports/pom.xml +++ b/eng/code-quality-reports/pom.xml @@ -21,7 +21,7 @@ 1.8 1.8 - 8.18 + 8.24 4.12 diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/EnforceFinalFieldsCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/EnforceFinalFieldsCheck.java new file mode 100644 index 000000000000..34b71ddc486c --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/EnforceFinalFieldsCheck.java @@ -0,0 +1,250 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.utils.TokenUtil; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Verify the whenever a field is assigned just once in constructor to be final + * Tree traversal will pre-compute and fill 3 private containers: + * nonFinalFields: keep an array of non private fields as tokens (to keep line number) + * assignmentsFromConstructor: Save a set of string for each field name that gets its value assigned in constructor + * assignmentsFromMethods: Save a set of strings for each field name that gets updated in any method + * + * On finish tree, check what non-final fields get a value only in constructor and nowhere else by looking for + * strings inside nonFinalFields AND assignmentsFromConstructor but NOT in assignmentsFromMethods + */ +public class EnforceFinalFieldsCheck extends AbstractCheck { + private static final String ERROR_SUGGESTION = "You should consider making the field final, " + + "or suppressing the warning."; + private static final String ERROR_MSG = "Field \"%s\" is only assigned in constructor and it is not final. " + + ERROR_SUGGESTION; + private static final String ERROR_FIELD_ALONE = "Field \"%s\" is not assigned in constructor or methods." + + ERROR_SUGGESTION; + + private List nonFinalFields; + private Set assignmentsFromConstructor; + private Set assignmentsFromMethods; + private DetailAST scopeParent = null; + private Set currentScopeParameterSet = null; + private String currentClassName = null; + + @Override + public int[] getDefaultTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getAcceptableTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getRequiredTokens() { + return new int[] { + TokenTypes.CLASS_DEF, + TokenTypes.ASSIGN, + TokenTypes.PLUS_ASSIGN, + TokenTypes.BAND_ASSIGN, + TokenTypes.BOR_ASSIGN, + TokenTypes.BSR_ASSIGN, + TokenTypes.BXOR_ASSIGN, + TokenTypes.DIV_ASSIGN, + TokenTypes.MINUS_ASSIGN, + TokenTypes.MOD_ASSIGN, + TokenTypes.SL_ASSIGN, + TokenTypes.SR_ASSIGN, + TokenTypes.STAR_ASSIGN, + TokenTypes.INC, + TokenTypes.POST_INC, + TokenTypes.DEC, + TokenTypes.POST_DEC, + TokenTypes.METHOD_DEF, + TokenTypes.CTOR_DEF, + }; + } + + @Override + public void beginTree(DetailAST root) { + nonFinalFields = new ArrayList<>(); + assignmentsFromConstructor = new HashSet<>(); + assignmentsFromMethods = new HashSet<>(); + } + + @Override + public void visitToken(DetailAST token) { + switch (token.getType()) { + case TokenTypes.CLASS_DEF: + this.currentClassName = token.findFirstToken(TokenTypes.IDENT).getText(); + fillClassFieldDefinitions(token); + break; + case TokenTypes.ASSIGN: + case TokenTypes.PLUS_ASSIGN: + case TokenTypes.BAND_ASSIGN: + case TokenTypes.BOR_ASSIGN: + case TokenTypes.BSR_ASSIGN: + case TokenTypes.BXOR_ASSIGN: + case TokenTypes.DIV_ASSIGN: + case TokenTypes.MINUS_ASSIGN: + case TokenTypes.MOD_ASSIGN: + case TokenTypes.SL_ASSIGN: + case TokenTypes.SR_ASSIGN: + case TokenTypes.STAR_ASSIGN: + case TokenTypes.INC: + case TokenTypes.POST_INC: + case TokenTypes.DEC: + case TokenTypes.POST_DEC: + checkAssignation(token); + break; + case TokenTypes.METHOD_DEF: + case TokenTypes.CTOR_DEF: + scopeParent = token; + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } + + @Override + public void leaveToken(DetailAST token) { + switch (token.getType()) { + case TokenTypes.METHOD_DEF: + case TokenTypes.CTOR_DEF: + scopeParent = null; + currentScopeParameterSet = null; + break; + default: + break; + } + } + + @Override + public void finishTree(DetailAST token) { + for (DetailAST field : nonFinalFields) { + final String fieldName = field.findFirstToken(TokenTypes.IDENT).getText(); + if (assignmentsFromConstructor.contains(fieldName) && !assignmentsFromMethods.contains(fieldName)) { + log(field, String.format(ERROR_MSG, fieldName)); + } else if (field.branchContains(TokenTypes.ASSIGN) + && !assignmentsFromConstructor.contains(fieldName) + && !assignmentsFromMethods.contains(fieldName)) { + log(field, String.format(ERROR_FIELD_ALONE, fieldName)); + } + } + } + + /* + * Get the field token from an assignation token. + * This method handles cases for fields referenced as `this.field` or only `field` + * It will get parameters from the method definition to ignore assignations to those parameters + */ + private DetailAST getAssignedField(final DetailAST assignationToken) { + final Set scopeParentParameterSet = getParameterSet(scopeParent.findFirstToken( + TokenTypes.PARAMETERS)); + final DetailAST firstChild = assignationToken.getFirstChild(); + final DetailAST assignationWithDot = firstChild.getType() == TokenTypes.DOT ? firstChild : null; + + if (assignationWithDot != null) { + if (assignationWithDot.branchContains(TokenTypes.LITERAL_THIS)) { + return assignationWithDot.findFirstToken(TokenTypes.IDENT); + } else if (TokenUtil.findFirstTokenByPredicate(assignationWithDot, + token -> token.getText().equals(this.currentClassName)).isPresent()) { + // Case when referencing same class for private static fields + return assignationWithDot.getLastChild(); + } + } else { + final DetailAST variableNameToken = assignationToken.getFirstChild(); + // make sure the assignation is not for a method parameter + if (!scopeParentParameterSet.contains(variableNameToken.getText())) { + return variableNameToken; + } + } + + return null; + } + + /* + * Saves a field name to a container depending on the provided type + */ + private void saveField(final String fieldName, final int scopeParentType) { + if (scopeParentType == TokenTypes.METHOD_DEF) { + assignmentsFromMethods.add(fieldName); + } else if (scopeParentType == TokenTypes.CTOR_DEF) { + assignmentsFromConstructor.add(fieldName); + } + } + + /* + * Review an assignation to save fields that gets assigned in constructor or in any method + * + * @param assignationToken an assignation token + */ + private void checkAssignation(final DetailAST assignationToken) { + if (scopeParent == null || assignationToken.getChildCount() == 0) { + // not inside any method or constructor definition. No need to check anything + // or this is an assignation from a notation like @Test(timeout = 5000) where assignation has not ChildCount + return; + } + + final DetailAST assignationParent = assignationToken.getParent(); + if (assignationParent != null && TokenTypes.VARIABLE_DEF == assignationParent.getType()) { + // Assignation for a variable definition. No need to check this assignation + return; + } + + DetailAST fieldToken = getAssignedField(assignationToken); + + if (fieldToken != null) { + saveField(fieldToken.getText(), scopeParent.getType()); + } + } + + + /* + * Check each non-final field definition from a class and fill nonFinalFields + * + * @param classDefinitionAST a class definition AST + */ + private void fillClassFieldDefinitions(DetailAST classDefinitionAST) { + final DetailAST classObjBlockAst = classDefinitionAST.findFirstToken(TokenTypes.OBJBLOCK); + + TokenUtil.forEachChild(classObjBlockAst, TokenTypes.VARIABLE_DEF, (definitionToken) -> { + final DetailAST variableModifiersAst = definitionToken.findFirstToken(TokenTypes.MODIFIERS); + if (!variableModifiersAst.branchContains(TokenTypes.FINAL) + && !Utils.hasIllegalCombination(variableModifiersAst)) { + nonFinalFields.add(definitionToken); + } + }); + } + + /* + * Get a node AST with parameters definition and return the list of all parameter names + * The set of parameters is created the first time an assignation is check within a method or constructor + * and we don't need to generate it again until visiting a different method or constructor. + * Field `currentScopeParameterSet` ensures we don't create the set multiple times for the same method/constructor + * + * @param parametersAST a TokenTypes.PARAMETERS + * @return a set of parameter names + */ + private Set getParameterSet(DetailAST parametersAST) { + if (currentScopeParameterSet != null) { + return currentScopeParameterSet; + } + currentScopeParameterSet = new HashSet<>(); + TokenUtil.forEachChild(parametersAST, TokenTypes.PARAMETER_DEF, (paramDefToken) -> { + final String parameterName = paramDefToken.findFirstToken(TokenTypes.IDENT).getText(); + currentScopeParameterSet.add(parameterName); + }); + + return currentScopeParameterSet; + } +} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ExternalDependencyExposedCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ExternalDependencyExposedCheck.java index 44522a4e8597..c7120c683069 100644 --- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ExternalDependencyExposedCheck.java +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ExternalDependencyExposedCheck.java @@ -21,9 +21,10 @@ * No external dependency exposed in public API */ public class ExternalDependencyExposedCheck extends AbstractCheck { - private static final String EXTERNAL_DEPENDENCY_ERROR = "Class ''%s'', is a class from external dependency. You should not use it as a %s type."; + private static final String EXTERNAL_DEPENDENCY_ERROR = + "Class ''%s'', is a class from external dependency. You should not use it as a %s type."; private static final Set VALID_DEPENDENCY_SET = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( - "java", "com.azure", "reactor", "io.netty.buffer.ByteBuf" + "java", "com.azure", "reactor" ))); private final Map simpleClassNameToQualifiedNameMap = new HashMap<>(); @@ -58,7 +59,8 @@ public int[] getRequiredTokens() { public void visitToken(DetailAST token) { switch (token.getType()) { case TokenTypes.IMPORT: - // Add all imported classes into a map, key is the name of class and value is the full package path of class. + // Add all imported classes into a map, key is the name of class and value is the full package + // path of class. final String importClassPath = FullIdent.createFullIdentBelow(token).getText(); final String className = importClassPath.substring(importClassPath.lastIndexOf(".") + 1); simpleClassNameToQualifiedNameMap.put(className, importClassPath); @@ -67,7 +69,8 @@ public void visitToken(DetailAST token) { // CLASS_DEF always has MODIFIERS final AccessModifier accessModifier = CheckUtil.getAccessModifierFromModifiersToken( token.findFirstToken(TokenTypes.MODIFIERS)); - isPublicClass = accessModifier.equals(AccessModifier.PUBLIC) || accessModifier.equals(AccessModifier.PROTECTED); + isPublicClass = + accessModifier.equals(AccessModifier.PUBLIC) || accessModifier.equals(AccessModifier.PROTECTED); break; case TokenTypes.METHOD_DEF: if (!isPublicClass) { @@ -100,14 +103,18 @@ private void checkNoExternalDependencyExposed(DetailAST methodDefToken) { final DetailAST typeToken = methodDefToken.findFirstToken(TokenTypes.TYPE); if (typeToken != null) { getInvalidReturnTypes(typeToken).forEach( - (token, returnTypeName) -> log(token, String.format(EXTERNAL_DEPENDENCY_ERROR, returnTypeName, "return"))); + (token, returnTypeName) -> log( + token, + String.format(EXTERNAL_DEPENDENCY_ERROR, returnTypeName, "return"))); } // Checks for the parameters of the method final DetailAST parametersToken = methodDefToken.findFirstToken(TokenTypes.PARAMETERS); if (parametersToken != null) { getInvalidParameterTypes(parametersToken).forEach( - (token, parameterTypeName) -> log(token, String.format(EXTERNAL_DEPENDENCY_ERROR, parameterTypeName, "method argument"))); + (token, parameterTypeName) -> log( + token, + String.format(EXTERNAL_DEPENDENCY_ERROR, parameterTypeName, "method argument"))); } } diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/FluentMethodNameCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/FluentMethodNameCheck.java new file mode 100644 index 000000000000..0a855e77d2b9 --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/FluentMethodNameCheck.java @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.utils.TokenUtil; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.HashSet; +import java.util.Queue; +import java.util.Set; + +/** + * Model Class Method check requirements: + *
    +*
  1. Fluent Methods: All methods that return an instance of the class, and that have one parameter.
  2. + *
  3. The method name should not start with {@code avoidStartWords}.
  4. + *
  5. All methods should not throw checked exceptions.
  6. + *
+ */ +public class FluentMethodNameCheck extends AbstractCheck { + /** + * This is a custom defined set which contains all prefixes that are not allowed. + */ + private final Set avoidStartWords = new HashSet<>(); + + /** + * A LIFO Queue tracks the status of the inner class names when traversals the AST tree. + */ + private final Queue classNameStack = Collections.asLifoQueue(new ArrayDeque<>()); + + /** + * Adds words that methods in fluent classes should not be prefixed with. + * @param avoidStartWords the starting strings that should not start with in fluent method + */ + public final void setAvoidStartWords(String... avoidStartWords) { + Collections.addAll(this.avoidStartWords, avoidStartWords); + } + + @Override + public int[] getDefaultTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getAcceptableTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getRequiredTokens() { + return new int[] { + TokenTypes.CLASS_DEF, + TokenTypes.METHOD_DEF + }; + } + + @Override + public void visitToken(DetailAST token) { + switch (token.getType()) { + case TokenTypes.CLASS_DEF: + classNameStack.offer(token.findFirstToken(TokenTypes.IDENT).getText()); + break; + case TokenTypes.METHOD_DEF: + if (!isFluentMethod(token)) { + return; + } + checkMethodNamePrefix(token); + + // logs error if the @Fluent method has 'throws' at the method declaration. + if (token.findFirstToken(TokenTypes.LITERAL_THROWS) != null) { + log(token, String.format( + "Fluent Method ''%s'' must not be declared to throw any checked exceptions")); + } + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } + + @Override + public void leaveToken(DetailAST token) { + if (token.getType() == TokenTypes.CLASS_DEF && !classNameStack.isEmpty()) { + classNameStack.poll(); + } + } + + /** + * Log the error if the method name is not start with {@code avoidStartWord} + * @param methodDefToken METHOD_DEF AST node + */ + private void checkMethodNamePrefix(DetailAST methodDefToken) { + // A fluent method should only has one parameter. + if (TokenUtil.findFirstTokenByPredicate(methodDefToken, parameters -> + parameters.getType() == TokenTypes.PARAMETERS && parameters.getChildCount() != 1).isPresent()) { + log(methodDefToken, "A fluent method should only have one parameter."); + } + + // A fluent method's return type should be the class itself + final DetailAST typeToken = methodDefToken.findFirstToken(TokenTypes.TYPE); + if (TokenUtil.findFirstTokenByPredicate(typeToken, ident -> ident.getType() == TokenTypes.IDENT + && !ident.getText().equals(classNameStack.peek())).isPresent()) { + log(methodDefToken, "Return type of fluent method should be the class itself"); + } + + final String methodName = methodDefToken.findFirstToken(TokenTypes.IDENT).getText(); + // method name should not start with words in the avoid string list + avoidStartWords.forEach(avoidStartWord -> { + if (methodName.length() >= avoidStartWord.length() && methodName.startsWith(avoidStartWord)) { + log(methodDefToken, String.format("''%s'' fluent method name should not start with keyword ''%s''.", + methodName, avoidStartWord)); + } + }); + } + + /** + * Checks if the method is annotated with annotation @Fluent + * + * @param methodDefToken the METHOD_DEF AST node + * @return true if the class is annotated with @Fluent, false otherwise. + */ + private boolean isFluentMethod(DetailAST methodDefToken) { + // Always has MODIFIERS node + final DetailAST modifiersToken = methodDefToken.findFirstToken(TokenTypes.MODIFIERS); + // If no @Fluent annotated with this class, return false + return TokenUtil.findFirstTokenByPredicate(modifiersToken, + annotationToken -> annotationToken.getType() == TokenTypes.ANNOTATION + && TokenUtil.findFirstTokenByPredicate(annotationToken, + identToken -> identToken.getType() == TokenTypes.IDENT + && "Fluent".equals(identToken.getText())).isPresent()) + .isPresent(); + } +} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/GoodLoggingCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/GoodLoggingCheck.java new file mode 100644 index 000000000000..7d90347c0ff8 --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/GoodLoggingCheck.java @@ -0,0 +1,187 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.utils.TokenUtil; + +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Queue; +import java.util.Set; + +/** + * Good Logging Practice: + *
    + *
  1. A non-static instance logger.
  2. + *
  3. ClientLogger in public API should all named 'logger', public API classes are those classes that are declared + * as public and that do not exist in an implementation package or subpackage.
  4. + *
  5. Should not use any external logger class, only use ClientLogger. No slf4j, log4j, or other logging imports are + * allowed.
  6. + *
  7. 'System.out' and 'System.err' is not allowed as well.
  8. + *
+ */ +public class GoodLoggingCheck extends AbstractCheck { + private static final String CLIENT_LOGGER_PATH = "com.azure.core.util.logging.ClientLogger"; + private static final String CLIENT_LOGGER = "ClientLogger"; + private static final String LOGGER = "logger"; + + private static final String LOGGER_NAME_ERROR = + "ClientLogger instance naming: use ''%s'' instead of ''%s'' for consistency."; + private static final String STATIC_LOGGER_ERROR = "ClientLogger should not be static. Remove static modifier."; + private static final String NOT_CLIENT_LOGGER_ERROR = + "Do not use %s class. Use ''%s'' as a logging mechanism instead of ''%s''."; + + // Boolean indicator that indicates if the java class imports ClientLogger + private boolean hasClientLoggerImported; + // A LIFO queue stores the class names, pop top element if exist the class name AST node + private Queue classNameDeque = Collections.asLifoQueue(new ArrayDeque<>()); + // Collection of Invalid logging packages + private static final Set INVALID_LOGS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + "org.slf4j", "org.apache.logging.log4j", "java.util.logging" + ))); + + @Override + public int[] getDefaultTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getAcceptableTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getRequiredTokens() { + return new int[] { + TokenTypes.IMPORT, + TokenTypes.CLASS_DEF, + TokenTypes.LITERAL_NEW, + TokenTypes.VARIABLE_DEF, + TokenTypes.METHOD_CALL + }; + } + + @Override + public void finishTree(DetailAST ast) { + hasClientLoggerImported = false; + } + + @Override + public void leaveToken(DetailAST ast) { + if (ast.getType() == TokenTypes.CLASS_DEF) { + classNameDeque.poll(); + } + } + + @Override + public void visitToken(DetailAST ast) { + switch (ast.getType()) { + case TokenTypes.IMPORT: + final String importClassPath = FullIdent.createFullIdentBelow(ast).getText(); + hasClientLoggerImported = hasClientLoggerImported || importClassPath.equals(CLIENT_LOGGER_PATH); + + INVALID_LOGS.forEach(item -> { + if (importClassPath.startsWith(item)) { + log(ast, String.format(NOT_CLIENT_LOGGER_ERROR, "external logger", CLIENT_LOGGER_PATH, item)); + } + }); + break; + case TokenTypes.CLASS_DEF: + classNameDeque.offer(ast.findFirstToken(TokenTypes.IDENT).getText()); + break; + case TokenTypes.LITERAL_NEW: + checkLoggerInstantiation(ast); + break; + case TokenTypes.VARIABLE_DEF: + checkLoggerNameMatch(ast); + break; + case TokenTypes.METHOD_CALL: + final DetailAST dotToken = ast.findFirstToken(TokenTypes.DOT); + if (dotToken == null) { + return; + } + final String methodCallName = FullIdent.createFullIdentBelow(dotToken).getText(); + if (methodCallName.startsWith("System.out") || methodCallName.startsWith("System.err")) { + log(ast, String.format(NOT_CLIENT_LOGGER_ERROR, "Java System", CLIENT_LOGGER_PATH, methodCallName)); + } + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } + + /** + * Check if the VARIABLE_DEF AST node type is 'ClientLogger'. + * + * @param varDefAST VARIABLE_DEF AST node + * @return true if the variable type is 'ClientLogger'. + */ + private boolean isTypeClientLogger(DetailAST varDefAST) { + final DetailAST typeAST = varDefAST.findFirstToken(TokenTypes.TYPE); + if (typeAST == null) { + return false; + } + return TokenUtil.findFirstTokenByPredicate(typeAST, node -> + node.getType() == TokenTypes.IDENT && node.getText().equals(CLIENT_LOGGER) + ).isPresent(); + } + + /** + * Check if instantiating a matched class name for the same class. + * + * @param literalNewToken LITERAL_NEW node + */ + private void checkLoggerInstantiation(DetailAST literalNewToken) { + final DetailAST identToken = literalNewToken.findFirstToken(TokenTypes.IDENT); + // Not ClientLogger instance + if (identToken == null || !identToken.getText().equals(CLIENT_LOGGER)) { + return; + } + // LITERAL_NEW node always has ELIST node below + TokenUtil.findFirstTokenByPredicate(literalNewToken.findFirstToken(TokenTypes.ELIST), exprToken -> { + // Skip check if not EXPR node or if has no DOT node below. EXPR always has children below + if (exprToken.getType() != TokenTypes.EXPR || exprToken.getFirstChild().getType() != TokenTypes.DOT) { + return false; + } + // Check instantiation of ClientLogger + final String containerClassName = FullIdent.createFullIdent(exprToken.getFirstChild()).getText(); + // Add suffix of '.class' at the end of class name + final String className = classNameDeque.peek(); + if (!containerClassName.equals(className + ".class")) { + log(exprToken, String.format("Not newing a ClientLogger with matching class name. Use ''%s.class'' " + + "instead of ''%s''", className, containerClassName)); + } + return true; + }); + } + + /** + * Check if the given ClientLogger named 'logger' + * + * @param varToken VARIABLE_DEF node + */ + private void checkLoggerNameMatch(DetailAST varToken) { + if (!hasClientLoggerImported || !isTypeClientLogger(varToken)) { + return; + } + // Check if the Logger instance named as 'logger'. + final DetailAST identAST = varToken.findFirstToken(TokenTypes.IDENT); + if (identAST != null && !identAST.getText().equals(LOGGER)) { + log(varToken, String.format(LOGGER_NAME_ERROR, LOGGER, identAST.getText())); + } + // Check if the Logger is static instance, log as error if it is static instance logger. + if (TokenUtil.findFirstTokenByPredicate(varToken, + node -> node.getType() == TokenTypes.MODIFIERS + && node.branchContains(TokenTypes.LITERAL_STATIC)).isPresent()) { + log(varToken, STATIC_LOGGER_ERROR); + } + } +} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/HttpPipelinePolicyCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/HttpPipelinePolicyCheck.java index a6c6b0b075b7..9168d5acb0c9 100644 --- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/HttpPipelinePolicyCheck.java +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/HttpPipelinePolicyCheck.java @@ -48,7 +48,7 @@ public void visitToken(DetailAST token) { switch (token.getType()) { case TokenTypes.PACKAGE_DEF: - final String packageName = FullIdent.createFullIdentBelow(token).getText(); + final String packageName = FullIdent.createFullIdent(token.findFirstToken(TokenTypes.DOT)).getText(); isImplementationPackage = packageName.contains("implementation"); break; case TokenTypes.CLASS_DEF: @@ -87,12 +87,14 @@ private void checkPublicNonImplementationPolicyClass(DetailAST classDefToken) { final String className = classDefToken.findFirstToken(TokenTypes.IDENT).getText(); // Public class check if (!accessModifier.equals(AccessModifier.PUBLIC)) { - log(modifiersToken, String.format("Class ''%s'' implementing ''%s'' and should be a public class", className, HTTP_PIPELINE_POLICY)); + log(modifiersToken, String.format("Class ''%s'' implementing ''%s'' and should be a public class", + className, HTTP_PIPELINE_POLICY)); } // Implementation and sub-package check if (isImplementationPackage) { - log(classDefToken, String.format("Class ''%s'' implementing ''%s'' and should not be a implementation package or sub-package of it", className, HTTP_PIPELINE_POLICY)); + log(classDefToken, String.format("Class ''%s'' implementing ''%s'' and should not be a implementation " + + "package or sub-package of it", className, HTTP_PIPELINE_POLICY)); } } } diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavaDocFormatting.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavaDocFormatting.java new file mode 100644 index 000000000000..10ed79ed0d8e --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavaDocFormatting.java @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.api.DetailNode; +import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes; +import com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck; +import com.puppycrawl.tools.checkstyle.utils.JavadocUtil; + +/** + * Description text should only have one space character after the parameter name or {@code @return} statement. + * Text should not start on a new line or have any additional spacing or indentation. + */ +public class JavaDocFormatting extends AbstractJavadocCheck { + + private static final String JAVA_DOC_RETURN = "javadoc return"; + private static final String JAVA_DOC_PARAMETER = "javadoc parameter"; + private static final String JAVA_DOC_THROW = "javadoc throw"; + private static final String JAVA_DOC_DEPRECATED = "javadoc deprecated"; + + private static final String ERROR_DESCRIPTION_ON_NEW_LINE = "Description for %s must be on same the same line."; + private static final String ERROR_NO_DESCRIPTION = "Description is missing for %s. Consider adding a description."; + private static final String ERROR_NO_WS_AFTER_IDENT = "No white space after %s. Consider fixing format."; + private static final String ERROR_EXTRA_SPACE = + "Only one white space is expected after %s. Consider removing extra spaces."; + + @Override + public int[] getAcceptableJavadocTokens() { + return getRequiredJavadocTokens(); + } + + @Override + public int[] getRequiredJavadocTokens() { + return new int[] { + JavadocTokenTypes.PARAMETER_NAME, + JavadocTokenTypes.RETURN_LITERAL, + JavadocTokenTypes.THROWS_LITERAL, + JavadocTokenTypes.DEPRECATED_LITERAL, + }; + } + + @Override + public int[] getDefaultJavadocTokens() { + return getRequiredJavadocTokens(); + } + + @Override + public void visitJavadocToken(DetailNode javaDocTag) { + switch (javaDocTag.getType()) { + case JavadocTokenTypes.RETURN_LITERAL: + evaluateValidFormat(javaDocTag, JAVA_DOC_RETURN); + break; + case JavadocTokenTypes.PARAMETER_NAME: + evaluateValidFormat(javaDocTag, JAVA_DOC_PARAMETER); + break; + case JavadocTokenTypes.THROWS_LITERAL: + // Evaluate what is the format after the CLASS_NAME of a @throw + DetailNode throwFormat = JavadocUtil.getNextSibling(javaDocTag, JavadocTokenTypes.CLASS_NAME); + evaluateValidFormat(throwFormat, JAVA_DOC_THROW); + break; + case JavadocTokenTypes.DEPRECATED_LITERAL: + evaluateValidFormat(javaDocTag, JAVA_DOC_DEPRECATED); + break; + default: + break; + } + } + + /* + * Function receives a DetailNode as the start token and then validates what comes after that node. + * valid format is: + * - A single white space is expected after the node. (no NEW_LINE) or other token + * + */ + private void evaluateValidFormat(DetailNode javaDocTag, String identifier) { + DetailNode nextNodeAfterParameterName = JavadocUtil.getNextSibling(javaDocTag); + + if (nextNodeAfterParameterName.getType() == JavadocTokenTypes.NEWLINE) { + if (JavadocUtil.getNextSibling(nextNodeAfterParameterName, JavadocTokenTypes.DESCRIPTION) != null) { + // Description on next line or after some other lines/spaces/staff + log(javaDocTag.getLineNumber(), String.format(ERROR_DESCRIPTION_ON_NEW_LINE, identifier)); + } else { + // No description for parameter name + log(javaDocTag.getLineNumber(), String.format(ERROR_NO_DESCRIPTION, identifier)); + } + } else if (nextNodeAfterParameterName.getType() != JavadocTokenTypes.WS) { + log(javaDocTag.getLineNumber(), String.format(ERROR_NO_WS_AFTER_IDENT, identifier)); + } else if (!nextNodeAfterParameterName.getText().equals(" ")) { + log(javaDocTag.getLineNumber(), String.format(ERROR_EXTRA_SPACE, identifier)); + } + } +} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocCodeSnippetCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocCodeSnippetCheck.java new file mode 100644 index 000000000000..c99a7f51ad0a --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocCodeSnippetCheck.java @@ -0,0 +1,248 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.DetailNodeTreeStringPrinter; +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.DetailNode; +import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.utils.BlockCommentPosition; +import com.puppycrawl.tools.checkstyle.utils.JavadocUtil; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Locale; +import java.util.Queue; + +/** + * Codesnippet description should match naming pattern requirement below: + *
    + *
  1. Package, class, and method names should be concatenated with a dot '.'. Ex., packageName.className + * .methodName
  2. + *
  3. Methods arguments should be concatenated with a dash '-'. Ex. String-String for methodName(String s, String + * s2)
  4. + *
  5. Use '#' to concatenate 1) and 2), ex packageName.className.methodName#String-String
  6. + *
  7. Ignore identifier after method arguments
  8. + *
+ */ +public class JavadocCodeSnippetCheck extends AbstractCheck { + + private static final String CODE_SNIPPET_ANNOTATION = "@codesnippet"; + private static final String MISSING_CODESNIPPET_TAG_MESSAGE = "There is a @codesnippet block in the JavaDoc, but it" + + " does not refer to any sample."; + + private static final int[] TOKENS = new int[] { + TokenTypes.PACKAGE_DEF, + TokenTypes.BLOCK_COMMENT_BEGIN, + TokenTypes.CLASS_DEF, + TokenTypes.METHOD_DEF + }; + + private String packageName; + // A LIFO queue contains all class name visited, remove the class name when leave the same token + private Queue classNameStack = Collections.asLifoQueue(new ArrayDeque<>()); + // Current METHOD_DEF token while traversal tree + private DetailAST methodDefToken = null; + + @Override + public int[] getDefaultTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getAcceptableTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getRequiredTokens() { + return TOKENS; + } + + @Override + public boolean isCommentNodesRequired() { + return true; + } + + @Override + public void leaveToken(DetailAST token) { + if (token.getType() == TokenTypes.CLASS_DEF && !classNameStack.isEmpty()) { + classNameStack.poll(); + } + } + + @Override + public void visitToken(DetailAST token) { + switch (token.getType()) { + case TokenTypes.PACKAGE_DEF: + packageName = FullIdent.createFullIdent(token.findFirstToken(TokenTypes.DOT)).getText(); + break; + case TokenTypes.CLASS_DEF: + classNameStack.offer(token.findFirstToken(TokenTypes.IDENT).getText()); + break; + case TokenTypes.METHOD_DEF: + methodDefToken = token; + break; + case TokenTypes.BLOCK_COMMENT_BEGIN: + checkNamingPattern(token); + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } + + /** + * Check if the given block comment is on method. If not, skip the check. + * Otherwise, check if the codesnippet has matching the naming pattern + * + * @param blockCommentToken BLOCK_COMMENT_BEGIN token + */ + private void checkNamingPattern(DetailAST blockCommentToken) { + if (!BlockCommentPosition.isOnMethod(blockCommentToken)) { + return; + } + + // Turn the DetailAST into a Javadoc DetailNode. + DetailNode javadocNode = null; + try { + javadocNode = DetailNodeTreeStringPrinter.parseJavadocAsDetailNode(blockCommentToken); + } catch (IllegalArgumentException ex) { + // Exceptions are thrown if the JavaDoc has invalid formatting. + } + + if (javadocNode == null) { + return; + } + + // Iterate through all the top level nodes in the Javadoc, looking for the @codesnippet tag. + for (DetailNode node : javadocNode.getChildren()) { + if (node.getType() != JavadocTokenTypes.JAVADOC_INLINE_TAG) { + continue; + } + // Skip if not codesnippet + DetailNode customNameNode = JavadocUtil.findFirstToken(node, JavadocTokenTypes.CUSTOM_NAME); + if (customNameNode == null || !CODE_SNIPPET_ANNOTATION.equals(customNameNode.getText())) { + return; + } + // Missing Description + DetailNode descriptionNode = JavadocUtil.findFirstToken(node, JavadocTokenTypes.DESCRIPTION); + if (descriptionNode == null) { + log(node.getLineNumber(), MISSING_CODESNIPPET_TAG_MESSAGE); + return; + } + + // There will always have TEXT token if there is DESCRIPTION token exists. + String customDescription = JavadocUtil.findFirstToken(descriptionNode, JavadocTokenTypes.TEXT).getText(); + + // Find method name + final String methodName = methodDefToken.findFirstToken(TokenTypes.IDENT).getText(); + final String className = classNameStack.isEmpty() ? "" : classNameStack.peek(); + final String parameters = constructParametersString(methodDefToken); + String fullPath = packageName + "." + className + "." + methodName; + final String fullPathWithoutParameters = fullPath; + if (parameters != null) { + fullPath = fullPath + "#" + parameters; + } + + // Check for CodeSnippet naming pattern matching + if (customDescription == null || customDescription.isEmpty() + || !isNamingMatched(customDescription.toLowerCase(Locale.ROOT), + fullPathWithoutParameters.toLowerCase(Locale.ROOT), parameters)) { + log(node.getLineNumber(), String.format("Naming pattern mismatch. The @codesnippet description " + + "''%s'' does not match ''%s''. Case Insensitive.", customDescription, fullPath)); + } + } + } + + /** + * Construct a parameters string if the method has arguments. + * + * @param methodDefToken METHOD_DEF token + * @return a valid parameter string or null if no method arguments exist. + */ + private String constructParametersString(DetailAST methodDefToken) { + final StringBuilder sb = new StringBuilder(); + // Checks for the parameters of the method + final DetailAST parametersToken = methodDefToken.findFirstToken(TokenTypes.PARAMETERS); + for (DetailAST ast = parametersToken.getFirstChild(); ast != null; ast = ast.getNextSibling()) { + if (ast.getType() != TokenTypes.PARAMETER_DEF) { + continue; + } + + final DetailAST typeToken = ast.findFirstToken(TokenTypes.TYPE); + final DetailAST identToken = typeToken.findFirstToken(TokenTypes.IDENT); + String parameterType = ""; + if (identToken != null) { + // For example, Map, String, Mono types + parameterType = identToken.getText(); + } else { + + DetailAST arrayDeclarator = typeToken.findFirstToken(TokenTypes.ARRAY_DECLARATOR); + if (arrayDeclarator == null) { + // For example, int, boolean, byte primitive types + parameterType = typeToken.getFirstChild().getText(); + } + + DetailAST arrayDeclaratorIterator = arrayDeclarator; + while (arrayDeclaratorIterator != null) { + DetailAST temp = arrayDeclaratorIterator.findFirstToken(TokenTypes.ARRAY_DECLARATOR); + if (temp == null) { + // For example, int[][], byte[] types + parameterType = arrayDeclaratorIterator.getFirstChild().getText(); + break; + } + arrayDeclaratorIterator = temp; + } + } + sb.append(parameterType).append("-"); + } + int size = sb.length(); + if (size == 0) { + return null; + } + return sb.substring(0, size - 1); + } + + /** + * Check if the given customDescription from codesnippet matches the naming pattern rule. + * + * @param customDescription full sample code reference name from annotation codesnippet + * @param fullPathWithoutParameters a string contains package name, class name, and method name if exist. + * @param parameters parameters string which concatenate of argument types + * @return false if the given custom description not matched with naming rule. Otherwise, return true. + */ + private boolean isNamingMatched(String customDescription, String fullPathWithoutParameters, String parameters) { + // Two same codesnippet samples should have two different key names, + // For example, for method name methodName(string, string), + // (1) packagename.classname.methodname#string-string + // (2) packagename.classname.methodname#string-string-2 + final String[] descriptionSegments = customDescription.split("#"); + if (descriptionSegments.length == 1) { + // There exists parameters in the actual Java sample, but there is no custom parameters exist. + if (parameters != null) { + return false; + } + + final String pathUntilMethodName = descriptionSegments[0].split("-")[0]; + if (!fullPathWithoutParameters.equalsIgnoreCase(pathUntilMethodName)) { + return false; + } + } + + if (descriptionSegments.length == 2) { + // Both of codesnippet name and the method has parameters + if (parameters != null) { + return descriptionSegments[1].toLowerCase().startsWith(parameters.toLowerCase()); + } + + // Codesnippet name has parameters but the method does not. + return false; + } + return true; + } +} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocInlineTagCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocInlineTagCheck.java new file mode 100644 index 000000000000..53753f3dea58 --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocInlineTagCheck.java @@ -0,0 +1,125 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.DetailNode; +import com.puppycrawl.tools.checkstyle.api.JavadocTokenTypes; +import com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractJavadocCheck; +import com.puppycrawl.tools.checkstyle.utils.BlockCommentPosition; +import com.puppycrawl.tools.checkstyle.utils.JavadocUtil; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * Javadoc Inline tag check: + *
    + *
  1. Use {@literal {@codesnippet ...}} instead of {@literal }, {@literal
    }, or {@literal {@code ...}}
    + * if these tags span multiple lines. Inline code sample are fine as-is
  2. + *
  3. No check on class-level Javadoc
  4. + *
+ */ +public class JavadocInlineTagCheck extends AbstractJavadocCheck { + private static final String MULTIPLE_LINE_SPAN_ERROR = "Tag '%s' spans multiple lines. Use @codesnippet annotation" + + " instead of '%s' to ensure that the code block always compiles."; + + // HTML tag set that need to be checked to see if there tags span on multiple lines. + private static final Set CHECK_TAGS = Collections.unmodifiableSet(new HashSet<>( + Arrays.asList("pre", "code"))); + + @Override + public int[] getDefaultJavadocTokens() { + return getRequiredJavadocTokens(); + } + + @Override + public int[] getRequiredJavadocTokens() { + return new int[] { + JavadocTokenTypes.HTML_ELEMENT_START, + JavadocTokenTypes.JAVADOC_INLINE_TAG + }; + } + + @Override + public void visitJavadocToken(DetailNode token) { + DetailAST blockCommentToken = getBlockCommentAst(); + // Skip check on class-level Javadoc + if (!BlockCommentPosition.isOnMethod(blockCommentToken) + && !BlockCommentPosition.isOnConstructor(blockCommentToken)) { + return; + } + + switch (token.getType()) { + case JavadocTokenTypes.HTML_ELEMENT_START: + checkHtmlElementStart(token); + break; + case JavadocTokenTypes.JAVADOC_INLINE_TAG: + checkJavadocInlineTag(token); + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } + + /** + * Use {@literal {@codesnippet ...}} instead of {@literal }, {@literal
}, or {@literal {@code ...}}
+     * if these tags span multiple lines. Inline code sample are fine as-is.
+     *
+     * @param htmlElementStartNode HTML_ELEMENT_START node
+     */
+    private void checkHtmlElementStart(DetailNode htmlElementStartNode) {
+        final DetailNode tagNameNode =
+            JavadocUtil.findFirstToken(htmlElementStartNode, JavadocTokenTypes.HTML_TAG_NAME);
+        // HTML tags are case-insensitive
+        final String tagName = tagNameNode.getText().toLowerCase();
+        if (!CHECK_TAGS.contains(tagName)) {
+            return;
+        }
+
+        final String tagNameBracket = "<" + tagName + ">";
+        final DetailNode htmlTagNode = htmlElementStartNode.getParent();
+        if (!isInlineCode(htmlTagNode)) {
+            log(htmlTagNode.getLineNumber(), htmlTagNode.getColumnNumber(),
+                String.format(MULTIPLE_LINE_SPAN_ERROR, tagNameBracket, tagNameBracket));
+        }
+    }
+
+    /**
+     * Check to see if the JAVADOC_INLINE_TAG node is {@literal @code} tag. If it is, check if the tag contains a new
+     * line or a leading asterisk, which implies the tag has spanned in multiple lines.
+     *
+     * @param inlineTagNode JAVADOC_INLINE_TAG javadoc node
+     */
+    private void checkJavadocInlineTag(DetailNode inlineTagNode) {
+        final DetailNode codeLiteralNode = JavadocUtil.findFirstToken(inlineTagNode, JavadocTokenTypes.CODE_LITERAL);
+        if (codeLiteralNode == null) {
+            return;
+        }
+
+        final String codeLiteral = codeLiteralNode.getText();
+        if (!isInlineCode(inlineTagNode)) {
+            log(codeLiteralNode.getLineNumber(), codeLiteralNode.getColumnNumber(),
+                String.format(MULTIPLE_LINE_SPAN_ERROR, codeLiteral, codeLiteral));
+        }
+    }
+
+    /**
+     * Find if the given tag node is in-line code sample.
+     * @param node A given node that could be HTML_TAG or JAVADOC_INLINE_TAG
+     * @return false if it is a code block, otherwise, return true if it is a in-line code.
+     */
+    private boolean isInlineCode(DetailNode node) {
+        for (final DetailNode child : node.getChildren()) {
+            final int childType = child.getType();
+            if (childType == JavadocTokenTypes.NEWLINE || childType == JavadocTokenTypes.LEADING_ASTERISK) {
+                return false;
+            }
+        }
+        return true;
+    }
+}
diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocThrowsChecks.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocThrowsChecks.java
index c12eeb540056..072a971c6c12 100644
--- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocThrowsChecks.java
+++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/JavadocThrowsChecks.java
@@ -18,7 +18,8 @@
 import java.util.Map;
 
 public class JavadocThrowsChecks extends AbstractCheck {
-    private static final String MISSING_DESCRIPTION_MESSAGE = "@throws tag requires a description explaining when the error is thrown.";
+    private static final String MISSING_DESCRIPTION_MESSAGE =
+        "@throws tag requires a description explaining when the error is thrown.";
     private static final String MISSING_THROWS_TAG_MESSAGE = "Javadoc @throws tag required for unchecked throw.";
     private static final int[] TOKENS = new int[] {
         TokenTypes.CTOR_DEF,
@@ -105,7 +106,8 @@ public void visitToken(DetailAST token) {
      */
     private void setIdentifierAndCheckStatus(DetailAST scopeDefToken) {
         currentScopeIdentifier = scopeDefToken.findFirstToken(TokenTypes.IDENT).getText() + scopeDefToken.getLineNo();
-        currentScopeNeedsChecking = visibilityIsPublicOrProtectedAndNotAbstractOrOverride(scopeDefToken.findFirstToken(TokenTypes.MODIFIERS));
+        currentScopeNeedsChecking =
+            visibilityIsPublicOrProtectedAndNotAbstractOrOverride(scopeDefToken.findFirstToken(TokenTypes.MODIFIERS));
     }
 
     /*
@@ -151,7 +153,8 @@ private boolean isOverrideAnnotation(DetailAST modifierToken) {
      * @param blockCommentToken Block comment token.
      */
     private void findJavadocThrows(DetailAST blockCommentToken) {
-        if (!BlockCommentPosition.isOnMethod(blockCommentToken) && !BlockCommentPosition.isOnConstructor(blockCommentToken)) {
+        if (!BlockCommentPosition.isOnMethod(blockCommentToken)
+            && !BlockCommentPosition.isOnConstructor(blockCommentToken)) {
             return;
         }
 
@@ -172,7 +175,8 @@ private void findJavadocThrows(DetailAST blockCommentToken) {
 
         // Iterate through all the top level nodes in the Javadoc, looking for the @throws statements.
         for (DetailNode node : javadocNode.getChildren()) {
-            if (node.getType() != JavadocTokenTypes.JAVADOC_TAG || JavadocUtil.findFirstToken(node, JavadocTokenTypes.THROWS_LITERAL) == null) {
+            if (node.getType() != JavadocTokenTypes.JAVADOC_TAG
+                || JavadocUtil.findFirstToken(node, JavadocTokenTypes.THROWS_LITERAL) == null) {
                 continue;
             }
 
diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/NoImplInPublicAPI.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/NoImplInPublicAPI.java
index a21ed603ab72..d2aafb9ac99c 100644
--- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/NoImplInPublicAPI.java
+++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/NoImplInPublicAPI.java
@@ -15,11 +15,14 @@ public class NoImplInPublicAPI extends AbstractCheck {
 
     private static final String COM_AZURE = "com.azure";
     private static final String DOT_IMPLEMENTATION = ".implementation";
-    private static final String PARAM_TYPE_ERROR = "\"%s\" class is in an implementation package, and it should not be used as a parameter type in public API. Alternatively, it can be removed from the implementation package and made public API, after appropriate API review.";
-    private static final String RETURN_TYPE_ERROR = "\"%s\" class is in an implementation package, and it should not be a return type from public API. Alternatively, it can be removed from the implementation package and made public API.";
+    private static final String PARAM_TYPE_ERROR =
+        "\"%s\" class is in an implementation package, and it should not be used as a parameter type in public API. "
+            + "Alternatively, it can be removed from the implementation package and made public API, after "
+            + "appropriate API review.";
+    private static final String RETURN_TYPE_ERROR =
+        "\"%s\" class is in an implementation package, and it should not be a return type from public API. "
+            + "Alternatively, it can be removed from the implementation package and made public API.";
 
-    private static boolean isTrackTwo;
-    private static boolean isImplPackage;
     private Set implementationClassSet = new HashSet<>();
 
     @Override
@@ -34,7 +37,7 @@ public int[] getAcceptableTokens() {
 
     @Override
     public int[] getRequiredTokens() {
-        return new int[] {
+        return new int[]{
             TokenTypes.PACKAGE_DEF,
             TokenTypes.IMPORT,
             TokenTypes.METHOD_DEF
@@ -43,28 +46,11 @@ public int[] getRequiredTokens() {
 
     @Override
     public void beginTree(DetailAST root) {
-        this.isImplPackage = false;
-        this.isTrackTwo = false;
         this.implementationClassSet.clear();
     }
 
     @Override
     public void visitToken(DetailAST ast) {
-        if (ast.getType() == TokenTypes.PACKAGE_DEF) {
-            String packageName = FullIdent.createFullIdent(ast.findFirstToken(TokenTypes.DOT)).getText();
-            this.isTrackTwo = packageName.startsWith(COM_AZURE);
-            this.isImplPackage = packageName.contains(DOT_IMPLEMENTATION);
-            return;
-        } else {
-            if (this.isTrackTwo) {
-                if (this.isImplPackage) {
-                    return;
-                }
-            } else {
-                return;
-            }
-        }
-
         switch (ast.getType()) {
             case TokenTypes.IMPORT:
                 String importClassPath = FullIdent.createFullIdentBelow(ast).getText();
diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/OnlyFinalFieldsForImmutableClassCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/OnlyFinalFieldsForImmutableClassCheck.java
index 85252a28a214..916c7533859f 100644
--- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/OnlyFinalFieldsForImmutableClassCheck.java
+++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/OnlyFinalFieldsForImmutableClassCheck.java
@@ -1,5 +1,5 @@
-// Licensed under the MIT License.
 // Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
 
 package com.azure.tools.checkstyle.checks;
 
@@ -19,8 +19,8 @@
  */
 public class OnlyFinalFieldsForImmutableClassCheck extends AbstractCheck {
     private static final String IMMUTABLE_NOTATION = "Immutable";
-    private static final String ERROR_MSG = "The variable field ''%s'' should be final." +
-        "Classes annotated with @Immutable are supposed to be immutable.";
+    private static final String ERROR_MSG = "The variable field ''%s'' should be final."
+        + "Classes annotated with @Immutable are supposed to be immutable.";
 
     private boolean hasImmutableAnnotation;
 
diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientBuilderCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientBuilderCheck.java
index 8623828a9c63..64119d96a3a8 100644
--- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientBuilderCheck.java
+++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientBuilderCheck.java
@@ -10,14 +10,17 @@
 import java.util.Stack;
 
 /**
- * The @ServiceClientBuilder class should have the following rules:
- *  1) All service client builder should be named ClientBuilder and annotated with @ServiceClientBuilder.
- *  2) No other method have prefix 'build' other than 'build*Client' or 'build*AsyncClient'.
+ * The {@literal @ServiceClientBuilder} class should have the following rules:
+ * 
    + *
  1. All service client builder should be named <ServiceName>ClientBuilder and annotated with + * {@literal @ServiceClientBuilder}.
  2. + *
  3. No other method have prefix 'build' other than 'build*Client' or 'build*AsyncClient'.
  4. + *
*/ public class ServiceClientBuilderCheck extends AbstractCheck { private static final String SERVICE_CLIENT_BUILDER = "ServiceClientBuilder"; - private Stack hasServiceClientBuilderAnnotationStack = new Stack(); + private Stack hasServiceClientBuilderAnnotationStack = new Stack<>(); private Stack hasBuildMethodStack = new Stack<>(); private boolean hasServiceClientBuilderAnnotation; private boolean hasBuildMethod; @@ -46,7 +49,8 @@ public void leaveToken(DetailAST token) { hasServiceClientBuilderAnnotation = hasServiceClientBuilderAnnotationStack.pop(); hasBuildMethod = hasBuildMethodStack.pop(); if (hasServiceClientBuilderAnnotation && !hasBuildMethod) { - log(token, "Class with @ServiceClientBuilder annotation must have a method starting with ''build'' and ending with ''Client''."); + log(token, "Class with @ServiceClientBuilder annotation must have a method starting with ''build'' " + + "and ending with ''Client''."); } } } @@ -63,16 +67,19 @@ public void visitToken(DetailAST token) { hasServiceClientBuilderAnnotation = serviceClientAnnotationBuilderToken != null; if (hasServiceClientBuilderAnnotation) { - // Don't need to check if the 'serviceClients' exist. It is required when using @ServiceClientBuilder + // Don't need to check if the 'serviceClients' exist. It is required when using + // @ServiceClientBuilder // HAS @ServiceClientBuilder annotation but NOT named the class ClientBuilder if (!className.endsWith("ClientBuilder")) { - log(token, String.format("Class annotated with @ServiceClientBuilder ''%s'' should be named ClientBuilder.", className)); + log(token, String.format("Class annotated with @ServiceClientBuilder ''%s'' should be named " + + "ClientBuilder.", className)); } } else { // No @ServiceClientBuilder annotation but HAS named the class ClientBuilder if (className.endsWith("ClientBuilder")) { - log(token, String.format("Class ''%s'' should be annotated with @ServiceClientBuilder.", className)); + log(token, String.format("Class ''%s'' should be annotated with @ServiceClientBuilder.", + className)); } } break; @@ -90,7 +97,8 @@ public void visitToken(DetailAST token) { // method name has prefix 'build' but not 'build*Client' or 'build*AsyncClient' if (!methodName.endsWith("Client")) { log(token, String.format( - "@ServiceClientBuilder class should not have a method name, ''%s'' starting with ''build'' but not ending with ''Client''." , methodName)); + "@ServiceClientBuilder class should not have a method name, ''%s'' starting with ''build'' " + + "but not ending with ''Client''.", methodName)); } break; default: diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientCheck.java new file mode 100644 index 000000000000..522c23cc2c2c --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientCheck.java @@ -0,0 +1,526 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; +import com.puppycrawl.tools.checkstyle.checks.naming.AccessModifier; +import com.puppycrawl.tools.checkstyle.utils.CheckUtil; +import com.puppycrawl.tools.checkstyle.utils.TokenUtil; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +/** + * Verify the classes with annotation @ServiceClient should have following rules: + *
    + *
  1. No public or protected constructors
  2. + *
  3. No public static method named 'builder'
  4. + *
  5. Since these classes are supposed to be immutable, all fields in the service client classes should be final
  6. + *
+ * + * All methods that has a @ServiceMethod annotation in a class annotated with @ServiceClient should follow below rules: + *
    + *
  1. Follows method naming pattern. Refer to + * Java Spec:
  2. + *
  3. Methods should not have "Async" added to the method name
  4. + *
  5. Return type of async and sync clients should be as per guidelines: + *
      + *
    1. The return type for async collection should be of type that extends PagedFlux
    2. + *
    3. The return type for async single value should be of type that extends Mono
    4. + *
    5. The return type for sync collection should be of type that extends PagedIterable
    6. + *
    7. The return type for sync single value should be of type that extends Response
    8. + *
    + *
  6. + *
+ */ +public class ServiceClientCheck extends AbstractCheck { + private static final String ASYNC = "Async"; + private static final String SERVICE_CLIENT = "ServiceClient"; + private static final String BUILDER = "builder"; + private static final String ASYNC_CLIENT = "AsyncClient"; + private static final String CLIENT = "Client"; + private static final String IS_ASYNC = "isAsync"; + private static final String CONTEXT = "Context"; + + private static final String RESPONSE_BRACKET = "Response<"; + private static final String MONO_BRACKET = "Mono<"; + private static final String MONO_RESPONSE_BRACKET = "Mono COMMON_NAMING_PREFIX_SET = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( + "upsert", "set", "create", "update", "replace", "delete", "add", "get", "list" + ))); + + // Add all imported classes into a map, key is the name of class and value is the full package path of class. + private final Map simpleClassNameToQualifiedNameMap = new HashMap<>(); + + private boolean isAsync; + private boolean isServiceClientAnnotation; + + @Override + public int[] getDefaultTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getAcceptableTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getRequiredTokens() { + return new int[] { + TokenTypes.IMPORT, + TokenTypes.CLASS_DEF, + TokenTypes.CTOR_DEF, + TokenTypes.METHOD_DEF, + TokenTypes.OBJBLOCK + }; + } + + @Override + public void beginTree(DetailAST root) { + isServiceClientAnnotation = false; + isAsync = false; + } + + @Override + public void visitToken(DetailAST token) { + switch (token.getType()) { + case TokenTypes.IMPORT: + addImportedClassPath(token); + break; + case TokenTypes.CLASS_DEF: + isServiceClientAnnotation = hasServiceClientAnnotation(token); + if (!isServiceClientAnnotation) { + return; + } + checkServiceClientNaming(token); + break; + case TokenTypes.CTOR_DEF: + if (!isServiceClientAnnotation) { + return; + } + checkConstructor(token); + break; + case TokenTypes.METHOD_DEF: + if (!isServiceClientAnnotation) { + return; + } + checkMethodNameBuilder(token); + checkMethodNamingPattern(token); + break; + case TokenTypes.OBJBLOCK: + if (!isServiceClientAnnotation) { + return; + } + checkClassField(token); + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } + + /** + * Checks for public or protected constructor for the service client class. + * Log error if the service client has public or protected constructor. + * + * @param ctorToken the CTOR_DEF AST node + */ + private void checkConstructor(DetailAST ctorToken) { + final DetailAST modifiersToken = ctorToken.findFirstToken(TokenTypes.MODIFIERS); + // find constructor's modifier accessibility, no public or protected constructor + final AccessModifier accessModifier = CheckUtil.getAccessModifierFromModifiersToken(modifiersToken); + if (accessModifier.equals(AccessModifier.PUBLIC) || accessModifier.equals(AccessModifier.PROTECTED)) { + log(modifiersToken, "@ServiceClient class should not have any public or protected constructor."); + } + } + + /** + * Checks for public static method named 'builder'. Should avoid to use method name, 'builder'. + * + * @param methodDefToken the METHOD_DEF AST node + */ + private void checkMethodNameBuilder(DetailAST methodDefToken) { + final DetailAST methodNameToken = methodDefToken.findFirstToken(TokenTypes.IDENT); + if (!BUILDER.equals(methodNameToken.getText())) { + return; + } + + final DetailAST modifiersToken = methodDefToken.findFirstToken(TokenTypes.MODIFIERS); + // find method's modifier accessibility, should not have a public static method called 'builder' + final AccessModifier accessModifier = CheckUtil.getAccessModifierFromModifiersToken(modifiersToken); + if (accessModifier.equals(AccessModifier.PUBLIC) && modifiersToken.branchContains(TokenTypes.LITERAL_STATIC)) { + log(modifiersToken, "@ServiceClient class should not have a public static method named ''builder''."); + } + } + + /** + * Checks that the field variables in the @ServiceClient are final. ServiceClients should be immutable. + * + * @param objBlockToken the OBJBLOCK AST node + */ + private void checkClassField(DetailAST objBlockToken) { + final Optional varDefTokenOption = TokenUtil.findFirstTokenByPredicate(objBlockToken, node -> + node.getType() == TokenTypes.VARIABLE_DEF + && !node.findFirstToken(TokenTypes.MODIFIERS).branchContains(TokenTypes.FINAL)); + if (varDefTokenOption.isPresent()) { + final DetailAST varDefToken = varDefTokenOption.get(); + final String varName = varDefToken.findFirstToken(TokenTypes.IDENT).getText(); + log(varDefToken, String.format("The variable field ''%s'' of class ''%s'' should be final. Classes " + + "annotated with @ServiceClient are supposed to be immutable.", varName, + objBlockToken.getPreviousSibling().getText())); + } + } + + /** + * Checks for the class name of Service Client. It should be named <ServiceName>AsyncClient or + * <ServiceName>Client. + * + * @param classDefToken the CLASS_DEF AST node + */ + private void checkServiceClientNaming(DetailAST classDefToken) { + final String className = classDefToken.findFirstToken(TokenTypes.IDENT).getText(); + // Async client must be named AsyncClient, and Sync client must be named Client + if (isAsync && !className.endsWith(ASYNC_CLIENT)) { + log(classDefToken, String.format("Asynchronous class ''%s'' must be named AsyncClient, which " + + "concatenates by service name and a fixed word 'AsyncClient'.", className)); + } else if (!isAsync && !className.endsWith(CLIENT)) { + log(classDefToken, String.format("Synchronous class %s must be named Client," + + " which concatenates by service name and a fixed word 'Client'.", className)); + } + + // Class named AsyncClient, the property 'isAsync' must set to true + // Class named Client, the property 'isAsync' must to be false or use the default value + if (className.endsWith(ASYNC_CLIENT) && !isAsync) { + log(classDefToken, String.format("class ''%s'' is an asynchronous client, must set property ''%s'' to " + + "true.", className, IS_ASYNC)); + } else if (className.endsWith(CLIENT) && !className.endsWith(ASYNC_CLIENT) && isAsync) { + log(classDefToken, String.format("class ''%s'' is a synchronous client, must set property ''%s'' to false" + + " or without the property.", className, IS_ASYNC)); + } + } + + /** + * Verify all methods that have a @ServiceMethod annotation in a class annotated with @ServiceClient should + * follow below rules: + * 1) Follows method naming pattern. Refer to Java Spec. + * 2) Methods should not have "Async" added to the method name. + * 3) The return type of async and sync clients should be as per guidelines: + * 3.1) The return type for async collection should be of type? extends PagedFlux. + * 3.2) The return type for async single value should be of type? extends Mono. + * 3.3) The return type for sync collection should be of type? extends PagedIterable. + * 3.4) The return type for sync single value should be of type? extends Response. + * 4) Naming pattern for 'WithResponse'. + * 5) Synchronous method with annotation @ServiceMethod has to have {@code Context} as a parameter. + * Asynchronous method with annotation @ServiceMethod must not has {@code Context} as a parameter. + * + * @param methodDefToken METHOD_DEF AST node + */ + private void checkMethodNamingPattern(DetailAST methodDefToken) { + final DetailAST modifiersToken = methodDefToken.findFirstToken(TokenTypes.MODIFIERS); + final Optional serviceMethodAnnotationOption = TokenUtil.findFirstTokenByPredicate(modifiersToken, + node -> { + if (node.getType() != TokenTypes.ANNOTATION) { + return false; + } + final DetailAST annotationIdentToken = node.findFirstToken(TokenTypes.IDENT); + return annotationIdentToken != null && "ServiceMethod".equals(annotationIdentToken.getText()); + }); + // NOT a @ServiceMethod method + if (!serviceMethodAnnotationOption.isPresent()) { + return; + } + + final DetailAST serviceMethodAnnotation = serviceMethodAnnotationOption.get(); + final String methodName = methodDefToken.findFirstToken(TokenTypes.IDENT).getText(); + + // 1) Follows method naming pattern. Refer to Java Spec. + // prefix of method name that contains all lower letters + final String prefix = methodName.split("[A-Z]", 2)[0]; + if (!methodName.endsWith("Exists") && !COMMON_NAMING_PREFIX_SET.contains(prefix)) { + log(methodDefToken, String.format( + "Method name ''%s'' should follow a common vocabulary. Refer to Java Spec: %s.", + methodName, JAVA_SPEC_LINK)); + } + + // 2) Methods should not have "Async" added to the method name + if (methodName.contains(ASYNC)) { + log(methodDefToken, String.format("Method name ''%s'' should not contain ''%s'' in the method name.", + methodName, ASYNC)); + } + + // 3) The return type of async and sync clients should be as per guidelines + checkServiceClientMethodReturnType(methodDefToken, serviceMethodAnnotation, methodName); + + // 4) Check 'withResponse' naming pattern + checkReturnTypeNamingPattern(methodDefToken, methodName); + + // 5) Synchronous method with annotation @ServiceMethod has to have {@code Context} as a parameter. + // Asynchronous method with annotation @ServiceMethod must not has {@code Context} as a parameter. + checkContextInRightPlace(methodDefToken); + } + + /** + * Checks for the return type of async and sync clients should be as per guidelines: + * 1) The return type for async collection should be of type? extends PagedFlux + * 2) The return type for async single value should be of type? extends Mono + * 3) The return type for sync collection should be of type? extends PagedIterable + * 4) The return type for sync single value should be of type? extends Response + * + * @param methodDefToken METHOD_DEF AST node + * @param serviceMethodAnnotation ANNOTATION AST node which used to find the if the annotation has 'return' key, + * @param methodName method name + * if found. return the value of member'return'. + */ + private void checkServiceClientMethodReturnType(DetailAST methodDefToken, DetailAST serviceMethodAnnotation, + String methodName) { + // Find the annotation member 'returns' value + String returnsAnnotationMemberValue = null; + final Optional returnValueOption = + TokenUtil.findFirstTokenByPredicate(serviceMethodAnnotation, node -> + node.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR + && node.findFirstToken(TokenTypes.IDENT).getText().equals("returns") + && !FullIdent.createFullIdentBelow(node.findFirstToken(TokenTypes.EXPR)).getText().isEmpty()); + + if (returnValueOption.isPresent()) { + returnsAnnotationMemberValue = + FullIdent.createFullIdentBelow(returnValueOption.get().findFirstToken(TokenTypes.EXPR)).getText(); + } + + final String returnType = + getReturnType(methodDefToken.findFirstToken(TokenTypes.TYPE), new StringBuilder()).toString(); + + if (isAsync) { + if (SINGLE_RETURN_TYPE.equals(returnsAnnotationMemberValue)) { + // If value of 'returns' is SINGLE, and then log error if the return type of the method is not start + // with {@code Mono} + if (!returnType.startsWith(MONO_BRACKET)) { + log(methodDefToken, String.format(RETURN_TYPE_ERROR, "Asynchronous", SINGLE_RETURN_TYPE, MONO)); + } + } else if (COLLECTION_RETURN_TYPE.equals(returnsAnnotationMemberValue)) { + // If value of 'returns' is COLLECTION, and then log error if the return type of the method is not + // start with {@code PagedFlux} + if (!returnType.startsWith(PAGED_FLUX_BRACKET)) { + log(methodDefToken, String.format(RETURN_TYPE_ERROR, "Asynchronous", COLLECTION_RETURN_TYPE, + PAGED_FLUX)); + } + } + } else { + if (SINGLE_RETURN_TYPE.equals(returnsAnnotationMemberValue)) { + // If value of 'returns' is SINGLE, and then log error if the return type of the method is not start + // with {@code Response} when the method name ends with 'WithResponse'. + if ((returnType.startsWith(RESPONSE_BRACKET) && !methodName.endsWith(WITH_RESPONSE)) + || (!returnType.startsWith(RESPONSE_BRACKET) && methodName.endsWith(WITH_RESPONSE))) { + log(methodDefToken, String.format(RESPONSE_METHOD_NAME_ERROR, "Synchronous", SINGLE_RETURN_TYPE, + RESPONSE, WITH_RESPONSE, WITH_RESPONSE, RESPONSE)); + } + } else if (COLLECTION_RETURN_TYPE.equals(returnsAnnotationMemberValue)) { + // If value of 'returns' is COLLECTION, and then log error if the return type of the method is not + // start with {@code PagedIterable} + if (!returnType.startsWith(PAGED_ITERABLE_BRACKET)) { + log(methodDefToken, String.format(RETURN_TYPE_ERROR, "Synchronous", COLLECTION_RETURN_TYPE, + PAGED_ITERABLE)); + } + } + } + } + + /** + * Given the method is already annotated @ServiceMethod. Checks if the return type is {@code Response} or + * {@code Mono>}, + * Sync: + * If the return type is {@code Response}, the method name must end with WithResponse. + * If the return type is T, the method name must NOT end with WithResponse. + * Async: + * If the return type is {@code Mono}, the method name must end with WithResponse. + * If the return type is {@code Mono}, the method name must NOT end with WithResponse. + * + * @param methodDefToken METHOD_DEF AST node + */ + private void checkReturnTypeNamingPattern(DetailAST methodDefToken, String methodName) { + final DetailAST typeToken = methodDefToken.findFirstToken(TokenTypes.TYPE); + // Use recursion to get the return type + final String returnType = getReturnType(typeToken, new StringBuilder()).toString(); + + if (methodName.endsWith(WITH_RESPONSE)) { + if (!returnType.startsWith(RESPONSE_BRACKET) && !returnType.startsWith(MONO_RESPONSE_BRACKET)) { + log(methodDefToken, String.format(RETURN_TYPE_WITH_RESPONSE_ERROR, returnType, "must not", + WITH_RESPONSE)); + } + } else { + if (returnType.startsWith(RESPONSE_BRACKET) || returnType.startsWith(MONO_RESPONSE_BRACKET)) { + log(methodDefToken, String.format(RETURN_TYPE_WITH_RESPONSE_ERROR, returnType, "must", WITH_RESPONSE)); + } + } + } + + /** + * Checks the type Context should be in the right place. Context should be passed in as an argument to all public + * methods annotated with @ServiceMethod that return {@code Response} in synchronous clients. + * Synchronous method with annotation @ServiceMethod has to have {@code Context} as a parameter. + * Asynchronous method with annotation @ServiceMethod must not has {@code Context} as a parameter. + * + * @param methodDefToken METHOD_DEF AST token + */ + private void checkContextInRightPlace(DetailAST methodDefToken) { + final DetailAST parametersToken = methodDefToken.findFirstToken(TokenTypes.PARAMETERS); + final String returnType = + getReturnType(methodDefToken.findFirstToken(TokenTypes.TYPE), new StringBuilder()).toString(); + + final boolean containsContextParameter = TokenUtil.findFirstTokenByPredicate(parametersToken, + parameterToken -> { + if (parameterToken.getType() != TokenTypes.PARAMETER_DEF) { + return false; + } + final DetailAST paramTypeIdentToken = + parameterToken.findFirstToken(TokenTypes.TYPE).findFirstToken(TokenTypes.IDENT); + return paramTypeIdentToken != null && CONTEXT.equals(paramTypeIdentToken.getText()); + }) + .isPresent(); + + if (containsContextParameter) { + // MONO and PagedFlux return type implies Asynchronous method + if (returnType.startsWith(MONO_BRACKET) || returnType.startsWith(PAGED_FLUX_BRACKET)) { + log(methodDefToken, String.format(ASYNC_CONTEXT_ERROR, CONTEXT)); + } + } else { + // Context should be passed in as an argument to all public methods annotated with @ServiceMethod that + // return Response in sync clients. + if (returnType.startsWith(RESPONSE_BRACKET)) { + log(methodDefToken, String.format(SYNC_CONTEXT_ERROR, CONTEXT)); + } + } + } + + /** + * Checks if the class is annotated with annotation @ServiceClient. A class could have multiple annotations. + * + * @param classDefToken the CLASS_DEF AST node + * @return true if the class is annotated with @ServiceClient, false otherwise. + */ + private boolean hasServiceClientAnnotation(DetailAST classDefToken) { + // Always has MODIFIERS node + final DetailAST modifiersToken = classDefToken.findFirstToken(TokenTypes.MODIFIERS); + final Optional serviceClientAnnotationOption = TokenUtil.findFirstTokenByPredicate(modifiersToken, + node -> { + if (node.getType() != TokenTypes.ANNOTATION) { + return false; + } + final DetailAST annotationIdentToken = node.findFirstToken(TokenTypes.IDENT); + return annotationIdentToken != null && SERVICE_CLIENT.equals(annotationIdentToken.getText()); + } + ); + if (serviceClientAnnotationOption.isPresent()) { + isAsync = isAsyncServiceClient(serviceClientAnnotationOption.get()); + return true; + } + // If no @ServiceClient annotated with this class, return false + return false; + } + + /** + * Add all imported classes into a map, key is the name of class and value is the full package path of class. + * + * @param token the IMPORT AST node + */ + private void addImportedClassPath(DetailAST token) { + final String importClassPath = FullIdent.createFullIdentBelow(token).getText(); + final String className = importClassPath.substring(importClassPath.lastIndexOf(".") + 1); + simpleClassNameToQualifiedNameMap.put(className, importClassPath); + } + + /** + * A function checks if the annotation node has a member key is {@code IS_ASYNC} with value equals to 'true'. + * If the value equals 'true', which indicates the {@code @ServiceClient} is an asynchronous client. + * If the member pair is missing. By default, it is a synchronous service client. + * + * @param annotationToken the ANNOTATION AST node + * @return true if the annotation has {@code IS_ASYNC} value 'true', otherwise, false. + */ + private boolean isAsyncServiceClient(DetailAST annotationToken) { + for (DetailAST ast = annotationToken.getFirstChild(); ast != null; ast = ast.getNextSibling()) { + if (ast.getType() != TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR) { + continue; + } + + // skip this annotation member value pair if no IDENT found, since we are looking for member, 'isAsync'. + final DetailAST identToken = ast.findFirstToken(TokenTypes.IDENT); + if (identToken == null) { + continue; + } + + // skip this annotation member value pair if the member is not 'isAsync'. + if (!IS_ASYNC.equals(identToken.getText())) { + continue; + } + + // skip this annotation member value pair if the member has no EXPR value + final DetailAST exprToken = ast.findFirstToken(TokenTypes.EXPR); + if (exprToken == null) { + continue; + } + + // true if isAsync = true, false otherwise. + return exprToken.branchContains(TokenTypes.LITERAL_TRUE); + } + // By default, if the IS_ASYNC doesn't exist, the service client is a synchronous client. + return false; + } + + /** + * Get full name of return type. Such as Response, {@code Mono}. + * + * @param token a token could be a TYPE, TYPE_ARGUMENT, TYPE_ARGUMENTS token + * @param sb a StringBuilder that used to collect method return type. + */ + private StringBuilder getReturnType(DetailAST token, StringBuilder sb) { + for (DetailAST currentToken = token.getFirstChild(); currentToken != null; + currentToken = currentToken.getNextSibling()) { + switch (currentToken.getType()) { + case TokenTypes.TYPE_ARGUMENT: + case TokenTypes.TYPE_ARGUMENTS: + // Recursive call + getReturnType(currentToken, sb); + break; + default: + sb.append(currentToken.getText()); + } + } + return sb; + } +} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientChecks.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientChecks.java deleted file mode 100644 index d5e15ce5f1f1..000000000000 --- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientChecks.java +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.tools.checkstyle.checks; - -import com.puppycrawl.tools.checkstyle.api.AbstractCheck; -import com.puppycrawl.tools.checkstyle.api.DetailAST; -import com.puppycrawl.tools.checkstyle.api.FullIdent; -import com.puppycrawl.tools.checkstyle.api.TokenTypes; -import com.puppycrawl.tools.checkstyle.utils.TokenUtil; - -/** - * Verifies that subclasses of ServiceClient meet a set of guidelines. - *
    - *
  1. No public or protected constructors
  2. - *
  3. Implements a public static method named builder
  4. - *
- */ -public class ServiceClientChecks extends AbstractCheck { - private static final String BUILDER_METHOD_NAME = "builder"; - private static final String SERVICE_CLIENT_CLASS_NAME = "com.azure.common.ServiceClient"; - - private static final String FAILED_TO_LOAD_MESSAGE = "%s class failed to load, ServiceClientChecks will be ignored."; - private static final String CONSTRUCTOR_ERROR_MESSAGE = "Descendants of ServiceClient cannot have public or protected constructors."; - private static final String BUILDER_ERROR_MESSAGE = "Descendants of ServiceClient must have a static method named builder."; - - private static final int[] TOKENS = new int[] { - TokenTypes.PACKAGE_DEF, - TokenTypes.CTOR_DEF, - TokenTypes.METHOD_DEF - }; - - private Class serviceClientClass; - private boolean extendsServiceClient; - private boolean hasStaticBuilder; - - @Override - public int[] getDefaultTokens() { - return getRequiredTokens(); - } - - @Override - public int[] getAcceptableTokens() { - return getRequiredTokens(); - } - - /** - * Array of tokens that trigger visitToken when the TreeWalker is traversing the AST. - * @return The list of tokens that trigger visitToken. - */ - @Override - public int[] getRequiredTokens() { - return TOKENS; - } - - @Override - public void init() { - try { - this.serviceClientClass = Class.forName(SERVICE_CLIENT_CLASS_NAME); - } catch (ClassNotFoundException ex) { - log(0, String.format(FAILED_TO_LOAD_MESSAGE, "ServiceClient")); - } - } - - /** - * Start of the TreeWalker traversal. - * @param rootAST Root of the AST. - */ - @Override - public void beginTree(DetailAST rootAST) { - this.extendsServiceClient = false; - this.hasStaticBuilder = false; - } - /** - * Processes a token from the required tokens list when the TreeWalker visits it. - * @param token Node in the AST. - */ - @Override - public void visitToken(DetailAST token) { - // Failed to load ServiceClient's class, don't validate anything. - if (this.serviceClientClass == null) { - return; - } - - switch (token.getType()) { - case TokenTypes.PACKAGE_DEF: - this.extendsServiceClient = extendsServiceClient(token); - break; - case TokenTypes.CTOR_DEF: - if (this.extendsServiceClient && visibilityIsPublicOrProtected(token)) { - log(token, CONSTRUCTOR_ERROR_MESSAGE); - } - break; - case TokenTypes.METHOD_DEF: - if (this.extendsServiceClient && !this.hasStaticBuilder && methodIsStaticBuilder(token)) { - this.hasStaticBuilder = true; - } - break; - default: - // Checkstyle complains if there's no default block in switch - break; - } - } - - /** - * End of the TreeWalker traversal. - * @param rootAST Root of the AST. - */ - @Override - public void finishTree(DetailAST rootAST) { - if (this.extendsServiceClient && !this.hasStaticBuilder) { - log(0, BUILDER_ERROR_MESSAGE); - } - } - - /** - * Determines if the class extends ServiceClient. - * @param packageDefinitionToken Package definition token. - * @return True if the package is not in "com.microsoft", the file is a class definition, and the class extends ServiceClient. - */ - private boolean extendsServiceClient(DetailAST packageDefinitionToken) { - String packageName = FullIdent.createFullIdent(packageDefinitionToken.findFirstToken(TokenTypes.DOT)).getText(); - if (packageName.startsWith("com.microsoft")) { - return false; - } - - DetailAST classDefinitionToken = packageDefinitionToken.findFirstToken(TokenTypes.CLASS_DEF); - if (classDefinitionToken == null) { - return false; - } - - String className = classDefinitionToken.findFirstToken(TokenTypes.IDENT).getText(); - try { - Class clazz = Class.forName(packageName + "." + className); - - return this.serviceClientClass.isAssignableFrom(clazz); - } catch (ClassNotFoundException ex) { - log(classDefinitionToken, String.format(FAILED_TO_LOAD_MESSAGE, className)); - return false; - } - } - - /** - * Checks if the constructor is using the public or protected scope. - * @param constructorToken Construction token. - * @return True if the constructor has a public or protected modifier token. - */ - private boolean visibilityIsPublicOrProtected(DetailAST constructorToken) { - DetailAST modifierToken = constructorToken.findFirstToken(TokenTypes.MODIFIERS); - - // No modifiers means package private. - if (modifierToken == null) { - return false; - } - - return TokenUtil.findFirstTokenByPredicate(modifierToken, - node -> node.getType() == TokenTypes.LITERAL_PUBLIC || node.getType() == TokenTypes.LITERAL_PROTECTED) - .isPresent(); - } - - /** - * Checks if the method node is public static and named builder. - * @param methodToken Method node - * @return True if the method is public static and is named builder - */ - private boolean methodIsStaticBuilder(DetailAST methodToken) { - DetailAST modifierToken = methodToken.findFirstToken(TokenTypes.MODIFIERS); - if (modifierToken == null) { - return false; - } - - if (modifierToken.findFirstToken(TokenTypes.LITERAL_STATIC) == null - || modifierToken.findFirstToken(TokenTypes.LITERAL_PUBLIC) == null) { - return false; - } - - return methodToken.findFirstToken(TokenTypes.IDENT).getText().equals(BUILDER_METHOD_NAME); - } -} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientInstantiationCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientInstantiationCheck.java deleted file mode 100644 index 02669178d0ca..000000000000 --- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceClientInstantiationCheck.java +++ /dev/null @@ -1,231 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -package com.azure.tools.checkstyle.checks; - -import com.puppycrawl.tools.checkstyle.api.AbstractCheck; -import com.puppycrawl.tools.checkstyle.api.DetailAST; -import com.puppycrawl.tools.checkstyle.api.FullIdent; -import com.puppycrawl.tools.checkstyle.api.TokenTypes; -import com.puppycrawl.tools.checkstyle.checks.naming.AccessModifier; -import com.puppycrawl.tools.checkstyle.utils.CheckUtil; - -/** - * Verify the classes with annotation @ServiceClient should have following rules: - *
    - *
  1. No public or protected constructors
  2. - *
  3. No public static method named 'builder'
  4. - *
  5. Since these classes are supposed to be immutable, all fields in the service client classes should be final.
  6. - *
- */ -public class ServiceClientInstantiationCheck extends AbstractCheck { - private static final String SERVICE_CLIENT = "ServiceClient"; - private static final String BUILDER = "builder"; - private static final String ASYNC_CLIENT = "AsyncClient"; - private static final String CLIENT = "Client"; - private static final String IS_ASYNC = "isAsync"; - - private static boolean hasServiceClientAnnotation; - private static boolean isAsync; - private static boolean isImplPackage; - - @Override - public int[] getDefaultTokens() { - return getRequiredTokens(); - } - - @Override - public int[] getAcceptableTokens() { - return getRequiredTokens(); - } - - @Override - public int[] getRequiredTokens() { - return new int[] { - TokenTypes.PACKAGE_DEF, - TokenTypes.CLASS_DEF, - TokenTypes.CTOR_DEF, - TokenTypes.METHOD_DEF, - TokenTypes.OBJBLOCK - }; - } - - @Override - public void beginTree(DetailAST root) { - hasServiceClientAnnotation = false; - isAsync = false; - isImplPackage = false; - } - - @Override - public void visitToken(DetailAST token) { - if (isImplPackage) { - return; - } - - switch (token.getType()) { - case TokenTypes.PACKAGE_DEF: - String packageName = FullIdent.createFullIdent(token.findFirstToken(TokenTypes.DOT)).getText(); - isImplPackage = packageName.contains(".implementation"); - break; - case TokenTypes.CLASS_DEF: - hasServiceClientAnnotation = hasServiceClientAnnotation(token); - if (hasServiceClientAnnotation) { - checkServiceClientNaming(token); - } - break; - case TokenTypes.CTOR_DEF: - if (hasServiceClientAnnotation) { - checkConstructor(token); - } - break; - case TokenTypes.METHOD_DEF: - if (hasServiceClientAnnotation) { - checkMethodName(token); - } - break; - case TokenTypes.OBJBLOCK: - if (hasServiceClientAnnotation) { - checkClassField(token); - } - break; - default: - // Checkstyle complains if there's no default block in switch - break; - } - } - - /** - * Checks if the class is annotated with annotation @ServiceClient. A class could have multiple annotations. - * - * @param classDefToken the CLASS_DEF AST node - * @return true if the class is annotated with @ServiceClient, false otherwise. - */ - private boolean hasServiceClientAnnotation(DetailAST classDefToken) { - // Always has MODIFIERS node - final DetailAST modifiersToken = classDefToken.findFirstToken(TokenTypes.MODIFIERS); - - for (DetailAST ast = modifiersToken.getFirstChild(); ast != null; ast = ast.getNextSibling()) { - if (ast.getType() != TokenTypes.ANNOTATION) { - continue; - } - // One class could have multiple annotations, return true if found one. - final DetailAST annotationIdent = ast.findFirstToken(TokenTypes.IDENT); - if (annotationIdent != null && SERVICE_CLIENT.equals(annotationIdent.getText())) { - isAsync = isAsyncServiceClient(ast); - return true; - } - } - // If no @ServiceClient annotated with this class, return false - return false; - } - - /** - * Checks for public or protected constructor for the service client class. - * Log error if the service client has public or protected constructor. - * - * @param ctorToken the CTOR_DEF AST node - */ - private void checkConstructor(DetailAST ctorToken) { - final DetailAST modifiersToken = ctorToken.findFirstToken(TokenTypes.MODIFIERS); - // find constructor's modifier accessibility, no public or protected constructor - final AccessModifier accessModifier = CheckUtil.getAccessModifierFromModifiersToken(modifiersToken); - if (accessModifier.equals(AccessModifier.PUBLIC) || accessModifier.equals(AccessModifier.PROTECTED)) { - log(modifiersToken, "@ServiceClient class should not have any public or protected constructor."); - } - } - - /** - * Checks for public static method named 'builder'. Should avoid to use method name, 'builder'. - * - * @param methodDefToken the METHOD_DEF AST node - */ - private void checkMethodName(DetailAST methodDefToken) { - final DetailAST methodNameToken = methodDefToken.findFirstToken(TokenTypes.IDENT); - if (!BUILDER.equals(methodNameToken.getText())) { - return; - } - - final DetailAST modifiersToken = methodDefToken.findFirstToken(TokenTypes.MODIFIERS); - // find method's modifier accessibility, should not have a public static method called 'builder' - final AccessModifier accessModifier = CheckUtil.getAccessModifierFromModifiersToken(modifiersToken); - if (accessModifier.equals(AccessModifier.PUBLIC) && modifiersToken.branchContains(TokenTypes.LITERAL_STATIC)) { - log(modifiersToken, "@ServiceClient class should not have a public static method named ''builder''."); - } - } - - /** - * Checks that the field variables in the @ServiceClient are final. ServiceClients should be immutable. - * - * @param objBlockToken the OBJBLOCK AST node - */ - private void checkClassField(DetailAST objBlockToken) { - for (DetailAST ast = objBlockToken.getFirstChild(); ast != null; ast = ast.getNextSibling()) { - if (TokenTypes.VARIABLE_DEF != ast.getType()) { - continue; - } - final DetailAST modifiersToken = ast.findFirstToken(TokenTypes.MODIFIERS); - // VARIABLE_DEF token will always MODIFIERS token. If there is no modifier at the variable, no child under - // MODIFIERS token. Also the previous sibling of OBJBLOCK will always be class name IDENT node. - if (!modifiersToken.branchContains(TokenTypes.FINAL)) { - log(modifiersToken, String.format("The variable field ''%s'' of class ''%s'' should be final. Classes annotated with @ServiceClient are supposed to be immutable.", - ast.findFirstToken(TokenTypes.IDENT).getText(), objBlockToken.getPreviousSibling().getText())); - } - } - } - - /** - * Checks for the class name of Service Client. It should be named AsyncClient or Client. - * - * @param classDefToken the CLASS_DEF AST node - */ - private void checkServiceClientNaming(DetailAST classDefToken) { - final String className = classDefToken.findFirstToken(TokenTypes.IDENT).getText(); - // Async service client - if (isAsync && !className.endsWith(ASYNC_CLIENT)) { - log(classDefToken, String.format("Async class ''%s'' must be named AsyncClient ", className)); - } - // Sync service client - if (!isAsync && !className.endsWith(CLIENT)) { - log(classDefToken, String.format("Sync class %s must be named Client.", className)); - } - } - - /** - * A function checks if the annotation node has a member key is {@code IS_ASYNC} with value equals to 'true'. - * If the value equals 'true', which indicates the @ServiceClient is an asynchronous client. - * If the member pair is missing. By default, it is a synchronous service client. - * - * @param annotationToken the ANNOTATION AST node - * @return true if the annotation has {@code IS_ASYNC} value 'true', otherwise, false. - */ - private boolean isAsyncServiceClient(DetailAST annotationToken) { - for (DetailAST ast = annotationToken.getFirstChild(); ast != null; ast = ast.getNextSibling()) { - if (ast.getType() != TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR) { - continue; - } - - // skip this annotation member value pair if no IDENT found, since we are looking for member, 'isAsync'. - final DetailAST identToken = ast.findFirstToken(TokenTypes.IDENT); - if (identToken == null) { - continue; - } - - // skip this annotation member value pair if the member is not 'isAsync'. - if (!IS_ASYNC.equals(identToken.getText())) { - continue; - } - - // skip this annotation member value pair if the member has no EXPR value - final DetailAST exprToken = ast.findFirstToken(TokenTypes.EXPR); - if (exprToken == null) { - continue; - } - - // true if isAsync = true, false otherwise. - return exprToken.branchContains(TokenTypes.LITERAL_TRUE); - } - // By default, if the IS_ASYNC doesn't exist, the service client is a synchronous client. - return false; - } -} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceInterfaceCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceInterfaceCheck.java index 3ac00ff0cd08..381367d71a99 100644 --- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceInterfaceCheck.java +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ServiceInterfaceCheck.java @@ -85,8 +85,8 @@ private void checkServiceInterface(DetailAST interfaceDefToken) { Pattern serviceNamePattern = Pattern.compile("^[a-zA-Z0-9]{1,20}$"); if (!serviceNamePattern.matcher(nameValue).find()) { log(serviceInterfaceAnnotationNode, String.format( - "The ''name'' property of @ServiceInterface, ''%s'' should be non-empty, alphanumeric and not more than 10 characters", - nameValue)); + "The ''name'' property of @ServiceInterface, ''%s'' should be non-empty, alphanumeric and not more " + + "than 10 characters", nameValue)); } } diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ThrowFromClientLoggerCheck.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ThrowFromClientLoggerCheck.java new file mode 100644 index 000000000000..e3ca1b901450 --- /dev/null +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/ThrowFromClientLoggerCheck.java @@ -0,0 +1,119 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.tools.checkstyle.checks; + +import com.puppycrawl.tools.checkstyle.api.AbstractCheck; +import com.puppycrawl.tools.checkstyle.api.DetailAST; +import com.puppycrawl.tools.checkstyle.api.FullIdent; +import com.puppycrawl.tools.checkstyle.api.TokenTypes; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Queue; + +/** + * To throw an exception, Must throw it through a 'logger.logExceptionAsError', rather than by directly calling 'throw + * exception'. + * + * Skip check if throwing exception from + *
    + *
  1. Static method
  2. + *
  3. Static class
  4. + *
  5. Constructor
  6. + *
+ */ +public class ThrowFromClientLoggerCheck extends AbstractCheck { + private static final String LOGGER_LOG_EXCEPTION_AS_ERROR = "logger.logExceptionAsError"; + private static final String LOGGER_LOG_EXCEPTION_AS_WARNING = "logger.logExceptionAsWarning"; + private static final String THROW_LOGGER_EXCEPTION_MESSAGE = "Directly throwing an exception is disallowed. Must " + + "throw through ''ClientLogger'' API, either of ''%s'' or ''%s'' where ''logger'' is type of ClientLogger " + + "from Azure Core package."; + + // A LIFO queue stores the static status of class, skip this ThrowFromClientLoggerCheck if the class is static + private final Queue classStaticDeque = Collections.asLifoQueue(new ArrayDeque<>()); + // A LIFO queue stores the static status of method, skip this ThrowFromClientLoggerCheck if the method is static + private final Queue methodStaticDeque = Collections.asLifoQueue(new ArrayDeque<>()); + // The variable is used to indicate if current node is still inside of constructor. + private boolean isInConstructor = false; + + @Override + public int[] getDefaultTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getAcceptableTokens() { + return getRequiredTokens(); + } + + @Override + public int[] getRequiredTokens() { + return new int[] { + TokenTypes.CLASS_DEF, + TokenTypes.CTOR_DEF, + TokenTypes.LITERAL_THROW, + TokenTypes.METHOD_DEF + }; + } + + @Override + public void leaveToken(DetailAST token) { + switch (token.getType()) { + case TokenTypes.CLASS_DEF: + classStaticDeque.poll(); + break; + case TokenTypes.CTOR_DEF: + isInConstructor = false; + break; + case TokenTypes.METHOD_DEF: + methodStaticDeque.poll(); + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } + + @Override + public void visitToken(DetailAST token) { + switch (token.getType()) { + case TokenTypes.CLASS_DEF: + DetailAST modifiersToken = token.findFirstToken(TokenTypes.MODIFIERS); + classStaticDeque.offer(modifiersToken.branchContains(TokenTypes.LITERAL_STATIC)); + break; + case TokenTypes.CTOR_DEF: + isInConstructor = true; + break; + case TokenTypes.METHOD_DEF: + DetailAST methodModifiersToken = token.findFirstToken(TokenTypes.MODIFIERS); + methodStaticDeque.offer(methodModifiersToken.branchContains(TokenTypes.LITERAL_STATIC)); + break; + case TokenTypes.LITERAL_THROW: + // Skip check if the throw exception from static class, constructor or static method + if (classStaticDeque.isEmpty() || classStaticDeque.peek() || isInConstructor + || methodStaticDeque.isEmpty() || methodStaticDeque.peek()) { + return; + } + DetailAST methodCallToken = + token.findFirstToken(TokenTypes.EXPR).findFirstToken(TokenTypes.METHOD_CALL); + if (methodCallToken == null) { + log(token, String.format(THROW_LOGGER_EXCEPTION_MESSAGE, LOGGER_LOG_EXCEPTION_AS_ERROR, + LOGGER_LOG_EXCEPTION_AS_WARNING)); + return; + } + + String methodCallName = + FullIdent.createFullIdent(methodCallToken.findFirstToken(TokenTypes.DOT)).getText(); + if (!LOGGER_LOG_EXCEPTION_AS_ERROR.equals(methodCallName) + && !LOGGER_LOG_EXCEPTION_AS_WARNING.equals(methodCallName)) { + log(token, String.format(THROW_LOGGER_EXCEPTION_MESSAGE, LOGGER_LOG_EXCEPTION_AS_ERROR, + LOGGER_LOG_EXCEPTION_AS_WARNING)); + } + break; + default: + // Checkstyle complains if there's no default block in switch + break; + } + } +} diff --git a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/Utils.java b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/Utils.java index 5cc32d5249c2..903c0a706d6e 100644 --- a/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/Utils.java +++ b/eng/code-quality-reports/src/main/java/com/azure/tools/checkstyle/checks/Utils.java @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + package com.azure.tools.checkstyle.checks; import com.puppycrawl.tools.checkstyle.api.DetailAST; @@ -14,13 +17,23 @@ * Common utils amount custom checks */ public class Utils { + /* + * Set of modifiers that cannot be combined with final because it causes a violation. + */ private static final Set INVALID_FINAL_COMBINATION = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( TokenTypes.LITERAL_TRANSIENT, - TokenTypes.LITERAL_VOLATILE + TokenTypes.LITERAL_VOLATILE, + TokenTypes.LITERAL_DEFAULT, + TokenTypes.LITERAL_PROTECTED ))); + /* + * Set of annotations that cannot be combined with modifier 'final' because it would break serialization. + */ private static final Set INVALID_FINAL_ANNOTATIONS = Collections.unmodifiableSet(new HashSet<>(Arrays.asList( - "JsonProperty" + "JsonProperty", + "JsonAlias", + "JacksonXmlProperty" ))); /** @@ -39,7 +52,7 @@ protected static boolean hasIllegalCombination(DetailAST modifiers) { Optional illegalCombination = TokenUtil.findFirstTokenByPredicate(modifiers, (node) -> { final int type = node.getType(); return INVALID_FINAL_COMBINATION.contains(node.getType()) || (TokenTypes.ANNOTATION == type - && INVALID_FINAL_ANNOTATIONS.contains(node.findFirstToken(TokenTypes.IDENT).getText())); + && INVALID_FINAL_ANNOTATIONS.contains(node.findFirstToken(TokenTypes.IDENT).getText())); }); return illegalCombination.isPresent(); diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml index 553c34ca080f..5ef1b8426a31 100755 --- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml +++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml @@ -32,7 +32,7 @@ - + @@ -76,57 +76,122 @@ + + + - - - - - - - - + - - - - - - + + + + + + + + + + + + + - - - - - + + - - - + + - - + + + + + + + + + + + + - - - - - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml index d9856fa79891..048abcf4b52e 100755 --- a/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml +++ b/eng/code-quality-reports/src/main/resources/checkstyle/checkstyle.xml @@ -10,6 +10,11 @@ page at http://checkstyle.sourceforge.net/config.html --> + + + + + @@ -45,6 +50,13 @@ page at http://checkstyle.sourceforge.net/config.html --> + + + + + + + @@ -96,6 +108,8 @@ page at http://checkstyle.sourceforge.net/config.html --> + + @@ -267,6 +281,7 @@ page at http://checkstyle.sourceforge.net/config.html --> + @@ -274,39 +289,42 @@ page at http://checkstyle.sourceforge.net/config.html --> - - - - - - + - + 3) Since these classes are supposed to be immutable, all fields in the service client classes should be final. + + Also, verify all methods that have a @ServiceMethod annotation in a class annotated with @ServiceClient should + follow below rules: + 1) Follows method naming pattern. Refer to Java Spec. + 2) Methods should not have "Async" added to the method name + 3) The return type of async and sync clients should be as per guidelines: + 3.1) The return type for async collection should be of type? extends PagedFlux + 3.2) The return type for async single value should be of type? extends Mono + 3.3) The return type for sync collection should be of type? extends PagedIterable + 3.4) The return type for sync single value should be of type? extends Response --> + - + - + - + @@ -317,14 +335,55 @@ page at http://checkstyle.sourceforge.net/config.html --> 1) All fields must be final --> - + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + diff --git a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml index 6cfdbbd51923..b2a90415cd0e 100755 --- a/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml +++ b/eng/code-quality-reports/src/main/resources/spotbugs/spotbugs-exclude.xml @@ -65,6 +65,9 @@ + + + @@ -265,7 +268,12 @@ - + + + + + @@ -275,12 +283,6 @@ - - - - - @@ -377,6 +379,7 @@ + @@ -446,18 +449,26 @@ - + + + + + + + + + @@ -476,6 +487,14 @@ + + + + + + + + @@ -509,10 +528,30 @@ + + + + + + + + + + + + + + + - + @@ -522,6 +561,7 @@ name="com.azure.data.appconfiguration.credentials.ConfigurationClientCredentials$AuthorizationHeaderProvider"/> + @@ -534,7 +574,40 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index bfe7f05dbccd..3360e808e496 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -10,7 +10,7 @@ com.azure azure-client-sdk-parent - 1.3.0 + 1.4.0 ../../pom.client.xml @@ -23,17 +23,22 @@ https://github.com/Azure/azure-sdk-for-java - 1.0.0-preview.4 - 1.0.0-preview.4 - 1.0.0-preview.4 - 1.0.0-preview.4 - 1.0.0-preview.3 - 1.0.0-preview.3 - 4.0.0-preview.3 - 5.0.0-preview.3 - 12.0.0-preview.3 - 12.0.0-preview.3 - 12.0.0-preview.3 + 1.0.0-preview.5 + 1.0.0-preview.5 + 1.0.0-preview.5 + 1.0.0-preview.5 + 1.0.0-preview.5 + 1.0.0-preview.4 + 1.0.0-preview.4 + 4.0.0-preview.4 + 5.0.0-preview.4 + 1.0.0-preview.2 + 12.0.0-preview.4 + 12.0.0-preview.4 + 12.0.0-preview.4 + 12.0.0-preview.4 + 12.0.0-preview.4 + 12.0.0-preview.4 @@ -60,6 +65,11 @@ azure-core-amqp ${azure-core.version} + + com.azure + azure-core-http-netty + ${azure-core-http-netty.version} + com.azure azure-core-management @@ -90,11 +100,26 @@ azure-messaging-eventhubs ${azure-messaging-eventhubs.version} + + com.azure + azure-messaging-eventhubs-checkpointstore-blob + ${azure-messaging-eventhubs-checkpointstore-blob.version} + + + com.azure + azure-storage-common + ${azure-storage-common.version} + com.azure azure-storage-blob ${azure-storage-blob.version} + + com.azure + azure-storage-blob-cryptography + ${azure-storage-blob-cryptography.version} + com.azure azure-storage-file @@ -105,6 +130,11 @@ azure-storage-queue ${azure-storage-queue.version} + + com.azure + azure-storage-queue-cryptography + ${azure-storage-queue-cryptography.version} + diff --git a/eng/pipelines/client.yml b/eng/pipelines/client.yml index af090116b59d..9ce1b2316ce8 100644 --- a/eng/pipelines/client.yml +++ b/eng/pipelines/client.yml @@ -4,6 +4,13 @@ trigger: - master +resources: + repositories: + - repository: azure-sdk-tools + type: github + name: Azure/azure-sdk-tools + endpoint: azure + variables: DefaultOptions: '--batch-mode -Dmaven.wagon.http.pool=false --settings eng/settings.xml' LoggingOptions: '-Dorg.slf4j.simpleLogger.defaultLogLevel=error -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn' @@ -36,7 +43,7 @@ jobs: inputs: mavenPomFile: $(pomFile) goals: 'package' - options: '$(DefaultOptions) $(ProfileFlag) "-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -Dmaven.test.skip=true -Dinclude-template' # We include template-module so we ensure it always builds in CI + options: '$(DefaultOptions) $(ProfileFlag) "-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -DskipTests -Dinclude-template' # We include template-module so we ensure it always builds in CI mavenOptions: '$(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: $(JavaVersion) @@ -202,7 +209,7 @@ jobs: ProfileFlag: '' Windows - Java 8: OSName: 'Windows' - OSVmImage: 'vs2017-win2016' + OSVmImage: 'windows-2019' JavaVersion: '1.8' ProfileFlag: '' Linux - Java LTS: @@ -217,7 +224,7 @@ jobs: ProfileFlag: '-Djava-lts' Windows - Java LTS: OSName: 'Windows' - OSVmImage: 'vs2017-win2016' + OSVmImage: 'windows-2019' JavaVersion: '1.11' ProfileFlag: '-Djava-lts' @@ -225,17 +232,9 @@ jobs: vmImage: $(OSVmImage) steps: - - powershell: | - Invoke-WebRequest -Uri "https://github.com/Azure/azure-sdk-tools/releases/download/sdk-tools_14793/sdk-tools.zip" ` - -OutFile "sdk-tools.zip" | Wait-Process; Expand-Archive -Path "sdk-tools.zip" -DestinationPath "./sdk-tools/" - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Download Tools Archive From Github Release and Extract it' - - - task: PythonScript@0 - displayName: 'Run VerifyAgentOS script' - inputs: - scriptPath: '$(Build.BinariesDirectory)/sdk-tools/scripts/python/verify_agent_os.py' - arguments: $(OSName) + - template: eng/pipelines/templates/scripts/verify-agent-os.yml@azure-sdk-tools + parameters: + OSName: $(OSVmImage) - task: Maven@3 displayName: 'Start Jetty' diff --git a/eng/pipelines/mgmt.yml b/eng/pipelines/mgmt.yml index c9c850dcc820..45f84e7cee2c 100644 --- a/eng/pipelines/mgmt.yml +++ b/eng/pipelines/mgmt.yml @@ -1,6 +1,19 @@ trigger: - - master - + branches: + include: + - master + paths: + exclude: + - sdk/ + +pr: + branches: + include: + - master + paths: + exclude: + - sdk/ + variables: MavenGoals: 'clean,compile' diff --git a/eng/pipelines/smoke-test.yml b/eng/pipelines/smoke-test.yml new file mode 100644 index 000000000000..d3aecfb1c19d --- /dev/null +++ b/eng/pipelines/smoke-test.yml @@ -0,0 +1,48 @@ +jobs: + - job: SmokeTest + variables: + - template: ./templates/variables/globals.yml + - name: PomFile + value: eng/smoke-tests/pom.xml + + strategy: + matrix: + Java 8: + ProfileFlag: '' + JavaVersion: '1.8' + Java LTS: + ProfileFlag: '-Djava-lts' + JavaVersion: '1.11' + + steps: + - task: Maven@3 + displayName: 'Build and Package' + inputs: + mavenPomFile: $(PomFile) + goals: 'package' + options: '$(DefaultOptions) $(ProfileFlag) -DskipTests' + javaHomeOption: 'JDKVersion' + jdkVersionOption: $(JavaVersion) + jdkArchitectureOption: 'x64' + publishJUnitResults: false + + - task: Maven@3 + displayName: 'Run Smoke Tests' + inputs: + mavenPomFile: $(PomFile) + goals: 'exec:java' + options: '$(DefaultOptions) $(ProfileFlag) -Dexec.mainClass="com.azure.App"' + javaHomeOption: 'JDKVersion' + jdkVersionOption: $(JavaVersion) + jdkArchitectureOption: 'x64' + publishJUnitResults: false + env: + AZURE_CLIENT_SECRET: $(aad-azure-sdk-test-client-secret) + AZURE_TENANT_ID: $(aad-azure-sdk-test-tenant-id) + AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id) + AZURE_PROJECT_URL: $(smoke-tests-key-vault-project-url) + AZURE_EVENT_HUBS_CONNECTION_STRING: $(smoke-tests-event-hubs-connection-string) + AZURE_STORAGE_CONNECTION_STRING: $(smoke-tests-storage-connection-string) + AZURE_COSMOS_KEY: $(smoke-tests-cosmos-key) + AZURE_COSMOS_ENDPOINT: $(smoke-tests-cosmos-endpoint) + AZURE_LOG_LEVEL: 2 \ No newline at end of file diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index 06ce79cd972c..638ac201fc3d 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -16,7 +16,7 @@ parameters: ProfileFlag: '' Windows - Java 8: OSName: 'Windows' - OSVmImage: 'vs2017-win2016' + OSVmImage: 'windows-2019' JavaVersion: '1.8' ProfileFlag: '' Linux - Java LTS: @@ -31,7 +31,7 @@ parameters: ProfileFlag: '-Djava-lts' Windows - Java LTS: OSName: 'Windows' - OSVmImage: 'vs2017-win2016' + OSVmImage: 'windows-2019' JavaVersion: '1.11' ProfileFlag: '-Djava-lts' @@ -61,13 +61,15 @@ jobs: displayName: 'Tag scheduled builds' condition: and(eq(variables['Build.SourceBranchName'],'master'),eq(variables['Build.Reason'],'Schedule')) + - template: ../steps/cache-maven-repository.yml + - task: Maven@3 displayName: 'Build and Package' inputs: mavenPomFile: sdk/${{parameters.ServiceDirectory}}/pom.service.xml goals: 'package' - options: '$(DefaultOptions) $(ProfileFlag) "-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -Dmaven.test.skip=true -Dinclude-template' # We include template-module so we ensure it always builds in CI - mavenOptions: '$(LoggingOptions)' + options: '$(DefaultOptions) $(ProfileFlag) "-DpackageOutputDirectory=$(Build.ArtifactStagingDirectory)" -DskipTests -Dinclude-template' # We include template-module so we ensure it always builds in CI + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: $(JavaVersion) jdkArchitectureOption: 'x64' @@ -79,6 +81,7 @@ jobs: - job: 'Analyze' + condition: ne(variables['Skip.Analyze'], 'true') variables: - template: ../variables/globals.yml @@ -110,14 +113,26 @@ jobs: - template: ../steps/install-reporting-tools.yml parameters: Options: --batch-mode - MavenOptions: $(LoggingOptions) + MavenOptions: $(MemoryOptions) $(LoggingOptions) + + - task: Maven@3 + displayName: 'Install azure-sdk-parent' + inputs: + mavenPomFile: parent/pom.xml + options: '$(DefaultOptions) -DskipTests -Dgpg.skip' + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.11' + jdkArchitectureOption: 'x64' + publishJUnitResults: false + goals: 'install' - task: Maven@3 displayName: 'Install all client libraries (for SpotBugs analysis)' inputs: mavenPomFile: pom.client.xml options: '$(DefaultOptions) -Djava-lts -DskipTests -Dgpg.skip -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dspotbugs.skip=true' - mavenOptions: '$(LoggingOptions)' + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' jdkArchitectureOption: 'x64' @@ -141,11 +156,10 @@ jobs: # running as a PR check. - task: Maven@3 displayName: 'Generate Maven project site, including JavaDocs, SpotBugs, and CheckStyle reports' - condition: ne(variables['Build.Reason'], 'PullRequest') inputs: mavenPomFile: pom.client.xml options: '$(DefaultOptions) -Djava-lts -DskipTests -Dgpg.skip' - mavenOptions: '$(LoggingOptions)' + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' jdkArchitectureOption: 'x64' @@ -153,14 +167,13 @@ jobs: goals: 'install site:site site:stage' # We run a separate SpotBugs aggregate report step here to roll-up all the issues identified per-module in the - # previous step. This is only generated in non-PR builds (i.e. nightly runs, etc) + # previous step. - task: Maven@3 displayName: 'Run SpotBugs' - condition: ne(variables['Build.Reason'], 'PullRequest') inputs: mavenPomFile: eng/spotbugs-aggregate-report/pom.xml options: '--batch-mode -Djava-lts -DskipTests -Dgpg.skip' - mavenOptions: '$(LoggingOptions)' + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' jdkArchitectureOption: 'x64' @@ -172,24 +185,12 @@ jobs: mkdir input && cp dependencies.json input/ displayName: 'Download dependency checker' - - task: Maven@3 - displayName: 'Install azure-sdk-parent' - inputs: - mavenPomFile: parent/pom.xml - options: '$(DefaultOptions) -DskipTests -Dgpg.skip' - mavenOptions: '$(LoggingOptions)' - javaHomeOption: 'JDKVersion' - jdkVersionOption: '1.11' - jdkArchitectureOption: 'x64' - publishJUnitResults: false - goals: 'install' - - task: Maven@3 displayName: 'Analyze dependencies' inputs: mavenPomFile: 'DependencyChecker/pom.xml' options: '-Dexec.args="-showall -dependencymanagement"' - mavenOptions: '$(LoggingOptions)' + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' jdkArchitectureOption: 'x64' @@ -226,12 +227,15 @@ jobs: parameters: OSName: $(OSName) + - template: ../steps/cache-maven-repository.yml + - task: Maven@3 displayName: 'Start Jetty' + condition: ne(variables['SdkType'], 'client') inputs: mavenPomFile: pom.client.xml options: '$(DefaultOptions) $(ProfileFlag)' - mavenOptions: '$(LoggingOptions)' + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: $(JavaVersion) jdkArchitectureOption: 'x64' @@ -245,7 +249,7 @@ jobs: inputs: mavenPomFile: sdk/${{parameters.ServiceDirectory}}/pom.service.xml options: ${{ parameters.TestOptions }} - mavenOptions: '-Xmx3072m $(LoggingOptions)' + mavenOptions: '$(MemoryOptions) $(LoggingOptions)' javaHomeOption: 'JDKVersion' jdkVersionOption: $(JavaVersion) jdkArchitectureOption: 'x64' diff --git a/eng/pipelines/templates/jobs/archetype-sdk-tests-pre-sdk.yml b/eng/pipelines/templates/jobs/archetype-sdk-tests-pre-sdk.yml index 39f6941e5c8a..a6c2c36cecd8 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-tests-pre-sdk.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-tests-pre-sdk.yml @@ -8,7 +8,7 @@ jobs: - job: 'LiveTest' pool: - vmImage: 'vs2017-win2016' + vmImage: 'windows-2019' steps: - task: Maven@3 diff --git a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml index e42186eac993..2fd7ef55242e 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml @@ -4,13 +4,13 @@ parameters: MaxParallel: 0 Matrix: Win2016: - OSVmImage: 'vs2017-win2016' + OSVmImage: 'windows-2019' DisplayName: 'Run Live tests' PreRunSteps: [] TestName: LiveTest TimeoutInMinutes: 60 TestStepMavenInputs: - options: '--batch-mode -Dmaven.wagon.http.pool=false -Dsurefire.rerunFailingTestsCount=3 --settings eng/settings.xml' + options: '--batch-mode --fail-at-end -Dmaven.wagon.http.pool=false -Dsurefire.rerunFailingTestsCount=3 --settings eng/settings.xml' mavenOptions: '-Xmx3072m -Dorg.slf4j.simpleLogger.defaultLogLevel=error -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.8' @@ -23,6 +23,8 @@ jobs: - job: ${{ parameters.TestName }} timeoutInMinutes: ${{ parameters.TimeoutInMinutes }} + variables: + - template: ../variables/globals.yml strategy: matrix: ${{ parameters.Matrix }} maxParallel: ${{ parameters.MaxParallel }} @@ -46,4 +48,4 @@ jobs: mergeTestResults: true testRunTitle: 'Live tests for ${{ parameters.ServiceDirectory }} $(DisplayName)' ${{ if ne(parameters.TestResultsFiles, '') }}: - testResultsFiles: ${{ parameters.TestResultsFiles }} \ No newline at end of file + testResultsFiles: ${{ parameters.TestResultsFiles }} diff --git a/eng/pipelines/templates/stages/cosmos-sdk-client.yml b/eng/pipelines/templates/stages/cosmos-sdk-client.yml new file mode 100644 index 000000000000..4ac907f97669 --- /dev/null +++ b/eng/pipelines/templates/stages/cosmos-sdk-client.yml @@ -0,0 +1,118 @@ +parameters: + Artifacts: [] + ServiceDirectory: not-specified + +stages: + - stage: Build + jobs: + - template: ../jobs/archetype-sdk-client.yml + parameters: + ServiceDirectory: ${{parameters.ServiceDirectory}} + TestMatrix: + Windows - java8: + OSVmImage: 'windows-2019' + JavaVersion: '1.8' + OSName: Windows + ProfileFlag: '-Punit' + MacOS - java8: + OSVmImage: 'macOS-10.13' + JavaVersion: '1.8' + OSName: macOS + ProfileFlag: '-Punit' + PreTestSteps: + - template: ../steps/install-reporting-tools.yml + + - template: ../jobs/archetype-sdk-tests.yml + parameters: + TestName: Emulator + ServiceDirectory: cosmos + Matrix: + Tcp_Integration_Tests_Java8: + OSVmImage: 'windows-2019' + JavaVersion: '1.8' + ProfileFlag: '-Pemulator' + DisplayName: 'Emulator only Integration Tests' + PROTOCOLS: '["Tcp"]' + DESIRED_CONSISTENCIES: '["Strong", "Session"]' + Https_Integration_Tests_Java8: + OSVmImage: 'windows-2019' + JavaVersion: '1.8' + ProfileFlag: '-Pemulator' + DisplayName: 'Emulator only Integration Tests' + PROTOCOLS: '["Https"]' + DESIRED_CONSISTENCIES: '["Strong", "Session"]' + Examples_Integration_Tests_Java8: + OSVmImage: 'windows-2019' + JavaVersion: '1.8' + ProfileFlag: '-Pexamples' + DisplayName: 'Examples Integration Tests' + PROTOCOLS: '["Https", "Tcp"]' + DESIRED_CONSISTENCIES: '["Strong", "Session"]' + + TestStepMavenInputs: + goals: 'verify' + options: '$(ProfileFlag) -Dgpg.skip -DargLine="-DACCOUNT_HOST=https://localhost:8081/"' + mavenAuthenticateFeed: true + jdkVersionOption: $(JavaVersion) + + PreRunSteps: + - powershell: | + Write-Host "Downloading Cosmos Emulator - $(EmulatorMsiUrl)" + wget "$(EmulatorMsiUrl)" -outfile "$env:temp\azure-cosmosdb-emulator.msi" + Write-Host "Finished Downloading Cosmos Emulator - $env:temp\azure-cosmosdb-emulator.msi" + dir "$env:temp" + displayName: 'Download Public Cosmos DB Emulator' + + - script: | + choco install lessmsi + choco upgrade lessmsi + mkdir "%TEMP%\Azure Cosmos DB Emulator" + lessmsi x "%TEMP%\azure-cosmosdb-emulator.msi" "%TEMP%\Azure Cosmos DB Emulator\" + displayName: 'Install Public Cosmos DB Emulator' + + - powershell: | + Write-Host "Starting Comsos DB Emulator" + Start-Process "$env:Temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\CosmosDB.Emulator.exe" "/NoExplorer /NoUI /DisableRateLimiting /PartitionCount=100 /Consistency=Strong" -Verb RunAs + displayName: 'Run Public Cosmos DB Emulator' + + - powershell: | + Import-Module "$env:Temp\Azure Cosmos DB Emulator\SourceDir\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator" + + Do { + sleep 5 + $cosmosStatus = Get-CosmosDbEmulatorStatus + Write-Host "Cosmos Status: $cosmosStatus" + } While ($cosmosStatus -ne 'Running') + + Write-Host "Done" + displayName: 'Check Public Cosmos DB Emulator Status' + + - powershell: | + $Key = 'C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==' + $password = ConvertTo-SecureString -String $Key -Force -AsPlainText + $cert = Get-ChildItem cert:\LocalMachine\My | Where-Object { $_.FriendlyName -eq "DocumentDbEmulatorCertificate" } + Export-PfxCertificate -Cert $cert -FilePath ".\CosmosDbEmulatorCert.pfx" -Password $password | Out-Null + $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 + $cert.Import(".\CosmosDbEmulatorCert.pfx", $Key, "DefaultKeySet") + $cert | Export-Certificate -FilePath "$env:temp\CosmosDbEmulatorCert.cer" -Type CERT + displayName: 'Export Cosmos DB Emulator Certificate' + + - powershell: | + cd $env:java_home\jre\lib\security + cp $env:temp\CosmosDbEmulatorCert.cer . + keytool -keystore cacerts -importcert -noprompt -trustcacerts -alias CosmosDbEmulatorCert -file CosmosDbEmulatorCert.cer -storepass changeit + displayName: 'Create Java TrustStore' + + # We `install` separately from running `site:site site:stage` so that the `install` brings in the non-shipping-modules, + # but we don't include them in the Maven site commands (so that we don't generate reports for the non-shipping modules). + - template: ../steps/install-reporting-tools.yml + + # The Prerelease and Release stages are conditioned on whether we are building a pull request and the branch. + - ${{if and(ne(variables['Build.Reason'], 'PullRequest'), eq(variables['System.TeamProject'], 'internal'))}}: + - template: pipelines/stages/archetype-java-release.yml@azure-sdk-build-tools + parameters: + DependsOn: Build + Artifacts: ${{parameters.Artifacts}} + ArtifactName: packages + + \ No newline at end of file diff --git a/eng/pipelines/templates/steps/cache-maven-repository.yml b/eng/pipelines/templates/steps/cache-maven-repository.yml new file mode 100644 index 000000000000..a5354397d894 --- /dev/null +++ b/eng/pipelines/templates/steps/cache-maven-repository.yml @@ -0,0 +1,15 @@ +steps: +- script: | + echo "##vso[task.setvariable variable=Maven.RepositoryPath;]%USERPROFILE%\.m2\repository" + condition: eq(variables['Agent.OS'], 'Windows_NT') + displayName: Detecting Maven repository on Windows +- script: | + echo "##vso[task.setvariable variable=Maven.RepositoryPath;]$HOME/.m2/repository" + condition: ne(variables['Agent.OS'], 'Windows_NT') + displayName: Detecting Maven repository on Linux and macOS +- task: CacheBeta@0 + inputs: + key: $(Agent.JobName)|$(CacheSalt)|$(Build.SourcesDirectory)/sdk/**/pom.xml|$(Build.SourcesDirectory)/pom*.xml|$(Build.SourcesDirectory)/parent/pom.xml + path: $(Maven.RepositoryPath) + displayName: 'Download/upload cache' + condition: ne(variables['EnableCaching'], 'false') \ No newline at end of file diff --git a/eng/pipelines/templates/steps/verify-agent-os.yml b/eng/pipelines/templates/steps/verify-agent-os.yml index af8bc10df309..3422f929c25e 100644 --- a/eng/pipelines/templates/steps/verify-agent-os.yml +++ b/eng/pipelines/templates/steps/verify-agent-os.yml @@ -2,14 +2,6 @@ parameters: OSName: $(OSName) steps: - - powershell: | - Invoke-WebRequest -Uri "https://github.com/Azure/azure-sdk-tools/releases/download/sdk-tools_14793/sdk-tools.zip" ` - -OutFile "sdk-tools.zip" | Wait-Process; Expand-Archive -Path "sdk-tools.zip" -DestinationPath "./sdk-tools/" - workingDirectory: '$(Build.BinariesDirectory)' - displayName: 'Download Tools Archive From Github Release and Extract it' - - - task: PythonScript@0 - displayName: 'Run VerifyAgentOS script' - inputs: - scriptPath: '$(Build.BinariesDirectory)/sdk-tools/scripts/python/verify_agent_os.py' - arguments: ${{ parameters.OSName }} + - template: eng/pipelines/templates/scripts/verify-agent-os.yml@azure-sdk-tools + parameters: + OSName: ${{ parameters.OSName }}} \ No newline at end of file diff --git a/eng/pipelines/templates/variables/globals.yml b/eng/pipelines/templates/variables/globals.yml index 72a7e440ad3f..82e14a0b4207 100644 --- a/eng/pipelines/templates/variables/globals.yml +++ b/eng/pipelines/templates/variables/globals.yml @@ -1,5 +1,7 @@ variables: - DefaultOptions: '--batch-mode -Dmaven.wagon.http.pool=false --settings eng/settings.xml' + DefaultOptions: '--batch-mode --fail-at-end --settings eng/settings.xml' LoggingOptions: '-Dorg.slf4j.simpleLogger.defaultLogLevel=error -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn' - Agent.Source.Git.ShallowFetchDepth: 1 - skipComponentGovernanceDetection: true \ No newline at end of file + MemoryOptions: '-Xmx3072m' + #Agent.Source.Git.ShallowFetchDepth: 1 + skipComponentGovernanceDetection: true + EmulatorMsiUrl: 'https://acpedaily1.blob.core.windows.net/emulator/azure-cosmos-emulator.msi' diff --git a/eng/repo-docs/index.html b/eng/repo-docs/index.html index 3070e9acb455..c3fe1a6c734d 100644 --- a/eng/repo-docs/index.html +++ b/eng/repo-docs/index.html @@ -474,7 +474,7 @@

Azure Java SDK